Skip to content

Comments

Skip invalid interpreters when searching for requested interpreter executable name#4308

Merged
zanieb merged 1 commit intomainfrom
zb/executable-name-find
Jun 13, 2024
Merged

Skip invalid interpreters when searching for requested interpreter executable name#4308
zanieb merged 1 commit intomainfrom
zb/executable-name-find

Conversation

@zanieb
Copy link
Member

@zanieb zanieb commented Jun 13, 2024

Previously, we took the first executable on the PATH but if it was not a usable interpreter we'd fail. Now, we'll continue searching in the path until we find an interpreter as we do with the standard executable names.

@zanieb zanieb added the enhancement New feature or improvement to existing functionality label Jun 13, 2024
@zanieb zanieb force-pushed the zb/executable-name-find branch from e88ea0b to eb8d5d1 Compare June 13, 2024 16:39
Comment on lines +364 to +365
// TODO(zanieb): Move filtering to callers
filter_by_system_python(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactor wasn't needed for this pull request but we'll do this in the next change to facilitate respecting the system python preferences when reading executable names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO addressed in #4310

Comment on lines -485 to 516

fn find_toolchain_with_executable_name(
name: &str,
cache: &Cache,
) -> Result<ToolchainResult, Error> {
let Some(executable) = which(name).ok() else {
return Ok(ToolchainResult::Err(
ToolchainNotFound::ExecutableNotFoundInSearchPath(name.to_string()),
));
};
Ok(ToolchainResult::Ok(Toolchain {
source: ToolchainSource::SearchPath,
interpreter: Interpreter::query(executable, cache)?,
}))
/// Lazily iterate over all Python interpreters on the path with the given executable name.
fn python_interpreters_with_executable_name<'a>(
name: &'a str,
cache: &'a Cache,
) -> impl Iterator<Item = Result<(ToolchainSource, Interpreter), Error>> + 'a {
python_interpreters_from_executables(
which_all(name)
.into_iter()
.flat_map(|inner| inner.map(|path| Ok((ToolchainSource::SearchPath, path)))),
cache,
)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the core change

@zanieb zanieb marked this pull request as ready for review June 13, 2024 17:03
@zanieb zanieb changed the title Search for valid interpreter with requested executable name Skip invalid interpreters when searching for requested interpreter executable name Jun 13, 2024
@zanieb zanieb merged commit b07c132 into main Jun 13, 2024
@zanieb zanieb deleted the zb/executable-name-find branch June 13, 2024 17:36
zanieb added a commit that referenced this pull request Aug 19, 2024
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.
zanieb added a commit that referenced this pull request Aug 19, 2024
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.
zanieb added a commit that referenced this pull request Aug 19, 2024
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.
zanieb added a commit that referenced this pull request Aug 20, 2024
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.
zanieb added a commit that referenced this pull request Aug 20, 2024
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.
zanieb added a commit that referenced this pull request Aug 20, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants