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

sdist fails to build if crate is in a subdirectory of a workspace #1803

Closed
1 of 2 tasks
Shadow53 opened this issue Oct 12, 2023 · 1 comment · Fixed by #1811
Closed
1 of 2 tasks

sdist fails to build if crate is in a subdirectory of a workspace #1803

Shadow53 opened this issue Oct 12, 2023 · 1 comment · Fixed by #1811
Labels
bug Something isn't working sdist Source distribution

Comments

@Shadow53
Copy link

Bug Description

When building an sdist file, the workspace Cargo.toml file added to the sdist has the workspace.members field conspicuously removed, causing the build of the sdist to fail with the following error:

  Running command Preparing metadata (pyproject.toml)
  error: current package believes it's in a workspace when it's not:
  current:   /tmp/pip-req-build-_gj0kdlu/crates/word-count/Cargo.toml
  workspace: /tmp/pip-req-build-_gj0kdlu/Cargo.toml

  this may be fixable by adding `crates/word-count` to the `workspace.members` array of the manifest located at: /tmp/pip-req-build-_gj0kdlu/Cargo.toml
  Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest.
  💥 maturin failed
    Caused by: Cargo metadata failed. Does your crate compile with `cargo build`?
    Caused by: `cargo metadata` exited with an error:
  Error running maturin: Command '['maturin', 'pep517', 'write-dist-info', '--metadata-directory', '/tmp/pip-modern-metadata-niydeb24', '--interpreter', '/usr/bin/python3']' returned non-zero exit status 1.
  Checking for Rust toolchain....
  Running `maturin pep517 write-dist-info --metadata-directory /tmp/pip-modern-metadata-niydeb24 --interpreter /usr/bin/python3`
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

As best as I can figure out, this is caused by having workspace members in a common subdirectory in the workspace. That is, instead of this structure...

.
├── Cargo.lock
├── Cargo.toml
└── word-count
    ├── Cargo.toml
    └── [etc.]

... the workspace looks like this:

.
├── Cargo.lock
├── Cargo.toml
└── crates
    └── word-count
        ├── Cargo.toml
        └── [etc.]

If I make the example look like the first file structure, building from the sdist is successful.

Your maturin version (maturin --version)

1.3.0

Your Python version (python -V)

3.11.2

Your pip version (pip -V)

23.0.1

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. Clone the repository at https://github.com/Shadow53/maturin-sdist-repro
  2. Follow the directions in the README.md
@Shadow53 Shadow53 added the bug Something isn't working label Oct 12, 2023
@messense messense added the sdist Source distribution label Oct 12, 2023
@messense
Copy link
Member

Thanks for the report, unfortuntely I may not have time to look into it this week.

If you feel like to investigate, the relevant code is in mostly in https://github.com/PyO3/maturin/blob/main/src/source_distribution.rs, change the code then run cargo run sdist -m <path to the binding Cargo.toml> -o dist to generate a sdist in $PWD/dist/, unpack it then run maturin build in it to verify the build. Pull requests are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sdist Source distribution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants