Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isort when run via the VSCode extension is inconsistent with the result of running isort separately #339

Closed
HarrisonWilde opened this issue Oct 17, 2023 · 2 comments
Labels
triage-needed Issue is not triaged.

Comments

@HarrisonWilde
Copy link

I am currently developing a package. When I use absolute imports within the package to import other parts of the package (e.g. from mypackage.module import x), isort on save from VSCode sorts these imports into the 3rd party package "section" at the top of the file. However, when I run isort explicitly on the command line on the same project, the absolute imports of parts of my package are separated from the third party ones. This is quite an annoying inconsistency as every time I commit I end up getting a warning from my pre-commit hooks.

The only config I have for isort is this in my pyproject.toml:

[tool.isort]
profile = "black"

This is the pre-commit config:

  - repo: https://github.com/pycqa/isort
    rev: 5.12.0
    hooks:
      - id: isort
        language_version: python3.11
        args: ["--settings-path", "pyproject.toml"]
@github-actions github-actions bot added the triage-needed Issue is not triaged. label Oct 17, 2023
@HarrisonWilde
Copy link
Author

Ok, adding --known-first-party mypackage arguments to the extension settings appendage fixes this problem.

Feel free to close this issue. However, I find it odd that there would be this discrepancy as this is not required when running isort directly.

@brettcannon
Copy link
Member

The discrepancy is quite possibly due to isort; we have discovered multiple places where isort operates differently when run against a file path compared to having code passed in via stdin (which is the default when using a language server).

We actually recommend people try our ruff as it supports isort-compatible import sorting, is extremely fast, and has a great VS Code extension: https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff .

@brettcannon brettcannon closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Issue is not triaged.
Projects
None yet
Development

No branches or pull requests

2 participants