-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathCondaUtils.py
88 lines (70 loc) · 2.99 KB
/
CondaUtils.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
import os
import sys
from Util import *
def get_conda_dir(workdir, py_ver):
#if py_ver.startswith('py2'):
# conda_dir = os.path.join(workdir, 'miniconda2')
#else:
# conda_dir = os.path.join(workdir, 'miniconda3')
conda_dir = os.path.join(workdir, 'miniconda')
return conda_dir
def install_miniconda(workdir, py_ver):
if os.path.isdir(workdir) == True:
print("INFO: {dir} already exists".format(dir=workdir))
else:
os.mkdir(workdir)
conda_dir = get_conda_dir(workdir, py_ver)
conda_path = os.path.join(conda_dir, 'bin')
if os.path.isdir(conda_dir) == True:
print("INFO: {dir} already exists".format(dir=conda_dir))
print("Conda is already installed.")
return(SUCCESS, conda_path)
url = "https://repo.anaconda.com/miniconda"
conda_script = os.path.join(workdir, 'miniconda.sh')
if py_ver.startswith('py2'):
conda_ver = 'Miniconda2'
else:
conda_ver = 'Miniconda3'
miniconda_ver = '4.7.12.1'
if sys.platform == 'darwin':
conda_script = "{c}-{v}-MacOSX-x86_64.sh".format(c=conda_ver, v=miniconda_ver)
conda_script_full_path = os.path.join(workdir, conda_script)
source_script = os.path.join(url, conda_script)
cmd = "curl {src} -o {dest}".format(src=source_script, dest=conda_script_full_path)
else:
conda_script = "{c}-{v}-Linux-x86_64.sh".format(c=conda_ver, v=miniconda_ver)
conda_script_full_path = os.path.join(workdir, conda_script)
source_script = os.path.join(url, conda_script)
cmd = "wget {src} -O {dest}".format(src=source_script, dest=conda_script_full_path)
print("DEBUG...cmd: {c}".format(c=cmd))
ret_code = run_cmd(cmd, True, False, True)
if ret_code != SUCCESS:
print("FAIL..." + cmd)
return(ret_code, None)
cmd = "bash {script} -b -p {dir}".format(script=conda_script_full_path,
dir=conda_dir)
# run the command, set verbose=False
ret_code = run_cmd(cmd, True, False, True)
if ret_code != SUCCESS:
print("FAIL...installing miniconda")
return(ret_code, None)
conda_cmd = os.path.join(conda_path, 'conda')
cmd = "{c} config --set always_yes yes --set changeps1 no".format(c=conda_cmd)
ret_code = run_cmd(cmd, True, False, True)
if ret_code != SUCCESS:
print('FAILED: ' + cmd)
return(ret_code, None)
cmd = "{c} config --set anaconda_upload no".format(c=conda_cmd)
ret_code = run_cmd(cmd)
if ret_code != SUCCESS:
print('FAILED: ' + cmd)
return(ret_code, None)
cmd = "{c} config --add channels conda-forge".format(c=conda_cmd)
ret_code = run_cmd(cmd)
if ret_code != SUCCESS:
print('FAILED: ' + cmd)
return(ret_code, None)
cmd = "{c} config --set channel_priority strict".format(c=conda_cmd)
ret_code = run_cmd(cmd)
print("DEBUG...install_miniconda() returning conda_path: {p}".format(p=conda_path))
return(ret_code, conda_path)