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?

zyxue
  • 7,904
  • 5
  • 48
  • 74

2 Answers2

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.

Brett Cannon
  • 14,438
  • 3
  • 45
  • 40
  • 2
    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/` – zyxue Jun 30 '20 at 02:57
  • 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? – anddam Jul 20 '22 at 09:26
  • @anddam 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. – Brett Cannon Jul 24 '22 at 04:13
  • 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 ? – Xiang ZHU Oct 17 '22 at 20:18
  • You can point to a custom isort installation via https://code.visualstudio.com/docs/python/settings-reference#_refactoring-sort-imports-settings . We don't use it by default because we can control for performance and compatibility better when we ship isort ourselves. – Brett Cannon Oct 24 '22 at 20:59
  • 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. – Shawn May 02 '23 at 18:37
  • @Shawn you can find the docs for the isort extension's settings at https://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. – Brett Cannon May 05 '23 at 19:28
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.
julie
  • 172
  • 1
  • 6
  • Should isort's output appear in Output > "Python" pane? – anddam Jul 19 '22 at 13:54
  • 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. – anddam Jul 20 '22 at 08:51