Skip to content

Commit f6c8108

Browse files
arcondellojoerick
andauthored
feat: make the {project} placeholder available to repair-wheel-command (#2589)
* Make the {project} placeholder available to repair-wheel-command * Add separate test for {project} placeholder in repair-wheel-command * Make the {project} placeholder available to repair-wheel-command * reduce duplicated work in tests * Use a valid wheel filename for the post-repair name --------- Co-authored-by: Joe Rickerby <[email protected]>
1 parent ccbae30 commit f6c8108

File tree

7 files changed

+58
-2
lines changed

7 files changed

+58
-2
lines changed

cibuildwheel/platforms/android.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,11 @@ def repair_wheel(state: BuildState, built_wheel: Path) -> Path:
447447
if state.options.repair_command:
448448
shell(
449449
prepare_command(
450-
state.options.repair_command, wheel=built_wheel, dest_dir=repaired_wheel_dir
450+
state.options.repair_command,
451+
wheel=built_wheel,
452+
dest_dir=repaired_wheel_dir,
453+
package=state.options.package_dir,
454+
project=".",
451455
),
452456
env=state.build_env,
453457
)

cibuildwheel/platforms/linux.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,11 @@ def build_in_container(
322322
if build_options.repair_command:
323323
log.step("Repairing wheel...")
324324
repair_command_prepared = prepare_command(
325-
build_options.repair_command, wheel=built_wheel, dest_dir=repaired_wheel_dir
325+
build_options.repair_command,
326+
wheel=built_wheel,
327+
dest_dir=repaired_wheel_dir,
328+
package=container_package_dir,
329+
project=container_project_path,
326330
)
327331
container.call(["sh", "-c", repair_command_prepared], env=env)
328332
else:

cibuildwheel/platforms/macos.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ def build(options: Options, tmp_path: Path) -> None:
522522
wheel=built_wheel,
523523
dest_dir=repaired_wheel_dir,
524524
delocate_archs=delocate_archs,
525+
package=build_options.package_dir,
526+
project=".",
525527
)
526528
shell(repair_command_prepared, env=env)
527529
else:

cibuildwheel/platforms/pyodide.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ def build(options: Options, tmp_path: Path) -> None:
439439
build_options.repair_command,
440440
wheel=built_wheel,
441441
dest_dir=repaired_wheel_dir,
442+
package=build_options.package_dir,
443+
project=".",
442444
)
443445
shell(repair_command_prepared, env=env)
444446
log.step_end()

cibuildwheel/platforms/windows.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ def build(options: Options, tmp_path: Path) -> None:
518518
build_options.repair_command,
519519
wheel=built_wheel,
520520
dest_dir=repaired_wheel_dir,
521+
package=build_options.package_dir,
522+
project=".",
521523
)
522524
shell(repair_command_prepared, env=env)
523525
else:

docs/options.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@ The following placeholders must be used inside the command and will be replaced
907907
- `{dest_dir}` for the absolute path of the directory where to create the repaired wheel
908908
- `{delocate_archs}` (macOS only) comma-separated list of architectures in the wheel.
909909

910+
You can use the `{package}` or `{project}` placeholders in your `repair-wheel-command` to refer to the package being built or the project root, respectively.
911+
910912
The command is run in a shell, so you can run multiple commands like `cmd1 && cmd2`.
911913

912914
Platform-specific environment variables are also available:<br/>

test/test_custom_repair_wheel.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
import textwrap
23
from contextlib import nullcontext as does_not_raise
34

45
import pytest
@@ -56,3 +57,42 @@ def test(tmp_path, capfd):
5657
# We only produced one wheel (perhaps Pyodide)
5758
# check that it has the right name
5859
assert result[0].startswith("spam-0.1.0-py2-none-")
60+
61+
62+
@pytest.mark.parametrize(
63+
"repair_command",
64+
[
65+
"python repair.py {wheel} {dest_dir}",
66+
"python {package}/repair.py {wheel} {dest_dir}",
67+
"python {project}/repair.py {wheel} {dest_dir}",
68+
],
69+
ids=["no-placeholder", "package-placeholder", "project-placeholder"],
70+
)
71+
def test_repair_wheel_command_structure(tmp_path, repair_command):
72+
project_dir = tmp_path / "project"
73+
project = test_projects.new_c_project()
74+
project.files["repair.py"] = textwrap.dedent("""
75+
import shutil
76+
import sys
77+
from pathlib import Path
78+
79+
wheel = Path(sys.argv[1])
80+
dest_dir = Path(sys.argv[2])
81+
82+
dest_dir.mkdir(parents=True, exist_ok=True)
83+
shutil.copy(wheel, dest_dir / "spamrepaired-0.0.1-py-none-any.whl")
84+
""")
85+
86+
# Combined test for repair wheel command formats (plain, {package}, {project})
87+
project.generate(project_dir)
88+
89+
result = utils.cibuildwheel_run(
90+
project_dir,
91+
add_env={
92+
"CIBW_REPAIR_WHEEL_COMMAND": repair_command,
93+
"CIBW_ARCHS": "native",
94+
},
95+
single_python=True,
96+
)
97+
98+
assert result == ["spamrepaired-0.0.1-py-none-any.whl"]

0 commit comments

Comments
 (0)