1 import os |
1 import os |
|
2 import re |
|
3 import sys |
|
4 from distutils.command.install import INSTALL_SCHEMES |
|
5 from distutils.command.install_data import install_data |
|
6 from shutil import move |
|
7 from tempfile import mkstemp |
|
8 |
|
9 from setuptools import Command |
|
10 |
2 try: |
11 try: |
3 from setuptools import setup |
12 from setuptools import setup |
4 except ImportError: |
13 except ImportError: |
5 from distutils.core import setup |
14 from distutils.core import setup |
6 from distutils.command.install_data import install_data |
15 |
7 from distutils.command.install import INSTALL_SCHEMES |
16 |
8 import sys |
17 """ |
|
18 See: https://dankeder.com/posts/adding-custom-commands-to-setup-py/ |
|
19 """ |
|
20 class SetVersion(Command): |
|
21 """ |
|
22 Set the version for the project |
|
23 """ |
|
24 description = "Set the version for the project" |
|
25 # command_consumes_arguments = True |
|
26 user_options = [ |
|
27 ('version=', 'v', 'version str') |
|
28 ] |
|
29 |
|
30 def initialize_options(self): |
|
31 """Set default values for options.""" |
|
32 # Each user option must be listed here with their default value. |
|
33 self.version = None |
|
34 |
|
35 def finalize_options(self): |
|
36 """Post-process options.""" |
|
37 if self.version is None: |
|
38 raise Exception("Parameter --version is missing") |
|
39 version_matches = re.match(r"(\d+).(\d+)(?:\.(\d+))?(?:(?:.(dev))|(?:(a|b|rc)(.*)))?", self.version) |
|
40 if version_matches is None: |
|
41 raise Exception("Parameter --version is not a version string (see )") |
|
42 version_list = version_matches.groups() |
|
43 version_tag = {'a': 'alpha', 'b': 'beta', 'rc': 'rc'}.get(version_list[4],'final') |
|
44 version_ext = int(version_list[5] or 0) |
|
45 if version_list[3] and version_list[3] == 'dev': |
|
46 version_tag = 'alpha' |
|
47 version_ext = 0 |
|
48 |
|
49 self.version_tuple = ( |
|
50 int(version_list[0]), |
|
51 int(version_list[1]), |
|
52 int(version_list[2] or 0), |
|
53 version_tag, |
|
54 version_ext, |
|
55 ) |
|
56 |
|
57 def run(self): |
|
58 filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)),"irinotes","__init__.py") |
|
59 print("Changing VERSION in %s to %r" % (filepath, self.version_tuple)) |
|
60 fh, abs_path = mkstemp() |
|
61 with os.fdopen(fh,'w') as temp_file: |
|
62 with open(filepath, 'r') as initfiles: |
|
63 for l in initfiles: |
|
64 if re.match(r"\s*VERSION\s*=\s*\(\d+\s*,\s*\d+\s*,\s*\d+,\s*\".+\",\s*.+\s*\)", l): |
|
65 temp_file.write("VERSION = %r" % (self.version_tuple,)) |
|
66 else: |
|
67 temp_file.write(l) |
|
68 os.remove(filepath) |
|
69 move(abs_path, filepath) |
|
70 |
9 |
71 |
10 |
72 |
11 class osx_install_data(install_data): |
73 class osx_install_data(install_data): |
12 """ |
74 """ |
13 On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../ |
75 On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../ |
106 m.write("include %s\n" % (filename)) |
168 m.write("include %s\n" % (filename)) |
107 |
169 |
108 long_description = '' |
170 long_description = '' |
109 with open('README', 'r') as f: |
171 with open('README', 'r') as f: |
110 long_description = f.read() |
172 long_description = f.read() |
|
173 |
|
174 cmdclasses = {**cmdclasses, **{ 'set_version': SetVersion }} |
111 |
175 |
112 setup( |
176 setup( |
113 script_name=setup_script_name, |
177 script_name=setup_script_name, |
114 script_args=setup_script_args, |
178 script_args=setup_script_args, |
115 name='irinotes', |
179 name='irinotes', |
138 "Django >= 1.11", |
202 "Django >= 1.11", |
139 "python-decouple", |
203 "python-decouple", |
140 "Unipath", |
204 "Unipath", |
141 "dj-database-url", |
205 "dj-database-url", |
142 "six", |
206 "six", |
143 "django-auditlog == 0.4.5dev", |
207 "django-auditlog @ https://github.com/IRI-Research/django-auditlog/tarball/master#egg=django-auditlog-0.4.5+IRI", |
144 "django-extensions", |
208 "django-extensions", |
145 "djangorestframework >= 3.6", |
209 "djangorestframework >= 3.6", |
146 "django-rest-auth[with_social]", |
210 "django-rest-auth[with_social]", |
147 "djangorestframework-jwt", |
211 "djangorestframework-jwt", |
148 "django-guardian >= 1.4", |
212 "django-guardian >= 1.4", |