-
Notifications
You must be signed in to change notification settings - Fork 119
/
check_env.py
128 lines (112 loc) · 3.23 KB
/
check_env.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
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2015-2016 California Institute of Technology.
# Copyright (c) 2016-2023 Mike McKerns.
# License: 3-clause BSD.
"""
check environment scipt
"""
import sys
# requirements
has = dict(
# optimization
scipy='0.6.0',
mystic='0.3.1',
# parallel computing
pathos='0.2.1',
# dependencies
pox='0.2.3',
dill='0.2.7',
klepto='0.1.4',
numpy='1.0',
sympy='0.6.7',
ppft='1.6.4.7',
multiprocess='0.70.5',
# examples
matplotlib='0.91',
jupyter='1.0',
cvxopt='1.1.0',
# optional
#pyina='0.2.0.dev0',
#pulp='1.6.0',
#Numberjack='1.1.0',
#python-constraints='1.2', # installs as 'constraints'
sqlalchemy='0.8.4',
)
# executables
# list: At least one item is expected
# tuple: All items are expected
run = dict(
# optimization
mystic=('mystic_log_reader.py','mystic_model_plotter.py',
'support_convergence.py','support_hypercube.py',
'support_hypercube_measures.py','support_hypercube_scenario.py',),
# parallel computing
pathos=('pathos_tunnel.py','pathos_server.py','tunneled_pathos_server.py',),
# dependencies
ppft=('ppserver.py',),
# examples
### jupyter-notebook
# optional
#pyina=('sync','cp','rm','ezpool.py','ezscatter.py',),
)
returns = 0
# check installed packages
for module in has.keys():
try:
_module = module.split('-')[-1]
__module__ = __import__(_module, globals(), locals(), [], 0)
exec('%s = __module__' % _module)
except ImportError:
print("%s:: %s" % (module, sys.exc_info()[1]))
run.pop(module, None)
returns += 1
# check required versions
from distutils.version import LooseVersion as V
for module,version in has.items():
try:
_module = module.split('-')[-1]
assert V(eval(_module).__version__) >= V(version)
except NameError:
pass # failed import
except AttributeError:
pass # can't version-check non-standard packages...
except AssertionError:
print("%s:: Version >= %s is required" % (module, version))
returns += 1
def executable_exist(module, prog):
try:
assert which(prog)
# process = Popen([prog, '--help'], stderr=STDOUT, stdout=PIPE)
# process.wait()
return True
except (OSError, AssertionError):
from sys import exc_info
print("%s:: Executable '%s' not found" % (module, prog))
#print("%s:: %s" % (prog, exc_info()[1]))
return False
# check required executables
try:
from pox import which
#from subprocess import Popen, STDOUT, PIPE#, call
except ImportError:
sys.exit(returns)
for module,executables in run.items():
if isinstance(executables, list):
found = False
for executable in executables:
if executable_exist(module, executable):
found = True
break
if not found:
returns += 1
else:
for executable in executables:
if not executable_exist(module, executable):
returns += 1
# final report
if not returns:
print('-'*50)
print('OK. All required items installed.')
sys.exit(returns)