mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 02:48:17 +00:00
Add support for relative URLs in simple metadata responses (#721)
## Summary This PR adds support for relative URLs in the simple JSON responses. We already support relative URLs for HTML responses, but the handling has been consolidated between the two. Similar to index URLs, we now store the base alongside the metadata, and use the base when resolving the URL. Closes #455. ## Test Plan `cargo test` (to test HTML indexes). Separately, I also ran `cargo run -p puffin-cli -- pip-compile requirements.in -n --index-url=http://localhost:3141/packages/pypi/+simple` on the `zb/relative` branch with `packse` running, and forced both HTML and JSON by limiting the `accept` header.
This commit is contained in:
parent
ae83a74309
commit
007f52bb4e
17 changed files with 285 additions and 134 deletions
|
@ -30,7 +30,7 @@ use crate::{
|
|||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DistributionDatabaseError {
|
||||
#[error("Failed to parse '{0}' as url")]
|
||||
#[error("Failed to parse URL: {0}")]
|
||||
Url(String, #[source] url::ParseError),
|
||||
#[error(transparent)]
|
||||
WheelFilename(#[from] WheelFilenameError),
|
||||
|
@ -108,9 +108,11 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
match &dist {
|
||||
Dist::Built(BuiltDist::Registry(wheel)) => {
|
||||
// Fetch the wheel.
|
||||
let url = Url::parse(&wheel.file.url).map_err(|err| {
|
||||
DistributionDatabaseError::Url(wheel.file.url.to_string(), err)
|
||||
})?;
|
||||
let url = wheel
|
||||
.base
|
||||
.join_relative(&wheel.file.url)
|
||||
.map_err(|err| DistributionDatabaseError::Url(wheel.file.url.clone(), err))?;
|
||||
|
||||
let wheel_filename = WheelFilename::from_str(&wheel.file.filename)?;
|
||||
|
||||
let reader = self.client.stream_external(&url).await?;
|
||||
|
|
|
@ -231,9 +231,12 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
|
|||
.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.clone(), err)
|
||||
})?;
|
||||
let url = registry_source_dist
|
||||
.base
|
||||
.join_relative(®istry_source_dist.file.url)
|
||||
.map_err(|err| {
|
||||
SourceDistError::UrlParse(registry_source_dist.file.url.clone(), err)
|
||||
})?;
|
||||
|
||||
// For registry source distributions, shard by package, then by SHA.
|
||||
// Ex) `pypi/requests/a673187abc19fe6c`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue