mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Remove redirects from the resolver (#2792)
## Summary Rather than storing the `redirects` on the resolver, this PR just re-uses the "convert this URL to precise" logic when we convert to a `Resolution` after-the-fact. I think this is a lot simpler: it removes state from the resolver, and simplifies a lot of the hooks around distribution fetching (e.g., `get_or_build_wheel_metadata` no longer returns `(Metadata23, Option<Url>)`).
This commit is contained in:
parent
ffd4b6fcac
commit
189d0d41d0
12 changed files with 80 additions and 182 deletions
|
@ -10,10 +10,8 @@ use url::Url;
|
|||
|
||||
use distribution_filename::WheelFilename;
|
||||
use distribution_types::{
|
||||
BuildableSource, BuiltDist, Dist, FileLocation, GitSourceDist, GitSourceUrl, IndexLocations,
|
||||
LocalEditable, Name, SourceDist, SourceUrl,
|
||||
BuildableSource, BuiltDist, Dist, FileLocation, IndexLocations, LocalEditable, Name, SourceDist,
|
||||
};
|
||||
use pep508_rs::VerbatimUrl;
|
||||
use platform_tags::Tags;
|
||||
use pypi_types::Metadata23;
|
||||
use uv_cache::{ArchiveTarget, ArchiveTimestamp, CacheBucket, CacheEntry, WheelCache};
|
||||
|
@ -21,7 +19,6 @@ use uv_client::{CacheControl, CachedClientError, Connectivity, RegistryClient};
|
|||
use uv_types::{BuildContext, NoBinary, NoBuild};
|
||||
|
||||
use crate::download::{BuiltWheel, UnzippedWheel};
|
||||
use crate::git::resolve_precise;
|
||||
use crate::locks::Locks;
|
||||
use crate::{DiskWheel, Error, LocalWheel, Reporter, SourceDistributionBuilder};
|
||||
|
||||
|
@ -42,7 +39,6 @@ pub struct DistributionDatabase<'a, Context: BuildContext + Send + Sync> {
|
|||
build_context: &'a Context,
|
||||
builder: SourceDistributionBuilder<'a, Context>,
|
||||
locks: Arc<Locks>,
|
||||
reporter: Option<Arc<dyn Reporter>>,
|
||||
}
|
||||
|
||||
impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context> {
|
||||
|
@ -52,7 +48,6 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
build_context,
|
||||
builder: SourceDistributionBuilder::new(client, build_context),
|
||||
locks: Arc::new(Locks::default()),
|
||||
reporter: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +56,6 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
|
||||
let reporter = Arc::new(reporter);
|
||||
Self {
|
||||
reporter: Some(reporter.clone()),
|
||||
builder: self.builder.with_reporter(reporter),
|
||||
..self
|
||||
}
|
||||
|
@ -100,15 +94,9 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
/// possible. For example, given a Git dependency with a reference to a branch or tag, return a
|
||||
/// URL with a precise reference to the current commit of that branch or tag.
|
||||
#[instrument(skip_all, fields(%dist))]
|
||||
pub async fn get_or_build_wheel_metadata(
|
||||
&self,
|
||||
dist: &Dist,
|
||||
) -> Result<(Metadata23, Option<Url>), Error> {
|
||||
pub async fn get_or_build_wheel_metadata(&self, dist: &Dist) -> Result<Metadata23, Error> {
|
||||
match dist {
|
||||
Dist::Built(built) => self
|
||||
.get_wheel_metadata(built)
|
||||
.await
|
||||
.map(|metadata| (metadata, None)),
|
||||
Dist::Built(built) => self.get_wheel_metadata(built).await,
|
||||
Dist::Source(source) => {
|
||||
self.build_wheel_metadata(&BuildableSource::Dist(source))
|
||||
.await
|
||||
|
@ -365,7 +353,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
pub async fn build_wheel_metadata(
|
||||
&self,
|
||||
source: &BuildableSource<'_>,
|
||||
) -> Result<(Metadata23, Option<Url>), Error> {
|
||||
) -> Result<Metadata23, Error> {
|
||||
let no_build = match self.build_context.no_build() {
|
||||
NoBuild::All => true,
|
||||
NoBuild::None => false,
|
||||
|
@ -382,54 +370,12 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
let lock = self.locks.acquire(source).await;
|
||||
let _guard = lock.lock().await;
|
||||
|
||||
// Insert the `precise` URL, if it exists.
|
||||
if let BuildableSource::Dist(SourceDist::Git(source)) = source {
|
||||
if let Some(precise) = resolve_precise(
|
||||
&source.url,
|
||||
self.build_context.cache(),
|
||||
self.reporter.as_ref(),
|
||||
)
|
||||
.await?
|
||||
{
|
||||
let source = SourceDist::Git(GitSourceDist {
|
||||
url: VerbatimUrl::unknown(precise.clone()),
|
||||
..source.clone()
|
||||
});
|
||||
let source = BuildableSource::Dist(&source);
|
||||
let metadata = self
|
||||
.builder
|
||||
.download_and_build_metadata(&source)
|
||||
.boxed()
|
||||
.await?;
|
||||
return Ok((metadata, Some(precise)));
|
||||
}
|
||||
}
|
||||
|
||||
if let BuildableSource::Url(SourceUrl::Git(source)) = source {
|
||||
if let Some(precise) = resolve_precise(
|
||||
source.url,
|
||||
self.build_context.cache(),
|
||||
self.reporter.as_ref(),
|
||||
)
|
||||
.await?
|
||||
{
|
||||
let source = SourceUrl::Git(GitSourceUrl { url: &precise });
|
||||
let source = BuildableSource::Url(source);
|
||||
let metadata = self
|
||||
.builder
|
||||
.download_and_build_metadata(&source)
|
||||
.boxed()
|
||||
.await?;
|
||||
return Ok((metadata, Some(precise)));
|
||||
}
|
||||
}
|
||||
|
||||
let metadata = self
|
||||
.builder
|
||||
.download_and_build_metadata(source)
|
||||
.boxed()
|
||||
.await?;
|
||||
Ok((metadata, None))
|
||||
Ok(metadata)
|
||||
}
|
||||
|
||||
/// Stream a wheel from a URL, unzipping it into the cache as it's downloaded.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue