mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
Reduce index credential stashing code duplication (#14419)
Reduces some duplicate code around index credentials.
This commit is contained in:
parent
e40d3d5dff
commit
bf5dcf9929
10 changed files with 25 additions and 124 deletions
|
@ -462,6 +462,19 @@ impl<'a> IndexLocations {
|
|||
indexes
|
||||
}
|
||||
}
|
||||
|
||||
/// Add all authenticated sources to the cache.
|
||||
pub fn cache_index_credentials(&self) {
|
||||
for index in self.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&IndexLocations> for uv_auth::Indexes {
|
||||
|
|
|
@ -3,7 +3,6 @@ use std::fmt::Write as _;
|
|||
use std::io::Write as _;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::{fmt, io};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
@ -504,16 +503,7 @@ async fn build_package(
|
|||
.await?
|
||||
.into_interpreter();
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
// Read build constraints.
|
||||
let build_constraints =
|
||||
|
|
|
@ -3,7 +3,6 @@ use std::env;
|
|||
use std::ffi::OsStr;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Result, anyhow};
|
||||
use itertools::Itertools;
|
||||
|
@ -388,16 +387,7 @@ pub(crate) async fn pip_compile(
|
|||
no_index,
|
||||
);
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
// Determine the PyTorch backend.
|
||||
let torch_backend = torch_backend
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fmt::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Context;
|
||||
use itertools::Itertools;
|
||||
|
@ -334,16 +333,7 @@ pub(crate) async fn pip_install(
|
|||
no_index,
|
||||
);
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
// Determine the PyTorch backend.
|
||||
let torch_backend = torch_backend
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fmt::Write;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use owo_colors::OwoColorize;
|
||||
|
@ -267,16 +266,7 @@ pub(crate) async fn pip_sync(
|
|||
no_index,
|
||||
);
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
// Determine the PyTorch backend.
|
||||
let torch_backend = torch_backend
|
||||
|
|
|
@ -374,16 +374,7 @@ pub(crate) async fn add(
|
|||
let hasher = HashStrategy::default();
|
||||
let sources = SourceStrategy::Enabled;
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in settings.resolver.index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
settings.resolver.index_locations.cache_index_credentials();
|
||||
|
||||
// Initialize the registry client.
|
||||
let client = RegistryClientBuilder::try_from(client_builder)?
|
||||
|
|
|
@ -593,16 +593,7 @@ async fn do_lock(
|
|||
.keyring(*keyring_provider)
|
||||
.allow_insecure_host(network_settings.allow_insecure_host.clone());
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
for index in target.indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
|
|
|
@ -1626,16 +1626,7 @@ pub(crate) async fn resolve_names(
|
|||
.keyring(*keyring_provider)
|
||||
.allow_insecure_host(network_settings.allow_insecure_host.clone());
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
// Initialize the registry client.
|
||||
let client = RegistryClientBuilder::try_from(client_builder)?
|
||||
|
@ -1797,16 +1788,7 @@ pub(crate) async fn resolve_environment(
|
|||
let marker_env = interpreter.resolver_marker_environment();
|
||||
let python_requirement = PythonRequirement::from_interpreter(interpreter);
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
// Initialize the registry client.
|
||||
let client = RegistryClientBuilder::try_from(client_builder)?
|
||||
|
@ -1978,16 +1960,7 @@ pub(crate) async fn sync_environment(
|
|||
let interpreter = venv.interpreter();
|
||||
let tags = venv.interpreter().tags()?;
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
// Initialize the registry client.
|
||||
let client = RegistryClientBuilder::try_from(client_builder)?
|
||||
|
@ -2193,16 +2166,7 @@ pub(crate) async fn update_environment(
|
|||
}
|
||||
}
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
// Initialize the registry client.
|
||||
let client = RegistryClientBuilder::try_from(client_builder)?
|
||||
|
|
|
@ -682,16 +682,7 @@ pub(super) async fn do_sync(
|
|||
// If necessary, convert editable to non-editable distributions.
|
||||
let resolution = apply_editable_mode(resolution, editable);
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
// Populate credentials from the target.
|
||||
store_credentials_from_target(target);
|
||||
|
|
|
@ -242,16 +242,7 @@ async fn venv_impl(
|
|||
python.into_interpreter()
|
||||
};
|
||||
|
||||
// Add all authenticated sources to the cache.
|
||||
for index in index_locations.allowed_indexes() {
|
||||
if let Some(credentials) = index.credentials() {
|
||||
let credentials = Arc::new(credentials);
|
||||
uv_auth::store_credentials(index.raw_url(), credentials.clone());
|
||||
if let Some(root_url) = index.root_url() {
|
||||
uv_auth::store_credentials(&root_url, credentials.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
index_locations.cache_index_credentials();
|
||||
|
||||
// Check if the discovered Python version is incompatible with the current workspace
|
||||
if let Some(requires_python) = requires_python {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue