-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_prerequisites.py
executable file
·222 lines (185 loc) · 5.16 KB
/
install_prerequisites.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env python3
import os
from pathlib import Path
import platform
import subprocess
import sys
import venv
class PackageManager:
def __init__(self):
config = f"{os.path.expanduser('~')}/.config"
if not Path(config).exists():
os.makedirs(config)
self.venv_path = f"{config}/new_cxx_project"
self.pip = f"{self.venv_path}/bin/pip"
def install_python_packages(self):
venv.create(
self.venv_path,
system_site_packages=True,
clear=True,
symlinks=True,
with_pip=True,
upgrade_deps=True,
)
subprocess.run(
[
self.pip,
"install",
"-r",
f"{Path(__file__).resolve().parent}/docs/requirements.txt",
]
).check_returncode()
print(
f"\033[1m\033[91mYou will need to add '{self.venv_path}/bin' to your PATH before running new_cxx_project.py\033[0m",
file=sys.stderr,
)
def install_prerequisites(self):
self.install_python_packages()
print(
"No supported package managers were detected, only the Python packages were installed. Please manually install the following packages:\n"
"git\n"
"curl\n"
"cmake\n"
"libz3\n"
"ninja\n"
"pkgconf\n"
"tar\n"
"unzip\n"
"zip\n",
file=sys.stderr,
)
class Apt(PackageManager):
def install_prerequisites(self):
subprocess.run(
[
"sudo",
"apt-get",
"install",
"build-essential",
"git",
"curl",
"cmake",
"libz3-dev",
"ninja-build",
"pkg-config",
"tar",
"unzip",
"zip",
]
).check_returncode()
self.install_python_packages()
class Pacman(PackageManager):
def install_prerequisites(self):
subprocess.run(
[
"sudo",
"pacman",
"-S",
"base-devel",
"cmake",
"curl",
"git",
"ninja",
"pkgconf",
"zip",
"unzip",
]
).check_returncode()
self.install_python_packages()
class DNF(PackageManager):
def install_prerequisites(self):
subprocess.run(
[
"sudo",
"dnf",
"install",
"make",
"automake",
"gcc",
"gcc-c++",
"git",
"kernel-devel",
"cmake",
"curl",
"ninja-build",
"pkgconf",
"tar",
"unzip",
"zip",
]
).check_returncode()
self.install_python_packages()
class ZYpp(PackageManager):
def install_prerequisites(self):
subprocess.run(
[
"sudo",
"zypper",
"install",
"cmake",
"curl",
"gcc-c++",
"git",
"ninja",
"patterns-devel-base-devel_basis",
"pkgconf",
"tar",
"unzip",
"zip",
]
).check_returncode()
self.install_python_packages()
class Brew(PackageManager):
def install_prerequisites(self):
subprocess.run(
[
"brew",
"install",
"cmake",
"curlpp",
"ninja",
"unzip",
"zip",
]
).check_returncode()
self.install_python_packages()
class UnsupportedPlatform(Exception):
def __init__(self, platform):
super().__init__(f"the platform '{platform}' isn't supported by {sys.argv[0]}")
def detect_platform():
system = platform.system()
if not system in ["Linux", "Darwin"]:
raise UnsupportedPlatform(system)
if system == "Darwin":
return Brew()
try:
release_info = platform.freedesktop_os_release()
except Exception as e:
raise
if "ID_LIKE" in release_info:
id = release_info["ID_LIKE"]
if id == "debian":
return Apt()
if "suse" in id:
return ZYpp()
if "ID" in release_info:
id = release_info["ID"]
if id == "arch":
return Pacman()
if id == "fedora":
return DNF()
return PackageManager()
def main():
if sys.version_info < (3, 10):
print(
f"python version is {sys.version_info.major}.{sys.version_info.minor}; install_prerequisites.py needs at least 3.10",
file=sys.stderr,
)
sys.exit(1)
try:
detect_platform().install_prerequisites()
except Exception as e:
print(e, file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()