-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_installation.py
88 lines (62 loc) · 2.66 KB
/
test_installation.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
"""Test that the environment is correctly installed."""
from distutils.spawn import find_executable
def is_installed(executable):
return bool(find_executable(executable))
# ======================================================================================
# Check Installations
# ======================================================================================
required_estimagic_version = "0.4.0"
try:
import estimagic # noqa: F401
except ModuleNotFoundError:
msg = (
"\n\nestimagic is not installed. Please install it via "
f"'conda install -c conda-forge estimagic=={required_estimagic_version}'"
)
raise ModuleNotFoundError(msg) # noqa: TC200
from estimagic import __version__ # noqa: E402
if required_estimagic_version not in __version__:
msg = (
f"You've installed estimagic version {__version__}, but we require version"
f"{required_estimagic_version}"
)
raise Exception(msg) # noqa: TC002
from estimagic.config import IS_DFOLS_INSTALLED # noqa: E402
from estimagic.config import IS_PYGMO_INSTALLED # noqa: E402
from estimagic.config import IS_PYBOBYQA_INSTALLED # noqa: E402
from estimagic.config import IS_NLOPT_INSTALLED # noqa: E402
from estimagic.config import IS_FIDES_INSTALLED # noqa: E402
from estimagic.config import IS_JAX_INSTALLED # noqa: E402
not_installed = []
if not is_installed("jupyter"):
not_installed.append(("jupyter", "conda"))
if not IS_NLOPT_INSTALLED:
not_installed.append(("nlopt", "conda"))
if not IS_JAX_INSTALLED:
not_installed.append(("jax", "conda"))
if not IS_PYGMO_INSTALLED:
not_installed.append(("pygmo", "conda"))
if not IS_FIDES_INSTALLED:
not_installed.append(("fides", "pip"))
if not IS_DFOLS_INSTALLED:
not_installed.append(("DFO-LS", "pip"))
if not IS_PYBOBYQA_INSTALLED:
not_installed.append(("Py-BOBYQA", "pip"))
try:
import jaxopt # noqa: E402, F401
except ModuleNotFoundError:
not_installed(("jaxopt", "pip"))
# ======================================================================================
# Raise Error
# ======================================================================================
not_installed_conda = [pkg for pkg, pkg_mng in not_installed if pkg_mng == "conda"]
not_installed_pip = [pkg for pkg, pkg_mng in not_installed if pkg_mng == "pip"]
msg = "The following packages are missing and need to be installed via:"
if not_installed_conda:
msg += f"\nconda: {not_installed_conda}."
if not_installed_pip:
msg += f"\npip: {not_installed_pip}."
if not_installed_conda or not_installed_pip:
raise ModuleNotFoundError(msg)
else:
print("\nYour installation is working!!!\n") # noqa: T201