-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
388 lines (333 loc) · 12 KB
/
setup.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import Command
from setuptools.command.test import test as TestCommand
import distutils.core as core
import os
import setuptools
import subprocess
import sys
import textwrap
import mafipy
VERSION = mafipy.__version__
NAME = "mafipy"
MAINTAINER = "i05nagai"
MAINTAINER_EMAIL = ""
DESCRIPTION = """ """
with open("README.rst") as f:
LONG_DESCRIPTION = f.read()
LICENSE = ""
URL = ""
DOWNLOAD_URL = ""
CLASSIFIERS = """ \
Development Status :: 1 - Planning
Intended Audience :: Science/Research
Intended Audience :: Developers
Programming Language :: Python
Programming Language :: Python :: 3.5
Topic :: Software Development
Topic :: Scientific/Engineering
Operating System :: Unix
Operating System :: MacOS
"""
class PyTest(TestCommand):
"""
"""
cov_report_desc = """type of report to generate:
term, term-missing, annotate, html, xml.
Comma separated multiple types is allowed (e.g. --cov-report=xml,html).
term, term missing may be followed by ':skip-covered'.
annotate, html and xml may be followed by ':DEST'
where DEST specifies the output location.
"""
user_options = [
('cov=', '-', "coverage target."),
('cov-report=', '-', textwrap.dedent(cov_report_desc)),
('pdb', '-', "start the interactive Python debugger on errors."),
('pudb', '-', "start the PuDB debugger on errors."),
('quiet', 'q', "decrease verbosity."),
('verbose', 'v', "increase verbosity."),
# collection:
('doctest-modules', '-', "run doctests in all .py modules"),
]
def initialize_options(self):
TestCommand.initialize_options(self)
self.cov = ''
self.cov_report = ''
self.pdb = ''
self.pudb = ''
self.quiet = ''
self.verbose = ''
# collection:
self.doctest_modules = ''
# for benchmarks tests
self.bench = ''
self.test_args = ["mafipy"]
self.test_suite = True
def finalize_options(self):
TestCommand.finalize_options(self)
# if cov option is specified, option is replaced.
if self.cov:
self.test_args += ["--cov={0}".format(self.cov)]
else:
self.test_args += ["--cov=mafipy"]
# user_options doesn't support multiple valued options
if self.cov_report is not None:
options = self.cov_report.split(',')
template = '--cov-report={0}'
self.test_args += [template.format(op) for op in options]
if self.pdb:
self.test_args += ["--pdb"]
if self.pudb:
self.test_args += ["--pudb"]
if self.quiet:
self.test_args += ["--quiet"]
if self.verbose:
self.test_args += ["--verbose"]
if self.doctest_modules:
self.test_args += ["--doctest-modules"]
def run_tests(self):
import pytest
print("executing 'pytest {0}'".format(" ".join(self.test_args)))
errno = pytest.main(self.test_args)
sys.exit(errno)
class Benchmark(Command):
"""
asv run command
"""
user_options = [
('run-type=', '-', "execcute asv run <run-type>. One of NEW, ALL."),
#
('bench=', 'b', "Regular expression(s) for benchmark to run. When not\
provided, all benchmarks are run."),
('config=', '-', "Benchmark configuration file"),
('dry-run', 'n', "Do not save any results to disk."),
('skip-existing', 'k', "Skip running benchmarks that have previous\
successful or failed results"),
('steps=', 's', "Maximum number of steps to benchmark. This is used to\
subsample the commits determined by range to a\
reasonable number."),
('verbose', 'v', "Increase verbosity"),
]
def initialize_options(self):
self.run_type = None
self.bench = None
self.config = None
self.dry_run = None
self.skip_existing = None
self.steps = None
self.verbose = None
self.args = []
def finalize_options(self):
pass
def run(self):
if self.run_type is not None:
self.args += ["{0}".format(self.run_type)]
if self.bench is not None:
self.args += ["--bench={0}".format(self.bench)]
if self.config is not None:
self.args += ["--config={0}".format(self.config)]
else:
self.args += ["--config=benchmarks/asv.conf.json"]
if self.dry_run is not None:
self.args += ["--dry-run"]
if self.skip_existing is not None:
self.args += ["--skip-existing"]
if self.steps is not None:
self.args += ["--steps={0}".format(self.steps)]
if self.verbose is not None:
self.args += ["--verbose"]
sys.exit(self.run_asv(self.args))
def run_asv(self, args):
# current working directory
cwd = os.path.abspath(os.path.dirname(__file__))
cmd = ["asv", "run"] + list(args)
env = dict(os.environ)
# essential to execute benchmarks withou installing this packages
env["PYTHONPATH"] = cwd
try:
print("executing '{0}'".format(" ".join(cmd)))
return subprocess.call(cmd, env=env, cwd=cwd)
except OSError as err:
if err.errno == 2:
print("Error when running '%s': %s\n" % (" ".join(cmd), str(err),))
print("You need to install Airspeed Velocity \
https://spacetelescope.github.io/asv/")
print("to run Scipy benchmarks")
return 1
raise err
class BenchmarkPublish(Command):
"""
asv publish
"""
user_options = [
# for benchmark tests
]
def initialize_options(self):
self.args = []
def finalize_options(self):
pass
def run(self):
sys.exit(self.publish_asv(self.args))
def publish_asv(self, args):
# current working directory
root_dir = os.path.dirname(__file__)
# output directory of html is asv_files/html from current directory.
# This configuration is written in asv.conf.json
cwd = os.path.abspath(os.path.join(root_dir, "benchmarks"))
cmd = ["asv", "publish"] + list(args)
env = dict(os.environ)
try:
print("executing '{0}'".format(" ".join(cmd)))
return subprocess.call(cmd, env=env, cwd=cwd)
except OSError as err:
if err.errno == 2:
print("Error when running '%s': %s\n" % (" ".join(cmd), str(err),))
print("You need to install Airspeed Velocity \
https://spacetelescope.github.io/asv/")
print("to run Scipy benchmarks")
return 1
raise err
class BenchmarkPreview(Command):
"""
asv preview
"""
user_options = [
# for benchmark tests
]
def initialize_options(self):
self.args = []
def finalize_options(self):
pass
def run(self):
sys.exit(self.preview_asv(self.args))
def preview_asv(self, args):
# current working directory
root_dir = os.path.dirname(__file__)
# output directory of html is asv_files/html from current directory.
# This configuration is written in asv.conf.json
cwd = os.path.abspath(os.path.join(root_dir, "benchmarks"))
cmd = ["asv", "preview"] + list(args)
env = dict(os.environ)
try:
print("executing '{0}'".format(" ".join(cmd)))
return subprocess.call(cmd, env=env, cwd=cwd)
except OSError as err:
if err.errno == 2:
print("Error when running '%s': %s\n" % (" ".join(cmd), str(err),))
print("You need to install Airspeed Velocity \
https://spacetelescope.github.io/asv/")
print("to run Scipy benchmarks")
return 1
raise err
def parse_setuppy_commands(args):
"""Check the commands and respond appropriately. Disable broken commands.
Return a boolean value for whether or not to run the build or not (avoid
parsing Cython and template files if False).
"""
if not args:
# User forgot to give an argument probably, let setuptools handle that.
return True
info_commands = ['--help-commands', '--name', '--version', '-V',
'--fullname', '--author', '--author-email',
'--maintainer', '--maintainer-email', '--contact',
'--contact-email', '--url', '--license', '--description',
'--long-description', '--platforms', '--classifiers',
'--keywords', '--provides', '--requires', '--obsoletes']
for command in info_commands:
if command in args:
return False
# Note that 'alias', 'saveopts' and 'setopt' commands also seem to work
# fine as they are, but are usually used together with one of the commands
# below and not standalone. Hence they're not added to good_commands.
good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py',
'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm',
'bdist_wininst', 'bdist_msi', 'bdist_mpkg', 'build_sphinx',
'test')
for command in good_commands:
if command in args:
return True
bad_commands = dict(
upload="""
`setup.py upload` is not supported, because it's insecure.
Instead, build what you want to upload and upload those files
with `twine upload -s <filenames>` instead.
""",
clean="""
`setup.py clean` is not supported, use one of the following instead:
- `git clean -xdf` (cleans all files)
- `git clean -Xdf` (cleans all versioned files, doesn't touch
files that aren't checked into the git repo)
""",
)
not_supported_commands = [
'upload_docs',
'easy_install',
'bdist',
'bdist_dumb',
'register',
'check',
'install_data',
'install_headers',
'install_lib',
'install_scripts',
'flake8',
]
for command in not_supported_commands:
bad_commands[command] = "`setup.py %s` is not supported" % command
for command in bad_commands.keys():
if command in args:
print(textwrap.dedent(bad_commands[command]) +
"\nAdd `--force` to your command to use it anyway if you "
"must (unsupported).\n")
sys.exit(1)
def get_ext_modules():
import Cython.Build
ext_sobol = core.Extension(
'mafipy.math.qmc._sobol',
['mafipy/math/qmc/*.pyx'],
)
extensions = [
ext_sobol,
]
ext_modules = Cython.Build.cythonize(extensions)
return ext_modules
def get_packages():
packages = setuptools.find_packages()
return packages
def get_install_requires():
return [
'numpy==1.21.0',
'scipy==1.10.0',
]
def main():
cmdclass = {
'test': PyTest,
'benchmark': Benchmark,
'benchmark_publish': BenchmarkPublish,
'benchmark_preview': BenchmarkPreview,
}
metadata = dict(
name=NAME,
packages=get_packages(),
version=VERSION,
description=DESCRIPTION,
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
url=URL,
download_url=DOWNLOAD_URL,
install_requires=get_install_requires(),
license=LICENSE,
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
long_description=LONG_DESCRIPTION,
tests_require=['pytest', 'pytest-cov'],
cmdclass=cmdclass,
)
args = sys.argv[1:]
build_required = parse_setuppy_commands(args)
if build_required:
ext_modules = get_ext_modules()
metadata['ext_modules'] = ext_modules
core.setup(**metadata)
if __name__ == '__main__':
main()