Skip to content

Commit 428c2bb

Browse files
Retry cibuildwheel bootstrap download
1 parent 3820325 commit 428c2bb

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

.github/scripts/run_cibuildwheel.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,53 @@
11
from __future__ import annotations
22

3+
import os
4+
import pathlib
5+
import shutil
36
import subprocess
47
import sys
8+
import time
9+
import urllib.request
510
from collections import deque
611

712

813
def escape_workflow_command(value: str) -> str:
914
return value.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")
1015

1116

17+
def prefetch_windows_virtualenv() -> None:
18+
if sys.platform != "win32":
19+
return
20+
21+
# Keep these values aligned with the cibuildwheel version pinned in the
22+
# workflow. cibuildwheel otherwise downloads this file only once, making a
23+
# transient GitHub error fail the entire Windows matrix.
24+
version = "20.35.2"
25+
cache_path = (
26+
pathlib.Path(os.environ["LOCALAPPDATA"]) / "pypa" / "cibuildwheel" / "Cache" / f"virtualenv-{version}.pyz"
27+
)
28+
if cache_path.exists():
29+
return
30+
31+
url = f"https://github.com/pypa/get-virtualenv/releases/download/{version}/virtualenv.pyz"
32+
cache_path.parent.mkdir(parents=True, exist_ok=True)
33+
temporary_path = cache_path.with_suffix(".tmp")
34+
35+
for attempt in range(1, 7):
36+
try:
37+
print(f"Prefetching {url} (attempt {attempt}/6)", flush=True)
38+
with urllib.request.urlopen(url, timeout=60) as response, temporary_path.open("wb") as output:
39+
shutil.copyfileobj(response, output)
40+
temporary_path.replace(cache_path)
41+
return
42+
except Exception:
43+
temporary_path.unlink(missing_ok=True)
44+
if attempt == 6:
45+
raise
46+
time.sleep(2 ** (attempt - 1))
47+
48+
49+
prefetch_windows_virtualenv()
50+
1251
process = subprocess.Popen(
1352
[sys.executable, "-m", "cibuildwheel", "--output-dir", "wheelhouse"],
1453
stdout=subprocess.PIPE,

0 commit comments

Comments
 (0)