Skip to content

Commit c45906f

Browse files
authored
Merge pull request numpy#27189 from mattip/download2
BUILD: improve download script
2 parents a65a28c + cd87c5c commit c45906f

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

tools/download-wheels.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,20 @@ def get_wheel_names(version):
5656
The release version. For instance, "1.18.3".
5757
5858
"""
59+
ret = []
5960
http = urllib3.PoolManager(cert_reqs="CERT_REQUIRED")
6061
tmpl = re.compile(rf"^.*{PREFIX}-{version}{SUFFIX}")
61-
index_url = f"{STAGING_URL}/files"
62-
index_html = http.request("GET", index_url)
63-
soup = BeautifulSoup(index_html.data, "html.parser")
64-
return soup.find_all(string=tmpl)
62+
# TODO: generalize this by searching for `showing 1 of N` and
63+
# looping over N pages, starting from 1
64+
for i in range(1, 3):
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)
69+
return ret
6570

6671

67-
def download_wheels(version, wheelhouse):
72+
def download_wheels(version, wheelhouse, test=False):
6873
"""Download release wheels.
6974
7075
The release wheels for the given NumPy version are downloaded
@@ -86,8 +91,15 @@ def download_wheels(version, wheelhouse):
8691
wheel_path = os.path.join(wheelhouse, wheel_name)
8792
with open(wheel_path, "wb") as f:
8893
with http.request("GET", wheel_url, preload_content=False,) as r:
89-
print(f"{i + 1:<4}{wheel_name}")
90-
shutil.copyfileobj(r, f)
94+
info = r.info()
95+
length = int(info.get('Content-Length', '0'))
96+
if length == 0:
97+
length = 'unknown size'
98+
else:
99+
length = f"{(length / 1024 / 1024):.2f}MB"
100+
print(f"{i + 1:<4}{wheel_name} {length}")
101+
if not test:
102+
shutil.copyfileobj(r, f)
91103
print(f"\nTotal files downloaded: {len(wheel_names)}")
92104

93105

@@ -101,6 +113,10 @@ def download_wheels(version, wheelhouse):
101113
default=os.path.join(os.getcwd(), "release", "installers"),
102114
help="Directory in which to store downloaded wheels\n"
103115
"[defaults to <cwd>/release/installers]")
116+
parser.add_argument(
117+
"-t", "--test",
118+
action = 'store_true',
119+
help="only list available wheels, do not download")
104120

105121
args = parser.parse_args()
106122

@@ -110,4 +126,4 @@ def download_wheels(version, wheelhouse):
110126
f"{wheelhouse} wheelhouse directory is not present."
111127
" Perhaps you need to use the '-w' flag to specify one.")
112128

113-
download_wheels(args.version, wheelhouse)
129+
download_wheels(args.version, wheelhouse, test=args.test)

0 commit comments

Comments
 (0)