forked from scipy/scipy
/
run.py
executable file
·96 lines (73 loc) · 2.65 KB
/
run.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
#!/usr/bin/env python
"""
run.py [options] ASV_COMMAND..
Convenience wrapper around the ``asv`` command; just sets environment
variables and chdirs to the correct place etc.
"""
from __future__ import division, absolute_import, print_function
import os
import sys
import subprocess
import argparse
import sysconfig
import errno
EXTRA_PATH = ['/usr/lib/ccache', '/usr/lib/f90cache',
'/usr/local/lib/ccache', '/usr/local/lib/f90cache']
from benchmarks.common import set_mem_rlimit
def main():
class ASVHelpAction(argparse.Action):
nargs = 0
def __call__(self, parser, namespace, values, option_string=None):
sys.exit(run_asv(['--help']))
p = argparse.ArgumentParser(usage=__doc__.strip())
p.add_argument('--help-asv', nargs=0, action=ASVHelpAction,
help="""show ASV help""")
p.add_argument('asv_command', nargs=argparse.REMAINDER)
args = p.parse_args()
sys.exit(run_asv(args.asv_command))
def run_asv(args):
cwd = os.path.abspath(os.path.dirname(__file__))
repo_dir = os.path.join(cwd, 'scipy')
cmd = ['asv'] + list(args)
env = dict(os.environ)
# Inject ccache/f90cache paths
if sys.platform.startswith('linux'):
env['PATH'] = os.pathsep.join(EXTRA_PATH + env.get('PATH', '').split(os.pathsep))
# Control BLAS and CFLAGS
env['OPENBLAS_NUM_THREADS'] = '1'
env['CFLAGS'] = drop_bad_flags(sysconfig.get_config_var('CFLAGS'))
# Limit memory usage
try:
set_mem_rlimit()
except (ImportError, RuntimeError):
pass
# Check scipy version if in dev mode; otherwise clone and setup results
# repository
if args and (args[0] == 'dev' or '--python=same' in args):
import scipy
print("Running benchmarks for Scipy version %s at %s" % (scipy.__version__, scipy.__file__))
# Override gh-pages
if 'gh-pages' in args:
print("gh-pages command is disabled")
return 1
# Run
try:
return subprocess.call(cmd, env=env, cwd=cwd)
except OSError as err:
if err.errno == errno.ENOENT:
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
def drop_bad_flags(flags):
"""
Drop flags that are problematic for compiling old scipy versions
"""
if not flags:
return flags
return " ".join(x for x in flags.split()
if not (x.startswith("-Werror")
or x in ("-pedantic-errors",)))
if __name__ == "__main__":
sys.exit(main())