-
-
Notifications
You must be signed in to change notification settings - Fork 581
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 should not change the uid/gid when writing a file #1638
Comments
isort does make a best effort attempt to do this, that seems to work in most cases for most people: That said I'm open to more ideas about how to improve this, or information that is leading this not to work in your case such as potentially a different run mode. Testing the same example across users on my own machine shows that for my use the uid and gid are preserved. isort and black are not really comparable in this regard because black works by loading the full file in memory and then writing to the same file in place. isort uses a streaming approach so it needs to write to a different file, while streaming in the original line by line. It then swaps the temp file over the old file, this makes the gid and uid question more complex but means isort can work against much larger files and consume a constant amount of memory. |
I don't know how either work under the hood. It might be possible to stat the file beforehand and opportunistically attempt to set the uid/gid from these values. I'd guess a majority of cases would be this happening with root vs. non-root users as show in the example. A warning could be emitted (or a flag could cause non-zero exit too) if the uid/gid couldn't be set. |
|
And I can reproduce it with something like this:
After that, the file is owned by me, not by nobody. But as the above example already shows. I needed |
Sorry for the delay here! There is now a work around in develop that will make its way out in the 5.8.0 release. |
If
isort
is run against a file, it will change the owner of the file to the uid/gid of the user running the command rather than the original owner of the file. It would be useful to attempt to retain original permissions. This is of particular concern when running dockerized dev containers with formatting tools installed that may run as a user other that of the host machine.For comparison, the tool
black
does not appear to have this issue when run in the same contexts.Example:
The expected result is the final
stat
returns1000:1000
.The text was updated successfully, but these errors were encountered: