Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow discovery of interpereters in virtual environments activated by a shim #4032

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Jun 5, 2024

Closes #4009
Closes #2109

@zanieb zanieb added the enhancement New feature or improvement to existing functionality label Jun 5, 2024
@zanieb
Copy link
Member Author

zanieb commented Jun 5, 2024

Considering if this is the correct approach still. We should also test with the pyenv-virtualenv shim.

@zanieb
Copy link
Member Author

zanieb commented Jun 5, 2024

I find this implementation awkward as I only want this to be used if it's a virtual environment interpreter but we can't easily enforce that in python_executables. I'll probably poke at a better implementation.

source,
InterpreterSource::ProvidedPath | InterpreterSource::ParentInterpreter
) {
match result {
Copy link
Member Author

Choose a reason for hiding this comment

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

No changes to the match statement, just indented

@zanieb zanieb marked this pull request as ready for review June 6, 2024 12:42
@zanieb
Copy link
Member Author

zanieb commented Jun 6, 2024

I'd appreciate input on a better approach here.

@zanieb zanieb requested a review from charliermarsh June 6, 2024 12:43
@charliermarsh
Copy link
Member

Just confirming: still relevant to review? I know there was some back-and-forth on the issue but didn't read it deeply.

@zanieb
Copy link
Member Author

zanieb commented Jun 8, 2024

@charliermarsh yeah this is still necessary if we want to support detecting virtual environments that are only activated by an executable shim. I'm not in love with the implementation though.

.chain(
sources.contains(InterpreterSource::ShimEnvironment).then(||
python_executables_from_search_path(version, implementation).next()
.map(|path| Ok((InterpreterSource::ShimEnvironment, path)))
Copy link
Member

Choose a reason for hiding this comment

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

How do we know this is a shim?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't. We're going to naively say the first executable in the path might be a shim then verify it during the interpreter query portion.

.filter(move |result| match result {
.filter(move |result| {
// Always skip shim environments that are not virtual environments; this filter is deferred
// from `python_executables` to avoid querying the interpreter there
Copy link
Member

Choose a reason for hiding this comment

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

What is a shim environment that isn't a virtual environment? What would appear here to fail this filter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we're just taking the first executable and calling it a "shim environment" in python_executables this filtering is where we check if the executable is actually a shim which invokes inside a virtual environment.

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 and the other review comment are my concern with this implementation, it's misleading but we do it to avoid querying the interpreter during python_executables)

@zanieb zanieb requested a review from konstin June 10, 2024 14:31
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
3 participants