Skip to content

Put all License-File entries at the sdist root - #3331

Merged
messense merged 1 commit into
PyO3:mainfrom
Fatin-Ishraq:fix/sdist-workspace-license-files
Oct 22, 2026
Merged

messense merged 1 commit into
PyO3:mainfrom
Fatin-Ishraq:fix/sdist-workspace-license-files

Conversation

@Fatin-Ishraq

Copy link
Copy Markdown
Contributor

Fixes #3327.

License-File paths in an sdist's PKG-INFO are relative to the sdist root, but only explicit project.license-files were copied there (#2704). Auto-discovered license files (no license-files, or license-files in project.dynamic) and Cargo's license-file were only packaged next to their crate. That is not the sdist root when pyproject.toml is moved up for a workspace member, or when the crate is in a subdirectory via manifest-path. PyPI rejects these uploads, which is how pyo3-introspection 0.30.0 failed (worked around in PyO3/pyo3#6528; PyO3/pyo3#6130 had earlier blamed license symlinks for the same failure). For auto-discovered licenses, a wheel built from the sdist also lost them.

This adds one pass before PKG-INFO is written that copies every entry of metadata24.license_files to the sdist root, resolving the source the same way write_dist_info does for wheels. So every License-File in PKG-INFO now exists at that path in the sdist. If a file is already at that path it is kept, so working layouts don't change; if its content differs, maturin prints a warning instead of failing.

Before / after, maturin sdist, then maturin build from the unpacked sdist:

  • workspace member with LICENSE-APACHE + LICENSE-MIT and dynamic = ["license-files"] (the pyo3-introspection shape): both missing at the root, and the wheel built from the sdist had no licenses → both at the root, and both in the wheel
  • pyproject.toml + LICENSE at the root, crate in rust/ via manifest-path: LICENSE not in the sdist at all, and the wheel had no license → included, and in the wheel
  • explicit license-files, and a plain single-crate package: sdists byte-identical to before
  • member whose root crate (a path dependency) already put a different LICENSE at that path: sdist byte-identical to before, plus a warning

Testing:

  • The new test sdist_auto_discovered_license_files_at_sdist_root covers the workspace-member and manifest-path layouts. It fails on main and passes with this change.
  • The real pyo3-introspection sdist at PyO3 240dae5 (just before pyo3-introspection sdist: skip maturin license lookup pyo3#6528) now has both licenses at the root, and a wheel built from it includes them.
  • twine check passes on the broken sdist, so the test parses PKG-INFO and checks each License-File against the tarball directly.
  • cargo test --test run -- sdist pep517 and cargo test --lib pass (on Windows), and cargo fmt is clean.
  • The change adds no clippy warnings. On Windows, cargo clippy --tests --all-features -- -D warnings stops on 11 unused imports in the #[cfg(unix)] tests of src/module_writer/mod.rs; main has the same errors.

#2531 reported the same symptom earlier and was closed by the PEP 639 work (#2647), which didn't cover auto-discovered files. #3049 (including arbitrary workspace-root files) is related but not addressed here.

Thanks to @davidhewitt for the report and the analysis in PyO3/pyo3#6528, and to @Viicos for narrowing it down to the non-explicit license-files case.

I used Claude to help investigate and write this; I reviewed and tested every change.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused implementation addresses the reported layouts with regression coverage and no identified blocking issues.

No open issues 🎉

What changed in this PR

Ensures every License-File entry in sdist metadata exists relative to the archive root, addressing missing licenses in workspace-member and subdirectory layouts.

Changes:

  • Copies recorded license files to their metadata paths, preserving existing files and warning on content conflicts.
  • Adds source-path lookup support to the virtual writer.
  • Adds regression coverage for both affected layouts.
File Description
tests/​run/​sdist.rs Checks license metadata paths against archive contents in both layouts.
src/​source_distribution/​mod.rs Adds the license-copy pass before writing PKG-INFO.
src/​module_writer/​virtual_writer.rs Exposes tracked source paths for conflict checks.

Review effort: Balanced

@messense

This comment was marked as resolved.

`License-File` paths in `PKG-INFO` are relative to the sdist root, but only
explicit `project.license-files` were copied there. Auto-discovered license
files (no `license-files`, or `license-files` in `project.dynamic`) and
Cargo's `license-file` were only packaged next to their crate. When
`pyproject.toml` is moved to the sdist root above the crate, e.g. for a cargo
workspace member, or when the crate lives in a subdirectory via
`manifest-path`, the listed paths did not exist in the sdist. PyPI rejects
such uploads (`pyo3-introspection` 0.30.0 hit this), and for auto-discovered
license files a wheel built from the sdist silently lost them too.

After the other sdist files are added, copy every entry of
`metadata24.license_files` to the sdist root, resolving the source the same
way `write_dist_info` does for wheels. A file already present at that path is
kept, so layouts that work today are unchanged; if its content differs from
the license file maturin found, print a warning.

Fixes PyO3#3327
@messense
messense force-pushed the fix/sdist-workspace-license-files branch from 98693fa to 49f42b4 Compare October 21, 2026 14:02
@messense
messense enabled auto-merge (squash) October 21, 2026 14:02
@messense
messense force-pushed the fix/sdist-workspace-license-files branch from dd39f31 to 49f42b4 Compare October 21, 2026 14:06
@messense
messense merged commit 979aad0 into PyO3:main Oct 22, 2026
83 of 85 checks passed
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.

sdist of package which is child of workspace has broken license files

3 participants