-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Sorting of imports (isort) is different if the file has unsaved modifications #4891
Comments
I'd be up for trying to fix this if that would help. Do you have any suggestions around how to approach this? From what I can see the issue here is that we're asking isort to operate on a temporary file like Would a suitable fix be to put the temporary file within the project workspace instead of within |
Dup of #2980 |
I don't believe that this is a duplicate of #2980 -- that issue seems to be about new, unsaved files (which presumably don't have a well-defined project nor path on disc). In contrast this issue is about unsaved modifications to existing files. I've updated the title to clarify that. |
Interestingly it looks like In any case, having tested the behaviour using stdin seems to correctly find configuration from the current directory (or ancestors), so I think this is a better solution than moving the temporary file. This would likely also solve #2980 for |
My current plan for this is to extend the I tried doing this using the existing I'm currently working on passing through a (new) |
This turns out to be redundant -- I'd missed that
I've done this via changing |
I believe that I'm experiencing the same issue that Peter originally brought up. In particular, here's how the issue arises:
Upon saving, my imports are re-ordered. The configurations in my If I were to commit the changes to git at this point, the diff would be a bit unwieldy, even thought the actual contents of the file were not changed before I saved. Then, without making any changes to the file, I save it again. This completely reorders the imports to what they previously were. The configurations in my So, in summary...
My current workaroundTo save, I have to press The effect on my workIt's definitely annoying, but it's not an earth-melting issue. I'm still able to get work done with VS Code. That said, because saving a file is such a frequent action, this annoyance comes up a lot. |
If anyone wants a workaround, setting the location of your settings file (pyproject.toml/setup.cfg) via an argument to isort works well. "python.sortImports.args": [
"--settings-path",
"somewhere/setup.cfg"
] |
I have the same issue and the this workaround save my sanity :) |
Environment data
Expected behaviour
That when running the "Sort Imports" command on a file, the imports are sorted according to my
setup.cfg
config regardless of whether the file is currently saved or not.Actual behaviour
When running the "Sort Imports" command on a file:
setup.cfg
config is respectedsetup.cfg
config is not respectedSteps to reproduce:
Given this config:
setup.cfg
anddemo.py
next to each other in a new folderdemo.py
demo.py
, it should be unchangeddemo.py
, without saving itdemo.py
, note that its imports have changed ordering to ignore thelength_sort
optionThis reproduces with much more complex configs, and other options are also ignored, so I strongly suspect the
setup.cfg
file isn't being picked up as a whole if the file is modified.The text was updated successfully, but these errors were encountered: