microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.29k stars 1.17k forks source link

Support discovering interpreters managed using `asdf-vm` which are run from workspace directory #20752

Open KevoSoftworks opened 1 year ago

KevoSoftworks commented 1 year ago

I use asdf-vm to manage various versions of Python binaries. This version manager allows one to define a specific Python version for a specific directory by making use of shims. However, this means that the selection of which Python version to use is dependent on the current working directory. This is where I am having issues with vscode-python.

Reproduction

Assume the VSCode workspace directory to be /home/kevin/dir1/dir2

Assume the following script, located in /tmp/test.sh:

#!/bin/sh
pwd

Select this script as the Python interpreter (Command pallette, > Python: Select Interpreter -> /tmp/test.sh).

Behaviour

Expected

pwd prints /home/kevin/dir1/dir2

Actual

pwd prints /home/kevin

Note: Both cases will generate an error as /tmp/test.sh is not a valid Python interpreter. The JSON error from the Python output found below is thus not related to the actual issue I am experiencing.

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` > /tmp/test.sh -I ~/.vscode-oss/extensions/ms-python.python-2023.3.10551009/pythonFiles/get_output_via_markers.py ~/.vscode-oss/extensions/ms-python.python-2023.3.10551009/pythonFiles/interpreterInfo.py [ERROR 2023-1-24 13:24:48.606]: Failed to parse interpreter information for >> /tmp/test.sh -I /home/kevin/.vscode-oss/extensions/ms-python.python-2023.3.10551009/pythonFiles/get_output_via_markers.py /home/kevin/.vscode-oss/extensions/ms-python.python-2023.3.10551009/pythonFiles/interpreterInfo.py << with Error: python /home/kevin/.vscode-oss/extensions/ms-python.python-2023.3.10551009/pythonFiles/interpreterInfo.py returned bad JSON (/home/kevin ) (SyntaxError: Unexpected token / in JSON at position 0) ```

User Settings

``` languageServer: "Pylance" ```

Extension version: 2023.3.10551009 VSCodium version: VSCodium 1.75.1 (c6a9727b801542499d2b59cb7db4224e060fc578, 2023-02-09T22:41:50.017Z) OS version: Linux x64 6.1.9-200.fc37.x86_64 Modes: Sandboxed: No

karrtikr commented 1 year ago

I'm assuming path to such interpreters is global. The issue is that if we're having multi-root workspace, i.e multiple workspace directories opened simultaneously, the same interpreter could be valid in one workspace directory but invalid in another. And there's no trivial way to know which directory the interpreter belongs to.

karrtikr commented 1 year ago

Turning this into a feature request. We are going to give the community 60 days from when this issue was created to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.

Feel free to update the title of the issue accordingly.

brettcannon commented 1 year ago

Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future.

We do encourage people to continue 👍 the first/opening comment as it helps us prioritize our work based on what the community seems to want the most.

karrtikr commented 5 months ago

Related: https://github.com/microsoft/vscode-python/issues/19132.