Skip to content

Commit

Permalink
Allow alternative implementations to be selected if they use the defa…
Browse files Browse the repository at this point in the history
…ult executable name
  • Loading branch information
zanieb committed Sep 18, 2024
1 parent a18fd5e commit f244cd5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/uv-python/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,9 @@ pub(crate) fn find_python_installation(
LenientImplementationName::Known(ImplementationName::CPython),
) && !request.allows_alternative_implementations()
&& !installation.source.allows_alternative_implementations()
// If found on the search path with the default executable name we should not skip it
&& !(installation.uses_default_executable_name()
&& installation.source == PythonSource::SearchPath)
{
debug!("Skipping alternative implementation {}", installation.key());
continue;
Expand Down
17 changes: 17 additions & 0 deletions crates/uv-python/src/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::managed::{ManagedPythonInstallation, ManagedPythonInstallations};
use crate::platform::{Arch, Libc, Os};
use crate::{
downloads, Error, Interpreter, PythonDownloads, PythonPreference, PythonSource, PythonVersion,
VersionRequest,
};

/// A Python interpreter and accompanying tools.
Expand Down Expand Up @@ -199,6 +200,22 @@ impl PythonInstallation {
pub fn into_interpreter(self) -> Interpreter {
self.interpreter
}

/// Whether or not this Python installation uses a default Python name, like `python`,
/// `python3`, or `python.exe`.
pub(crate) fn uses_default_executable_name(&self) -> bool {
let Some(file_name) = self.interpreter.sys_executable().file_name() else {
return false;
};
let Some(name) = file_name.to_str() else {
return false;
};
VersionRequest::Any
.default_names()
.into_iter()
.flatten()
.any(|default_name| name == default_name)
}
}

#[derive(Error, Debug)]
Expand Down

0 comments on commit f244cd5

Please sign in to comment.