Skip to content
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

Include pattern treated differently when building sdist versus wheel #2320

Open
1 of 2 tasks
ckutlu opened this issue Nov 25, 2024 · 0 comments
Open
1 of 2 tasks

Include pattern treated differently when building sdist versus wheel #2320

ckutlu opened this issue Nov 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ckutlu
Copy link

ckutlu commented Nov 25, 2024

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)
@ckutlu ckutlu added the bug Something isn't working label Nov 25, 2024
@ckutlu ckutlu changed the title Include pattern behaves differently when building sdist versus wheel Include pattern treated differently when building sdist versus wheel Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant