Rename distribution to packages in lockfile (#5861)

Currently, the entry for a package+version+source table is called
`distribution`. That is incorrect, the `sdist` and `wheel` fields inside
of that table are distributions, the table itself is for a package. We
also align ourselves closer with PEP 751.

I went through `lock.rs` and renamed all occurrences of "distribution"
that actually referred to a "package".

This change invalidates all existing lockfiles.

Bikeshedding: Do we call it `package` or `packages`? See also
https://github.com/python/peps/pull/3877

`package` is nice because it looks like a header:

```toml
[[package]]
name = "anyio"
version = "4.3.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
    { name = "idna" },
    { name = "sniffio" },
]
sdist = { url = "3970183622/anyio-4.3.0.tar.gz", hash = "sha256:f75253795a87df48568485fd18cdd2a3fa5c4f7c5be8e5e36637733fce06fed6", size = 159642 }
wheels = [
    { url = "2f20c40b45/anyio-4.3.0-py3-none-any.whl", hash = "sha256:048e05d0f6caeed70d731f3db756d35dcc1f35747c8c403364a8332c630441b8", size = 85584 },
]
```

`packages` is nice because the field is not a single entry, but a list.

2/3 for https://github.com/astral-sh/uv/issues/4893

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This commit is contained in:
konsti 2024-08-08 17:25:06 +02:00 committed by GitHub
parent 4fd9b115d5
commit 4038c9a6af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 1198 additions and 1073 deletions

View file

@ -67,17 +67,17 @@ pub fn read_lock_requirements(lock: &Lock, upgrade: &Upgrade) -> LockedRequireme
let mut preferences = Vec::new();
let mut git = Vec::new();
for dist in lock.distributions() {
for package in lock.packages() {
// Skip the distribution if it's not included in the upgrade strategy.
if upgrade.contains(dist.name()) {
if upgrade.contains(package.name()) {
continue;
}
// Map each entry in the lockfile to a preference.
preferences.push(Preference::from_lock(dist));
preferences.push(Preference::from_lock(package));
// Map each entry in the lockfile to a Git SHA.
if let Some(git_ref) = dist.as_git_ref() {
if let Some(git_ref) = package.as_git_ref() {
git.push(git_ref);
}
}