forked from NASA-NAVO/navo-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_env.py
71 lines (58 loc) · 2.13 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
#!/usr/bin/env python
"""
Check for required dependencies for the workshop.
Usage::
% python check_env.py
"""
from packaging.version import Version
# NOTE: Update minversion values as needed.
# Set both min and max versions to avoid ambiguity.
# This should match environment.yml file.
PKGS = {'jupyter': None,
'notebook': ('6.0', None),
'numpy': ('1.16', None),
'matplotlib': ('3.2', None),
'jupyterlab': ('3.0', None),
'astropy': ('4.1', None),
'pyvo': ('1.4', '1.4'),
'astroquery': ('0.4.3', None)
}
def check_package(package_name, versions=None, verbose=True):
errors = False
try:
pkg = __import__(package_name)
except ImportError as err:
print(f'Error: Failed import: {err}')
errors = True
else:
if package_name in ('jupyter', 'keyring'):
installed_version = ''
elif package_name == 'xlwt':
installed_version = pkg.__VERSION__
else:
installed_version = pkg.__version__
if versions is not None:
if (versions[0] is not None
and Version(installed_version) < Version(versions[0])):
print(f'Error: {package_name} version {versions[0]} or '
f'later is required, you have version {installed_version}')
errors = True
if (versions[1] is not None
and Version(versions[1]) < Version(installed_version)):
print(f'Error: {package_name} version {versions[1]} or '
f'older is required, you have version {installed_version}')
errors = True
if not errors and verbose:
print('Found', package_name, installed_version)
return errors
def run_checks():
errors = []
for package_name in PKGS:
errors.append(check_package(package_name, versions=PKGS[package_name]))
if any(errors):
print('\nThere are errors that you must resolve before running the '
'tutorials.')
else:
print('\nYour Python environment is good to go!')
if __name__ == '__main__':
run_checks()