-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
Β·146 lines (131 loc) Β· 5.45 KB
/
setup.py
File metadata and controls
executable file
Β·146 lines (131 loc) Β· 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import setuptools
#from setuptools_scm import get_version
import re
with open("README.md", "r") as fh:
long_description = fh.read()
def local_scheme(version):
return ""
"""
Very specific Docker tag naming for this project
This could have been done in Sh, Makefile, ... but here it's integrated
with the setup script.
See https://dankeder.com/posts/adding-custom-commands-to-setup-py/
What variables are available from Github Actions : https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context
"""
class DockerTagsCommand(setuptools.Command):
description = """Prints a tag list for the given 'base tag'.
Each tag is printed on its own line,
more specific tag first : versionned > variant > 'latest'."""
user_options = [
('image=', 'i', 'Image name (defaults to nicolabs/nicobot)'),
('variant=', 'v', 'Image variant / base tag : debian|signal-debian|alpine'),
('branch=', 'b', 'The git ref as <branch name> or refs/heads/<branch name>'),
('tag=', 't', 'The git ref as <tag name> or refs/tags/<tag name>'),
('ref=', 'r', 'The git ref as refs/tags|heads/<tag or branch name>'),
('sep=', 's', 'A string to separate each tag in the output (defaults to a new line)'),
]
def initialize_options(self):
self.image = 'nicolabs/nicobot'
self.variant = None
self.branch = None
# Git tag (so the version)
self.tag = None
self.ref = None
self.sep = '\n'
def finalize_options(self):
"""
ref is the backup value for either tag or branch
final tag & branch values are normalized anyway
"""
stag = self.tag
if not stag and self.ref:
stag = self.ref
try:
# If semver, we don't retain the 'v' prefix
self.tag = re.search('refs/tags/v?(.*)', stag, flags=re.IGNORECASE).group(1)
except:
pass
sbranch = self.branch
if not sbranch and self.ref:
sbranch = self.ref
try:
self.branch = re.search('refs/heads/(.*)', sbranch, flags=re.IGNORECASE).group(1)
except:
pass
def run(self):
# # TODO How to get the actual configuration as set up by setuptools ?
# version = get_version(local_scheme='no-local-version')
tags = []
if self.tag:
# It is first tagged with the version
tags = tags + [ "%s:%s-%s" % (self.image,self.tag,self.variant) ]
# When git-tagged, the variant name alone means : the 'latest' for this variant
tags = tags + [ "%s:%s" % (self.image,self.variant) ]
# Only signal-debian is explicitely tagged with 'latest'
if self.variant == "signal-debian":
tags = tags + [ "%s:latest" % (self.image) ]
elif self.branch:
# All non git-tagged commits overwrite the 'dev' tag (only one is useful currently)
tags = [ "%s:dev-%s" % (self.image,self.variant) ]
print( self.sep.join(tags) )
setuptools.setup(
# See https://packaging.python.org/tutorials/packaging-projects/
name="nicobot",
author="nicobo",
author_email="nicobo@users.noreply.github.com",
description="A collection of π€ cool π€ chat bots",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/nicolabs/nicobot",
packages=setuptools.find_packages(),
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Development Status :: 3 - Alpha',
'Topic :: Communications :: Chat',
'Topic :: Internet :: XMPP',
'Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator',
'Topic :: Software Development :: Internationalization'
],
# PyYAML requires Python 3.5+
# slixmpp 1.7.0+ requires Python 3.7 (but still compiles on 3.6)
python_requires='>=3.6',
# TODO This duplicates requirements-build.txt ?
setup_requires=['setuptools-scm'],
# TODO This duplicates requirements-runtime.txt
# Is runnning setup.py enough to replace pip install -r requirements-runtime.txt ?
install_requires=[
##### Requirements for signalcli #####
'python-i18n',
###### Requirements for transbot #####
'python-i18n',
# https://requests.readthedocs.io/en/master/
'requests',
# https://github.com/cvzi/flag
'emoji-country-flag',
# https://pyyaml.org/wiki/PyYAMLDocumentation
'pyyaml',
###### Requirements for jabber #####
'slixmpp-omemo',
],
entry_points={
'console_scripts': [
'askbot=nicobot.askbot:run',
'transbot=nicobot.transbot:run',
],
},
# Extracts version from SCM ; https://github.com/pypa/setuptools_scm/
use_scm_version = {
"write_to": "nicobot/version.py",
# Only enable to upload local versions to test repo
# See https://mixstersite.wordpress.com/2019/12/31/setuptools-with-testpypi-error-invalid-version-pep-440/
# and https://github.com/pypa/setuptools_scm#user-content-version-number-construction
"local_scheme": 'no-local-version',
},
cmdclass = {
'docker_tags': DockerTagsCommand,
},
)