forked from conda-forge/conda-smithy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-obvious-ci-and-miniconda.py
149 lines (129 loc) · 4.16 KB
/
bootstrap-obvious-ci-and-miniconda.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
#!/usr/bin/env python
"""
Installs Miniconda with the latest version of Obvious-CI.
This script supports Python 3 (>=3.2+) and is
designed to run on OSX, Linux and Windows.
"""
import argparse
import os
import platform
import subprocess
try:
from urllib.request import urlretrieve
except ImportError:
from urllib import urlretrieve
MINICONDA_URL_TEMPLATE = (
"https://repo.continuum.io/miniconda/Miniconda{major_py_version}-"
"{miniconda_version}-{OS}-{arch}.{ext}"
)
def miniconda_url(
target_system, target_arch, major_py_version, miniconda_version
):
template_values = {"miniconda_version": miniconda_version}
if target_arch == "x86":
template_values["arch"] = "x86"
elif target_arch == "x64":
template_values["arch"] = "x86_64"
else:
raise ValueError("Unexpected target arch.")
system_to_miniconda_os = {
"Linux": "Linux",
"Darwin": "MacOSX",
"Windows": "Windows",
}
if target_system not in system_to_miniconda_os:
raise ValueError(f"Unexpected system {target_system!r}.")
template_values["OS"] = system_to_miniconda_os[target_system]
miniconda_os_ext = {"Linux": "sh", "MacOSX": "sh", "Windows": "exe"}
template_values["ext"] = miniconda_os_ext[template_values["OS"]]
if major_py_version not in ["3"]:
raise ValueError(
f"Unexpected major Python version {major_py_version!r}."
)
template_values["major_py_version"] = major_py_version
return MINICONDA_URL_TEMPLATE.format(**template_values)
def main(
target_dir,
target_arch,
major_py_version,
miniconda_version="latest",
install_obvci=True,
):
system = platform.system()
url = miniconda_url(
system, target_arch, major_py_version, miniconda_version
)
basename = url.rsplit("/", 1)[1]
if system in ["Linux", "Darwin"]:
cmd = ["bash", basename, "-b", "-p", target_dir]
bin_dir = "bin"
elif system in ["Windows"]:
cmd = [
"powershell",
"Start-Process",
"-FilePath",
basename,
"-ArgumentList",
"/S,/D=" + target_dir,
"-Wait",
] # '-Passthru']
bin_dir = "scripts"
else:
raise ValueError("Unsupported operating system.")
if not os.path.exists(basename):
print(f"Downloading from {url}")
urlretrieve(url, basename)
else:
print(f"Using cached version of {url}")
# Install with powershell.
if os.path.exists(target_dir):
raise OSError("Installation directory already exists")
subprocess.check_call(cmd)
if not os.path.isdir(target_dir):
raise RuntimeError("Failed to install miniconda :(")
if install_obvci:
conda_path = os.path.join(target_dir, bin_dir, "conda")
subprocess.check_call(
[
conda_path,
"install",
"--yes",
"--quiet",
"-c",
"pelson",
"obvious-ci",
]
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="""A script to download and install miniconda for Linux/OSX/Windows."""
)
parser.add_argument(
"installation_directory",
help="""Where miniconda should be installed.""",
)
parser.add_argument(
"arch",
help="""The target architecture of this build. (must be either "x86" or "x64").""",
choices=["x86", "x64"],
)
parser.add_argument(
"major_py_version",
help="""The major Python version for the miniconda root env (may
still subsequently use another Python version).""",
choices=["3"],
)
parser.add_argument(
"--without-obvci",
help="Disable the installation of Obvious-ci.",
action="store_true",
)
parser.add_argument("--miniconda-version", default="latest")
args = parser.parse_args()
main(
args.installation_directory,
args.arch,
args.major_py_version,
miniconda_version=args.miniconda_version,
install_obvci=not args.without_obvci,
)