From 3fb3c9af03599d5ebcca6bc0d663daf396c18578 Mon Sep 17 00:00:00 2001 From: liam Date: Tue, 28 Oct 2025 08:18:13 -0400 Subject: [PATCH] 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. --- crates/uv-python/src/discovery.rs | 49 +++++++++++++++++++++++++++++-- crates/uv/tests/it/common/mod.rs | 4 +++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/crates/uv-python/src/discovery.rs b/crates/uv-python/src/discovery.rs index 9c922e90e..b4c816a9e 100644 --- a/crates/uv-python/src/discovery.rs +++ b/crates/uv-python/src/discovery.rs @@ -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"); diff --git a/crates/uv/tests/it/common/mod.rs b/crates/uv/tests/it/common/mod.rs index 3ca205ee6..6f0157ece 100644 --- a/crates/uv/tests/it/common/mod.rs +++ b/crates/uv/tests/it/common/mod.rs @@ -227,6 +227,10 @@ impl TestContext { "managed installations, search path, or registry".to_string(), "[PYTHON SOURCES]".to_string(), )); + self.filters.push(( + "search path or registry".to_string(), + "[PYTHON SOURCES]".to_string(), + )); self.filters.push(( "registry or search path".to_string(), "[PYTHON SOURCES]".to_string(),