Respect metadata_directory in build_wheel per PEP 517#3086
Respect metadata_directory in build_wheel per PEP 517#3086
metadata_directory in build_wheel per PEP 517#3086Conversation
There was a problem hiding this comment.
Pull request overview
Implements PEP 517 build_wheel(..., metadata_directory=...) support by reusing pre-generated .dist-info metadata created by prepare_metadata_for_build_wheel, enabling wrapper backends to adjust metadata without repacking wheels.
Changes:
- Python PEP 517 wrapper passes
metadata_directoryto the Rust subprocess viaMATURIN_PEP517_METADATA_DIR. - Rust wheel metadata writer conditionally copies
.dist-infocontents fromMATURIN_PEP517_METADATA_DIR, while always regeneratingWHEELand skippingRECORD. - Adds a unit test ensuring copied metadata is used and
WHEEL/RECORDbehaviors are correct.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/module_writer/mod.rs |
Adds env-var-driven branch to copy pre-generated .dist-info content into the wheel. |
src/module_writer/mock_writer.rs |
Adds unit test for env-var metadata directory behavior (copy vs regenerate/skip). |
maturin/__init__.py |
Propagates metadata_directory into the maturin subprocess environment. |
You can also share your feedback on Copilot code review. Take the survey.
c5a6b8f to
5c7c6cf
Compare
There was a problem hiding this comment.
Pull request overview
Implements PEP 517’s build_wheel(..., metadata_directory=...) behavior by allowing the wheel build step to reuse pre-generated .dist-info metadata (typically produced by prepare_metadata_for_build_wheel), enabling wrappers that adjust metadata without repacking the wheel.
Changes:
- Python: when
metadata_directoryis provided tobuild_wheel, pass it to the Rust subprocess viaMATURIN_PEP517_METADATA_DIR. - Rust:
write_dist_info()can copy existing.dist-infocontents from disk (skippingRECORD, regeneratingWHEEL) instead of regenerating all metadata. - Tests: add a unit test asserting that copied metadata is used and that
WHEEL/RECORDhandling is correct.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/module_writer/mod.rs |
Adds env-var-controlled path to reuse/copy pre-generated .dist-info metadata during wheel creation. |
src/module_writer/mock_writer.rs |
Adds a test covering the “reuse pre-generated metadata” path and validates WHEEL regeneration / RECORD omission. |
maturin/__init__.py |
Sets MATURIN_PEP517_METADATA_DIR for the Rust subprocess when metadata_directory is provided to build_wheel. |
You can also share your feedback on Copilot code review. Take the survey.
When a PEP 517 frontend passes metadata_directory to build_wheel, the built wheel should use the pre-generated metadata from that directory. This enables wrapping build backends that modify metadata in prepare_metadata_for_build_wheel. Python side: when metadata_directory is not None, set MATURIN_PEP517_METADATA_DIR in the subprocess environment. Rust side: write_dist_info() checks the env var and copies files from the pre-existing .dist-info directory instead of regenerating them. The WHEEL file is always regenerated to ensure correct tags, and RECORD is skipped since it is generated by WheelWriter::finish(). If the env var is set but the expected directory does not exist, an error is raised instead of silently falling back. Fixes PyO3#1973
5c7c6cf to
a0dca02
Compare
When a PEP 517 frontend passes
metadata_directorytobuild_wheel, the built wheel should use the pre-generated metadata from that directory. This enables wrapping build backends that modify metadata inprepare_metadata_for_build_wheel.Python side: when
metadata_directoryis not None, setMATURIN_PEP517_METADATA_DIRin the subprocess environment.Rust side:
write_dist_info()checks the env var and copies files from the pre-existing .dist-info directory instead of regenerating them. The WHEEL file is always regenerated to ensure correct tags, andRECORDis skipped since it is generated byWheelWriter::finish(). If the env var is set but the expected directory does not exist, an error is raised instead of silently falling back.Fixes #1973