Skip to content

Commit

Permalink
Drop hash fragment when downloading from registry
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 4, 2024
1 parent fda6914 commit cda3e1d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
12 changes: 10 additions & 2 deletions crates/uv-client/src/registry_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ impl RegistryClient {
) -> Result<Result<OwnedArchive<SimpleMetadata>, CachedClientError<Error>>, Error> {
// Format the URL for PyPI.
let mut url: Url = index.clone().into();
url.set_fragment(None);
url.path_segments_mut()
.unwrap()
.pop_if_empty()
Expand Down Expand Up @@ -386,7 +387,10 @@ impl RegistryClient {
.as_ref()
.is_some_and(pypi_types::DistInfoMetadata::is_available)
{
let url = Url::parse(&format!("{url}.metadata")).map_err(ErrorKind::UrlParseError)?;
// Like `pip`, drop the fragment, if it exists.
let mut url = url.clone();
url.set_fragment(None);
url.set_path(&format!("{}.metadata", url.path()));

let cache_entry = self.cache.entry(
CacheBucket::Wheels,
Expand Down Expand Up @@ -455,6 +459,10 @@ impl RegistryClient {
Connectivity::Offline => CacheControl::AllowStale,
};

// Like `pip`, drop the fragment, if it exists.
let mut url = url.clone();
url.set_fragment(None);

let client = self.client_raw.clone();
let req = self
.client
Expand Down Expand Up @@ -521,7 +529,7 @@ impl RegistryClient {
}

// Stream the file, searching for the METADATA.
let reader = self.stream_external(url).await?;
let reader = self.stream_external(&url).await?;
read_metadata_async_stream(filename, url.to_string(), reader).await
}

Expand Down
16 changes: 9 additions & 7 deletions crates/uv-distribution/src/distribution_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
return Err(Error::NoBinary);
}

let url = match &wheel.file.url {
let mut url = match &wheel.file.url {
FileLocation::RelativeUrl(base, url) => {
pypi_types::base_url_join_relative(base, url)?
}
Expand Down Expand Up @@ -150,6 +150,9 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
}
};

// Like `pip`, drop the fragment, if it exists.
url.set_fragment(None);

// Create an entry for the wheel itself alongside its HTTP cache.
let wheel_entry = self.cache.entry(
CacheBucket::Wheels,
Expand Down Expand Up @@ -242,12 +245,11 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
.instrument(info_span!("download", wheel = %wheel))
};

let req = self
.client
.cached_client()
.uncached()
.get(wheel.url.raw().clone())
.build()?;
// Like `pip`, drop the fragment, if it exists.
let mut url = wheel.url.raw().clone();
url.set_fragment(None);

let req = self.client.cached_client().uncached().get(url).build()?;
let cache_control = match self.client.connectivity() {
Connectivity::Online => CacheControl::from(
self.cache
Expand Down
22 changes: 10 additions & 12 deletions crates/uv-distribution/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
Connectivity::Offline => CacheControl::AllowStale,
};

// Like `pip`, drop the fragment, if it exists.
let mut url = url.clone();
url.set_fragment(None);

let download = |response| {
async {
// At this point, we're seeing a new or updated source distribution. Initialize a
Expand All @@ -280,12 +284,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
.boxed()
.instrument(info_span!("download", source_dist = %source_dist))
};
let req = self
.client
.cached_client()
.uncached()
.get(url.clone())
.build()?;
let req = self.client.cached_client().uncached().get(url).build()?;
let manifest = self
.client
.cached_client()
Expand Down Expand Up @@ -366,6 +365,10 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
Connectivity::Offline => CacheControl::AllowStale,
};

// Like `pip`, drop the fragment, if it exists.
let mut url = url.clone();
url.set_fragment(None);

let download = |response| {
async {
// At this point, we're seeing a new or updated source distribution. Initialize a
Expand All @@ -383,12 +386,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
.boxed()
.instrument(info_span!("download", source_dist = %source_dist))
};
let req = self
.client
.cached_client()
.uncached()
.get(url.clone())
.build()?;
let req = self.client.cached_client().uncached().get(url).build()?;
let manifest = self
.client
.cached_client()
Expand Down

0 comments on commit cda3e1d

Please sign in to comment.