| author | ymh <ymh.work@gmail.com> |
| Sat, 01 Dec 2018 02:38:12 +0100 | |
| changeset 188 | 00cf90eb0f5a |
| parent 179 | e7c7e6e0a8bc |
| permissions | -rw-r--r-- |
| 24 | 1 |
import os |
| 175 | 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 |
||
| 24 | 11 |
try: |
12 |
from setuptools import setup |
|
13 |
except ImportError: |
|
14 |
from distutils.core import setup |
|
| 175 | 15 |
|
16 |
||
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: |
|
|
188
00cf90eb0f5a
Correct index file and add a favicon. increment version
ymh <ymh.work@gmail.com>
parents:
179
diff
changeset
|
64 |
if re.match(r"\s*VERSION\s*=\s*\(\d+\s*,\s*\d+\s*,\s*\d+,\s*[\"\'].+[\"\'],\s*.+\s*\)", l): |
|
00cf90eb0f5a
Correct index file and add a favicon. increment version
ymh <ymh.work@gmail.com>
parents:
179
diff
changeset
|
65 |
temp_file.write("VERSION = %r\n" % (self.version_tuple,)) |
| 175 | 66 |
else: |
67 |
temp_file.write(l) |
|
68 |
os.remove(filepath) |
|
69 |
move(abs_path, filepath) |
|
70 |
||
| 24 | 71 |
|
72 |
||
73 |
class osx_install_data(install_data): |
|
74 |
""" |
|
75 |
On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../ |
|
76 |
which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific fix |
|
77 |
for this in distutils.command.install_data#306. It fixes install_lib but not |
|
78 |
install_data, which is why we roll our own install_data class. |
|
79 |
""" |
|
80 |
||
81 |
def finalize_options(self): |
|
82 |
""" |
|
83 |
By the time finalize_options is called, install.install_lib is set to the |
|
84 |
fixed directory, so we set the installdir to install_lib. The |
|
85 |
install_data class uses ('install_data', 'install_dir') instead. |
|
86 |
""" |
|
87 |
self.set_undefined_options('install', ('install_lib', 'install_dir')) |
|
88 |
install_data.finalize_options(self) |
|
89 |
||
90 |
def fullsplit(path, result=None): |
|
91 |
""" |
|
92 |
Split a pathname into components (the opposite of os.path.join) in a |
|
93 |
platform-neutral way. |
|
94 |
""" |
|
95 |
if result is None: |
|
96 |
result = [] |
|
97 |
head, tail = os.path.split(path) |
|
98 |
if head == '': |
|
99 |
return [tail] + result |
|
100 |
if head == path: |
|
101 |
return result |
|
102 |
return fullsplit(head, [tail] + result) |
|
103 |
||
104 |
||
105 |
def launch_setup(setup_script_name, setup_script_args): |
|
106 |
""" |
|
107 |
Start setup |
|
108 |
""" |
|
109 |
if sys.platform == "darwin": |
|
110 |
cmdclasses = {'install_data': osx_install_data} |
|
111 |
else: |
|
112 |
cmdclasses = {'install_data': install_data} |
|
113 |
||
114 |
||
115 |
root_dir = os.path.dirname(__file__) |
|
116 |
if root_dir != '': |
|
117 |
os.chdir(root_dir) |
|
|
179
e7c7e6e0a8bc
Add protocols module, and add a way to change the config ini file path
ymh <ymh.work@gmail.com>
parents:
175
diff
changeset
|
118 |
source_dirs = ['irinotes', 'notes', 'protocols'] |
| 24 | 119 |
|
120 |
version_variables = {} |
|
121 |
try: |
|
122 |
with open(os.path.join(source_dirs[0], "__init__.py")) as f: |
|
123 |
code = compile(f.read(), "__init__.py", 'exec') |
|
124 |
exec(code, version_variables) |
|
125 |
except: |
|
126 |
pass |
|
127 |
||
128 |
version = version_variables['__version__'] |
|
129 |
||
130 |
packages, data_files = [], [] |
|
131 |
||
132 |
for source_dir in source_dirs: |
|
133 |
for dirpath, dirnames, filenames in os.walk(source_dir): |
|
134 |
# Ignore dirnames that start with '.' |
|
135 |
for i, dirname in enumerate(dirnames): |
|
136 |
if dirname.startswith('.') or dirname.startswith('__pycache__'): del dirnames[i] |
|
137 |
if '__init__.py' in filenames: |
|
138 |
packages.append('.'.join(fullsplit(dirpath))) |
|
139 |
elif filenames: |
|
140 |
data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]]) |
|
141 |
||
142 |
||
143 |
# Tell distutils to put the data_files in platform-specific installation |
|
144 |
# locations. See here for an explanation: |
|
145 |
# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb |
|
146 |
for scheme in INSTALL_SCHEMES.values(): |
|
147 |
scheme['data'] = scheme['purelib'] |
|
148 |
||
149 |
# Small hack for working with bdist_wininst. |
|
150 |
# See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html |
|
151 |
if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst': |
|
152 |
for file_info in data_files: |
|
153 |
file_info[0] = '\\PURELIB\\%s' % file_info[0] |
|
154 |
||
155 |
#write MANIFEST.in |
|
156 |
||
157 |
with open("MANIFEST.in", "w") as m: |
|
158 |
m.write("include CHANGES\n") |
|
159 |
m.write("include LICENSE\n") |
|
160 |
m.write("include README\n") |
|
161 |
m.write("include MANIFEST.in\n") |
|
162 |
m.write("include requirements/base.txt\n") |
|
163 |
m.write("include requirements/dev.txt\n") |
|
164 |
m.write("include requirements/prod.txt\n") |
|
165 |
for entry in data_files: |
|
166 |
file_list = entry[1] |
|
167 |
for filename in file_list: |
|
168 |
m.write("include %s\n" % (filename)) |
|
169 |
||
170 |
long_description = '' |
|
171 |
with open('README', 'r') as f: |
|
172 |
long_description = f.read() |
|
173 |
||
| 175 | 174 |
cmdclasses = {**cmdclasses, **{ 'set_version': SetVersion }} |
175 |
||
| 24 | 176 |
setup( |
177 |
script_name=setup_script_name, |
|
178 |
script_args=setup_script_args, |
|
179 |
name='irinotes', |
|
180 |
version=version, |
|
181 |
author='IRI', |
|
182 |
author_email='contact@iri.centrepompidou.fr', |
|
183 |
packages=packages, |
|
184 |
data_files=data_files, |
|
185 |
cmdclass=cmdclasses, |
|
186 |
scripts=[], |
|
187 |
url='http://www.iri.centrepompidou.fr/dev/hg/irinotes', |
|
188 |
license='CECILL-C', |
|
189 |
description='projet Irinotes', |
|
190 |
long_description=long_description, |
|
191 |
classifiers=[ |
|
192 |
'Development Status :: 4 - Beta', |
|
193 |
'Environment :: Web Environment', |
|
194 |
'Framework :: Django', |
|
195 |
'Intended Audience :: Developers', |
|
196 |
'License :: Ceccil-B', |
|
197 |
'Operating System :: OS Independent', |
|
198 |
'Programming Language :: Python', |
|
199 |
'Topic :: Utilities' |
|
200 |
], |
|
201 |
install_requires=[ |
|
202 |
"Django >= 1.11", |
|
203 |
"python-decouple", |
|
204 |
"Unipath", |
|
205 |
"dj-database-url", |
|
206 |
"six", |
|
| 175 | 207 |
"django-auditlog @ https://github.com/IRI-Research/django-auditlog/tarball/master#egg=django-auditlog-0.4.5+IRI", |
| 38 | 208 |
"django-extensions", |
| 24 | 209 |
"djangorestframework >= 3.6", |
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
210 |
"django-rest-auth[with_social]", |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
211 |
"djangorestframework-jwt", |
| 24 | 212 |
"django-guardian >= 1.4", |
213 |
"django-colorful", |
|
| 39 | 214 |
"django-cors-headers", |
| 31 | 215 |
"django-concurrency", |
216 |
"django-filter", |
|
| 38 | 217 |
"drf-nested-routers", |
| 31 | 218 |
"markdown" |
| 24 | 219 |
], |
| 175 | 220 |
# dependency_links=[ |
221 |
# "https://github.com/IRI-Research/django-auditlog/tarball/master#egg=django-auditlog-0.4.5dev" |
|
222 |
# ] |
|
| 24 | 223 |
) |
224 |
||
225 |
||
226 |
if __name__ == "__main__": |
|
227 |
||
228 |
script_name = os.path.basename(sys.argv[0]) |
|
229 |
script_args = sys.argv[1:] |
|
230 |
||
231 |
launch_setup(script_name, script_args) |