Skip to content

Commit

Permalink
Add registry file size to lockfile (#3652)
Browse files Browse the repository at this point in the history
## Summary

Mentioned in #3611.
  • Loading branch information
charliermarsh authored May 19, 2024
1 parent 98b3325 commit a0745d0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
33 changes: 28 additions & 5 deletions crates/uv-resolver/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl Distribution {
filename: filename.to_string(),
hashes: vec![],
requires_python: None,
size: None,
size: sdist.size,
upload_time_utc_ms: None,
url: FileLocation::AbsoluteUrl(sdist.url.to_string()),
yanked: None,
Expand Down Expand Up @@ -758,6 +758,10 @@ pub(crate) struct SourceDist {
/// and direct URLs. Source distributions from git or path dependencies do
/// not have hashes associated with them.
hash: Option<Hash>,
/// The size of the source distribution in bytes.
///
/// This is only present for source distributions that come from registries.
size: Option<u64>,
}

impl SourceDist {
Expand Down Expand Up @@ -819,27 +823,31 @@ impl SourceDist {
.to_url()
.map_err(LockError::invalid_file_url)?;
let hash = reg_dist.file.hashes.first().cloned().map(Hash::from);
Ok(SourceDist { url, hash })
let size = reg_dist.file.size;
Ok(SourceDist { url, hash, size })
}

fn from_direct_dist(direct_dist: &DirectUrlSourceDist, hashes: &[HashDigest]) -> SourceDist {
SourceDist {
url: direct_dist.url.to_url(),
hash: hashes.first().cloned().map(Hash::from),
size: None,
}
}

fn from_git_dist(git_dist: &GitSourceDist, hashes: &[HashDigest]) -> SourceDist {
SourceDist {
url: locked_git_url(git_dist),
hash: hashes.first().cloned().map(Hash::from),
size: None,
}
}

fn from_path_dist(path_dist: &PathSourceDist, hashes: &[HashDigest]) -> SourceDist {
SourceDist {
url: path_dist.url.to_url(),
hash: hashes.first().cloned().map(Hash::from),
size: None,
}
}

Expand All @@ -850,6 +858,7 @@ impl SourceDist {
SourceDist {
url: directory_dist.url.to_url(),
hash: hashes.first().cloned().map(Hash::from),
size: None,
}
}
}
Expand Down Expand Up @@ -937,12 +946,16 @@ pub(crate) struct Wheel {
/// so this should be treated as only a hint to where to look and/or
/// recording where the wheel file originally came from.
url: Url,
/// A hash of the source distribution.
/// A hash of the built distribution.
///
/// This is only present for wheels that come from registries and direct
/// URLs. Wheels from git or path dependencies do not have hashes
/// associated with them.
hash: Option<Hash>,
/// The size of the built distribution in bytes.
///
/// This is only present for wheels that come from registries.
size: Option<u64>,
/// The filename of the wheel.
///
/// This isn't part of the wire format since it's redundant with the
Expand Down Expand Up @@ -1003,9 +1016,11 @@ impl Wheel {
.to_url()
.map_err(LockError::invalid_file_url)?;
let hash = wheel.file.hashes.first().cloned().map(Hash::from);
let size = wheel.file.size;
Ok(Wheel {
url,
hash,
size,
filename,
})
}
Expand All @@ -1014,6 +1029,7 @@ impl Wheel {
Wheel {
url: direct_dist.url.to_url(),
hash: hashes.first().cloned().map(Hash::from),
size: None,
filename: direct_dist.filename.clone(),
}
}
Expand All @@ -1022,6 +1038,7 @@ impl Wheel {
Wheel {
url: path_dist.url.to_url(),
hash: hashes.first().cloned().map(Hash::from),
size: None,
filename: path_dist.filename.clone(),
}
}
Expand All @@ -1033,7 +1050,7 @@ impl Wheel {
filename: filename.to_string(),
hashes: vec![],
requires_python: None,
size: None,
size: self.size,
upload_time_utc_ms: None,
url: FileLocation::AbsoluteUrl(self.url.to_string()),
yanked: None,
Expand All @@ -1054,19 +1071,24 @@ struct WheelWire {
/// so this should be treated as only a hint to where to look and/or
/// recording where the wheel file originally came from.
url: Url,
/// A hash of the source distribution.
/// A hash of the built distribution.
///
/// This is only present for wheels that come from registries and direct
/// URLs. Wheels from git or path dependencies do not have hashes
/// associated with them.
hash: Option<Hash>,
/// The size of the built distribution in bytes.
///
/// This is only present for wheels that come from registries.
size: Option<u64>,
}

impl From<Wheel> for WheelWire {
fn from(wheel: Wheel) -> WheelWire {
WheelWire {
url: wheel.url,
hash: wheel.hash,
size: wheel.size,
}
}
}
Expand All @@ -1087,6 +1109,7 @@ impl TryFrom<WheelWire> for Wheel {
Ok(Wheel {
url: wire.url,
hash: wire.hash,
size: wire.size,
filename,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Ok(
},
),
),
size: None,
filename: WheelFilename {
name: PackageName(
"anyio",
Expand Down
35 changes: 35 additions & 0 deletions crates/uv/tests/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ fn lock_wheel_registry() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/c6/b3/fefbf7e78ab3b805dec67d698dc18dd505af7a18a8dd08868c9b4fa736b5/anyio-3.7.0.tar.gz"
hash = "sha256:275d9973793619a5374e1c89a4f4ad3f4b0a5510a2b5b939444bee8f4c4d37ce"
size = 142737
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/68/fe/7ce1926952c8a403b35029e194555558514b365ad77d75125f521a2bec62/anyio-3.7.0-py3-none-any.whl"
hash = "sha256:eddca883c4175f14df8aedce21054bfca3adb70ffe76a9f607aef9d7fa2ea7f0"
size = 80873
[[distribution.dependencies]]
name = "exceptiongroup"
Expand Down Expand Up @@ -98,10 +100,12 @@ fn lock_wheel_registry() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/8e/1c/beef724eaf5b01bb44b6338c8c3494eff7cab376fab4904cfbbc3585dc79/exceptiongroup-1.2.0.tar.gz"
hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"
size = 26264
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/b8/9a/5028fd52db10e600f1c4674441b968cf2ea4959085bfb5b99fb1250e5f68/exceptiongroup-1.2.0-py3-none-any.whl"
hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"
size = 16210
[[distribution]]
name = "idna"
Expand All @@ -111,10 +115,12 @@ fn lock_wheel_registry() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/bf/3f/ea4b9117521a1e9c50344b909be7886dd00a519552724809bb1f486986c2/idna-3.6.tar.gz"
hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"
size = 175426
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl"
hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"
size = 61567
[[distribution]]
name = "sniffio"
Expand All @@ -124,10 +130,12 @@ fn lock_wheel_registry() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz"
hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"
size = 20372
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl"
hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2"
size = 10235
[[distribution]]
name = "typing-extensions"
Expand All @@ -137,10 +145,12 @@ fn lock_wheel_registry() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/16/3a/0d26ce356c7465a19c9ea8814b960f8a36c3b0d07c323176620b7b483e44/typing_extensions-4.10.0.tar.gz"
hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb"
size = 77558
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/f9/de/dc04a3ea60b22624b51c703a84bbe0184abcd1d0b9bc8074b5d6b7ab90bb/typing_extensions-4.10.0-py3-none-any.whl"
hash = "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475"
size = 33926
"###
);

Expand Down Expand Up @@ -203,6 +213,7 @@ fn lock_sdist_registry() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/9d/01/4aacc00ffd2ed59595769e233baf1e72b3a4034ddabf65ff4ef34e1d487e/netwell-0.4.0.tar.gz"
hash = "sha256:cd6940614081790099b8fc1fdcf65cb930d54c647ed8bc9ba90dc781cf33926e"
size = 6671
"###
);

Expand Down Expand Up @@ -303,10 +314,12 @@ fn lock_sdist_git() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/8e/1c/beef724eaf5b01bb44b6338c8c3494eff7cab376fab4904cfbbc3585dc79/exceptiongroup-1.2.0.tar.gz"
hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"
size = 26264
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/b8/9a/5028fd52db10e600f1c4674441b968cf2ea4959085bfb5b99fb1250e5f68/exceptiongroup-1.2.0-py3-none-any.whl"
hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"
size = 16210
[[distribution]]
name = "idna"
Expand All @@ -316,10 +329,12 @@ fn lock_sdist_git() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/bf/3f/ea4b9117521a1e9c50344b909be7886dd00a519552724809bb1f486986c2/idna-3.6.tar.gz"
hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"
size = 175426
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl"
hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"
size = 61567
[[distribution]]
name = "sniffio"
Expand All @@ -329,10 +344,12 @@ fn lock_sdist_git() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz"
hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"
size = 20372
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl"
hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2"
size = 10235
[[distribution]]
name = "typing-extensions"
Expand All @@ -342,10 +359,12 @@ fn lock_sdist_git() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/16/3a/0d26ce356c7465a19c9ea8814b960f8a36c3b0d07c323176620b7b483e44/typing_extensions-4.10.0.tar.gz"
hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb"
size = 77558
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/f9/de/dc04a3ea60b22624b51c703a84bbe0184abcd1d0b9bc8074b5d6b7ab90bb/typing_extensions-4.10.0-py3-none-any.whl"
hash = "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475"
size = 33926
"###
);

Expand Down Expand Up @@ -452,10 +471,12 @@ fn lock_wheel_url() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/8e/1c/beef724eaf5b01bb44b6338c8c3494eff7cab376fab4904cfbbc3585dc79/exceptiongroup-1.2.0.tar.gz"
hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"
size = 26264
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/b8/9a/5028fd52db10e600f1c4674441b968cf2ea4959085bfb5b99fb1250e5f68/exceptiongroup-1.2.0-py3-none-any.whl"
hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"
size = 16210
[[distribution]]
name = "idna"
Expand All @@ -465,10 +486,12 @@ fn lock_wheel_url() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/bf/3f/ea4b9117521a1e9c50344b909be7886dd00a519552724809bb1f486986c2/idna-3.6.tar.gz"
hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"
size = 175426
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl"
hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"
size = 61567
[[distribution]]
name = "sniffio"
Expand All @@ -478,10 +501,12 @@ fn lock_wheel_url() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz"
hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"
size = 20372
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl"
hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2"
size = 10235
[[distribution]]
name = "typing-extensions"
Expand All @@ -491,10 +516,12 @@ fn lock_wheel_url() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/16/3a/0d26ce356c7465a19c9ea8814b960f8a36c3b0d07c323176620b7b483e44/typing_extensions-4.10.0.tar.gz"
hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb"
size = 77558
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/f9/de/dc04a3ea60b22624b51c703a84bbe0184abcd1d0b9bc8074b5d6b7ab90bb/typing_extensions-4.10.0-py3-none-any.whl"
hash = "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475"
size = 33926
"###
);

Expand Down Expand Up @@ -601,10 +628,12 @@ fn lock_sdist_url() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/8e/1c/beef724eaf5b01bb44b6338c8c3494eff7cab376fab4904cfbbc3585dc79/exceptiongroup-1.2.0.tar.gz"
hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"
size = 26264
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/b8/9a/5028fd52db10e600f1c4674441b968cf2ea4959085bfb5b99fb1250e5f68/exceptiongroup-1.2.0-py3-none-any.whl"
hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"
size = 16210
[[distribution]]
name = "idna"
Expand All @@ -614,10 +643,12 @@ fn lock_sdist_url() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/bf/3f/ea4b9117521a1e9c50344b909be7886dd00a519552724809bb1f486986c2/idna-3.6.tar.gz"
hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"
size = 175426
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl"
hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"
size = 61567
[[distribution]]
name = "sniffio"
Expand All @@ -627,10 +658,12 @@ fn lock_sdist_url() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz"
hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"
size = 20372
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl"
hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2"
size = 10235
[[distribution]]
name = "typing-extensions"
Expand All @@ -640,10 +673,12 @@ fn lock_sdist_url() -> Result<()> {
[distribution.sdist]
url = "https://files.pythonhosted.org/packages/16/3a/0d26ce356c7465a19c9ea8814b960f8a36c3b0d07c323176620b7b483e44/typing_extensions-4.10.0.tar.gz"
hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb"
size = 77558
[[distribution.wheel]]
url = "https://files.pythonhosted.org/packages/f9/de/dc04a3ea60b22624b51c703a84bbe0184abcd1d0b9bc8074b5d6b7ab90bb/typing_extensions-4.10.0-py3-none-any.whl"
hash = "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475"
size = 33926
"###
);

Expand Down

0 comments on commit a0745d0

Please sign in to comment.