Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cibuildwheel/platforms/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,11 @@ def repair_wheel(state: BuildState, built_wheel: Path) -> Path:
if state.options.repair_command:
shell(
prepare_command(
state.options.repair_command, wheel=built_wheel, dest_dir=repaired_wheel_dir
state.options.repair_command,
wheel=built_wheel,
dest_dir=repaired_wheel_dir,
package=state.options.package_dir,
project=".",
),
env=state.build_env,
)
Expand Down
6 changes: 5 additions & 1 deletion cibuildwheel/platforms/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ def build_in_container(
if build_options.repair_command:
log.step("Repairing wheel...")
repair_command_prepared = prepare_command(
build_options.repair_command, wheel=built_wheel, dest_dir=repaired_wheel_dir
build_options.repair_command,
wheel=built_wheel,
dest_dir=repaired_wheel_dir,
package=container_package_dir,
project=container_project_path,
)
container.call(["sh", "-c", repair_command_prepared], env=env)
else:
Expand Down
2 changes: 2 additions & 0 deletions cibuildwheel/platforms/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ def build(options: Options, tmp_path: Path) -> None:
wheel=built_wheel,
dest_dir=repaired_wheel_dir,
delocate_archs=delocate_archs,
package=build_options.package_dir,
project=".",
)
shell(repair_command_prepared, env=env)
else:
Expand Down
2 changes: 2 additions & 0 deletions cibuildwheel/platforms/pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ def build(options: Options, tmp_path: Path) -> None:
build_options.repair_command,
wheel=built_wheel,
dest_dir=repaired_wheel_dir,
package=build_options.package_dir,
project=".",
)
shell(repair_command_prepared, env=env)
log.step_end()
Expand Down
2 changes: 2 additions & 0 deletions cibuildwheel/platforms/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ def build(options: Options, tmp_path: Path) -> None:
build_options.repair_command,
wheel=built_wheel,
dest_dir=repaired_wheel_dir,
package=build_options.package_dir,
project=".",
)
shell(repair_command_prepared, env=env)
else:
Expand Down
2 changes: 2 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,8 @@ The following placeholders must be used inside the command and will be replaced
- `{dest_dir}` for the absolute path of the directory where to create the repaired wheel
- `{delocate_archs}` (macOS only) comma-separated list of architectures in the wheel.

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.

The command is run in a shell, so you can run multiple commands like `cmd1 && cmd2`.

Platform-specific environment variables are also available:<br/>
Expand Down
39 changes: 39 additions & 0 deletions test/test_custom_repair_wheel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess
import textwrap
from contextlib import nullcontext as does_not_raise

import pytest
Expand Down Expand Up @@ -56,3 +57,41 @@ def test(tmp_path, capfd):
# 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, repair_command):
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 / "spam-repaired.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,
},
single_python=True,
)

assert result == ["spam-repaired.whl"]
Loading