Skip to content

Use a global BaseClientBuilder#15548

Merged
zanieb merged 4 commits intomainfrom
konsti/global-client-builder
Aug 29, 2025
Merged

Use a global BaseClientBuilder#15548
zanieb merged 4 commits intomainfrom
konsti/global-client-builder

Conversation

@konstin
Copy link
Member

@konstin konstin commented Aug 27, 2025

Alternative to #15105

Instead of building a BaseClientBuilder from NetworkSettings each time we need a client, we instead build a single BaseClientBuilder and pass it around. The RegistryClientBuilder then uses BaseClientBuilder exclusively for configuration. This removes a chunk of copy-and-paste code, and also moves the fallible retries_from_env into a single place

Borrow vs. clone is mostly ad-hoc, we can change it in either direction if it matters.

Closes #15105

@konstin konstin added the internal A refactor or improvement that is not user-facing label Aug 27, 2025
@konstin konstin temporarily deployed to uv-test-registries August 27, 2025 12:05 — with GitHub Actions Inactive
impl RegistryClientBuilder<'_> {
pub fn new(cache: Cache) -> Self {
impl<'a> RegistryClientBuilder<'a> {
pub fn new(base_client_builder: BaseClientBuilder<'a>, cache: Cache) -> Self {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative in one direction would be starting with a default base client builder (easier for the tests, easier to get wrong in production code), an alternative in the other direction would be making IndexLocations a parameter here to clarify them as mandatory.

@konstin konstin temporarily deployed to uv-test-publish August 27, 2025 12:06 — with GitHub Actions Inactive
Comment on lines -405 to +394
let client = RegistryClientBuilder::try_from(client_builder)?
let client = RegistryClientBuilder::new(client_builder.clone(), cache.clone())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a logic change as it was previously (accidentally?) using a temporary cache.

index_urls: IndexUrls::default(),
index_strategy: IndexStrategy::default(),
torch_backend: None,
cache: Cache::temp()?,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid this fallible construction by passing the cache in explicitly. This avoids creating temp dirs we drop immediately after.

@konstin konstin force-pushed the konsti/global-client-builder branch from 1c4a25d to c3cb63f Compare August 29, 2025 16:07
@konstin konstin temporarily deployed to uv-test-registries August 29, 2025 16:11 — with GitHub Actions Inactive
@konstin konstin temporarily deployed to uv-test-publish August 29, 2025 16:11 — with GitHub Actions Inactive
.native_tls(network_settings.native_tls)
.keyring(keyring_provider)
.allow_insecure_host(network_settings.allow_insecure_host.clone());
let client_builder = client_builder.clone().keyring(keyring_provider);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry about the friction this adds to adding a keyring provider, i.e., that it makes it easier to forget. I'm not sure what we can do though, it's not substantively worse than the status quo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a motivation for this change! I want to move towards something that's more consolidated instead of having to remember to add each field to the builder each time. I looked at the keyring quickly, but it seemed to complex to pull out for now.

Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrighty

@zanieb zanieb merged commit 289ed86 into main Aug 29, 2025
96 checks passed
@zanieb zanieb deleted the konsti/global-client-builder branch August 29, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user-facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants