-
Notifications
You must be signed in to change notification settings - Fork 11
/
development_setup.py
90 lines (77 loc) · 3.39 KB
/
development_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
"""Development dependencies setup script."""
import argparse
import pathlib
import subprocess
import sys
import tarfile
import requests
submodules = [
"cobmo",
]
# Get repository base path.
base_path = pathlib.Path(__file__).parent.absolute()
# Get command line arguments.
parser = argparse.ArgumentParser(description="Development dependencies setup script for SITEM Middleware")
parser.add_argument("--highs", action="store_true", help="Only (re)install HiGHS solver and skip other steps")
args = parser.parse_args()
def main():
# Check which steps to be run.
run_highs = args.highs
run_all = not run_highs
# Check if submodules are loaded.
if run_all:
print("Checking if submodules are loaded.")
for submodule in submodules:
if not (base_path / submodule / "setup.py").is_file():
try:
subprocess.check_call(["git", "-C", f"{base_path}", "submodule", "update", "--init", "--recursive"])
except FileNotFoundError as exception:
raise FileNotFoundError(
f"ERROR: No setup file found for submodule `{submodule}`. "
f"Please check if the submodule is loaded correctly."
) from exception
# Install submodules in develop mode.
if run_all:
print("Installing submodules in development mode.")
for submodule in submodules:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", f"{base_path / submodule}"])
# Install MESMO.
if run_all:
print("Installing MESMO in development mode.")
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", f"{base_path}[tests]"])
# Install HiGHS solver.
if run_all or run_highs:
print("Installing HiGHS solver.")
# Make HiGHS directory.
(base_path / "highs").mkdir(exist_ok=True)
# Construct HiGHS binary download URL.
base_url = "https://github.com/JuliaBinaryWrappers/HiGHSstatic_jll.jl/releases/download/"
version_string = "HiGHSstatic-v1.2.2%2B0/HiGHSstatic.v1.2.2"
if sys.platform == "win32":
architecture_string = "x86_64-w64-mingw32"
elif sys.platform == "darwin":
architecture_string = "x86_64-apple-darwin"
else:
architecture_string = "x86_64-linux-gnu-cxx11"
url = f"{base_url}{version_string}.{architecture_string}.tar.gz"
# Download and unpack HiGHS binary files.
try:
with requests.get(url, stream=True) as request:
request.raise_for_status()
with open(base_path / "highs" / "highs.tar.gz", "wb") as file:
for chunk in request.iter_content(chunk_size=10240):
file.write(chunk)
with tarfile.open(base_path / "highs" / "highs.tar.gz") as file:
file.extractall(base_path / "highs")
# Remove downloaded archive file.
(base_path / "highs" / "highs.tar.gz").unlink()
except requests.ConnectionError:
# Soft-fail on download connection errors.
print(
"WARNING: HiGHS solver could not be installed automatically. "
"Please configure optimization solver for MESMO manually."
)
else:
print("Successfully installed HiGHS solver.")
if __name__ == "__main__":
main()