You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sorting imports ignores configuration on unsaved files #4433
Extension version (available under the Extensions sidebar): 2019.1.0
OS and version: macOS 10.14.3
Python version (& distribution if applicable, e.g. Anaconda): 3.5.6
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv
Expected behaviour
When I edit a Python file and sort imports, I expect it to respect the isort configuration in my project.
Actual behaviour
When I have a file that has been edited and not yet saved, sorting imports uses the default isort configuration, rather than the project specific isort configuration in setup.cfg.
I understand that it is difficult or impossible to accurately determine the config file to use for an entirely unsaved file, however this is an edited file that does exist on disk, so an appropriate configuration file for isort should be able to be found.
Steps to reproduce:
Create a Python file with the following content:
importbimportcc
Create a setup.cfg file with the following content:
[isort]
length_sort = True
Open the Python file, and add a 3rd line:
importbimportccimportaaa
Note that this file is sorted according to the length_sort configuration, but is unsorted according to the isort default of alphabetical sorting of imports.
Without saving the file, run "Sort Imports"
The file will be:
importaaaimportbimportcc
It should have remained unchanged.
Logs
No logging output.
Console output:
[Extension Host] Python Extension: Cached data exists getEnvironmentVariables, test.py
Activity
ghost added
triage-neededNeeds assignment to the proper sub-team
A few times people have asked about running commands like import sorting, formatting, etc. on unsaved, brand new files (i.e. Untitled-1). We should notify users that the command does not work on such files so they don't get a weird error message talking about e.g. EACCES.
From this issue:
I understand that it is difficult or impossible to accurately determine the config file to use for an entirely unsaved file, however this is an edited file that does exist on disk, so an appropriate configuration file for isort should be able to be found.
I apologise if this wasn't clear enough, but I was already aware of #2980 and reported this specifically because it is a different issue. In this case we know what the filename is, therefore we can either save the file automatically before formatting, or use the filename to determine the correct config file to use for formatting. Also note that the isort integration in VSCode does not need the file to be saved, again different to the linked issue.
Don Jayamanne (@DonJayamanne) I do not agree that #2980 is the "original issue", I believe it to be a different issue, that is a much more complicated issue. It would be great to get this easier, and related but different issue solved separately, as I suspect the resolutions will be entirely distinct.
For clarity: finding the correct configuration is trivial for modified files that already exist on disk, and very difficult for files that do not exist on disk at all. The former likely needs no user prompt, can always work correctly automatically, and is an obvious UX win. The latter is a complex UX issue.
Grouping this issue in with #2980 essentially means it will take longer to be solved, and will likely be solved in a worse way as a result.
I suspect that #3306 may be the same as this one, but that issue was also incorrectly closed as a duplicate of #2980.
In general, it would be great to get a reasoning for closing issues, and for us to be open to discussion around when things are actually duplicates. So far this issue has received 2 responses from maintainers containing no information. This makes it very difficult to contribute, and signals that input is not valued, as it is not being listened to and discussion is being shut down. I'm sure this is not the intention at all, and VSCode has a great community around it, but this is how it may appear.
Dan Palmer (@danpalmer)
They are the same. When running isort against a file that hasn't been saved, its the same as running it against a file that doesn't exist on disk.
The way isort works is, it will look for the configuration files by walking up form the directory containing the file that needs to be formatted. When formatting files that haven't been saved, we create a temporary file in a temporary directory, and that's where things go wonky, at that point the file is NOT in your project directory.
Again, whether the file has been saved or not or its a new file (& not saved), they are the same.
Grouping this issue in with #2980 essentially means it will take longer to be solved, and will likely be solved in a worse way as a result.
I'm sorry you feel this way, however please understand that we're doing our best to resolve issues in a timely manner.
As a temporary solution you can enable auto save in vsc. That should fix it.
But you know the actual path on disk, so could tell isort the correct config file, or instruct it on what the file path should be for a file provided over stdin. This is how flake8 is able to lint modified files with the correct config.
On 22 Feb 2019, at 18:01, Don Jayamanne ***@***.***> wrote:
@danpalmer
They are the same. When running isort against a file that hasn't been saved, its the same as running it against a file that doesn't exist on disc.
The way isort works is, it will look for the configuration files by walking up form the directory containing the file that needs to be formatted. When formatting files that haven't been saved, we create a temporary file in a temporary directory, and that's where things go wonky, at that point the file is NOT in your project directory.
Again, whether the file has been saved or not or its a new file (& not saved), they are the same.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
Activity
karrtikr commentedon Feb 19, 2019
Closing in favour of #2980
danpalmer commentedon Feb 20, 2019
Kartik Raj (@karrtikr) could we re-open this please, that is a separate issue.
From the linked issue #2980:
From this issue:
I apologise if this wasn't clear enough, but I was already aware of #2980 and reported this specifically because it is a different issue. In this case we know what the filename is, therefore we can either save the file automatically before formatting, or use the filename to determine the correct config file to use for formatting. Also note that the isort integration in VSCode does not need the file to be saved, again different to the linked issue.
danpalmer commentedon Feb 22, 2019
Kartik Raj (@karrtikr) ping on this, it needs to be re-opened.
DonJayamanne commentedon Feb 22, 2019
Updated the original issue accordingly.
danpalmer commentedon Feb 22, 2019
Don Jayamanne (@DonJayamanne) I do not agree that #2980 is the "original issue", I believe it to be a different issue, that is a much more complicated issue. It would be great to get this easier, and related but different issue solved separately, as I suspect the resolutions will be entirely distinct.
For clarity: finding the correct configuration is trivial for modified files that already exist on disk, and very difficult for files that do not exist on disk at all. The former likely needs no user prompt, can always work correctly automatically, and is an obvious UX win. The latter is a complex UX issue.
Grouping this issue in with #2980 essentially means it will take longer to be solved, and will likely be solved in a worse way as a result.
I suspect that #3306 may be the same as this one, but that issue was also incorrectly closed as a duplicate of #2980.
In general, it would be great to get a reasoning for closing issues, and for us to be open to discussion around when things are actually duplicates. So far this issue has received 2 responses from maintainers containing no information. This makes it very difficult to contribute, and signals that input is not valued, as it is not being listened to and discussion is being shut down. I'm sure this is not the intention at all, and VSCode has a great community around it, but this is how it may appear.
DonJayamanne commentedon Feb 22, 2019
Dan Palmer (@danpalmer)
They are the same. When running
isortagainst a file that hasn't been saved, its the same as running it against a file that doesn't exist on disk.The way isort works is, it will look for the configuration files by walking up form the directory containing the file that needs to be formatted. When formatting files that haven't been saved, we create a temporary file in a temporary directory, and that's where things go wonky, at that point the file is NOT in your project directory.
Again, whether the file has been saved or not or its a new file (& not saved), they are the same.
I'm sorry you feel this way, however please understand that we're doing our best to resolve issues in a timely manner.
As a temporary solution you can enable
auto savein vsc. That should fix it.danpalmer commentedon Feb 22, 2019