Skip to content

Commit b723e9e

Browse files
authored
Merge pull request #7407 from hugovk/ci-appveyor-depends
AppVeyor: don't download huge pillow-depends.zip
2 parents 7a633e3 + 9c754eb commit b723e9e

File tree

2 files changed

+65
-48
lines changed

2 files changed

+65
-48
lines changed

.appveyor.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ environment:
2121
install:
2222
- '%PYTHON%\%EXECUTABLE% --version'
2323
- '%PYTHON%\%EXECUTABLE% -m pip install --upgrade pip'
24-
- curl -fsSL -o pillow-depends.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
2524
- curl -fsSL -o pillow-test-images.zip https://github.com/python-pillow/test-images/archive/main.zip
26-
- 7z x pillow-depends.zip -oc:\
2725
- 7z x pillow-test-images.zip -oc:\
28-
- mv c:\pillow-depends-main c:\pillow-depends
2926
- xcopy /S /Y c:\test-images-main\* c:\pillow\tests\images
30-
- 7z x ..\pillow-depends\nasm-2.16.01-win64.zip -oc:\
27+
- curl -fsSL -o nasm-win64.zip https://raw.githubusercontent.com/python-pillow/pillow-depends/main/nasm-2.16.01-win64.zip
28+
- 7z x nasm-win64.zip -oc:\
3129
- choco install ghostscript --version=10.0.0.20230317
3230
- path c:\nasm-2.16.01;C:\Program Files\gs\gs10.00.0\bin;%PATH%
3331
- cd c:\pillow\winbuild\

winbuild/build_prepare.py

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import argparse
24
import os
35
import platform
@@ -7,42 +9,41 @@
79
import subprocess
810

911

10-
def cmd_cd(path):
12+
def cmd_cd(path: str) -> str:
1113
return f"cd /D {path}"
1214

1315

14-
def cmd_set(name, value):
16+
def cmd_set(name: str, value: str) -> str:
1517
return f"set {name}={value}"
1618

1719

18-
def cmd_append(name, value):
20+
def cmd_append(name: str, value: str) -> str:
1921
op = "path " if name == "PATH" else f"set {name}="
2022
return op + f"%{name}%;{value}"
2123

2224

23-
def cmd_copy(src, tgt):
25+
def cmd_copy(src: str, tgt: str) -> str:
2426
return f'copy /Y /B "{src}" "{tgt}"'
2527

2628

27-
def cmd_xcopy(src, tgt):
29+
def cmd_xcopy(src: str, tgt: str) -> str:
2830
return f'xcopy /Y /E "{src}" "{tgt}"'
2931

3032

31-
def cmd_mkdir(path):
33+
def cmd_mkdir(path: str) -> str:
3234
return f'mkdir "{path}"'
3335

3436

35-
def cmd_rmdir(path):
37+
def cmd_rmdir(path: str) -> str:
3638
return f'rmdir /S /Q "{path}"'
3739

3840

39-
def cmd_nmake(makefile=None, target="", params=None):
40-
if params is None:
41-
params = ""
42-
elif isinstance(params, (list, tuple)):
43-
params = " ".join(params)
44-
else:
45-
params = str(params)
41+
def cmd_nmake(
42+
makefile: str | None = None,
43+
target: str = "",
44+
params: list[str] | None = None,
45+
) -> str:
46+
params = "" if params is None else " ".join(params)
4647

4748
return " ".join(
4849
[
@@ -55,7 +56,7 @@ def cmd_nmake(makefile=None, target="", params=None):
5556
)
5657

5758

58-
def cmds_cmake(target, *params):
59+
def cmds_cmake(target: str | tuple[str, ...] | list[str], *params) -> list[str]:
5960
if not isinstance(target, str):
6061
target = " ".join(target)
6162

@@ -80,8 +81,11 @@ def cmds_cmake(target, *params):
8081

8182

8283
def cmd_msbuild(
83-
file, configuration="Release", target="Build", platform="{msbuild_arch}"
84-
):
84+
file: str,
85+
configuration: str = "Release",
86+
target: str = "Build",
87+
platform: str = "{msbuild_arch}",
88+
) -> str:
8589
return " ".join(
8690
[
8791
"{msbuild}",
@@ -96,14 +100,14 @@ def cmd_msbuild(
96100

97101
SF_PROJECTS = "https://sourceforge.net/projects"
98102

99-
architectures = {
103+
ARCHITECTURES = {
100104
"x86": {"vcvars_arch": "x86", "msbuild_arch": "Win32"},
101105
"x64": {"vcvars_arch": "x86_amd64", "msbuild_arch": "x64"},
102106
"ARM64": {"vcvars_arch": "x86_arm64", "msbuild_arch": "ARM64"},
103107
}
104108

105109
# dependencies, listed in order of compilation
106-
deps = {
110+
DEPS = {
107111
"libjpeg": {
108112
"url": SF_PROJECTS
109113
+ "/libjpeg-turbo/files/3.0.0/libjpeg-turbo-3.0.0.tar.gz/download",
@@ -365,7 +369,7 @@ def cmd_msbuild(
365369

366370

367371
# based on distutils._msvccompiler from CPython 3.7.4
368-
def find_msvs():
372+
def find_msvs() -> dict[str, str] | None:
369373
root = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")
370374
if not root:
371375
print("Program Files not found")
@@ -421,25 +425,40 @@ def find_msvs():
421425
}
422426

423427

424-
def extract_dep(url, filename):
425-
import tarfile
428+
def download_dep(url: str, file: str) -> None:
426429
import urllib.request
430+
431+
ex = None
432+
for i in range(3):
433+
try:
434+
print(f"Fetching {url} (attempt {i + 1})...")
435+
content = urllib.request.urlopen(url).read()
436+
with open(file, "wb") as f:
437+
f.write(content)
438+
break
439+
except urllib.error.URLError as e:
440+
ex = e
441+
else:
442+
raise RuntimeError(ex)
443+
444+
445+
def extract_dep(url: str, filename: str) -> None:
446+
import tarfile
427447
import zipfile
428448

429449
file = os.path.join(args.depends_dir, filename)
430450
if not os.path.exists(file):
431-
ex = None
432-
for i in range(3):
433-
try:
434-
print("Fetching %s (attempt %d)..." % (url, i + 1))
435-
content = urllib.request.urlopen(url).read()
436-
with open(file, "wb") as f:
437-
f.write(content)
438-
break
439-
except urllib.error.URLError as e:
440-
ex = e
441-
else:
442-
raise RuntimeError(ex)
451+
# First try our mirror
452+
mirror_url = (
453+
f"https://raw.githubusercontent.com/"
454+
f"python-pillow/pillow-depends/main/{filename}"
455+
)
456+
try:
457+
download_dep(mirror_url, file)
458+
except RuntimeError as exc:
459+
# Otherwise try upstream
460+
print(exc)
461+
download_dep(url, file)
443462

444463
print("Extracting " + filename)
445464
sources_dir_abs = os.path.abspath(sources_dir)
@@ -466,7 +485,7 @@ def extract_dep(url, filename):
466485
raise RuntimeError(msg)
467486

468487

469-
def write_script(name, lines):
488+
def write_script(name: str, lines: list[str]) -> None:
470489
name = os.path.join(args.build_dir, name)
471490
lines = [line.format(**prefs) for line in lines]
472491
print("Writing " + name)
@@ -477,7 +496,7 @@ def write_script(name, lines):
477496
print(" " + line)
478497

479498

480-
def get_footer(dep):
499+
def get_footer(dep: dict) -> list[str]:
481500
lines = []
482501
for out in dep.get("headers", []):
483502
lines.append(cmd_copy(out, "{inc_dir}"))
@@ -488,7 +507,7 @@ def get_footer(dep):
488507
return lines
489508

490509

491-
def build_env():
510+
def build_env() -> None:
492511
lines = [
493512
"if defined DISTUTILS_USE_SDK goto end",
494513
cmd_set("INCLUDE", "{inc_dir}"),
@@ -504,8 +523,8 @@ def build_env():
504523
write_script("build_env.cmd", lines)
505524

506525

507-
def build_dep(name):
508-
dep = deps[name]
526+
def build_dep(name: str) -> str:
527+
dep = DEPS[name]
509528
dir = dep["dir"]
510529
file = f"build_dep_{name}.cmd"
511530

@@ -554,9 +573,9 @@ def build_dep(name):
554573
return file
555574

556575

557-
def build_dep_all():
576+
def build_dep_all() -> None:
558577
lines = [r'call "{build_dir}\build_env.cmd"']
559-
for dep_name in deps:
578+
for dep_name in DEPS:
560579
print()
561580
if dep_name in disabled:
562581
print(f"Skipping disabled dependency {dep_name}")
@@ -602,7 +621,7 @@ def build_dep_all():
602621
)
603622
parser.add_argument(
604623
"--architecture",
605-
choices=architectures,
624+
choices=ARCHITECTURES,
606625
default=os.environ.get(
607626
"ARCHITECTURE",
608627
(
@@ -634,7 +653,7 @@ def build_dep_all():
634653
)
635654
args = parser.parse_args()
636655

637-
arch_prefs = architectures[args.architecture]
656+
arch_prefs = ARCHITECTURES[args.architecture]
638657
print("Target architecture:", args.architecture)
639658

640659
msvs = find_msvs()
@@ -693,7 +712,7 @@ def build_dep_all():
693712
# TODO find NASM automatically
694713
}
695714

696-
for k, v in deps.items():
715+
for k, v in DEPS.items():
697716
prefs[f"dir_{k}"] = os.path.join(sources_dir, v["dir"])
698717

699718
print()

0 commit comments

Comments
 (0)