diff --git a/crates/puffin-cache/src/metadata.rs b/crates/puffin-cache/src/metadata.rs index d0917f79a..9e63fff08 100644 --- a/crates/puffin-cache/src/metadata.rs +++ b/crates/puffin-cache/src/metadata.rs @@ -16,19 +16,19 @@ const BUILT_WHEEL_METADATA_CACHE: &str = "built-wheel-metadata-v0"; /// See [`WheelMetadataCache::wheel_dir`] for remote wheel metadata caching and /// [`WheelMetadataCache::built_wheel_dir`] for caching of metadata of built source /// distributions. -pub enum WheelMetadataCache { +pub enum WheelMetadataCache<'a> { /// Either pypi or an alternative index, which we key by index url - Index(IndexUrl), + Index(&'a IndexUrl), /// A direct url dependency, which we key by url - Url(Url), + Url(&'a Url), /// A git dependency, which we key by repository url. We use the revision as filename. /// /// Note that this variant only exists for source distributions, wheels can't be delivered /// through git. - Git(Url), + Git(&'a Url), } -impl WheelMetadataCache { +impl<'a> WheelMetadataCache<'a> { fn bucket(&self) -> PathBuf { match self { WheelMetadataCache::Index(IndexUrl::Pypi) => PathBuf::from("pypi"), diff --git a/crates/puffin-client/src/client.rs b/crates/puffin-client/src/client.rs index de3de492e..cd3ad1b87 100644 --- a/crates/puffin-client/src/client.rs +++ b/crates/puffin-client/src/client.rs @@ -219,7 +219,7 @@ impl RegistryClient { self.wheel_metadata_no_pep658( &wheel.filename, &wheel.url, - WheelMetadataCache::Url(wheel.url.clone()), + WheelMetadataCache::Url(&wheel.url), ) .await? } @@ -262,7 +262,7 @@ impl RegistryClient { let cache_dir = self .cache - .join(WheelMetadataCache::Index(index).wheel_dir()); + .join(WheelMetadataCache::Index(&index).wheel_dir()); let cache_file = format!("{}.json", filename.stem()); let response_callback = |response: Response| async { @@ -278,17 +278,17 @@ impl RegistryClient { // If we lack PEP 658 support, try using HTTP range requests to read only the // `.dist-info/METADATA` file from the zip, and if that also fails, download the whole wheel // into the cache and read from there - self.wheel_metadata_no_pep658(&filename, &url, WheelMetadataCache::Index(index)) + self.wheel_metadata_no_pep658(&filename, &url, WheelMetadataCache::Index(&index)) .await } } /// Get the wheel metadata if it isn't available in an index through PEP 658 - async fn wheel_metadata_no_pep658( + async fn wheel_metadata_no_pep658<'data>( &self, - filename: &WheelFilename, - url: &Url, - cache_shard: WheelMetadataCache, + filename: &'data WheelFilename, + url: &'data Url, + cache_shard: WheelMetadataCache<'data>, ) -> Result { if self.no_index { return Err(Error::NoIndex(url.to_string())); diff --git a/crates/puffin-distribution/src/source_dist.rs b/crates/puffin-distribution/src/source_dist.rs index 7d3bdb240..d0372125c 100644 --- a/crates/puffin-distribution/src/source_dist.rs +++ b/crates/puffin-distribution/src/source_dist.rs @@ -41,7 +41,7 @@ const GIT_CACHE: &str = "git-v0"; #[derive(Debug, Error)] pub enum SourceDistError { // Network error - #[error("Failed to parse url '{0}'")] + #[error("Failed to parse URL: `{0}`")] UrlParse(String, #[source] url::ParseError), #[error("Git operation failed")] Git(#[source] anyhow::Error), @@ -158,20 +158,20 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> { source_dist, filename, &url, - WheelMetadataCache::Url(url.clone()), + WheelMetadataCache::Url(&url), subdirectory.as_deref(), ) .await? } SourceDist::Registry(registry_source_dist) => { let url = Url::parse(®istry_source_dist.file.url).map_err(|err| { - SourceDistError::UrlParse(registry_source_dist.file.url.to_string(), err) + SourceDistError::UrlParse(registry_source_dist.file.url.clone(), err) })?; self.url( source_dist, ®istry_source_dist.file.filename, &url, - WheelMetadataCache::Index(registry_source_dist.index.clone()), + WheelMetadataCache::Index(®istry_source_dist.index), None, ) .await? @@ -223,13 +223,13 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> { } #[allow(clippy::too_many_arguments)] - async fn url( + async fn url<'data>( &self, - source_dist: &SourceDist, - filename: &str, - url: &Url, - cache_shard: WheelMetadataCache, - subdirectory: Option<&Path>, + source_dist: &'data SourceDist, + filename: &'data str, + url: &'data Url, + cache_shard: WheelMetadataCache<'data>, + subdirectory: Option<&'data Path>, ) -> Result { let cache_dir = self .build_context @@ -368,7 +368,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> { .precise() .expect("Exact commit after checkout") .to_string(); - let cache_shard = WheelMetadataCache::Git(git_source_dist.url.clone()); + let cache_shard = WheelMetadataCache::Git(&git_source_dist.url); let cache_dir = self .build_context .cache()