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:
Charlie Marsh 2024-04-02 22:43:57 -04:00 committed by GitHub
parent ffd4b6fcac
commit 189d0d41d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 80 additions and 182 deletions

View file

@ -34,7 +34,7 @@ use uv_fs::write_atomic;
use uv_types::{BuildContext, BuildKind, NoBuild, SourceBuildTrait};
use crate::error::Error;
use crate::git::fetch_git_archive;
use crate::git::{fetch_git_archive, resolve_precise};
use crate::source::built_wheel_metadata::BuiltWheelMetadata;
use crate::source::manifest::Manifest;
use crate::Reporter;
@ -713,17 +713,27 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
resource: &GitSourceUrl<'_>,
tags: &Tags,
) -> Result<BuiltWheelMetadata, Error> {
let (fetch, subdirectory) = fetch_git_archive(
// Resolve to a precise Git SHA.
let url = if let Some(url) = resolve_precise(
resource.url,
self.build_context.cache(),
self.reporter.as_ref(),
)
.await?;
.await?
{
Cow::Owned(url)
} else {
Cow::Borrowed(resource.url)
};
// Fetch the Git repository.
let (fetch, subdirectory) =
fetch_git_archive(&url, self.build_context.cache(), self.reporter.as_ref()).await?;
let git_sha = fetch.git().precise().expect("Exact commit after checkout");
let cache_shard = self.build_context.cache().shard(
CacheBucket::BuiltWheels,
WheelCache::Git(resource.url, &git_sha.to_short_string()).root(),
WheelCache::Git(&url, &git_sha.to_short_string()).root(),
);
// If the cache contains a compatible wheel, return it.
@ -768,17 +778,27 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
source: &BuildableSource<'_>,
resource: &GitSourceUrl<'_>,
) -> Result<Metadata23, Error> {
let (fetch, subdirectory) = fetch_git_archive(
// Resolve to a precise Git SHA.
let url = if let Some(url) = resolve_precise(
resource.url,
self.build_context.cache(),
self.reporter.as_ref(),
)
.await?;
.await?
{
Cow::Owned(url)
} else {
Cow::Borrowed(resource.url)
};
// Fetch the Git repository.
let (fetch, subdirectory) =
fetch_git_archive(&url, self.build_context.cache(), self.reporter.as_ref()).await?;
let git_sha = fetch.git().precise().expect("Exact commit after checkout");
let cache_shard = self.build_context.cache().shard(
CacheBucket::BuiltWheels,
WheelCache::Git(resource.url, &git_sha.to_short_string()).root(),
WheelCache::Git(&url, &git_sha.to_short_string()).root(),
);
// If the cache contains compatible metadata, return it.