question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable import sorting for virtualenv

See original GitHub issue

Environment data

  • VS Code version: 1.49.2
  • Extension version (available under the Extensions sidebar): 2020.9.111407
  • OS and version: macOS 10.15.6
  • Type of virtual environment used: poetry
  • Value of the python.languageServer setting: Pylance

Expected behaviour

isort shouldn’t run. Because the extension passes file contents via stdin, isort can’t know whether the file should be ignored: https://github.com/PyCQA/isort/issues/1500

More generally, it’s counterintuitive that 3rd party files are treated the same as project files. These files are sometimes viewed or edited to aid in debugging, but that shouldn’t trigger formatting, import sorting, etc.

Actual behaviour

isort is run.

Output pane:

> <...>/.venv/bin/isort - --diff
cwd: <...>/.venv/lib/python3.8/site-packages/<package>

Steps to reproduce:

  1. Open a file in the project’s virtualenv site-packages directory and save it.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:21

github_iconTop GitHub Comments

2reactions
alexregcommented, Jun 2, 2022

@elpablete Yep, it’s a bit odd… definitely a hack, but it works. Hopefully the authors of vscode-python will add a proper solution soon.

1reaction
elpabletecommented, Jun 2, 2022

Thanks for the class. That true seemed weird to me so it is cool to actually learn what it means.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable python import sorting in VSCode - Stack Overflow
I am trying to disable vscode from formatting my python imports when I save my file. I have some code that must run...
Read more >
Configuration options for isort
To enable this, isort exposes a plethora of options to specify how you want your imports sorted, organized, and formatted. Too busy to...
Read more >
reorder-python-imports - Visual Studio Marketplace
VSCode extension to sort and refactor python imports using reorder-python-imports . Unlike other import organizers, reorder-python-imports ...
Read more >
Incorrect import sorting: Local libraries are treated as third-party
path and thus in the interpreter paths when we're indexing the configured SDK. As a workaround you can explicitly remove the corresponding entry...
Read more >
Python layer - Spacemacs (develop)
If you want imports to be automatically sorted when you save a file (using isort), set the python-sort-imports-on-save variable in the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found