3
Script to download NumPy wheels from the Anaconda staging area.
7
$ ./tools/download-wheels.py <version> -w <optional-wheelhouse>
9
The default wheelhouse is ``release/installers``.
20
While in the repository root::
22
$ python tools/download-wheels.py 1.19.0
23
$ python tools/download-wheels.py 1.19.0 -w ~/wheelhouse
32
from bs4 import BeautifulSoup
37
STAGING_URL = "https://anaconda.org/multibuild-wheels-staging/numpy"
44
SUFFIX = rf"({WHL}|{GZIP}|{ZIP})"
47
def get_wheel_names(version):
48
""" Get wheel names from Anaconda HTML directory.
50
This looks in the Anaconda multibuild-wheels-staging page and
51
parses the HTML to get all the wheel names for a release version.
56
The release version. For instance, "1.18.3".
60
http = urllib3.PoolManager(cert_reqs="CERT_REQUIRED")
61
tmpl = re.compile(rf"^.*{PREFIX}-{version}{SUFFIX}")
65
index_url = f"{STAGING_URL}/files?page={i}"
66
index_html = http.request("GET", index_url)
67
soup = BeautifulSoup(index_html.data, "html.parser")
68
ret += soup.find_all(string=tmpl)
72
def download_wheels(version, wheelhouse, test=False):
73
"""Download release wheels.
75
The release wheels for the given NumPy version are downloaded
76
into the given directory.
81
The release version. For instance, "1.18.3".
83
Directory in which to download the wheels.
86
http = urllib3.PoolManager(cert_reqs="CERT_REQUIRED")
87
wheel_names = get_wheel_names(version)
89
for i, wheel_name in enumerate(wheel_names):
90
wheel_url = f"{STAGING_URL}/{version}/download/{wheel_name}"
91
wheel_path = os.path.join(wheelhouse, wheel_name)
92
with open(wheel_path, "wb") as f:
93
with http.request("GET", wheel_url, preload_content=False,) as r:
95
length = int(info.get('Content-Length', '0'))
97
length = 'unknown size'
99
length = f"{(length / 1024 / 1024):.2f}MB"
100
print(f"{i + 1:<4}{wheel_name} {length}")
102
shutil.copyfileobj(r, f)
103
print(f"\nTotal files downloaded: {len(wheel_names)}")
106
if __name__ == "__main__":
107
parser = argparse.ArgumentParser()
110
help="NumPy version to download.")
112
"-w", "--wheelhouse",
113
default=os.path.join(os.getcwd(), "release", "installers"),
114
help="Directory in which to store downloaded wheels\n"
115
"[defaults to <cwd>/release/installers]")
118
action = 'store_true',
119
help="only list available wheels, do not download")
121
args = parser.parse_args()
123
wheelhouse = os.path.expanduser(args.wheelhouse)
124
if not os.path.isdir(wheelhouse):
126
f"{wheelhouse} wheelhouse directory is not present."
127
" Perhaps you need to use the '-w' flag to specify one.")
129
download_wheels(args.version, wheelhouse, test=args.test)