-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathinstall_prereqs.py
More file actions
115 lines (98 loc) · 3.93 KB
/
Copy pathinstall_prereqs.py
File metadata and controls
115 lines (98 loc) · 3.93 KB
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
#!/usr/bin/env python3
"""
installs Gemini prerequisite libraries for CentOS, Debian, Ubuntu, Homebrew and Cygwin, assuming GCC/Gfortran
Michael Hirsch, Ph.D.
"""
import subprocess
from pathlib import Path
import sys
from configparser import ConfigParser
from argparse import ArgumentParser
import typing
def os_release() -> typing.List[str]:
"""
reads /etc/os-release with fallback to legacy methods
returns
-------
'rhel' or 'debian'
"""
fn = Path("/etc/os-release")
if not fn.is_file():
if Path("/etc/redhat-release").is_file() or Path("/etc/centos-release").is_file():
return ["rhel"]
elif Path("/etc/debian_version").is_file():
return ["debian"]
C = ConfigParser(inline_comment_prefixes=("#", ";"))
ini = "[all]" + fn.read_text()
C.read_string(ini)
return C["all"].get("ID_LIKE").strip('"').strip("'").split()
def get_package_manager(like: typing.List[str] = None) -> str:
if not like:
like = os_release()
if isinstance(like, str):
like = [like]
if {"centos", "rhel", "fedora"}.intersection(like):
return "yum"
elif {"debian", "ubuntu"}.intersection(like):
return "apt"
else:
raise ValueError(f"Unknown ID_LIKE={like}, please file bug report or manually specify package manager")
def main(package_manager: str):
if sys.platform == "linux":
if not package_manager:
package_manager = get_package_manager()
pkgs = {
"yum": [
"epel-release",
"pkg-config",
"gcc-gfortran",
"MUMPS-openmpi-devel",
"lapack-devel",
"blacs-openmpi-devel",
"scalapack-openmpi-devel",
"openmpi-devel",
],
"apt": [
"pkg-config",
"gfortran",
"libmumps-dev",
"liblapack-dev",
"libblacs-mpi-dev",
"libscalapack-mpi-dev",
"libopenmpi-dev",
"openmpi-bin",
],
}
if package_manager == "yum":
if subprocess.run(["sudo", "yum", "--assumeyes", "install"] + pkgs["yum"]).returncode:
raise SystemExit(
"This script is made for personal laptops/desktops.\n"
"HPCs using CentOS have system-specific library setup. \n"
"If using gfortran, version >= 6 is required."
"Try devtoolset-7 if gcc/gfortran is too old on your system."
)
elif package_manager == "apt":
if subprocess.run(["sudo", "apt", "update"]).returncode:
raise SystemExit("installing prereqs failed.")
if subprocess.run(["sudo", "apt", "--yes", "install"] + pkgs["apt"]).returncode:
raise SystemExit("installing prereqs failed.")
else:
raise ValueError(f"I don't know package manager {package_manager}, try installing the prereqs manually")
elif sys.platform == "darwin":
pkgs = {"brew": ["gcc", "make", "cmake", "lapack", "openmpi"]}
subprocess.run(["brew", "install"] + pkgs["brew"])
subprocess.run(["brew", "tap", "dpo/openblas"])
subprocess.run(["brew", "install", "mumps"])
elif sys.platform == "cygwin":
pkgs = ["gcc-fortran", "liblapack-devel", "libopenmpi-devel"]
if subprocess.run(["setup-x86_64.exe", "-P"] + pkgs).returncode:
raise SystemExit("installing prereqs failed.")
elif sys.platform == "win32":
raise SystemExit("It is easiest to use Intel compilers for Windows, or Windows Subsystem for Linux.")
else:
raise NotImplementedError(f"unknown platform {sys.platform}")
if __name__ == "__main__":
p = ArgumentParser()
p.add_argument("package_manager", help="specify package manager e.g. apt, yum", nargs="?")
P = p.parse_args()
main(P.package_manager)