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(),