Files
cibuildwheel/test/test_custom_repair_wheel.py
T
d2c0e59833 feat: pyemscripten platform tag (PEP 783), 314.0a1, pyodide-eol flag, and maintenance updates (#2812)
* Use `pyodide config get emscripten_dir`

* Update constraints

* Updates for `pyemscripten` platform tag

* Weird constraints stuff...

* Revert "Weird constraints stuff..."

This reverts commit 4bd785de872269c0b27362ee800f17288b2b4789.

* Add some special constraints for pyodide

* Wheel pyemscripten collision

* Put delocate back in constraints (not needed tho)

* Drop Pyodide 0.27.7 (cp312-pyodide_wasm32)

* Add Pyodide 314.0.0a1 (cp314-pyodide_wasm32)

* Delete no-longer-needed Pyodide 312 constraints

* Update Pyodide 313 and 314 constraints

* Add back prerelease stuff and update tests

* Fix `test_pyodide_on_windows`

* Update and fix tests some more

* Also enable pyodide-prerelease in GHA sample build

* Update tests yet again (`SINGLE_PYTHON_VERSION` changes)

* Add a Pyodide-specific maintenance guide

* Add suggestions from Hood and Gyeongjae

Co-Authored-By: Hood Chatham <roberthoodchatham@gmail.com>
Co-Authored-By: Gyeongjae Choi <def6488@gmail.com>

* Add "Last updated: May 2026" to Pyodide document

* Add a Pyodide EOL filter

* Fix typo

* Update maintenance docs about EoL Pyodide

* Add Pyodide 312 constraints back

* Update Pyodide 313 and 314 constraints

* Remove "experimental" note about Pyodide

* Remove another experimental Pyodide sentence

* Add docs about the `pyodide-eol` enable option

---------

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Co-authored-by: Gyeongjae Choi <def6488@gmail.com>
Co-authored-by: Henry Schreiner <henryfs@princeton.edu>
2026-05-09 14:01:41 -04:00

100 lines
3.0 KiB
Python

import subprocess
import textwrap
from contextlib import nullcontext as does_not_raise
from pathlib import Path
import pytest
from test import test_projects
from . import utils
basic_project = test_projects.new_c_project()
basic_project.files["repair.py"] = """
import shutil
import sys
from pathlib import Path
wheel = Path(sys.argv[1])
dest_dir = Path(sys.argv[2])
platform = wheel.stem.split("-")[-1]
if platform.startswith("pyemscripten"):
# for the sake of this test, munge the pyemscripten platforms into one, it's
# not valid, but it does activate the uniqueness check
platform = "pyemscripten"
name = f"spam-0.1.0-py2-none-{platform}.whl"
dest = dest_dir / name
dest_dir.mkdir(parents=True, exist_ok=True)
dest.unlink(missing_ok=True)
shutil.copy(wheel, dest)
"""
def test(tmp_path: Path, capfd: pytest.CaptureFixture[str]) -> None:
# this test checks that a generated wheel name shall be unique in a given cibuildwheel run
project_dir = tmp_path / "project"
basic_project.generate(project_dir)
num_builds = len(utils.cibuildwheel_get_build_identifiers(project_dir))
expectation = (
pytest.raises(subprocess.CalledProcessError) if num_builds > 1 else does_not_raise()
)
with expectation as exc_info:
result = utils.cibuildwheel_run(
project_dir,
add_env={
"CIBW_REPAIR_WHEEL_COMMAND": "python repair.py {wheel} {dest_dir}",
},
)
captured = capfd.readouterr()
if num_builds > 1:
assert exc_info is not None
assert "Build failed because a wheel named" in captured.err
assert exc_info.value.returncode == 6
else:
# We only produced one wheel (perhaps Pyodide)
# check that it has the right name
assert result[0].startswith("spam-0.1.0-py2-none-")
@pytest.mark.parametrize(
"repair_command",
[
"python repair.py {wheel} {dest_dir}",
"python {package}/repair.py {wheel} {dest_dir}",
"python {project}/repair.py {wheel} {dest_dir}",
],
ids=["no-placeholder", "package-placeholder", "project-placeholder"],
)
def test_repair_wheel_command_structure(tmp_path: Path, repair_command: str) -> None:
project_dir = tmp_path / "project"
project = test_projects.new_c_project()
project.files["repair.py"] = textwrap.dedent("""
import shutil
import sys
from pathlib import Path
wheel = Path(sys.argv[1])
dest_dir = Path(sys.argv[2])
dest_dir.mkdir(parents=True, exist_ok=True)
shutil.copy(wheel, dest_dir / "spamrepaired-0.0.1-py-none-any.whl")
""")
# Combined test for repair wheel command formats (plain, {package}, {project})
project.generate(project_dir)
result = utils.cibuildwheel_run(
project_dir,
add_env={
"CIBW_REPAIR_WHEEL_COMMAND": repair_command,
"CIBW_ARCHS": "native",
},
single_python=True,
)
assert result == ["spamrepaired-0.0.1-py-none-any.whl"]