From 61379f09ec868cdec6b97b56e1fcc9444fae42ab Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 1 Mar 2026 16:26:21 -0800 Subject: [PATCH] shim: retry downloads on transient network errors (#41) --- _shim_setup.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/_shim_setup.py b/_shim_setup.py index 42e1695..c61b241 100644 --- a/_shim_setup.py +++ b/_shim_setup.py @@ -1,8 +1,10 @@ """Shim setup.py: downloads pre-built wheels from GitHub Releases at install time.""" import os import platform +import time import zipfile from io import BytesIO +from urllib.error import URLError from urllib.request import urlopen try: @@ -45,7 +47,16 @@ class InstallPrebuilt(build_py): url = f"{REPO_URL}/releases/download/{TAG}/{whl_name}" print(f"Downloading {url} ...") - raw = urlopen(url).read() + for attempt in range(3): + try: + raw = urlopen(url, timeout=60).read() + break + except (URLError, OSError) as e: + if attempt == 2: + raise + wait = 2 ** attempt + print(f"Download failed ({e}), retrying in {wait}s ...") + time.sleep(wait) print(f"Extracting {DATADIR} ...") with zipfile.ZipFile(BytesIO(raw)) as zf: