Skip to content

Commit 58e0a1d

Browse files
arcondellohenryiii
authored andcommitted
Make the {project} placeholder available to repair-wheel-command
1 parent ad4c9d1 commit 58e0a1d

File tree

7 files changed

+38
-2
lines changed

7 files changed

+38
-2
lines changed

cibuildwheel/platforms/android.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ def repair_wheel(state: BuildState, built_wheel: Path) -> Path:
442442
state.options.repair_command,
443443
wheel=built_wheel,
444444
dest_dir=repaired_wheel_dir,
445+
package=state.options.package_dir,
445446
project=".",
446447
),
447448
env=state.build_env,

cibuildwheel/platforms/linux.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ def build_in_container(
323323
build_options.repair_command,
324324
wheel=built_wheel,
325325
dest_dir=repaired_wheel_dir,
326+
package=container_package_dir,
326327
project=container_project_path,
327328
)
328329
container.call(["sh", "-c", repair_command_prepared], env=env)

cibuildwheel/platforms/macos.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ def build(options: Options, tmp_path: Path) -> None:
528528
wheel=built_wheel,
529529
dest_dir=repaired_wheel_dir,
530530
delocate_archs=delocate_archs,
531+
package=build_options.package_dir,
531532
project=".",
532533
)
533534
shell(repair_command_prepared, env=env)

cibuildwheel/platforms/pyodide.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ def build(options: Options, tmp_path: Path) -> None:
443443
build_options.repair_command,
444444
wheel=built_wheel,
445445
dest_dir=repaired_wheel_dir,
446+
package=build_options.package_dir,
446447
project=".",
447448
)
448449
shell(repair_command_prepared, env=env)

cibuildwheel/platforms/windows.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ def build(options: Options, tmp_path: Path) -> None:
525525
build_options.repair_command,
526526
wheel=built_wheel,
527527
dest_dir=repaired_wheel_dir,
528+
package=build_options.package_dir,
528529
project=".",
529530
)
530531
shell(repair_command_prepared, env=env)

docs/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ The following placeholders must be used inside the command and will be replaced
906906
- `{dest_dir}` for the absolute path of the directory where to create the repaired wheel
907907
- `{delocate_archs}` (macOS only) comma-separated list of architectures in the wheel.
908908

909-
You can use the `{project}` placeholder in your `repair-wheel-command` to the project root.
909+
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.
910910

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

test/test_custom_repair_wheel.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test(tmp_path, capfd):
5858
assert result[0].startswith("spam-0.1.0-py2-none-")
5959

6060

61-
def test_project_placeholder(tmp_path, capfd):
61+
def test_package_placeholder(tmp_path, capfd):
6262
# Identical to the previous test with the additional assumption that the {project}
6363
# placeholder has been replaced correctly
6464

@@ -70,6 +70,37 @@ def test_project_placeholder(tmp_path, capfd):
7070
pytest.raises(subprocess.CalledProcessError) if num_builds > 1 else does_not_raise()
7171
)
7272

73+
with expectation as exc_info:
74+
result = utils.cibuildwheel_run(
75+
project_dir,
76+
add_env={
77+
"CIBW_REPAIR_WHEEL_COMMAND": "python {package}/repair.py {wheel} {dest_dir}",
78+
},
79+
)
80+
81+
captured = capfd.readouterr()
82+
if num_builds > 1:
83+
assert exc_info is not None
84+
assert "Build failed because a wheel named" in captured.err
85+
assert exc_info.value.returncode == 6
86+
else:
87+
# We only produced one wheel (perhaps Pyodide)
88+
# check that it has the right name
89+
assert result[0].startswith("spam-0.1.0-py2-none-")
90+
91+
92+
def test_project_placeholder(tmp_path, capfd):
93+
# Identical to the previous two tests with the additional assumption that the {package}
94+
# placeholder has been replaced correctly
95+
96+
project_dir = tmp_path / "project"
97+
basic_project.generate(project_dir)
98+
99+
num_builds = len(utils.cibuildwheel_get_build_identifiers(project_dir))
100+
expectation = (
101+
pytest.raises(subprocess.CalledProcessError) if num_builds > 1 else does_not_raise()
102+
)
103+
73104
with expectation as exc_info:
74105
result = utils.cibuildwheel_run(
75106
project_dir,

0 commit comments

Comments
 (0)