microsoft / vscode-isort

Import sorting for python using the isort library.
https://marketplace.visualstudio.com/items?itemName=ms-python.isort
MIT License
91 stars 22 forks source link

`fromEnvironment` should also pick up the python path from jupyter #389

Closed tautomer closed 9 months ago

tautomer commented 9 months ago

I am not sure if this is a bug or not.

Say, you create a new folder and work with some Jupyter notebooks. Before the first time you open a python script in this workspace, isort will still pick up the default python interpreter, even if a kernel for Jupyter is already selected.

For example, here I created a folder called isort. The fromEnvironment option actually picks up the default python shipped with the OS. This will only be changed if I create a dummy python script, open it up, and select an interpreter there. In my view, the moment you select Jupyter kernel, isort extension should be aware as well.

2024-02-20 11:50:04.827 [info] Name: isort
2024-02-20 11:50:04.827 [info] Module: isort
2024-02-20 11:50:04.827 [info] Python extension loading
2024-02-20 11:50:04.827 [info] Waiting for interpreter from python extension.
2024-02-20 11:50:04.827 [error] Python version 3.6 is not supported.
2024-02-20 11:50:04.827 [error] Selected python path: /usr/bin/python3
2024-02-20 11:50:04.827 [error] Supported versions are 3.7 and above.
2024-02-20 11:50:04.827 [info] No interpreter found from setting isort.interpreter
2024-02-20 11:50:04.827 [info] Getting interpreter from ms-python.python extension for workspace /vast/home/user/codes/isort
2024-02-20 11:50:04.827 [info] Python extension loaded
2024-02-20 11:50:04.827 [error] Python version 3.6 is not supported.
2024-02-20 11:50:04.827 [error] Selected python path: /usr/bin/python3
2024-02-20 11:50:04.827 [error] Supported versions are 3.7 and above.
2024-02-20 11:50:04.827 [info] No interpreter found for /vast/home/user/codes/isort in settings or from ms-python.python extension
2024-02-20 11:50:04.827 [error] Python interpreter missing:
[Option 1] Select python interpreter using the ms-python.python.
[Option 2] Set an interpreter using "isort.interpreter" setting.
 Please use Python 3.7 or greater.
karthiknadig commented 9 months ago

@tautomer The python selection is coming from python extension. isort uses whatever it gets from either the isort.interpreter setting or from the python extension. It does not do its own selection.