Reputation: 79
I want to use autosave in Visual Studio Code and apply commonly used tools like flake8, mypy, isort, and black.
Flake8, mypy, and black work fine, but isort doesn't work at all. Is there a way to solve this problem?
My settings.json file looks like this:
{
"python.terminal.activateEnvInCurrentTerminal": false,
"python.defaultInterpreterPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.flake8Path": "${workspaceFolder}\\.venv\\Scripts\\pflake8.exe",
"python.linting.mypyEnabled": true,
"python.formatting.provider": "black",
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.formatOnSave": true
}
}
Upvotes: 5
Views: 4311
Reputation: 1237
There's now a new and much better, faster, and more popular alternative now:
with
It is an extremely efficient implementation of isort, black, and other linting tools, available as a single package.
Then, just set up ruff to format your file on auto-save.
Upvotes: 3
Reputation: 79
I have solved this issue. I did not know that "isort" was a default in vscode, and so I uninstalled it.
I have reinstalled "isort". And I have modified the "settings.json" as follows:
{
"python.terminal.activateEnvInCurrentTerminal": false,
"python.defaultInterpreterPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
"isort.args": [
"--profile",
"black"
]
}
Upvotes: 2
Reputation: 35
You can try adding the following line to your settings.json file:
"python.sortImports.path": "${workspaceFolder}\\.venv\\Scripts\\isort.exe"
After that, save the settings.json file and restart VS Code. Hope this answer can help you
Upvotes: 0