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 65b41b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/uv-python/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,14 @@ pub(crate) fn find_python_installation(

// If it's an alternative implementation, and alternative implementations aren't allowed
// skip it
let allows_alternative_implementation = !(request.allows_alternative_implementations()
|| installation.source.allows_alternative_implementations()
|| (installation.uses_default_executable_name()
&& installation.source == PythonSource::SearchPath));
if !matches!(
installation.implementation(),
LenientImplementationName::Known(ImplementationName::CPython),
) && !request.allows_alternative_implementations()
&& !installation.source.allows_alternative_implementations()
) && !allows_alternative_implementation
{
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 65b41b4

Please sign in to comment.