Skip to content

Include pattern treated differently when building sdist versus wheel #2320

Open
@ckutlu

Description

Bug Description

Hi there! I noticed that when doing maturin build --sdist on a git managed repo with data files, the files included in the wheel were omitted in the sdist. After investigating further, I realized the pattern matching behavior for the entries in tool.maturin.include differs for sdist and wheel targets. Let me try to explain:

The folder structure is:

.
├──.gitignore
├── Cargo.lock
├── Cargo.toml
├── pyproject.toml
└── src
    ├── python
    │   └── pyfoo
    │       ├── bar.html
    │       └── __init__.py
    └── rust
        └── rustfoo
            ├── Cargo.toml
            └── src
                └── lib.rs

pyproject.toml contains

[tool.maturin]
manifest-path = "./src/rust/rustfoo/Cargo.toml"
module-name = "foobar.rustfoo"

python-source = "src/python"
python-packages = ["pyfoo"]

include = ["pyfoo/bar.html"]

and .gitignore contains

*.html

Note that bar.html is already committed to the repo. Now if I do maturin build --sdist, the resulting tarball does not contain bar.html but the wheel has it. To include it in both, one can do either:

  1. By adding sdist-generator = "git" under tool.maturin, or
  2. By modifying include to have separate entries for wheel and sdist
include = [{ path = "src/python/pyfoo/bar.html", format = "sdist"}, {path = "pyfoo/bar.html", format="wheel"}]

or
3. By having an extra bit of globbing in the path, e.g. include = ["**/pyfoo/bar.html"].

Option 1 only works if bar.html is committed to the repo. Option 2 creates unnecessary duplication. Option 3 is fine as a workaround but I would expect the behavior without double wildcard to be the same.

Your maturin version (maturin --version)

1.7.4

Your Python version (python -V)

3.9.20

Your pip version (pip -V)

uv-pip 0.4.20

What bindings you're using

pyo3

Does cargo build work?

  • Yes, it works

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

  • Yes

Steps to Reproduce

  1. mkdir foobar && cd foobar
  2. Cargo.toml
[workspace.package]
version = "0.1.0"
authors = ["footang"]
edition = "2021"
publish = false

[workspace]
members = ["**/src/rust/*"]
resolver = "2"
  1. pyproject.toml
[build-system]
requires = ["maturin>=1.7,<2.0"]
build-backend = "maturin"

[project]
name = "pyfoo"
requires-python = ">=3.9"
version = "0.1.0"

[tool.maturin]
manifest-path = "./src/rust/rustfoo/Cargo.toml"
module-name = "pyfoo.rustfoo"

python-source = "src/python"
python-packages = ["pyfoo"]

include = ["pyfoo/bar.html"]

# sdist-generator = "git"
  1. src/rust/rustfoo/Cargo.toml
[package]
name = "rustfoo"
version.workspace = true
authors.workspace = true
edition.workspace = true
publish.workspace = true

[lib]
name = "rustfoo"
crate-type = ["cdylib"]

[dependencies.pyo3]
version = "0.22.2"

[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]
  1. src/rust/rustfoo/src/lib.rs
use pyo3::prelude::*;

/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
    Ok((a + b).to_string())
}

/// A Python module implemented in Rust.
#[pymodule]
fn rustfoo(m: &Bound<'_, PyModule>) -> PyResult<()> {
    m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
    Ok(())
}
  1. touch src/python/pyfoo/bar.html

  2. git init && git add . && git commit -m "mre"

  3. .gitignore

# Cargo
.cargo/
Cargo.lock
target/

# Environments
.venv

*.html
  1. Run maturin build --sdist and observe the built sdist under target/wheels/foo-0.1.0.tar.gz does not contain bar.html. (I used maturin build --sdist --zig && tar xzf target/wheels/pyfoo-0.1.0.tar.gz && ls -ahl pyfoo-0.1.0/src/python/pyfoo && rm -rf target && rm -rf pyfoo-0.1.0 to quickly iterate on changes)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions