-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathconfigure.py
73 lines (52 loc) · 1.66 KB
/
configure.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
import errno
import os
import platform
import shutil
import subprocess
def is_nvidia_installed():
installed = True
try:
subprocess.check_output('nvidia-smi')
except Exception:
installed = False
return installed
def is_windows():
return platform.system() == 'Windows'
def is_linux():
return platform.system() == 'Linux'
def is_macos():
return platform.system() == 'Darwin'
def is_ppc64le():
return platform.machine() == 'ppc64le'
def is_cygwin():
return platform.system().startswith('CYGWIN_NT')
def symlink_force(target, link_name):
"""Force symlink, equivalent of 'ln -sf'.
Args:
target: items to link to.
link_name: name of the link.
"""
try:
os.symlink(target, link_name)
except OSError as e:
if e.errno == errno.EEXIST:
os.remove(link_name)
os.symlink(target, link_name)
else:
raise e
def setup_python():
# TODO By Default python version is 3.8.8. We might need to make this
# user specific. Conda downloads the python interpreter.
if not is_nvidia_installed() or is_macos() or is_windows() or is_cygwin():
src = os.path.join(os.getcwd(), "python/py38_condaenv.yaml")
else:
src = os.path.join(os.getcwd(), "python/py38_condaenvcuda.yaml")
dst = os.path.join(os.getcwd(), "python/conda_env.yaml")
# We do not create a symlink, because when copying the files inside the image,
# the content of symlinked files are not transferred. Hence, the hard copy.
# symlink_force(source, target)
shutil.copy(src, dst)
def main():
setup_python()
if __name__ == '__main__':
main()