How to find which isort is vscode exactly using
Asked Answered
A

2

6

https://code.visualstudio.com/docs/python/editing#_sort-imports

I have set

    "[python]": {
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    },

in vscode, it looks the right python interpreter is chosen, but it doesn't produce sorted imports as expected. I suspect a wrong isort is being used by vscode, how could I find out which isort is vscode exactly using?

Achorn answered 26/6, 2020 at 23:48 Comment(0)
P
7

VS Code ships with its own copy of isort that it uses which is currently isort 5.10.1. You can look in the Output panel in the Python channel to see how the extension is executing isort.

But do note that the Python extension is moving away from embedded isort support and instead to a dedicated isort extension.

Portie answered 30/6, 2020 at 0:29 Comment(7)
thank you I found it in ~/.vscode/extensions/ms-python.python-2020.6.90262/pythonFiles/sortImports.py and ~/.vscode/extensions/ms-python.python-2020.6.90262/pythonFiles/lib/python/isort/Achorn
I cleaned my setup, using ms-python.isort (I was using third party freakypie.code-python-isort before) then installing ms-python.black-formatter in place of in-environment black and using the specific config suggested in ms-python.isort README. I set "isort.trace": "debug" and still I cannot see any output in either Python or Extensions channel when running Organize imports. Is that still supposed to show there?Mahratta
@Mahratta if there's going to be anything in an Output Channel it would be for the isort extension itself. If there's something specific you want to see there then please open an issue.Portie
is there any reason why VSCode doesn't use directly isort bound with the Python interpreter (so isort installed in the venv if Python interpreter is set to the venv), but use a isort extension ?Eustoliaeutectic
You can point to a custom isort installation via code.visualstudio.com/docs/python/… . We don't use it by default because we can control for performance and compatibility better when we ship isort ourselves.Portie
It appears that the link referenced by @BrettCannon no longer mentions isort at all. I don't see any way to reference a custom sort installation.Bethezel
@Bethezel you can find the docs for the isort extension's settings at marketplace.visualstudio.com/items?itemName=ms-python.isort . You can also always look under the "Feature Contributions" tab for an installed extension in the extensions view to see what settings, commands, etc. it supports.Portie
P
2

To further answer your question.

  1. Open the output console ctrl-shift-u

In the toolbar at the top of the output panel there is a dropdown list of logs/outputs that you can select.

  1. Select Python.
  2. Save a python file. You will see the commands that run, both formatting and runOnSave which are configured in the vscode settings file.
Periclean answered 22/3, 2022 at 21:47 Comment(2)
Should isort's output appear in Output > "Python" pane?Mahratta
Not even sure how to edit my own comment, but now with a working isort extension (I can see it rewriting imports in my currently open file) I have no output at all in the Output pane (from View > Output menuitem) choosing"Python" in the select menu on the right. I have actually no output at all in Output when isort works, nor in Extension choice or any other.Mahratta

© 2022 - 2024 — McMap. All rights reserved.