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
5 changes: 4 additions & 1 deletion cibuildwheel/platforms/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,10 @@ 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,
project=".",
),
env=state.build_env,
)
Expand Down
5 changes: 4 additions & 1 deletion cibuildwheel/platforms/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ 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,
project=container_project_path,
)
container.call(["sh", "-c", repair_command_prepared], env=env)
else:
Expand Down
1 change: 1 addition & 0 deletions cibuildwheel/platforms/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ def build(options: Options, tmp_path: Path) -> None:
wheel=built_wheel,
dest_dir=repaired_wheel_dir,
delocate_archs=delocate_archs,
project=".",
)
shell(repair_command_prepared, env=env)
else:
Expand Down
1 change: 1 addition & 0 deletions cibuildwheel/platforms/pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def build(options: Options, tmp_path: Path) -> None:
build_options.repair_command,
wheel=built_wheel,
dest_dir=repaired_wheel_dir,
project=".",
)
shell(repair_command_prepared, env=env)
log.step_end()
Expand Down
1 change: 1 addition & 0 deletions cibuildwheel/platforms/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ def build(options: Options, tmp_path: Path) -> None:
build_options.repair_command,
wheel=built_wheel,
dest_dir=repaired_wheel_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 @@ -904,6 +904,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 `{project}` placeholder in your `repair-wheel-command` to the project root.

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
31 changes: 31 additions & 0 deletions test/test_custom_repair_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,34 @@ 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-")


def test_project_placeholder(tmp_path, capfd):
# Identical to the previous test with the additional assumption that the {project}
# placeholder has been replaced correctly

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 {project}/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-")