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

Isort configuration in $HOME folder not used when project is under git #1414

Closed
igroen opened this issue Aug 26, 2020 · 3 comments
Closed

Isort configuration in $HOME folder not used when project is under git #1414

igroen opened this issue Aug 26, 2020 · 3 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@igroen
Copy link

igroen commented Aug 26, 2020

When a project is under git version control it doesn't seem to use the .isort.cfg file in the user's $HOME folder anymore.

Steps to reproduce:

~ $ docker run -it --rm debian:testing /bin/bash
root@bdb47edb19d8:/# apt-get update
...
root@bdb47edb19d8:/# apt-get install git python3 python3-pip
...
root@91a7d05011e0:/# cat > .isort.cfg << EOL
> [settings]
> line_length=79
> multi_line_output=3
> include_trailing_comma=True
> force_grid_wrap=2
> combine_as_imports=True
> balanced_wrapping=True
> EOL
root@91a7d05011e0:/# mkdir test && cd test
root@91a7d05011e0:/test# cat > utils.py << EOL
> def do_a():
>     pass
>
> def do_b():
>     pass
> EOL
root@91a7d05011e0:/test# cat > main.py << EOL
> from utils import (
>     do_a,
>     do_b,
> )
> EOL
root@91a7d05011e0:/test# pip install isort
...
Successfully installed isort-5.4.2
root@91a7d05011e0:/test# isort --diff main.py  # No output, imports sorted according to .isort.cfg in $HOME dir
root@91a7d05011e0:/test# git init
Initialized empty Git repository in /test/.git/
root@91a7d05011e0:/test# isort --diff main.py  # Output, imports not sorted according .isort.cfg in $HOME dir anymore
--- /test/main.py:before	2020-08-26 16:50:24.192227
+++ /test/main.py:after	2020-08-26 16:51:42.572927
@@ -1,4 +1 @@
-from utils import (
-    do_a,
-    do_b,
-)
+from utils import do_a, do_b
root@91a7d05011e0:/test# rm -fr .git
root@91a7d05011e0:/test# isort --diff main.py  # No output, .isort.cfg in $HOME dir used again after removing .git folder
root@91a7d05011e0:/test#

The behavior changed since isort 5.0.0. Earlier versions of isort used the .isort.cfg in the user's $HOME folder also when the project is under git.
I know I can use an .isort.cfg file at the project level but sometimes it's more convenient to have a 'global' config, especially on projects which don't use isort.

Is this the intended behavior now?

@igroen
Copy link
Author

igroen commented Aug 26, 2020

I now see this is the intended behavior for a while: 2221d46
But I can't find the reasoning behind this change. Performance?

@timothycrosley
Copy link
Member

Hi @igroen,

Thanks for reaching out! The reason the behaviour changed was really that the usage of isort has evolved over the years. Originally since isort was a new tool it was used primarily from individual developers to clean up their own code. They would do this independent from any project level guidelines. This was actually the usage I initially designed isort for. However, overtime as isort got better and better at its job of sorting imports, projects started feeling comfortable requiring isort for all commits, and it started being centered more around projects and less around individual developers. This led to many issues on the isort code base where individual developer config files were conflicting with the projects imports. And projects should be able to use isort without any config set, just like users can, and rest assured that there wont be any conflicts.

That said, I still use isort even on the few code bases I interact with that don't have it included. And certainly, I want to support both use cases well. What I do for now, is set the settings path to my personal config If I'm interacting with one of those code bases:

isort --sp ~/.isort.cfg .

You can also set up an alias to make this behaviour automatic.

I'm also very open to other strategies to support both modes of operation well.

Thanks!

~Timothy

@timothycrosley timothycrosley added documentation Improvements or additions to documentation question Further information is requested labels Aug 26, 2020
@igroen igroen closed this as completed Aug 27, 2020
@igroen
Copy link
Author

igroen commented Aug 27, 2020

Thanks for the clear explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants