Skip to content

AppVeyor: don't download huge pillow-depends.zip #7407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 24, 2023
Next Next commit
Attempt download from pillow-depends mirror first
  • Loading branch information
hugovk committed Sep 18, 2023
commit c50b11b3caaf32c9be699f24956628feab3ce9b2
44 changes: 30 additions & 14 deletions winbuild/build_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,25 +421,41 @@ def find_msvs():
}


def extract_dep(url, filename):
import tarfile
def download_dep(url: str, file: str) -> None:
import urllib.request

ex = None
for i in range(3):
try:
print(f"Fetching {url} (attempt {i + 1})...")
content = urllib.request.urlopen(url).read()
with open(file, "wb") as f:
f.write(content)
break
except urllib.error.URLError as e:
ex = e

if ex:
raise RuntimeError(ex)


def extract_dep(url: str, filename: str) -> None:
import tarfile
import zipfile

file = os.path.join(args.depends_dir, filename)
if not os.path.exists(file):
ex = None
for i in range(3):
try:
print("Fetching %s (attempt %d)..." % (url, i + 1))
content = urllib.request.urlopen(url).read()
with open(file, "wb") as f:
f.write(content)
break
except urllib.error.URLError as e:
ex = e
else:
raise RuntimeError(ex)
# First try our mirror
mirror_url = (
f"https://raw.githubusercontent.com/"
f"python-pillow/pillow-depends/main/{filename}"
)
try:
download_dep(mirror_url, file)
except RuntimeError as exc:
# Otherwise try upstream
print(exc)
download_dep(url, file)

print("Extracting " + filename)
sources_dir_abs = os.path.abspath(sources_dir)
Expand Down