Remove flat index client's dependency on registry client (#12393)

## Summary

I want to use the flat index client from within the registry client, so
making them both depend on the same underlying primitives rather than
having the flat index client depend on the registry client.
This commit is contained in:
Charlie Marsh 2025-03-22 11:14:25 -07:00 committed by GitHub
parent ed0759fb45
commit bbf4f830b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 24 additions and 18 deletions

View File

@ -14,7 +14,7 @@ use uv_small_str::SmallString;
use crate::cached_client::{CacheControl, CachedClientError};
use crate::html::SimpleHtml;
use crate::{Connectivity, Error, ErrorKind, OwnedArchive, RegistryClient};
use crate::{CachedClient, Connectivity, Error, ErrorKind, OwnedArchive};
#[derive(Debug, thiserror::Error)]
pub enum FlatIndexError {
@ -91,14 +91,19 @@ impl FlatIndexEntries {
/// remote HTML indexes).
#[derive(Debug, Clone)]
pub struct FlatIndexClient<'a> {
client: &'a RegistryClient,
client: &'a CachedClient,
connectivity: Connectivity,
cache: &'a Cache,
}
impl<'a> FlatIndexClient<'a> {
/// Create a new [`FlatIndexClient`].
pub fn new(client: &'a RegistryClient, cache: &'a Cache) -> Self {
Self { client, cache }
pub fn new(client: &'a CachedClient, connectivity: Connectivity, cache: &'a Cache) -> Self {
Self {
client,
connectivity,
cache,
}
}
/// Read the directories and flat remote indexes from `--find-links`.
@ -157,7 +162,7 @@ impl<'a> FlatIndexClient<'a> {
"html",
format!("{}.msgpack", cache_digest(&url.to_string())),
);
let cache_control = match self.client.connectivity() {
let cache_control = match self.connectivity {
Connectivity::Online => CacheControl::from(
self.cache
.freshness(&cache_entry, None, None)
@ -168,7 +173,8 @@ impl<'a> FlatIndexClient<'a> {
let flat_index_request = self
.client
.uncached_client(url)
.uncached()
.for_host(url)
.get(url.clone())
.header("Accept-Encoding", "gzip")
.header("Accept", "text/html")
@ -210,7 +216,6 @@ impl<'a> FlatIndexClient<'a> {
};
let response = self
.client
.cached_client()
.get_cacheable_with_retry(
flat_index_request,
&cache_entry,

View File

@ -550,7 +550,7 @@ async fn build_package(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, cache);
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
let entries = client
.fetch(index_locations.flat_indexes().map(Index::url))
.await?;

View File

@ -373,7 +373,7 @@ pub(crate) async fn pip_compile(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, &cache);
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), &cache);
let entries = client
.fetch(index_locations.flat_indexes().map(Index::url))
.await?;

View File

@ -366,7 +366,7 @@ pub(crate) async fn pip_install(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, &cache);
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), &cache);
let entries = client
.fetch(index_locations.flat_indexes().map(Index::url))
.await?;

View File

@ -294,7 +294,7 @@ pub(crate) async fn pip_sync(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, &cache);
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), &cache);
let entries = client
.fetch(index_locations.flat_indexes().map(Index::url))
.await?;

View File

@ -345,7 +345,8 @@ pub(crate) async fn add(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, cache);
let client =
FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
let entries = client
.fetch(
settings

View File

@ -634,7 +634,7 @@ async fn do_lock(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, cache);
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
let entries = client
.fetch(index_locations.flat_indexes().map(Index::url))
.await?;

View File

@ -1752,7 +1752,7 @@ pub(crate) async fn resolve_environment(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, cache);
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
let entries = client
.fetch(index_locations.flat_indexes().map(Index::url))
.await?;
@ -1895,7 +1895,7 @@ pub(crate) async fn sync_environment(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, cache);
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
let entries = client
.fetch(index_locations.flat_indexes().map(Index::url))
.await?;
@ -2122,7 +2122,7 @@ pub(crate) async fn update_environment(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, cache);
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
let entries = client
.fetch(index_locations.flat_indexes().map(Index::url))
.await?;

View File

@ -654,7 +654,7 @@ pub(super) async fn do_sync(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, cache);
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
let entries = client
.fetch(index_locations.flat_indexes().map(Index::url))
.await?;

View File

@ -306,7 +306,7 @@ async fn venv_impl(
// Resolve the flat indexes from `--find-links`.
let flat_index = {
let tags = interpreter.tags().map_err(VenvError::Tags)?;
let client = FlatIndexClient::new(&client, cache);
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
let entries = client
.fetch(index_locations.flat_indexes().map(Index::url))
.await