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 <joerick@mac.com>
This commit is contained in:
co-authored by
Joe Rickerby
parent
ccbae30b53
commit
f6c810852d
@@ -447,7 +447,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,
|
||||
)
|
||||
|
||||
@@ -322,7 +322,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:
|
||||
|
||||
@@ -522,6 +522,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:
|
||||
|
||||
@@ -439,6 +439,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()
|
||||
|
||||
@@ -518,6 +518,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:
|
||||
|
||||
@@ -907,6 +907,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/>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import subprocess
|
||||
import textwrap
|
||||
from contextlib import nullcontext as does_not_raise
|
||||
|
||||
import pytest
|
||||
@@ -56,3 +57,42 @@ 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 / "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"]
|
||||
|
||||
Reference in New Issue
Block a user