-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.py
More file actions
154 lines (116 loc) · 4.51 KB
/
install.py
File metadata and controls
154 lines (116 loc) · 4.51 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
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
import glob
import os
import shutil
import subprocess
import sys
def query_yes_no(question, default="no"):
"""Ask a yes/no question via raw_input() and return their answer.
"question" is a string that is presented to the user.
"default" is the presumed answer if the user just hits <Enter>.
It must be "yes" (the default), "no" or None (meaning
an answer is required of the user).
The "answer" return value is True for "yes" or False for "no".
"""
valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
if default is None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError(f"invalid default answer: '{default}'")
while True:
sys.stdout.write(question + prompt)
choice = input().lower()
if default is not None and choice == "":
return valid[default]
elif choice in valid:
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n")
def init():
print("================================\n")
print("This is the installer for Q-GPU\n")
print("================================\n")
def check_python():
print("Checking Python version")
print("================================")
print(f"version is {sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}")
print("================================")
if sys.version_info[0] == 3 and sys.version_info[1] < 6:
print("Q-GPU only works with Python 3.6 or higher")
print("Exiting now")
sys.exit()
def check_CUDA():
print("================================")
print("Checking CUDA version")
out = subprocess.check_output(["which", "nvcc"]).decode("utf-8")
if len(out) == 0:
print("Can't find nvcc, exiting now")
print("Exiting now")
sys.exit()
out = subprocess.check_output(["nvcc", "--version"]).decode("utf-8")
print(f"version is {out.split()[-1]}")
print("================================")
def get_installdir():
print("Please provide the installation directory: ")
INSTALLDIR = input()
INSTALLDIR = INSTALLDIR.strip()
return INSTALLDIR
def create_installdir(INSTALLDIR):
if os.path.isdir(INSTALLDIR) is True:
write = query_yes_no("Directory exists, are you sure you want to install here?")
if len(glob.glob(f"{INSTALLDIR}/*")) > 0:
overwrite = query_yes_no("Directory not empty, clean up?")
if write is False:
print("Will not write in specified folder, exiting now")
sys.exit()
if overwrite is False:
print("Directory needs to be empty, exiting now")
sys.exit()
if overwrite is True:
print("Deleting files in folder")
for file in glob.glob(f"{INSTALLDIR}/*"):
if os.path.isfile(file):
os.remove(file)
if os.path.isdir(file):
shutil.rmtree(file)
write_in_folder = os.access(INSTALLDIR, os.W_OK)
if write_in_folder is False or write is False:
print("Can't write in specified folder, exiting now")
sys.exit()
else:
try:
os.mkdir(INSTALLDIR)
except Exception as e:
print(f"Error: {e}")
print("Can't create installation directory, exiting now")
sys.exit()
ROOTDIR = os.path.abspath(INSTALLDIR)
return ROOTDIR
def install(ROOTDIR):
print(f"Installing Q-GPU in {ROOTDIR}")
for file in glob.glob("*"):
if file == "install":
continue
if os.path.isfile(file):
shutil.copy(file, ROOTDIR + "/" + file)
if os.path.isdir(file):
shutil.copytree(file, ROOTDIR + "/" + file)
os.chdir(ROOTDIR)
os.chdir("src/core")
out = subprocess.check_output("make")
print("If you want to have Q-GPU executable files in your path permanently.")
print("Please add the following to .bashrc or .bash_profile:")
print(f"export PATH={ROOTDIR}/bin:$PATH")
print("If you want to have Q-GPU python libraries available as modules in python:")
print('export PYTHONPATH="${}:{}/bin"'.format("{PYTHONPATH}", ROOTDIR))
print("\n==== INSTALLATION COMPLETE ====")
if __name__ == "__main__":
init()
check_python()
check_CUDA()
INSTALLDIR = get_installdir()
ROOTDIR = create_installdir(INSTALLDIR)
install(ROOTDIR)