Closed amirkarimi closed 10 months ago
@amirkarimi Check if you have a configuration file like setup.cfg where the order is being set. Also, this is a issue on isort
library itself.
We recommend using ruff
(see Ruff extension) for import sorting, as isort
has not published a fix for the issues with running using stdin. We need to use stdin to handle cases where imports are organized on save.
If you do install Ruff
, be sure to remove isort
extension, and add this to your settings ("source.organizeImports.ruff": true
) in place of "source.organizeImports": true
.
Thanks @karthiknadig.
Check if you have a configuration file like setup.cfg where the order is being set.
The only config is in pyproject.toml
which is not changing the :
[tool.isort]
profile = "black"
multi_line_output = 3
We recommend using
ruff
Thanks will give it a try though we use isort
and flake
in our pre-commit stuff, I'd rather not change those.
I'm closing this issue since seems like nothing else can be done by the extension.
@amirkarimi Ruff is a multi-tool, it implements isort
, flake8
, and black
formatter in rust. It is incredibly fast. So you can replace two tools with one. Ruff actually implements several other linter rules too (including but not limited to pylint, pyflakes, bandit, pycodestyle, pydocstyle, etc).
Consider this file which is sorted using
isort --profile black {file-name}
in the terminal:And this is the same file after running vscode
Organize Import
command.Diff:
isort
log in vscode:My theory is that
isort
behaves differently when the file content is piped into it vs provided as a file.VS Code Config
Version
OS: Ubuntu 22.04.3 Python: 3.11 isort: 5.12.0
VSCode: Commit: f1b07bd25dfad64b0167beb15359ae573aecd2cc Date: 2023-10-10T23:45:31.402Z Electron: 25.8.4 ElectronBuildId: 24154031 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Linux x64 6.2.0-36-generic snap