Skip to content

fix: resolve include patterns relative to python-source for sdist and wheel#3000

Merged
messense merged 2 commits intoPyO3:mainfrom
messense:fix/include-pattern-python-source
Feb 15, 2026
Merged

fix: resolve include patterns relative to python-source for sdist and wheel#3000
messense merged 2 commits intoPyO3:mainfrom
messense:fix/include-pattern-python-source

Conversation

@messense
Copy link
Member

When python-source is set (e.g. python-source = "src/python"), include patterns like include = ["pyfoo/bar.html"] now work for both sdist and wheel targets. Previously, patterns were only resolved relative to pyproject.toml, so the file at src/python/pyfoo/bar.html would not be found.

The fix tries the primary root (pyproject.toml dir) first, then falls back to python_dir if no files matched. For wheel, files inside python_dir are stripped to package-relative paths. For sdist, they are mapped back to preserve the source layout.

Also fixes wheel include with explicit paths like
include = ["src/python/pyfoo/bar.html"] which previously placed files at the wrong path in the wheel.

Shared glob resolution logic is extracted into
src/module_writer/glob.rs with input validation rejecting absolute paths and `.." components.

Closes #2320

@messense messense requested a review from Copilot February 15, 2026 02:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes include glob resolution so patterns work consistently when python-source is configured, for both sdist and wheel outputs.

Changes:

  • Resolve include patterns relative to pyproject.toml first, then fall back to python-source when no matches are found.
  • Normalize wheel vs sdist target paths for matches found under python-source.
  • Extract shared glob resolution + validation into src/module_writer/glob.rs and update docs/schema.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/source_distribution.rs Uses shared glob resolver and maps python-source matches back into sdist source layout.
src/pyproject_toml.rs Updates rustdoc for include/exclude path resolution behavior.
src/module_writer/mod.rs Uses shared glob resolver and normalizes wheel target paths for python-source.
src/module_writer/glob.rs New shared glob resolution + validation helpers with unit tests.
maturin.schema.json Updates schema descriptions for include/exclude resolution rules.
guide/src/config.md Documents fallback behavior when python-source is set.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

… wheel

When `python-source` is set (e.g. `python-source = "src/python"`),
include patterns like `include = ["pyfoo/bar.html"]` now work for both
sdist and wheel targets. Previously, patterns were only resolved relative
to `pyproject.toml`, so the file at `src/python/pyfoo/bar.html` would
not be found.

The fix tries the primary root (pyproject.toml dir) first, then falls
back to `python_dir` if no files matched. For wheel, files inside
`python_dir` are stripped to package-relative paths. For sdist, they
are mapped back to preserve the source layout.

Also fixes wheel include with explicit paths like
`include = ["src/python/pyfoo/bar.html"]` which previously placed
files at the wrong path in the wheel.

Shared glob resolution logic is extracted into
`src/module_writer/glob.rs` with input validation rejecting absolute
paths and `.." components.

Closes PyO3#2320
@messense messense force-pushed the fix/include-pattern-python-source branch from 6bc7c6c to 159f188 Compare February 15, 2026 03:36
@messense messense force-pushed the fix/include-pattern-python-source branch from f5a4566 to f3eabca Compare February 15, 2026 04:48
@messense messense merged commit 8f8f9f7 into PyO3:main Feb 15, 2026
45 checks passed
@messense messense deleted the fix/include-pattern-python-source branch February 15, 2026 06:06
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.

Include pattern treated differently when building sdist versus wheel

1 participant