Clarify system Python discovery logging order (#16463)

Resolves https://github.com/astral-sh/uv/issues/16453

When `--system` is used, the debug log now reports interpreter discovery
sources in the same order they are probed, prioritising the PATH ahead
of managed installs on every platform. I also added a few unit tests
that use `DiscoveryPreferences::sources`, ensuring the log strings stay
aligned with the actual discovery sequence for both System and
OnlySystem preferences.
This commit is contained in:
liam
2025-10-28 08:18:13 -04:00
committed by GitHub
parent 399094aedc
commit 3fb3c9af03
2 changed files with 50 additions and 3 deletions
+46 -3
View File
@@ -3167,7 +3167,7 @@ impl PythonPreference {
fn sources(self) -> &'static [PythonSource] {
match self {
Self::OnlyManaged => &[PythonSource::Managed],
Self::Managed | Self::System => {
Self::Managed => {
if cfg!(windows) {
&[
PythonSource::Managed,
@@ -3178,9 +3178,20 @@ impl PythonPreference {
&[PythonSource::Managed, PythonSource::SearchPath]
}
}
Self::System => {
if cfg!(windows) {
&[
PythonSource::SearchPath,
PythonSource::Registry,
PythonSource::Managed,
]
} else {
&[PythonSource::SearchPath, PythonSource::Managed]
}
}
Self::OnlySystem => {
if cfg!(windows) {
&[PythonSource::Registry, PythonSource::SearchPath]
&[PythonSource::SearchPath, PythonSource::Registry]
} else {
&[PythonSource::SearchPath]
}
@@ -3345,7 +3356,9 @@ mod tests {
};
use uv_platform::{Arch, Libc, Os};
use super::{Error, PythonVariant};
use super::{
DiscoveryPreferences, EnvironmentPreference, Error, PythonPreference, PythonVariant,
};
#[test]
fn interpreter_request_from_str() {
@@ -3591,6 +3604,36 @@ mod tests {
);
}
#[test]
fn discovery_sources_prefer_system_orders_search_path_first() {
let preferences = DiscoveryPreferences {
python_preference: PythonPreference::System,
environment_preference: EnvironmentPreference::OnlySystem,
};
let sources = preferences.sources(&PythonRequest::Default);
if cfg!(windows) {
assert_eq!(sources, "search path, registry, or managed installations");
} else {
assert_eq!(sources, "search path or managed installations");
}
}
#[test]
fn discovery_sources_only_system_matches_platform_order() {
let preferences = DiscoveryPreferences {
python_preference: PythonPreference::OnlySystem,
environment_preference: EnvironmentPreference::OnlySystem,
};
let sources = preferences.sources(&PythonRequest::Default);
if cfg!(windows) {
assert_eq!(sources, "search path or registry");
} else {
assert_eq!(sources, "search path");
}
}
#[test]
fn interpreter_request_to_canonical_string() {
assert_eq!(PythonRequest::Default.to_canonical_string(), "default");