From fd0daae9697cb476877a28ac90873679bc2203fc Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 15 Aug 2024 08:51:41 -0400 Subject: [PATCH] Add immutable definition to `Source` struct (#6108) ## Summary Centralizes the definition of an "immutable" source. --- crates/uv-resolver/src/lock.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/uv-resolver/src/lock.rs b/crates/uv-resolver/src/lock.rs index f58f0bcc9..64d7b86d1 100644 --- a/crates/uv-resolver/src/lock.rs +++ b/crates/uv-resolver/src/lock.rs @@ -754,8 +754,8 @@ impl Lock { } while let Some(package) = queue.pop_front() { - // Assume that registry dependencies are immutable. - if matches!(package.id.source, Source::Registry(..)) { + // If the package is immutable, we don't need to validate it (or its dependencies). + if package.id.source.is_immutable() { continue; } @@ -1009,12 +1009,12 @@ impl Package { let id = PackageId::from_annotated_dist(annotated_dist); let sdist = SourceDist::from_annotated_dist(&id, annotated_dist)?; let wheels = Wheel::from_annotated_dist(annotated_dist)?; - let requires_dist = if matches!(id.source, Source::Registry(..)) { + let requires_dist = if id.source.is_immutable() { vec![] } else { annotated_dist.metadata.requires_dist.clone() }; - let requires_dev = if matches!(id.source, Source::Registry(..)) { + let requires_dev = if id.source.is_immutable() { BTreeMap::default() } else { annotated_dist.metadata.dev_dependencies.clone() @@ -1795,6 +1795,14 @@ impl Source { ) } + /// Returns `true` if the source should be considered immutable. + /// + /// We assume that registry sources are immutable. In other words, we expect that once a + /// package-version is published to a registry, its metadata will not change. + fn is_immutable(&self) -> bool { + matches!(self, Self::Registry(..)) + } + fn to_toml(&self, table: &mut Table) { let mut source_table = InlineTable::new(); match *self {