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

"organize imports" is inconsistent depending on whether the file is saved or not #8245

Closed
jleclanche opened this issue Oct 28, 2019 · 9 comments
Labels
area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug

Comments

@jleclanche
Copy link

Related: #4831

I have some isort config set up in tox.ini with a different configuration (specifically, a different set of known_first_party) than the global one set up in vscode.

The problem: If the file is not saved yet, "organize imports" will result in a different output (using the global isort config) than if the file is saved (using the project-wide one). The behaviour when the file is saved is the correct and expected one.

I suspect this happens because vscode runs isort on a temp file in a different directory when it's not saved.

@jleclanche jleclanche added data science bug Issue identified by VS Code Team member as probable bug labels Oct 28, 2019
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Oct 28, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Oct 28, 2019
@brettcannon
Copy link
Member

Chances are the difference is when running isort on a saved file it is discovering its configuration file while an unsaved file buffer is being run in a temp directory and thus not in a place where isort will pick up its configuration file.

@jleclanche
Copy link
Author

Yep that was my guess in the OP as well ;)

@ericsnowcurrently
Copy link
Member

@jleclanche in the interest of reproducing this, what should I put in my tox.ini to reproduce the behavior?

@ericsnowcurrently ericsnowcurrently added the info-needed Issue requires more information from poster label Oct 28, 2019
@jleclanche
Copy link
Author

@ericsnowcurrently any mismatch works. This especially:

[isort]
indent = tab
line_length = 88
balanced_wrapping = true
combine_as_imports = true
default_section = THIRDPARTY
ensure_newline_before_comments = true
include_trailing_comma=True
multi_line_output = 3
known_first_party = foo

And then give a different known_first_party or none at all to vscode. Then do:

import foo
import os
import django
from foo import bar
from django import baz

And imports should be wildly inconsistent between saves.

@ericsnowcurrently ericsnowcurrently removed the info-needed Issue requires more information from poster label Oct 28, 2019
@ericsnowcurrently
Copy link
Member

@jleclanche, I'll take a look as soon as I can.

@mikeroll
Copy link

mikeroll commented Nov 1, 2019

@ericsnowcurrently also please take a look at my comment here: #5840 (comment)
I was interested in tackling this a while ago, but there is a lot of confusion surrounding the current isort implementation.

@ericsnowcurrently
Copy link
Member

I was able to verify that with an unsaved file I get:

import os

import django
import foo
from django import baz
from foo import bar

and with a saved file I get:

import os

import django
from django import baz

import foo
from foo import bar

We'll investigate further.

@ericsnowcurrently ericsnowcurrently removed their assignment Nov 11, 2019
@ericsnowcurrently ericsnowcurrently added feature-refactoring needs proposal Need to make some design decisions and removed triage labels Nov 11, 2019
@brettcannon brettcannon added area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. and removed feature-refactoring labels Apr 9, 2020
@pe224
Copy link

pe224 commented May 3, 2020

Stumbled over this coming from issue #5840

@DonJayamanne suggested a fix there which would solve the issue here as well.
Creating the tmpfile at the same location as the original file so that formatters can pick up the right project-specific configurations.

@karrtikr
Copy link

karrtikr commented Aug 3, 2020

Can anyone confirm if this issue is solved with #9128? This looks like dup of #4891.

@karrtikr karrtikr closed this as completed Aug 6, 2020
@ghost ghost removed the needs proposal Need to make some design decisions label Aug 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

8 participants