Skip to content

Commit 553636d

Browse files
committed
refactor: add constraints for pyodide
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 4c1180f commit 553636d

File tree

4 files changed

+158
-10
lines changed

4 files changed

+158
-10
lines changed

cibuildwheel/pyodide.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ def setup_python(
108108
environment: ParsedEnvironment,
109109
) -> dict[str, str]:
110110
base_python = get_base_python(python_configuration.identifier)
111-
pyodide_version = python_configuration.pyodide_version
112111

113112
log.step("Setting up build environment...")
114113
venv_path = tmp / "venv"
@@ -165,7 +164,7 @@ def setup_python(
165164
"--upgrade",
166165
"auditwheel-emscripten",
167166
"build[virtualenv]",
168-
f"pyodide-build=={pyodide_version}",
167+
"pyodide-build",
169168
*dependency_constraint_flags,
170169
env=env,
171170
)
@@ -233,7 +232,7 @@ def build(options: Options, tmp_path: Path) -> None:
233232
dependency_constraint_flags: Sequence[PathOrStr] = []
234233
if build_options.dependency_constraints:
235234
constraints_path = build_options.dependency_constraints.get_for_python_version(
236-
config.version
235+
config.version, variant="pyodide"
237236
)
238237
dependency_constraint_flags = ["-c", constraints_path]
239238

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# This file was autogenerated by uv via the following command:
2+
# nox -s update_constraints
3+
annotated-types==0.7.0
4+
# via pydantic
5+
anyio==4.3.0
6+
# via httpx
7+
auditwheel-emscripten==0.0.14
8+
# via
9+
# -r .nox/update_constraints/tmp/constraints-pyodide.in
10+
# pyodide-build
11+
build==1.2.1
12+
# via
13+
# -r .nox/update_constraints/tmp/constraints-pyodide.in
14+
# pyodide-build
15+
certifi==2024.2.2
16+
# via
17+
# httpcore
18+
# httpx
19+
# requests
20+
charset-normalizer==3.3.2
21+
# via requests
22+
click==8.1.7
23+
# via typer
24+
cloudpickle==3.0.0
25+
# via loky
26+
cmake==3.29.3
27+
# via pyodide-build
28+
distlib==0.3.8
29+
# via virtualenv
30+
filelock==3.14.0
31+
# via virtualenv
32+
h11==0.14.0
33+
# via httpcore
34+
httpcore==1.0.5
35+
# via httpx
36+
httpx==0.27.0
37+
# via unearth
38+
idna==3.7
39+
# via
40+
# anyio
41+
# httpx
42+
# requests
43+
leb128==1.0.7
44+
# via auditwheel-emscripten
45+
loky==3.4.1
46+
# via pyodide-build
47+
markdown-it-py==3.0.0
48+
# via rich
49+
mdurl==0.1.2
50+
# via markdown-it-py
51+
packaging==24.0
52+
# via
53+
# auditwheel-emscripten
54+
# build
55+
# pyodide-build
56+
# unearth
57+
platformdirs==4.2.2
58+
# via virtualenv
59+
pydantic==2.7.1
60+
# via
61+
# pyodide-build
62+
# pyodide-lock
63+
pydantic-core==2.18.2
64+
# via pydantic
65+
pygments==2.18.0
66+
# via rich
67+
pyodide-build==0.26.0a6
68+
# via -r .nox/update_constraints/tmp/constraints-pyodide.in
69+
pyodide-cli==0.2.3
70+
# via
71+
# auditwheel-emscripten
72+
# pyodide-build
73+
pyodide-lock==0.1.0a6
74+
# via pyodide-build
75+
pyproject-hooks==1.1.0
76+
# via build
77+
pyyaml==6.0.1
78+
# via pyodide-build
79+
requests==2.32.2
80+
# via pyodide-build
81+
resolvelib==1.0.1
82+
# via pyodide-build
83+
rich==13.7.1
84+
# via
85+
# pyodide-build
86+
# pyodide-cli
87+
# typer
88+
ruamel-yaml==0.18.6
89+
# via pyodide-build
90+
ruamel-yaml-clib==0.2.8
91+
# via ruamel-yaml
92+
shellingham==1.5.4
93+
# via typer
94+
sniffio==1.3.1
95+
# via
96+
# anyio
97+
# httpx
98+
typer==0.12.3
99+
# via
100+
# auditwheel-emscripten
101+
# pyodide-build
102+
# pyodide-cli
103+
types-requests==2.32.0.20240523
104+
# via pyodide-build
105+
typing-extensions==4.12.0
106+
# via
107+
# pydantic
108+
# pydantic-core
109+
# typer
110+
unearth==0.15.2
111+
# via pyodide-build
112+
urllib3==2.2.1
113+
# via
114+
# requests
115+
# types-requests
116+
virtualenv==20.26.2
117+
# via
118+
# build
119+
# pyodide-build
120+
wheel==0.43.0
121+
# via
122+
# auditwheel-emscripten
123+
# pyodide-build

cibuildwheel/util.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,14 @@ def __init__(self, base_file_path: Path):
359359
def with_defaults() -> DependencyConstraints:
360360
return DependencyConstraints(base_file_path=resources_dir / "constraints.txt")
361361

362-
def get_for_python_version(self, version: str) -> Path:
362+
def get_for_python_version(
363+
self, version: str, *, variant: Literal["python", "pyodide"] = "python"
364+
) -> Path:
363365
version_parts = version.split(".")
364366

365367
# try to find a version-specific dependency file e.g. if
366368
# ./constraints.txt is the base, look for ./constraints-python36.txt
367-
specific_stem = self.base_file_path.stem + f"-python{version_parts[0]}{version_parts[1]}"
369+
specific_stem = self.base_file_path.stem + f"-{variant}{version_parts[0]}{version_parts[1]}"
368370
specific_name = specific_stem + self.base_file_path.suffix
369371
specific_file_path = self.base_file_path.with_name(specific_name)
370372

noxfile.py

+29-5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def update_constraints(session: nox.Session) -> None:
7070
Update the dependencies inplace.
7171
"""
7272

73+
resources = Path("cibuildwheel/resources")
74+
7375
if session.venv_backend != "uv":
7476
session.install("uv>=0.1.23")
7577

@@ -79,22 +81,44 @@ def update_constraints(session: nox.Session) -> None:
7981
# CUSTOM_COMPILE_COMMAND is a pip-compile option that tells users how to
8082
# regenerate the constraints files
8183
env["UV_CUSTOM_COMPILE_COMMAND"] = f"nox -s {session.name}"
84+
output_file = resources / f"constraints-python{python_version.replace('.', '')}.txt"
8285
session.run(
8386
"uv",
8487
"pip",
8588
"compile",
8689
f"--python-version={python_version}",
8790
"--upgrade",
88-
"cibuildwheel/resources/constraints.in",
89-
f"--output-file=cibuildwheel/resources/constraints-python{python_version.replace('.', '')}.txt",
91+
resources / "constraints.in",
92+
f"--output-file={output_file}",
9093
env=env,
9194
)
92-
RESOURCES = DIR / "cibuildwheel" / "resources"
95+
9396
shutil.copyfile(
94-
RESOURCES / "constraints-python312.txt",
95-
RESOURCES / "constraints.txt",
97+
resources / "constraints-python312.txt",
98+
resources / "constraints.txt",
9699
)
97100

101+
build_platforms = nox.project.load_toml(resources / "build-platforms.toml")
102+
pyodides = build_platforms["pyodide"]["python_configurations"]
103+
for pyodide in pyodides:
104+
python_version = ".".join(pyodide["version"].split(".")[:2])
105+
pyodide_version = pyodide["pyodide_version"]
106+
output_file = resources / f"constraints-pyodide{python_version.replace('.', '')}.txt"
107+
tmp_file = Path(session.create_tmp()) / "constraints-pyodide.in"
108+
tmp_file.write_text(
109+
f"auditwheel-emscripten\nbuild[virtualenv]\npyodide-build=={pyodide_version}"
110+
)
111+
session.run(
112+
"uv",
113+
"pip",
114+
"compile",
115+
f"--python-version={python_version}",
116+
"--upgrade",
117+
tmp_file,
118+
f"--output-file={output_file}",
119+
env=env,
120+
)
121+
98122

99123
@nox.session
100124
def update_pins(session: nox.Session) -> None:

0 commit comments

Comments
 (0)