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