- Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathsetupinfo.py
305 lines (216 loc) · 6.8 KB
/
setupinfo.py
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# Copyright (c) The PyAMF Project.
# See LICENSE.txt for details.
"""
Meta data and helper functions for setup
"""
importsys
importos.path
importfnmatch
try:
fromCython.Distutilsimportbuild_ext
have_cython=True
exceptImportError:
fromsetuptools.command.build_extimportbuild_ext
have_cython=False
fromsetuptools.commandimporttest, sdist
fromsetuptoolsimportExtension
fromdistutils.coreimportDistribution
_version=None
jython=sys.platform.startswith('java')
can_compile_extensions=notjython
classMyDistribution(Distribution):
"""
This seems to be is the only obvious way to add a global option to
distutils.
Provide the ability to disable building the extensions for any called
command.
"""
global_options=Distribution.global_options+ [
('disable-ext', None, 'Disable building extensions.')
]
deffinalize_options(self):
Distribution.finalize_options(self)
try:
i=self.script_args.index('--disable-ext')
exceptValueError:
self.disable_ext=False
else:
self.disable_ext=True
self.script_args.pop(i)
classMyBuildExt(build_ext):
"""
The companion to L{MyDistribution} that checks to see if building the
extensions are disabled.
"""
defrun(self, *args, **kwargs):
ifself.distribution.disable_ext:
return
build_ext.run(self, *args, **kwargs)
classMySDist(sdist.sdist):
"""
We generate the Cython code for a source distribution
"""
defcythonise(self):
ext=MyBuildExt(self.distribution)
ext.initialize_options()
ext.finalize_options()
ext.check_extensions_list(ext.extensions)
foreinext.extensions:
e.sources=ext.cython_sources(e.sources, e)
defrun(self):
ifnothave_cython:
print('ERROR - Cython is required to build source distributions')
raiseSystemExit(1)
self.cythonise()
returnsdist.sdist.run(self)
classTestCommand(test.test):
"""
Ensures that unittest2 is imported if required and replaces the old
unittest module.
"""
defrun_tests(self):
try:
importunittest2
sys.modules['unittest'] =unittest2
exceptImportError:
pass
returntest.test.run_tests(self)
defset_version(version):
global_version
_version=version
defget_version():
v=''
prev=None
forxin_version:
ifprevisnotNone:
ifisinstance(x, int):
v+='.'
prev=x
v+=str(x)
returnv.strip('.')
defget_extras_require():
return {
'wsgi': ['wsgiref'],
'twisted': ['Twisted>=2.5.0'],
'django': ['Django>=0.96'],
'sqlalchemy': ['SQLAlchemy>=0.4'],
'elixir': ['Elixir>=0.7.1'],
'lxml': ['lxml>=2.2'],
}
defget_package_data():
return {
'cpyamf': ['*.pxd'],
}
defextra_setup_args():
"""
Extra kwargs to supply in the call to C{setup}.
This is used to supply custom commands, not metadata - that should live in
setup.py itself.
"""
return {
'distclass': MyDistribution,
'cmdclass': {
'test': TestCommand,
'build_ext': MyBuildExt,
'sdist': MySDist
},
'package_data': get_package_data(),
}
defget_install_requirements():
"""
Returns a list of dependencies for PyAMF to function correctly on the
target platform.
"""
install_requires= ['defusedxml']
ifsys.version_info< (2, 5):
install_requires.extend(["elementtree>=1.2.6", "uuid>=1.30"])
if'dev'inget_version():
ifcan_compile_extensions:
install_requires.extend(['Cython>=0.13'])
returninstall_requires
defget_test_requirements():
"""
Returns a list of required packages to run the test suite.
"""
tests_require= []
ifsys.version_info< (2, 7):
tests_require.extend(['unittest2'])
returntests_require
defwrite_version_py(filename='pyamf/_version.py'):
"""
"""
ifos.path.exists(filename):
os.remove(filename)
content="""\
# THIS FILE IS GENERATED BY PYAMF SETUP.PY
from pyamf.versions import Version
version = Version(*%(version)r)
"""
a=open(filename, 'wt')
try:
a.write(content% {'version': _version})
finally:
a.close()
defmake_extension(mod_name, **extra_options):
"""
Tries is best to return an Extension instance based on the mod_name
"""
base_name=os.path.join(mod_name.replace('.', os.path.sep))
ifhave_cython:
forextin ['.pyx', '.py']:
source=base_name+ext
ifos.path.exists(source):
returnExtension(mod_name, [source], **extra_options)
print('WARNING: Could not find Cython source for %r'% (mod_name,))
else:
source=base_name+'.c'
ifos.path.exists(source):
returnExtension(mod_name, [source], **extra_options)
print('WARNING: Could not build extension for %r, no source found'% (
mod_name,))
defread(fname):
returnopen(os.path.join(os.path.dirname(__file__), fname)).read()
defget_extensions():
"""
Return a list of Extension instances that can be compiled.
"""
ifnotcan_compile_extensions:
print(80*'*')
print('WARNING:')
print(
'\tAn optional code optimization (C extension) could not be '
'compiled.\n\n'
)
print('\tOptimizations for this package will not be available!\n\n')
print('Compiling extensions is not supported on %r'% (sys.platform,))
print(80*'*')
return []
extensions= []
forpinrecursive_glob('.', '*.pyx'):
mod_name=os.path.splitext(p)[0].replace(os.path.sep, '.')
e=make_extension(mod_name)
ife:
extensions.append(e)
returnextensions
defget_trove_classifiers():
"""
Return a list of trove classifiers that are setup dependent.
"""
classifiers= []
defdev_status():
version=get_version()
if'dev'inversion:
return'Development Status :: 2 - Pre-Alpha'
elif'alpha'inversion:
return'Development Status :: 3 - Alpha'
elif'beta'inversion:
return'Development Status :: 4 - Beta'
else:
return'Development Status :: 5 - Production/Stable'
returnclassifiers+ [dev_status()]
defrecursive_glob(path, pattern):
matches= []
forroot, dirnames, filenamesinos.walk(path):
forfilenameinfnmatch.filter(filenames, pattern):
matches.append(os.path.normpath(os.path.join(root, filename)))
returnmatches