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:
- By adding
sdist-generator = "git"
under tool.maturin, or - 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
mkdir foobar && cd foobar
- Cargo.toml
[workspace.package]
version = "0.1.0"
authors = ["footang"]
edition = "2021"
publish = false
[workspace]
members = ["**/src/rust/*"]
resolver = "2"
- 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"
- 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"]
- 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(())
}
-
touch src/python/pyfoo/bar.html
-
git init && git add . && git commit -m "mre"
-
.gitignore
# Cargo
.cargo/
Cargo.lock
target/
# Environments
.venv
*.html
- Run
maturin build --sdist
and observe the built sdist undertarget/wheels/foo-0.1.0.tar.gz
does not containbar.html
. (I usedmaturin 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