Skip to content

Conversation

@konstin
Copy link
Member

@konstin konstin commented Mar 17, 2025

Reject all cases where a source distribution builds into a wheel of a different version than was locked in the lockfile.

As an example:

[[package]]
name = "sniffio"
version = "2.3.4"
source = { url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz" }
sdist = { hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc" }

This now fails with:

  × Failed to download and build `sniffio @
  │ https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz`
  ╰─▶ Package metadata version `1.3.1` does not match given version `2.3.4`
  help: `sniffio` was included because `foo` (v0.1.0) depends on `sniffio`

The potential clash could be with git dependencies that use a version-from-git integration. I.e., with the change, we're enforcing coherence where we've been previously lenient. It is on the other hand the only good option for catching errors such as #12164 for source distributions.

Needs tests.

konstin added 2 commits March 17, 2025 11:08
Reject lockfiles where the package version and the wheel versions are incoherent. This implicitly checks that all wheel files have the same version.

It does not check for the source dist version, since a source dist may not contain a version in the filename and attempting to deserialize source dist filenames we may not need is a performance overhead for something that's already slow in `uv run`.

Fixes #12164
@konstin konstin added the bug Something isn't working label Mar 17, 2025
// the filename in advance.
if let Some(wheel) = built_index.url(sdist)? {
if wheel.filename.name == sdist.name {
if wheel.filename.name == sdist.name
Copy link
Contributor

Choose a reason for hiding this comment

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

These will be false if we don't know the sdist version, right? Should we instead maintain the old behavior in that case?

Something like:

if wheel.filename.name == sdist.name
  && dist.version().map_or(true, |version| version == &wheel.filename.version)

Base automatically changed from konsti/locked-version-coherence to main March 17, 2025 22:33
@zanieb zanieb changed the title Konsti/reject incoherent source dist Error on lockfiles with inconsistent source distribution versions Mar 17, 2025
@konstin konstin closed this Oct 9, 2025
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.

3 participants