Apply system Python filtering to executable name requests (#4309)

Executable name requests were being treated as explicit requests to
install into system environments, but I don't think it should be as it's
implicit what environment you'll end up in. Following #4308, we allow
multiple executables to be found so we can filter here.

Concretely, this means `--system` is required to install into a system
environment discovered with e.g. `--python=python`. The flag is still
not required for cases where we're not mutating environment.
This commit is contained in:
Zanie Blue 2024-08-19 15:51:37 -05:00
parent 01fb41f5c4
commit 47fb902104
2 changed files with 51 additions and 5 deletions

View file

@ -717,11 +717,15 @@ pub fn find_python_installations<'a>(
if preference.allows(PythonSource::SearchPath) {
debug!("Checking for Python interpreter at {request}");
Box::new(
python_interpreters_with_executable_name(name, cache).map(|result| {
result
.map(PythonInstallation::from_tuple)
.map(FindPythonResult::Ok)
}),
python_interpreters_with_executable_name(name, cache)
.filter(move |result| {
result_satisfies_environment_preference(result, environments)
})
.map(|result| {
result
.map(PythonInstallation::from_tuple)
.map(FindPythonResult::Ok)
}),
)
} else {
Box::new(std::iter::once(Err(Error::SourceNotAllowed(