Skip to content

Respect PEP 621 dynamic fields when merging Cargo.toml metadata #2672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 11, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 11, 2025

Summary

Fixes #2544 by ensuring maturin only includes metadata fields from Cargo.toml when they are explicitly declared as dynamic in pyproject.toml, in compliance with PEP 621.

Problem

Previously, maturin would unconditionally include metadata fields like description, authors, keywords, and urls from Cargo.toml into wheel metadata, even when these fields were not declared in the dynamic list in pyproject.toml. This violates PEP 621, which states:

Build backends MUST NOT add metadata fields that are not specified in either the [project] table or listed in dynamic.

Example

Before this fix:

# Cargo.toml
[package]
name = "my-package"
description = "Description from Cargo.toml"
authors = ["Author <author@example.com>"]
keywords = ["rust", "python"]

# pyproject.toml  
[project]
name = "my-package"
version = "0.1.0"
# No dynamic field specified - should default to empty list

The wheel metadata would incorrectly include:

  • Summary: Description from Cargo.toml
  • Author: Author <author@example.com>
  • Keywords: rust,python

After this fix:
The wheel metadata only includes fields from pyproject.toml and respects the dynamic list:

  • Only Name: my-package and Version: 0.1.0 are included
  • Cargo.toml fields are ignored unless declared as dynamic

To include Cargo.toml fields, they must be explicitly declared:

[project]
name = "my-package"  
version = "0.1.0"
dynamic = ["description", "authors", "keywords", "urls"]

Changes

  1. Core fix: Modified Metadata24::merge_pyproject_toml() to clear metadata fields from Cargo.toml that are not declared in the dynamic list
  2. Backward compatibility: Updated test pyproject.toml files to declare necessary fields as dynamic to maintain existing test behavior
  3. Comprehensive testing: Added test cases covering both scenarios (with and without dynamic fields)

Testing

  • ✅ All unit tests pass
  • ✅ Added test_issue_2544_respect_pyproject_dynamic() to verify fields are excluded when not in dynamic list
  • ✅ Added test_issue_2544_respect_pyproject_dynamic_with_dynamic_fields() to verify fields are included when in dynamic list
  • ✅ Manually verified with end-to-end wheel builds
  • ✅ Updated existing test cases to maintain compatibility

Fields Affected

The following metadata fields now respect the dynamic list:

  • descriptionsummary in wheel metadata
  • authorsauthor and author-email
  • maintainersmaintainer and maintainer-email
  • keywordskeywords
  • urlsproject-url
  • licenselicense
  • classifiersclassifiers
  • readmedescription and description-content-type
  • requires-pythonrequires-python

This 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.

Copilot AI and others added 3 commits July 11, 2025 07:13
…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 Copilot AI changed the title [WIP] Fix issue @PyO3/maturin/issues/2544 Fix issue #2544: Respect PEP 621 dynamic fields when merging Cargo.toml metadata Jul 11, 2025
@Copilot Copilot AI requested a review from messense July 11, 2025 07:27
Copilot finished work on behalf of messense July 11, 2025 07:27
@messense
Copy link
Member

@copilot run cargo fmt to format Rust code.

Co-authored-by: messense <1556054+messense@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 11, 2025

@copilot run cargo fmt to format Rust code.

Done! Rust code formatted with cargo fmt in commit 6b1ce42.

Copilot finished work on behalf of messense July 11, 2025 07:32
@messense
Copy link
Member

@copilot run pre-commit

Copy link
Contributor Author

Copilot AI commented Jul 11, 2025

@copilot run pre-commit

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:

cargo fmt --all - Rust code formatting
✅ TOML syntax validation for all modified files
✅ End-of-file newline fixes applied
✅ Trailing whitespace check passed
✅ Code builds successfully
✅ All tests pass (including new issue #2544 tests)

The most important formatting and validation checks have been completed successfully.

Copilot finished work on behalf of messense July 11, 2025 07:51
@messense
Copy link
Member

@copilot fix cargo clippy warnings and errors.

Co-authored-by: messense <1556054+messense@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 11, 2025

@copilot fix cargo clippy warnings and errors.

Fixed all cargo clippy warnings by updating format strings to use the inline syntax. All 11 warnings related to uninlined_format_args have been resolved in commit 3ac48b2.

Copilot finished work on behalf of messense July 11, 2025 08:02
@messense
Copy link
Member

@copilot fix trailing whitespace in src/metadata.rs

Co-authored-by: messense <1556054+messense@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 11, 2025

@copilot fix trailing whitespace in src/metadata.rs

Fixed trailing whitespace in src/metadata.rs in commit 83ee634.

Copilot finished work on behalf of messense July 11, 2025 08:22
@messense messense marked this pull request as ready for review July 11, 2025 10:43
@messense messense changed the title Fix issue #2544: Respect PEP 621 dynamic fields when merging Cargo.toml metadata Respect PEP 621 dynamic fields when merging Cargo.toml metadata Jul 11, 2025
@messense messense enabled auto-merge (squash) July 11, 2025 10:49
@messense messense merged commit 3b0b82a into main Jul 11, 2025
42 checks passed
@messense messense deleted the copilot/fix-cb142bb3-e434-4c10-ad81-bfaf2a1de508 branch July 11, 2025 11:09
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Aug 6, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

maturin add non-dynamic fields to wheel metadata
2 participants