Respect named --index and --default-index values in tool.uv.sources (#7910)

## Summary

If you pass a named index via the CLI, you can now reference it as a
named source. This required some surprisingly large refactors, since we
now need to be able to track whether a given index was provided on the
CLI vs. elsewhere (since, e.g., we don't want users to be able to
reference named indexes defined in global configuration).

Closes https://github.com/astral-sh/uv/issues/7899.
This commit is contained in:
Charlie Marsh 2024-10-15 16:56:24 -07:00 committed by GitHub
parent a034a8b83b
commit 2153c6ac0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 370 additions and 133 deletions

View file

@ -30,7 +30,7 @@ use tracing::{debug, info_span, instrument, Instrument};
pub use crate::error::{Error, MissingHeaderCause};
use uv_configuration::{BuildKind, BuildOutput, ConfigSettings, SourceStrategy};
use uv_distribution::{LowerBound, RequiresDist};
use uv_distribution_types::Resolution;
use uv_distribution_types::{IndexLocations, Resolution};
use uv_fs::{rename_with_retry, PythonExt, Simplified};
use uv_pep440::Version;
use uv_pep508::PackageName;
@ -250,6 +250,7 @@ impl SourceBuild {
build_context: &impl BuildContext,
source_build_context: SourceBuildContext,
version_id: Option<String>,
locations: &IndexLocations,
source_strategy: SourceStrategy,
config_settings: ConfigSettings,
build_isolation: BuildIsolation<'_>,
@ -272,6 +273,7 @@ impl SourceBuild {
let (pep517_backend, project) = Self::extract_pep517_backend(
&source_tree,
fallback_package_name,
locations,
source_strategy,
&default_backend,
)
@ -371,6 +373,7 @@ impl SourceBuild {
package_name.as_ref(),
package_version.as_ref(),
version_id.as_deref(),
locations,
source_strategy,
build_kind,
level,
@ -433,6 +436,7 @@ impl SourceBuild {
async fn extract_pep517_backend(
source_tree: &Path,
package_name: Option<&PackageName>,
locations: &IndexLocations,
source_strategy: SourceStrategy,
default_backend: &Pep517Backend,
) -> Result<(Pep517Backend, Option<Project>), Box<Error>> {
@ -465,6 +469,7 @@ impl SourceBuild {
let requires_dist = RequiresDist::from_project_maybe_workspace(
requires_dist,
source_tree,
locations,
source_strategy,
LowerBound::Allow,
)
@ -803,6 +808,7 @@ async fn create_pep517_build_environment(
package_name: Option<&PackageName>,
package_version: Option<&Version>,
version_id: Option<&str>,
locations: &IndexLocations,
source_strategy: SourceStrategy,
build_kind: BuildKind,
level: BuildOutput,
@ -915,6 +921,7 @@ async fn create_pep517_build_environment(
let requires_dist = RequiresDist::from_project_maybe_workspace(
requires_dist,
source_tree,
locations,
source_strategy,
LowerBound::Allow,
)