Skip to content

sdist fails to install when maturin project is a Cargo workspace member #3181

@ybjeon01

Description

@ybjeon01

Bug Description

When a maturin project lives inside a Cargo workspace (i.e., the pyproject.toml is in a subdirectory of the workspace root), maturin sdist produces an inconsistent archive structure:

pyproject.toml is elevated to the sdist root
The Python package directory is elevated to the sdist root
But files referenced by pyproject.toml (e.g., README.md via [project.readme]) are not elevated — they remain under the original subdirectory path

This causes pip install from the sdist to fail with:

$ pip install ../target/wheels/python_pkg-0.1.0.tar.gz
Processing /home/ybjeon01/work/study/temp/issue-reproduction/repro/target/wheels/python_pkg-0.1.0.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      💥 maturin failed
        Caused by: Failed to read readme specified in pyproject.toml, which should be at /tmp/pip-req-build-fbfqa0q8/README.md
        Caused by: failed to open file `/tmp/pip-req-build-fbfqa0q8/README.md`: No such file or directory (os error 2)
      Error running maturin: Command '['maturin', 'pep517', 'write-dist-info', '--metadata-directory', '/tmp/pip-modern-metadata-z8annbi1', '--interpreter', '/home/ybjeon01/work/study/temp/issue-reproduction/venv/bin/python3']' returned non-zero exit status 1.
      Checking for Rust toolchain....
      Running `maturin pep517 write-dist-info --metadata-directory /tmp/pip-modern-metadata-z8annbi1 --interpreter /home/ybjeon01/work/study/temp/issue-reproduction/venv/bin/python3`
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Project structure

repro/                             <- git root + Cargo workspace root
  Cargo.toml                    <- [workspace] definition
  Cargo.lock
  python-pkg/                 <- maturin project
    pyproject.toml            <-[project.readme] file = "README.md"
    README.md
    Cargo.toml
    src/
    my_pkg/

Actual sdist structure (maturin sdist)

my-pkg-0.1.0/
  pyproject.toml           <- elevated from python-pkg/
  my_pkg/                    <- elevated from python-pkg/my_pkg/
  Cargo.toml                <- workspace root
  Cargo.lock                 <- workspace root
  python-pkg/
    README.md            <- NOT elevated  (still in subdirectory)
    Cargo.toml

Expected sdist structure

my-pkg-0.1.0/
  pyproject.toml
  README.md                 <- should be at root alongside pyproject.toml
  my_pkg/
  Cargo.toml
  Cargo.lock

Environment
rustc: 1.94.0 (4a4ef493e 2026-03-02)
OS: Ubuntu

Your maturin version (maturin --version)

1.13.1

Your Python version (python -V)

3.12.3

Your pip version (pip -V)

pip 24.0

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. Create workspace root
mkdir repro && cd repro

cat > Cargo.toml << 'EOF'
[workspace]
members = [
    "python-pkg"
]
resolver = "3"
EOF
  1. Create maturin project
maturin new python-pkg
cd python-pkg
  1. Create README.md
echo "# my-pkg" > README.md
  1. Add readme section to pyproject.toml
cat >> pyproject.toml << 'EOF'

[project.readme]
file = "README.md"
content-type = "text/markdown"
EOF
  1. Build sdist
maturin sdist
  1. Install
pip install ../target/wheels/python_pkg-0.1.0.tar.gz

Metadata

Metadata

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions