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

Match dependency readmes by package id #1915

Merged
merged 1 commit into from Jan 22, 2024

Conversation

konstin
Copy link
Member

@konstin konstin commented Jan 19, 2024

We have a project which depends on a vendored version of pep440_rs, while some of our dependencies depend on the crates.io version. The published version uses Readme.md, while the vendored one follows a different convention and uses README.md. This causes maturin sdist to fail:

🍹 Building a mixed python/rust project
🔗 Found bin bindings
📡 Using build options bindings from pyproject.toml
💥 maturin failed
  Caused by: Failed to build source distribution
  Caused by: failed to normalize path `Readme.md`
  Caused by: No such file or directory (os error 2)

Internally, maturin uses the package name to match dependencies with their resolved readme. This failed in our cased since the second entry for pep440_rs with the crates.io readme was overwriting the first entry with the project local readme.

The fix is to match by package id instead. The implementation is somewhat awkward, since there's no API to get the package id directly (rust-lang/cargo#7289), so we have to get list of dependency package ids and dependency Dependencys and match them by name, assuming in a single [dependency] each package name must be unique.

I also made the error message more distinct so easier to map a failure back to its source code origin.

Relevant `cargo metadata` excerpt
[
  {
    "name": "pep440_rs",
    "version": "0.3.12",
    "id": "pep440_rs 0.3.12 (path+file:///home/konsti/projects/internal/crates/pep440-rs)",
    "license": "Apache-2.0 OR BSD-2-Clause",
    "license_file": null,
    "description": "A library for python version numbers and specifiers, implementing PEP 440",
    "source": null,
    "dependencies": ["..."],
    "targets": ["..."],
    "features": {
      "...": [
        "..."
      ]
    },
    "manifest_path": "/home/konsti/projects/internal/crates/pep440-rs/Cargo.toml",
    "metadata": null,
    "publish": null,
    "authors": [
      "Puffin"
    ],
    "categories": [],
    "keywords": [],
    "readme": "README.md",
    "repository": "https://github.com/astral-sh/internal",
    "homepage": "https://pypi.org/project/internal-alpha/",
    "documentation": "https://pypi.org/project/internal-alpha/",
    "edition": "2021",
    "links": null,
    "default_run": null,
    "rust_version": "1.74"
  },
  {
    "name": "pep440_rs",
    "version": "0.3.12",
    "id": "pep440_rs 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
    "license": "Apache-2.0 OR BSD-2-Clause",
    "license_file": null,
    "description": "A library for python version numbers and specifiers, implementing PEP 440",
    "source": "registry+https://github.com/rust-lang/crates.io-index",
    "dependencies": ["..."],
    "targets": ["..."],
    "features": {
      "...": [
        "..."
      ]
    },
    "manifest_path": "/home/konsti/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pep440_rs-0.3.12/Cargo.toml",
    "metadata": null,
    "publish": null,
    "authors": [],
    "categories": [],
    "keywords": [],
    "readme": "Readme.md",
    "repository": "https://github.com/konstin/pep440-rs",
    "homepage": null,
    "documentation": null,
    "edition": "2021",
    "links": null,
    "default_run": null,
    "rust_version": null
  }
]

@konstin konstin added the bug Something isn't working label Jan 19, 2024
Copy link

netlify bot commented Jan 19, 2024

Deploy Preview for maturin-guide ready!

Name Link
🔨 Latest commit e302648
🔍 Latest deploy log https://app.netlify.com/sites/maturin-guide/deploys/65aa6c6da45a380008ff2e1e
😎 Deploy Preview https://deploy-preview-1915--maturin-guide.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

We have a project which depends on a vendored version of `pep440_rs`, while some of our dependencies depend on the crates.io version. The published version uses `Readme.md`, while the vendored one follows a different convention and uses `README.md`. This causes `maturin sdist` to fail:

```
🍹 Building a mixed python/rust project
🔗 Found bin bindings
📡 Using build options bindings from pyproject.toml
💥 maturin failed
  Caused by: Failed to build source distribution
  Caused by: failed to normalize path `Readme.md`
  Caused by: No such file or directory (os error 2)
  ```

  Internally, maturin uses the package name to match dependencies with their resolved readme. This failed in our cased since the second entry for `pep440_rs` with the crates.io readme was overwriting the first entry with the project local readme.

  The fix is to match by package id instead. The implementation is somewhat awkward, since there's no API to get the package id directly, so we again have to get list of dependency package ids and dependency `Dependency`s and match them by name, assuming in a single `[dependency]` each package name must be unique.

<details>
  <summary>Relevant `cargo metadata` excerpt</summary>

  ```javascript
  [
    {
      "name": "pep440_rs",
      "version": "0.3.12",
      "id": "pep440_rs 0.3.12 (path+file:///home/konsti/projects/internal/crates/pep440-rs)",
      "license": "Apache-2.0 OR BSD-2-Clause",
      "license_file": null,
      "description": "A library for python version numbers and specifiers, implementing PEP 440",
      "source": null,
      "dependencies": ["..."],
      "targets": ["..."],
      "features": {
        "...": [
          "..."
        ]
      },
      "manifest_path": "/home/konsti/projects/internal/crates/pep440-rs/Cargo.toml",
      "metadata": null,
      "publish": null,
      "authors": [
        "Puffin"
      ],
      "categories": [],
      "keywords": [],
      "readme": "README.md",
      "repository": "https://github.com/astral-sh/internal",
      "homepage": "https://pypi.org/project/internal-alpha/",
      "documentation": "https://pypi.org/project/internal-alpha/",
      "edition": "2021",
      "links": null,
      "default_run": null,
      "rust_version": "1.74"
    },
    {
      "name": "pep440_rs",
      "version": "0.3.12",
      "id": "pep440_rs 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
      "license": "Apache-2.0 OR BSD-2-Clause",
      "license_file": null,
      "description": "A library for python version numbers and specifiers, implementing PEP 440",
      "source": "registry+https://github.com/rust-lang/crates.io-index",
      "dependencies": ["..."],
      "targets": ["..."],
      "features": {
        "...": [
          "..."
        ]
      },
      "manifest_path": "/home/konsti/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pep440_rs-0.3.12/Cargo.toml",
      "metadata": null,
      "publish": null,
      "authors": [],
      "categories": [],
      "keywords": [],
      "readme": "Readme.md",
      "repository": "https://github.com/konstin/pep440-rs",
      "homepage": null,
      "documentation": null,
      "edition": "2021",
      "links": null,
      "default_run": null,
      "rust_version": null
    }
  ]
  ```

</details>
@konstin konstin force-pushed the konsti/use-package-ids-to-match-readmes branch from cd2ad95 to e302648 Compare January 19, 2024 12:34
charliermarsh added a commit to astral-sh/uv that referenced this pull request Jan 19, 2024
This is due to a bug in Maturin
(PyO3/maturin#1915), so I'll just fix our setup
to work with existing versions.

Closes #991.
Copy link
Member

@messense messense left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@messense messense merged commit 0770b58 into main Jan 22, 2024
29 checks passed
@messense messense deleted the konsti/use-package-ids-to-match-readmes branch January 22, 2024 02:51
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Mar 18, 2024
https://build.opensuse.org/request/show/1158801
by user mia + anag+factory
- Update to 1.5.0
  * tutorial: fix abi to match comment
    gh#PyO3/maturin#1876
  * Allow identical VIRTUAL_ENV and CONDA_PREFIX env vars
    gh#PyO3/maturin#1879
  * Upgrade pyo3 to 0.20
    gh#PyO3/maturin#1881
  * Skip directory when adding license files to wheel
    gh#PyO3/maturin#1890
  * Reject -i python when cross compiling
    gh#PyO3/maturin#1891
  * simplified clear-cache github action
    gh#PyO3/maturin#1897
  * Support uniffi-bindgen in cargo workspaces
    gh#PyO3/maturin#1909
  * Upgrade globlin to 0.8.0
    gh#PyO3/maturin#1912
  * Update **Note** to [!NOTE] in README
    gh#PyO3/maturin#1917
  * Match dependency readmes
    gh#PyO3/maturin#1915
  * Update some actions version in generate ci cli
    gh#PyO3/maturin#1916
  * Use extension name as library name, instead of h
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

Successfully merging this pull request may close these issues.

None yet

2 participants