Remove incompatible wheels from uv.lock (#4799)

Remove wheels from the lockfile that don't match the required python
version. For example, we remove
`charset_normalizer-3.3.2-cp311-cp311-win_amd64.whl` when we have
`requires-python = ">=3.12"`.

Our snapshots barely show changes since we avoid the large binaries for
which matters. Here are 3 real world `uv.lock` before/after comparisons
to show the large difference:
*
[warehouse](https://gist.github.com/konstin/9a1ed6a32b410e250fcf4c6ea8c536a5)
(5677 -> 4214)
*
[transformers](https://gist.github.com/konstin/5636281b5226f64aa44ce3244d5230cd)
(6484 -> 5816)
*
[github-wikidata-bot](https://gist.github.com/konstin/ebbd7b9474523aaa61d9a8945bc02071)
(793 -> 454)

We only remove wheels we are certain don't match the python version and
still keep those with unknown tags. We could remove even more wheels by
also considering other markers, e.g. removing linux wheels for a
windows-only dep, but we would trade complex, easy-to-get-wrong logic
for diminishing returns.
This commit is contained in:
konsti 2024-07-04 20:03:54 +02:00 committed by GitHub
parent dac3161f90
commit 11cb0059c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 96 additions and 187 deletions

View file

@ -190,6 +190,16 @@ impl Lock {
}
}
}
// Remove wheels that don't match `requires-python` and can't be selected for
// installation.
if let Some(requires_python) = &requires_python {
dist.wheels.retain(|wheel| {
wheel
.filename
.matches_requires_python(requires_python.specifiers())
});
}
}
distributions.sort_by(|dist1, dist2| dist1.id.cmp(&dist2.id));