From bbf4f830b5b346d9bdba18b6bc319c9527e5e92c Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 22 Mar 2025 11:14:25 -0700 Subject: [PATCH] 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. --- crates/uv-client/src/flat_index.rs | 19 ++++++++++++------- crates/uv/src/commands/build_frontend.rs | 2 +- crates/uv/src/commands/pip/compile.rs | 2 +- crates/uv/src/commands/pip/install.rs | 2 +- crates/uv/src/commands/pip/sync.rs | 2 +- crates/uv/src/commands/project/add.rs | 3 ++- crates/uv/src/commands/project/lock.rs | 2 +- crates/uv/src/commands/project/mod.rs | 6 +++--- crates/uv/src/commands/project/sync.rs | 2 +- crates/uv/src/commands/venv.rs | 2 +- 10 files changed, 24 insertions(+), 18 deletions(-) diff --git a/crates/uv-client/src/flat_index.rs b/crates/uv-client/src/flat_index.rs index 1bf9800ce..95be0944b 100644 --- a/crates/uv-client/src/flat_index.rs +++ b/crates/uv-client/src/flat_index.rs @@ -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, diff --git a/crates/uv/src/commands/build_frontend.rs b/crates/uv/src/commands/build_frontend.rs index 69be6fda9..f4e6bcd27 100644 --- a/crates/uv/src/commands/build_frontend.rs +++ b/crates/uv/src/commands/build_frontend.rs @@ -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?; diff --git a/crates/uv/src/commands/pip/compile.rs b/crates/uv/src/commands/pip/compile.rs index d425f832a..875463a26 100644 --- a/crates/uv/src/commands/pip/compile.rs +++ b/crates/uv/src/commands/pip/compile.rs @@ -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?; diff --git a/crates/uv/src/commands/pip/install.rs b/crates/uv/src/commands/pip/install.rs index 5e0a50f66..4d98e7b58 100644 --- a/crates/uv/src/commands/pip/install.rs +++ b/crates/uv/src/commands/pip/install.rs @@ -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?; diff --git a/crates/uv/src/commands/pip/sync.rs b/crates/uv/src/commands/pip/sync.rs index d9a63622a..d778b9d27 100644 --- a/crates/uv/src/commands/pip/sync.rs +++ b/crates/uv/src/commands/pip/sync.rs @@ -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?; diff --git a/crates/uv/src/commands/project/add.rs b/crates/uv/src/commands/project/add.rs index bcd65ee29..b8fd4d988 100644 --- a/crates/uv/src/commands/project/add.rs +++ b/crates/uv/src/commands/project/add.rs @@ -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 diff --git a/crates/uv/src/commands/project/lock.rs b/crates/uv/src/commands/project/lock.rs index aea8dad77..869fc2981 100644 --- a/crates/uv/src/commands/project/lock.rs +++ b/crates/uv/src/commands/project/lock.rs @@ -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?; diff --git a/crates/uv/src/commands/project/mod.rs b/crates/uv/src/commands/project/mod.rs index f66a1bf0c..d69eb3c3d 100644 --- a/crates/uv/src/commands/project/mod.rs +++ b/crates/uv/src/commands/project/mod.rs @@ -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?; diff --git a/crates/uv/src/commands/project/sync.rs b/crates/uv/src/commands/project/sync.rs index 001f25600..d98aa59dc 100644 --- a/crates/uv/src/commands/project/sync.rs +++ b/crates/uv/src/commands/project/sync.rs @@ -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?; diff --git a/crates/uv/src/commands/venv.rs b/crates/uv/src/commands/venv.rs index d679806c0..2b8b22c4a 100644 --- a/crates/uv/src/commands/venv.rs +++ b/crates/uv/src/commands/venv.rs @@ -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