diff --git a/crates/uv-cache/src/lib.rs b/crates/uv-cache/src/lib.rs index 7fb61e772..4049d3f4b 100644 --- a/crates/uv-cache/src/lib.rs +++ b/crates/uv-cache/src/lib.rs @@ -793,7 +793,7 @@ impl CacheBucket { match self { // Note that when bumping this, you'll also need to bump it // in crates/uv/tests/cache_prune.rs. - Self::SourceDistributions => "sdists-v6", + Self::SourceDistributions => "sdists-v7", Self::FlatIndex => "flat-index-v2", Self::Git => "git-v0", Self::Interpreter => "interpreter-v4", diff --git a/crates/uv-distribution/src/source/mod.rs b/crates/uv-distribution/src/source/mod.rs index 7b5190d94..d4e0993c4 100644 --- a/crates/uv-distribution/src/source/mod.rs +++ b/crates/uv-distribution/src/source/mod.rs @@ -551,15 +551,21 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> { // If the cache contains compatible metadata, return it. let metadata_entry = cache_shard.entry(METADATA); - if let Some(metadata) = CachedMetadata::read(&metadata_entry) - .await? - .filter(|metadata| metadata.matches(source.name(), source.version())) - { - debug!("Using cached metadata for: {source}"); - return Ok(ArchiveMetadata { - metadata: Metadata::from_metadata23(metadata.into()), - hashes: revision.into_hashes(), - }); + match CachedMetadata::read(&metadata_entry).await { + Ok(Some(metadata)) => { + if metadata.matches(source.name(), source.version()) { + debug!("Using cached metadata for: {source}"); + return Ok(ArchiveMetadata { + metadata: Metadata::from_metadata23(metadata.into()), + hashes: revision.into_hashes(), + }); + } + debug!("Cached metadata does not match expected name and version for: {source}"); + } + Ok(None) => {} + Err(err) => { + debug!("Failed to deserialize cached metadata for: {source} ({err})"); + } } // Otherwise, we need a wheel. @@ -882,15 +888,21 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> { // If the cache contains compatible metadata, return it. let metadata_entry = cache_shard.entry(METADATA); - if let Some(metadata) = CachedMetadata::read(&metadata_entry) - .await? - .filter(|metadata| metadata.matches(source.name(), source.version())) - { - debug!("Using cached metadata for: {source}"); - return Ok(ArchiveMetadata { - metadata: Metadata::from_metadata23(metadata.into()), - hashes: revision.into_hashes(), - }); + match CachedMetadata::read(&metadata_entry).await { + Ok(Some(metadata)) => { + if metadata.matches(source.name(), source.version()) { + debug!("Using cached metadata for: {source}"); + return Ok(ArchiveMetadata { + metadata: Metadata::from_metadata23(metadata.into()), + hashes: revision.into_hashes(), + }); + } + debug!("Cached metadata does not match expected name and version for: {source}"); + } + Ok(None) => {} + Err(err) => { + debug!("Failed to deserialize cached metadata for: {source} ({err})"); + } } // Otherwise, we need a source distribution. @@ -1183,31 +1195,38 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> { // If the cache contains compatible metadata, return it. let metadata_entry = cache_shard.entry(METADATA); - if let Some(metadata) = CachedMetadata::read(&metadata_entry) - .await? - .filter(|metadata| metadata.matches(source.name(), source.version())) - { - // If necessary, mark the metadata as dynamic. - let metadata = if dynamic { - ResolutionMetadata { - dynamic: true, - ..metadata.into() - } - } else { - metadata.into() - }; + match CachedMetadata::read(&metadata_entry).await { + Ok(Some(metadata)) => { + if metadata.matches(source.name(), source.version()) { + debug!("Using cached metadata for: {source}"); - return Ok(ArchiveMetadata::from( - Metadata::from_workspace( - metadata, - resource.install_path.as_ref(), - None, - self.build_context.locations(), - self.build_context.sources(), - self.build_context.bounds(), - ) - .await?, - )); + // If necessary, mark the metadata as dynamic. + let metadata = if dynamic { + ResolutionMetadata { + dynamic: true, + ..metadata.into() + } + } else { + metadata.into() + }; + return Ok(ArchiveMetadata::from( + Metadata::from_workspace( + metadata, + resource.install_path.as_ref(), + None, + self.build_context.locations(), + self.build_context.sources(), + self.build_context.bounds(), + ) + .await?, + )); + } + debug!("Cached metadata does not match expected name and version for: {source}"); + } + Ok(None) => {} + Err(err) => { + debug!("Failed to deserialize cached metadata for: {source} ({err})"); + } } // If the backend supports `prepare_metadata_for_build_wheel`, use it. @@ -1635,27 +1654,35 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> { .map_err(Error::CacheRead)? .is_fresh() { - if let Some(metadata) = CachedMetadata::read(&metadata_entry) - .await? - .filter(|metadata| metadata.matches(source.name(), source.version())) - { - let git_member = GitWorkspaceMember { - fetch_root: fetch.path(), - git_source: resource, - }; + match CachedMetadata::read(&metadata_entry).await { + Ok(Some(metadata)) => { + if metadata.matches(source.name(), source.version()) { + debug!("Using cached metadata for: {source}"); - debug!("Using cached metadata for: {source}"); - return Ok(ArchiveMetadata::from( - Metadata::from_workspace( - metadata.into(), - &path, - Some(&git_member), - self.build_context.locations(), - self.build_context.sources(), - self.build_context.bounds(), - ) - .await?, - )); + let git_member = GitWorkspaceMember { + fetch_root: fetch.path(), + git_source: resource, + }; + return Ok(ArchiveMetadata::from( + Metadata::from_workspace( + metadata.into(), + &path, + Some(&git_member), + self.build_context.locations(), + self.build_context.sources(), + self.build_context.bounds(), + ) + .await?, + )); + } + debug!( + "Cached metadata does not match expected name and version for: {source}" + ); + } + Ok(None) => {} + Err(err) => { + debug!("Failed to deserialize cached metadata for: {source} ({err})"); + } } } diff --git a/crates/uv/tests/it/cache_prune.rs b/crates/uv/tests/it/cache_prune.rs index 1fb80d08a..4cf8642ec 100644 --- a/crates/uv/tests/it/cache_prune.rs +++ b/crates/uv/tests/it/cache_prune.rs @@ -348,7 +348,7 @@ fn prune_stale_revision() -> Result<()> { ----- stderr ----- DEBUG uv [VERSION] ([COMMIT] DATE) Pruning cache at: [CACHE_DIR]/ - DEBUG Removing dangling source revision: [CACHE_DIR]/sdists-v6/[ENTRY] + DEBUG Removing dangling source revision: [CACHE_DIR]/sdists-v7/[ENTRY] DEBUG Removing dangling cache archive: [CACHE_DIR]/archive-v0/[ENTRY] Removed [N] files ([SIZE]) "###);