Closed dan-blanchard closed 3 months ago
https://github.com/pyenv/pyenv#choosing-the-python-version has the specification on how pyenv chooses an interpreter by default. I think detecting the file and using it as appropriate seems like a sensible enhancement (maybe even the file traversal to the parent directory, but not as sure on that one).
@brettcannon I'm not sure if it's possible but you should be able to let pyenv do the heavy lifting if you use the shims it provides as the interpreter, as long as its run in a context (i.e. directory) aware way.
Hi @brettcannon, will this issue be addressed in any near future? Thanks!
@eugenweissbart sorry, we don't give ETAs since they always turn out to be wrong. 😉
Would like to see this feature as well.
@djdembeck please make sure to upvote the opening comment as that's how we determine community interest.
please make sure to upvote the opening comment as that's how we determine community interest.
@brettcannon This is now the 8th most upvoted issue in this project. Is there anything else we can do to get this prioritized?
This is now the 8th most upvoted issue in this project. Is there anything else we can do to get this prioritized?
Solve the first 7 issues or write a PR? 😉 Unfortunately our environment time has been spent on UX improvements that affect everyone as of late (especially beginners), so we have not tried to tackle this specific issue (or other issues related to specific tools).
We are also working on a proposed API for the extension which would allow someone to create their own extension to implement this functionality if someone wanted to.
Would like to see this feature as well.
Couple ways to go about it:
pyenv determines which Python version to use by reading it from the following sources, in this order: https://github.com/pyenv/pyenv/blob/master/README.md#understanding-python-version-selection
Pros: No need to launch the pyenv binary
Cons: This would imply that we do the heavy lifting:
.python-version
file correctlyRun <pyenv> which python
in the cwd of the workspace. We can either:
2.1 Locate the pyenv binary and run the command using child_process.exec.
For eg. it could be /home/node/.pyenv/bin/pyenv which python
.
2.2 Open a hidden terminal and simply run the command: pyenv which python
.
2.2
is potentially more reliable as it makes sure shell initialization scripts are being run, which include pyenv install instructions. However this requires https://github.com/microsoft/vscode/issues/199611 to be fixed.
To avoid relying on internal details of pyenv and keep things simple, approach 2 sounds reasonable.
Tested 2.1
and it seems to be working just fine on Windows and Linux, despite not executing the shell instructions, hence deciding to go with that for now. If we observe issues with that, we can switch to 2.2
once https://github.com/microsoft/vscode/issues/199611 is fixed.
Fix should be out in the pre-release version of the extension, use the following to try it out:
Environment data
Actual behavior
You have to manually select the pyenv interpreter for each workspace folder.
Expected behavior
It should detect the workspace pyenv interpreter based on the
.python-version
file present in the workspace folder root.For example, every folder I have added to my workspace has a
.python-version
file that pyenv creates when you runpyenv local NAME_OF_VENV
in that folder. The file contains a single string which is the name of the folder/symlink in~/.pyenv/versions/
that should be used.