Add parsed URL fields to Dist variants (#3429)

Avoid reparsing urls by storing the parsed parts across resolution on
`Dist`.

Part 2 of https://github.com/astral-sh/uv/issues/3408 and part of #3409

Closes #3408
This commit is contained in:
konsti 2024-05-14 03:23:27 +02:00 committed by GitHub
parent 0010954ca7
commit c22c7cad4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 107 additions and 83 deletions

View file

@ -27,6 +27,7 @@ uv-configuration = { workspace = true }
uv-distribution = { workspace = true }
uv-extract = { workspace = true }
uv-fs = { workspace = true }
uv-git = { workspace = true }
uv-interpreter = { workspace = true }
uv-normalize = { workspace = true }
uv-types = { workspace = true }

View file

@ -21,6 +21,7 @@ use uv_distribution::{
BuiltWheelIndex, HttpArchivePointer, LocalArchivePointer, RegistryWheelIndex,
};
use uv_fs::Simplified;
use uv_git::GitUrl;
use uv_interpreter::PythonEnvironment;
use uv_types::HashStrategy;
@ -224,7 +225,11 @@ impl<'a> Planner<'a> {
continue;
}
}
RequirementSource::Url { url, .. } => {
RequirementSource::Url {
subdirectory,
location,
url,
} => {
// Check if we have a wheel or a source distribution.
if Path::new(url.path())
.extension()
@ -243,6 +248,8 @@ impl<'a> Planner<'a> {
let wheel = DirectUrlBuiltDist {
filename,
location: location.clone(),
subdirectory: subdirectory.clone(),
url: url.clone(),
};
@ -288,6 +295,8 @@ impl<'a> Planner<'a> {
} else {
let sdist = DirectUrlSourceDist {
name: requirement.name.clone(),
location: location.clone(),
subdirectory: subdirectory.clone(),
url: url.clone(),
};
// Find the most-compatible wheel from the cache, since we don't know
@ -300,9 +309,16 @@ impl<'a> Planner<'a> {
}
}
}
RequirementSource::Git { url, .. } => {
RequirementSource::Git {
repository,
reference,
subdirectory,
url,
} => {
let sdist = GitSourceDist {
name: requirement.name.clone(),
git: Box::new(GitUrl::new(repository.clone(), reference.clone())),
subdirectory: subdirectory.clone(),
url: url.clone(),
};
// Find the most-compatible wheel from the cache, since we don't know