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:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user