Use base client pattern in more sites (#13227)

## Summary

For consistency. No functional changes.
This commit is contained in:
Charlie Marsh 2025-04-30 20:00:59 -04:00 committed by GitHub
parent 0593b967ba
commit a261995449
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 95 additions and 71 deletions

View File

@ -30,6 +30,9 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
WheelFilename(#[from] uv_distribution_filename::WheelFilenameError), WheelFilename(#[from] uv_distribution_filename::WheelFilenameError),
#[error(transparent)]
Io(#[from] std::io::Error),
} }
impl Error { impl Error {

View File

@ -11,12 +11,6 @@ use owo_colors::OwoColorize;
use thiserror::Error; use thiserror::Error;
use tracing::instrument; use tracing::instrument;
use crate::commands::pip::operations;
use crate::commands::project::{find_requires_python, ProjectError};
use crate::commands::reporters::PythonDownloadReporter;
use crate::commands::ExitStatus;
use crate::printer::Printer;
use crate::settings::{NetworkSettings, ResolverSettings};
use uv_build_backend::check_direct_build; use uv_build_backend::check_direct_build;
use uv_cache::{Cache, CacheBucket}; use uv_cache::{Cache, CacheBucket};
use uv_client::{BaseClientBuilder, FlatIndexClient, RegistryClientBuilder}; use uv_client::{BaseClientBuilder, FlatIndexClient, RegistryClientBuilder};
@ -44,6 +38,13 @@ use uv_settings::PythonInstallMirrors;
use uv_types::{AnyErrorBuild, BuildContext, BuildIsolation, BuildStack, HashStrategy}; use uv_types::{AnyErrorBuild, BuildContext, BuildIsolation, BuildStack, HashStrategy};
use uv_workspace::{DiscoveryOptions, Workspace, WorkspaceCache, WorkspaceError}; use uv_workspace::{DiscoveryOptions, Workspace, WorkspaceCache, WorkspaceError};
use crate::commands::pip::operations;
use crate::commands::project::{find_requires_python, ProjectError};
use crate::commands::reporters::PythonDownloadReporter;
use crate::commands::ExitStatus;
use crate::printer::Printer;
use crate::settings::{NetworkSettings, ResolverSettings};
#[derive(Debug, Error)] #[derive(Debug, Error)]
enum Error { enum Error {
#[error(transparent)] #[error(transparent)]
@ -332,14 +333,13 @@ async fn build_impl(
cache, cache,
printer, printer,
index_locations, index_locations,
&client_builder, client_builder.clone(),
hash_checking, hash_checking,
build_logs, build_logs,
force_pep517, force_pep517,
build_constraints, build_constraints,
*no_build_isolation, *no_build_isolation,
no_build_isolation_package, no_build_isolation_package,
network_settings,
*index_strategy, *index_strategy,
*keyring_provider, *keyring_provider,
*exclude_newer, *exclude_newer,
@ -410,14 +410,13 @@ async fn build_package(
cache: &Cache, cache: &Cache,
printer: Printer, printer: Printer,
index_locations: &IndexLocations, index_locations: &IndexLocations,
client_builder: &BaseClientBuilder<'_>, client_builder: BaseClientBuilder<'_>,
hash_checking: Option<HashCheckingMode>, hash_checking: Option<HashCheckingMode>,
build_logs: bool, build_logs: bool,
force_pep517: bool, force_pep517: bool,
build_constraints: &[RequirementsSource], build_constraints: &[RequirementsSource],
no_build_isolation: bool, no_build_isolation: bool,
no_build_isolation_package: &[PackageName], no_build_isolation_package: &[PackageName],
network_settings: &NetworkSettings,
index_strategy: IndexStrategy, index_strategy: IndexStrategy,
keyring_provider: KeyringProviderType, keyring_provider: KeyringProviderType,
exclude_newer: Option<ExcludeNewer>, exclude_newer: Option<ExcludeNewer>,
@ -479,7 +478,7 @@ async fn build_package(
EnvironmentPreference::Any, EnvironmentPreference::Any,
python_preference, python_preference,
python_downloads, python_downloads,
client_builder, &client_builder,
cache, cache,
Some(&PythonDownloadReporter::single(printer)), Some(&PythonDownloadReporter::single(printer)),
install_mirrors.python_install_mirror.as_deref(), install_mirrors.python_install_mirror.as_deref(),
@ -501,7 +500,8 @@ async fn build_package(
} }
// Read build constraints. // Read build constraints.
let build_constraints = operations::read_constraints(build_constraints, client_builder).await?; let build_constraints =
operations::read_constraints(build_constraints, &client_builder).await?;
// Collect the set of required hashes. // Collect the set of required hashes.
let hasher = if let Some(hash_checking) = hash_checking { let hasher = if let Some(hash_checking) = hash_checking {
@ -524,10 +524,8 @@ async fn build_package(
); );
// Initialize the registry client. // Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone()) let client = RegistryClientBuilder::try_from(client_builder)?
.native_tls(network_settings.native_tls) .cache(cache.clone())
.connectivity(network_settings.connectivity)
.allow_insecure_host(network_settings.allow_insecure_host.clone())
.index_locations(index_locations) .index_locations(index_locations)
.index_strategy(index_strategy) .index_strategy(index_strategy)
.keyring(keyring_provider) .keyring(keyring_provider)

View File

@ -14,7 +14,7 @@ use unicode_width::UnicodeWidthStr;
use uv_cache::{Cache, Refresh}; use uv_cache::{Cache, Refresh};
use uv_cache_info::Timestamp; use uv_cache_info::Timestamp;
use uv_cli::ListFormat; use uv_cli::ListFormat;
use uv_client::RegistryClientBuilder; use uv_client::{BaseClientBuilder, RegistryClientBuilder};
use uv_configuration::{Concurrency, IndexStrategy, KeyringProviderType}; use uv_configuration::{Concurrency, IndexStrategy, KeyringProviderType};
use uv_distribution_filename::DistFilename; use uv_distribution_filename::DistFilename;
use uv_distribution_types::{Diagnostic, IndexCapabilities, IndexLocations, InstalledDist, Name}; use uv_distribution_types::{Diagnostic, IndexCapabilities, IndexLocations, InstalledDist, Name};
@ -82,18 +82,20 @@ pub(crate) async fn pip_list(
let latest = if outdated && !results.is_empty() { let latest = if outdated && !results.is_empty() {
let capabilities = IndexCapabilities::default(); let capabilities = IndexCapabilities::default();
let client_builder = BaseClientBuilder::new()
.connectivity(network_settings.connectivity)
.native_tls(network_settings.native_tls)
.keyring(keyring_provider)
.allow_insecure_host(network_settings.allow_insecure_host.clone());
// Initialize the registry client. // Initialize the registry client.
let client = let client = RegistryClientBuilder::try_from(client_builder)?
RegistryClientBuilder::new(cache.clone().with_refresh(Refresh::All(Timestamp::now()))) .cache(cache.clone().with_refresh(Refresh::All(Timestamp::now())))
.native_tls(network_settings.native_tls) .index_locations(&index_locations)
.connectivity(network_settings.connectivity) .index_strategy(index_strategy)
.allow_insecure_host(network_settings.allow_insecure_host.clone()) .markers(environment.interpreter().markers())
.index_locations(&index_locations) .platform(environment.interpreter().platform())
.index_strategy(index_strategy) .build();
.keyring(keyring_provider)
.markers(environment.interpreter().markers())
.platform(environment.interpreter().platform())
.build();
let download_concurrency = Semaphore::new(concurrency.downloads); let download_concurrency = Semaphore::new(concurrency.downloads);
// Determine the platform tags. // Determine the platform tags.

View File

@ -12,7 +12,7 @@ use tokio::sync::Semaphore;
use uv_cache::{Cache, Refresh}; use uv_cache::{Cache, Refresh};
use uv_cache_info::Timestamp; use uv_cache_info::Timestamp;
use uv_client::RegistryClientBuilder; use uv_client::{BaseClientBuilder, RegistryClientBuilder};
use uv_configuration::{Concurrency, IndexStrategy, KeyringProviderType}; use uv_configuration::{Concurrency, IndexStrategy, KeyringProviderType};
use uv_distribution_types::{Diagnostic, IndexCapabilities, IndexLocations, Name}; use uv_distribution_types::{Diagnostic, IndexCapabilities, IndexLocations, Name};
use uv_installer::SitePackages; use uv_installer::SitePackages;
@ -83,18 +83,20 @@ pub(crate) async fn pip_tree(
let latest = if outdated && !packages.is_empty() { let latest = if outdated && !packages.is_empty() {
let capabilities = IndexCapabilities::default(); let capabilities = IndexCapabilities::default();
let client_builder = BaseClientBuilder::new()
.connectivity(network_settings.connectivity)
.native_tls(network_settings.native_tls)
.keyring(keyring_provider)
.allow_insecure_host(network_settings.allow_insecure_host.clone());
// Initialize the registry client. // Initialize the registry client.
let client = let client = RegistryClientBuilder::try_from(client_builder)?
RegistryClientBuilder::new(cache.clone().with_refresh(Refresh::All(Timestamp::now()))) .cache(cache.clone().with_refresh(Refresh::All(Timestamp::now())))
.native_tls(network_settings.native_tls) .index_locations(&index_locations)
.connectivity(network_settings.connectivity) .index_strategy(index_strategy)
.allow_insecure_host(network_settings.allow_insecure_host.clone()) .markers(environment.interpreter().markers())
.index_locations(&index_locations) .platform(environment.interpreter().platform())
.index_strategy(index_strategy) .build();
.keyring(keyring_provider)
.markers(environment.interpreter().markers())
.platform(environment.interpreter().platform())
.build();
let download_concurrency = Semaphore::new(concurrency.downloads); let download_concurrency = Semaphore::new(concurrency.downloads);
// Determine the platform tags. // Determine the platform tags.

View File

@ -566,6 +566,13 @@ async fn do_lock(
let python_requirement = let python_requirement =
PythonRequirement::from_requires_python(interpreter, requires_python.clone()); PythonRequirement::from_requires_python(interpreter, requires_python.clone());
// Initialize the client.
let client_builder = BaseClientBuilder::new()
.connectivity(network_settings.connectivity)
.native_tls(network_settings.native_tls)
.keyring(*keyring_provider)
.allow_insecure_host(network_settings.allow_insecure_host.clone());
// Add all authenticated sources to the cache. // Add all authenticated sources to the cache.
for index in index_locations.allowed_indexes() { for index in index_locations.allowed_indexes() {
if let Some(credentials) = index.credentials() { if let Some(credentials) = index.credentials() {
@ -588,13 +595,10 @@ async fn do_lock(
} }
// Initialize the registry client. // Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone()) let client = RegistryClientBuilder::try_from(client_builder)?
.native_tls(network_settings.native_tls) .cache(cache.clone())
.connectivity(network_settings.connectivity)
.allow_insecure_host(network_settings.allow_insecure_host.clone())
.index_locations(index_locations) .index_locations(index_locations)
.index_strategy(*index_strategy) .index_strategy(*index_strategy)
.keyring(*keyring_provider)
.markers(interpreter.markers()) .markers(interpreter.markers())
.platform(interpreter.platform()) .platform(interpreter.platform())
.build(); .build();

View File

@ -1549,6 +1549,12 @@ pub(crate) async fn resolve_names(
reinstall: _, reinstall: _,
} = settings; } = settings;
let client_builder = BaseClientBuilder::new()
.connectivity(network_settings.connectivity)
.native_tls(network_settings.native_tls)
.keyring(*keyring_provider)
.allow_insecure_host(network_settings.allow_insecure_host.clone());
// Add all authenticated sources to the cache. // Add all authenticated sources to the cache.
for index in index_locations.allowed_indexes() { for index in index_locations.allowed_indexes() {
if let Some(credentials) = index.credentials() { if let Some(credentials) = index.credentials() {
@ -1561,13 +1567,10 @@ pub(crate) async fn resolve_names(
} }
// Initialize the registry client. // Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone()) let client = RegistryClientBuilder::try_from(client_builder)?
.native_tls(network_settings.native_tls) .cache(cache.clone())
.connectivity(network_settings.connectivity)
.allow_insecure_host(network_settings.allow_insecure_host.clone())
.index_locations(index_locations) .index_locations(index_locations)
.index_strategy(*index_strategy) .index_strategy(*index_strategy)
.keyring(*keyring_provider)
.markers(interpreter.markers()) .markers(interpreter.markers())
.platform(interpreter.platform()) .platform(interpreter.platform())
.build(); .build();
@ -1696,6 +1699,12 @@ pub(crate) async fn resolve_environment(
.. ..
} = spec.requirements; } = spec.requirements;
let client_builder = BaseClientBuilder::new()
.connectivity(network_settings.connectivity)
.native_tls(network_settings.native_tls)
.keyring(*keyring_provider)
.allow_insecure_host(network_settings.allow_insecure_host.clone());
// Determine the tags, markers, and interpreter to use for resolution. // Determine the tags, markers, and interpreter to use for resolution.
let tags = interpreter.tags()?; let tags = interpreter.tags()?;
let marker_env = interpreter.resolver_marker_environment(); let marker_env = interpreter.resolver_marker_environment();
@ -1713,13 +1722,10 @@ pub(crate) async fn resolve_environment(
} }
// Initialize the registry client. // Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone()) let client = RegistryClientBuilder::try_from(client_builder)?
.native_tls(network_settings.native_tls) .cache(cache.clone())
.connectivity(network_settings.connectivity)
.allow_insecure_host(network_settings.allow_insecure_host.clone())
.index_locations(index_locations) .index_locations(index_locations)
.index_strategy(*index_strategy) .index_strategy(*index_strategy)
.keyring(*keyring_provider)
.markers(interpreter.markers()) .markers(interpreter.markers())
.platform(interpreter.platform()) .platform(interpreter.platform())
.build(); .build();
@ -1868,6 +1874,12 @@ pub(crate) async fn sync_environment(
sources, sources,
} = settings; } = settings;
let client_builder = BaseClientBuilder::new()
.connectivity(network_settings.connectivity)
.native_tls(network_settings.native_tls)
.keyring(keyring_provider)
.allow_insecure_host(network_settings.allow_insecure_host.clone());
let site_packages = SitePackages::from_environment(&venv)?; let site_packages = SitePackages::from_environment(&venv)?;
// Determine the markers tags to use for resolution. // Determine the markers tags to use for resolution.
@ -1886,13 +1898,10 @@ pub(crate) async fn sync_environment(
} }
// Initialize the registry client. // Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone()) let client = RegistryClientBuilder::try_from(client_builder)?
.native_tls(network_settings.native_tls) .cache(cache.clone())
.connectivity(network_settings.connectivity)
.allow_insecure_host(network_settings.allow_insecure_host.clone())
.index_locations(index_locations) .index_locations(index_locations)
.index_strategy(index_strategy) .index_strategy(index_strategy)
.keyring(keyring_provider)
.markers(interpreter.markers()) .markers(interpreter.markers())
.platform(interpreter.platform()) .platform(interpreter.platform())
.build(); .build();
@ -2037,6 +2046,12 @@ pub(crate) async fn update_environment(
reinstall, reinstall,
} = settings; } = settings;
let client_builder = BaseClientBuilder::new()
.connectivity(network_settings.connectivity)
.native_tls(network_settings.native_tls)
.keyring(*keyring_provider)
.allow_insecure_host(network_settings.allow_insecure_host.clone());
// Respect all requirements from the provided sources. // Respect all requirements from the provided sources.
let RequirementsSpecification { let RequirementsSpecification {
project, project,
@ -2098,13 +2113,10 @@ pub(crate) async fn update_environment(
} }
// Initialize the registry client. // Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone()) let client = RegistryClientBuilder::try_from(client_builder)?
.native_tls(network_settings.native_tls) .cache(cache.clone())
.connectivity(network_settings.connectivity)
.allow_insecure_host(network_settings.allow_insecure_host.clone())
.index_locations(index_locations) .index_locations(index_locations)
.index_strategy(*index_strategy) .index_strategy(*index_strategy)
.keyring(*keyring_provider)
.markers(interpreter.markers()) .markers(interpreter.markers())
.platform(interpreter.platform()) .platform(interpreter.platform())
.build(); .build();

View File

@ -8,7 +8,7 @@ use itertools::Itertools;
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
use uv_cache::Cache; use uv_cache::Cache;
use uv_client::{FlatIndexClient, RegistryClientBuilder}; use uv_client::{BaseClientBuilder, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{ use uv_configuration::{
Concurrency, Constraints, DependencyGroups, DependencyGroupsWithDefaults, DryRun, EditableMode, Concurrency, Constraints, DependencyGroups, DependencyGroupsWithDefaults, DryRun, EditableMode,
ExtrasSpecification, ExtrasSpecificationWithDefaults, HashCheckingMode, InstallOptions, ExtrasSpecification, ExtrasSpecificationWithDefaults, HashCheckingMode, InstallOptions,
@ -598,6 +598,12 @@ pub(super) async fn do_sync(
sources, sources,
} = settings; } = settings;
let client_builder = BaseClientBuilder::new()
.connectivity(network_settings.connectivity)
.native_tls(network_settings.native_tls)
.keyring(keyring_provider)
.allow_insecure_host(network_settings.allow_insecure_host.clone());
// Validate that the Python version is supported by the lockfile. // Validate that the Python version is supported by the lockfile.
if !target if !target
.lock() .lock()
@ -678,13 +684,10 @@ pub(super) async fn do_sync(
store_credentials_from_target(target); store_credentials_from_target(target);
// Initialize the registry client. // Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone()) let client = RegistryClientBuilder::try_from(client_builder)?
.native_tls(network_settings.native_tls) .cache(cache.clone())
.connectivity(network_settings.connectivity)
.allow_insecure_host(network_settings.allow_insecure_host.clone())
.index_locations(index_locations) .index_locations(index_locations)
.index_strategy(index_strategy) .index_strategy(index_strategy)
.keyring(keyring_provider)
.markers(venv.interpreter().markers()) .markers(venv.interpreter().markers())
.platform(venv.interpreter().platform()) .platform(venv.interpreter().platform())
.build(); .build();