Respect PEP 621 dynamic fields when merging Cargo.toml metadata#2672
Respect PEP 621 dynamic fields when merging Cargo.toml metadata#2672
Conversation
…from Cargo.toml Co-authored-by: messense <1556054+messense@users.noreply.github.com>
…ml metadata - Add logic to only include Cargo.toml metadata fields when explicitly declared as dynamic in pyproject.toml - Update test pyproject.toml files to declare necessary fields as dynamic for backward compatibility - Add comprehensive test cases for both behaviors (with and without dynamic fields) - Manually verified the fix works end-to-end with real wheel builds Co-authored-by: messense <1556054+messense@users.noreply.github.com>
…yproject.toml This maintains compatibility with the existing test expectations while respecting PEP 621 dynamic field requirements. Co-authored-by: messense <1556054+messense@users.noreply.github.com>
|
@copilot run |
Co-authored-by: messense <1556054+messense@users.noreply.github.com>
|
@copilot run |
I've run the pre-commit checks. Due to network connectivity issues, I couldn't install all external tools, but I completed the core checks: ✅ The most important formatting and validation checks have been completed successfully. |
|
@copilot fix |
Co-authored-by: messense <1556054+messense@users.noreply.github.com>
|
@copilot fix trailing whitespace in |
Co-authored-by: messense <1556054+messense@users.noreply.github.com>
https://build.opensuse.org/request/show/1297806 by user mia + dimstar_suse - Update to 1.9.3 * Add support for RISC-V architecture in manylinux gh#PyO3/maturin#2694 * pyproject.toml: bump setuptools for PEP 639 gh#PyO3/maturin#2698 * Fix PEP 639 support for source distributions gh#PyO3/maturin#2704 * Fix relative README rewrite in source distributions gh#PyO3/maturin#2705 - Update to 1.9.2 * Respect PEP 621 dynamic fields when merging Cargo.toml metadata gh#PyO3/maturin#2672 * Only use all_features=true in sdist when local path dependencies exist gh#PyO3/maturin#2674 * auditwheel: add manylinux_2_26 policy gh#PyO3/maturin#2677 * Use user-specified library search paths in RUSTFLAGS in auditwheel gh#PyO3/maturin#2676 * pyproject.toml: add license-files gh#PyO3/maturin#2690 * Update manylinux/musllinux
|
This is an important bugfix. I noticed that the latest version of Maturin behaves correctly, and that older versions did not, but I couldn’t find anything in the changelog about this fix. Only when I tested a few different versions, and then read through the |
… metadata We extend the `dynamic` field in `pyproject.toml` to ensure that the Python package is built with all the metadata defined in `Cargo.toml`. The behavior of `maturin` has changed to omit metadata defined in `Cargo.toml` unless the corresponding `pyproject.toml` fields are specifed as `dynamic`, cf. PyO3/maturin#2672
Summary
Fixes #2544 by ensuring maturin only includes metadata fields from
Cargo.tomlwhen they are explicitly declared asdynamicinpyproject.toml, in compliance with PEP 621.Problem
Previously, maturin would unconditionally include metadata fields like
description,authors,keywords, andurlsfromCargo.tomlinto wheel metadata, even when these fields were not declared in thedynamiclist inpyproject.toml. This violates PEP 621, which states:Example
Before this fix:
The wheel metadata would incorrectly include:
Summary: Description from Cargo.tomlAuthor: Author <author@example.com>Keywords: rust,pythonAfter this fix:
The wheel metadata only includes fields from
pyproject.tomland respects the dynamic list:Name: my-packageandVersion: 0.1.0are includedTo include Cargo.toml fields, they must be explicitly declared:
Changes
Metadata24::merge_pyproject_toml()to clear metadata fields from Cargo.toml that are not declared in thedynamiclistpyproject.tomlfiles to declare necessary fields as dynamic to maintain existing test behaviorTesting
test_issue_2544_respect_pyproject_dynamic()to verify fields are excluded when not in dynamic listtest_issue_2544_respect_pyproject_dynamic_with_dynamic_fields()to verify fields are included when in dynamic listFields Affected
The following metadata fields now respect the dynamic list:
description→summaryin wheel metadataauthors→authorandauthor-emailmaintainers→maintainerandmaintainer-emailkeywords→keywordsurls→project-urllicense→licenseclassifiers→classifiersreadme→descriptionanddescription-content-typerequires-python→requires-pythonThis ensures full PEP 621 compliance while maintaining backward compatibility for projects that explicitly declare their dynamic fields.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.