Skip to content

Commit 483b4c8

Browse files
authored
Don't fail direct URL hash checking with dependency metadata (#13736)
Fixes #12512
1 parent 891fe52 commit 483b4c8

3 files changed

Lines changed: 56 additions & 15 deletions

File tree

crates/uv-distribution/src/distribution_database.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,6 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
418418
dist: &BuiltDist,
419419
hashes: HashPolicy<'_>,
420420
) -> Result<ArchiveMetadata, Error> {
421-
// If the metadata was provided by the user directly, prefer it.
422-
if let Some(metadata) = self
423-
.build_context
424-
.dependency_metadata()
425-
.get(dist.name(), Some(dist.version()))
426-
{
427-
return Ok(ArchiveMetadata::from_metadata23(metadata.clone()));
428-
}
429-
430421
// If hash generation is enabled, and the distribution isn't hosted on a registry, get the
431422
// entire wheel to ensure that the hashes are included in the response. If the distribution
432423
// is hosted on an index, the hashes will be included in the simple metadata response.
@@ -443,14 +434,32 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
443434
// TODO(charlie): Request the hashes via a separate method, to reduce the coupling in this API.
444435
if hashes.is_generate(dist) {
445436
let wheel = self.get_wheel(dist, hashes).await?;
446-
let metadata = wheel.metadata()?;
437+
// If the metadata was provided by the user directly, prefer it.
438+
let metadata = if let Some(metadata) = self
439+
.build_context
440+
.dependency_metadata()
441+
.get(dist.name(), Some(dist.version()))
442+
{
443+
metadata.clone()
444+
} else {
445+
wheel.metadata()?
446+
};
447447
let hashes = wheel.hashes;
448448
return Ok(ArchiveMetadata {
449449
metadata: Metadata::from_metadata23(metadata),
450450
hashes,
451451
});
452452
}
453453

454+
// If the metadata was provided by the user directly, prefer it.
455+
if let Some(metadata) = self
456+
.build_context
457+
.dependency_metadata()
458+
.get(dist.name(), Some(dist.version()))
459+
{
460+
return Ok(ArchiveMetadata::from_metadata23(metadata.clone()));
461+
}
462+
454463
let result = self
455464
.client
456465
.managed(|client| {

crates/uv-distribution/src/metadata/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ impl ArchiveMetadata {
142142
hashes: HashDigests::empty(),
143143
}
144144
}
145-
146-
/// Create an [`ArchiveMetadata`] with the given metadata and hashes.
147-
pub fn with_hashes(metadata: Metadata, hashes: HashDigests) -> Self {
148-
Self { metadata, hashes }
149-
}
150145
}
151146

152147
impl From<Metadata> for ArchiveMetadata {

crates/uv/tests/it/sync.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9572,3 +9572,40 @@ fn repeated_dev_member_all_packages() -> Result<()> {
95729572

95739573
Ok(())
95749574
}
9575+
9576+
/// Test that hash checking doesn't fail with dependency metadata.
9577+
#[test]
9578+
fn direct_url_dependency_metadata() -> Result<()> {
9579+
let context = TestContext::new("3.12");
9580+
context.temp_dir.child("pyproject.toml").write_str(r#"
9581+
[project]
9582+
name = "debug"
9583+
version = "0.1.0"
9584+
requires-python = ">=3.9"
9585+
dependencies = [
9586+
"tqdm",
9587+
]
9588+
9589+
[tool.uv]
9590+
dependency-metadata = [
9591+
{ name = "tqdm", version = "4.67.1", requires-dist = [] },
9592+
]
9593+
9594+
[tool.uv.sources]
9595+
tqdm = { url = "https://files.pythonhosted.org/packages/d0/30/dc54f88dd4a2b5dc8a0279bdd7270e735851848b762aeb1c1184ed1f6b14/tqdm-4.67.1-py3-none-any.whl" }
9596+
"#
9597+
)?;
9598+
9599+
uv_snapshot!(context.sync(), @r"
9600+
success: true
9601+
exit_code: 0
9602+
----- stdout -----
9603+
9604+
----- stderr -----
9605+
Resolved 2 packages in [TIME]
9606+
Installed 1 package in [TIME]
9607+
+ tqdm==4.67.1 (from https://files.pythonhosted.org/packages/d0/30/dc54f88dd4a2b5dc8a0279bdd7270e735851848b762aeb1c1184ed1f6b14/tqdm-4.67.1-py3-none-any.whl)
9608+
");
9609+
9610+
Ok(())
9611+
}

0 commit comments

Comments
 (0)