-
-
Notifications
You must be signed in to change notification settings - Fork 583
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
How to make isort black compatible. Original Question: isort conflicts with black? #1518
Comments
you can choose the |
@anirudnits is correct. The easiest way to do this would be to create a .isort.cfg file at the root of your repository with the following:
Alternatively, you could update your precommit to set the profile when running isort:
See: https://pycqa.github.io/isort/docs/configuration/config_files/ Hope this is helpful! Let us know if we were able to resolve your issue :). Thanks! ~Timothy |
Thanks, this solution worked beautifully!
|
Glad to hear! This has come up a couple of times so I'm going to pin this issue until the documentation makes this solution more prominent so others that run into it can also see how to fix compatibility |
I was just experiencing a similar issue. Black wanted to split up an import statement, and then isort wanted to undo blacks changes. I solved it by adding a --line-length parameter also in the arguments for isort. The resulting .pre-commit-config.yaml looks like this:
|
Line length is a nice hackish way of solving this but it creates a new problem, I don't want line-length to be 72. |
@alexisgaziello couldn't you just set it something other than 72? Whatever you're preferred line length is? Am I missing something? |
The .isort.cfg does not seem to work for me I keep getting an error saying to files will be fixed. I also tried to add multi_line_output:
|
Refs: - PyCQA/isort#1518 modified: .pre-commit-config.yaml
There are some incompatibilities between the standard configurations for isort and black ([ref](PyCQA/isort#1518). To avoid issues of black and isort continuously reformatting the same file, add the `--profile black` option to isort
I'm adding isort to my project that already runs pre-commit and black and I'm experiencing the same thing right now. I was able to make it work with the following config:
Removing the line length config for isort create the "deadlock" ehavior mentioned several times in this thread, which is weird because 79 is the default value according to isort documentation. |
There are some corner-cases where isort and black revert each other's changes and you can't resolve your code such that they're both happy. There's a related issue in the iSort repo (cookiecutter#1518) (PyCQA/isort#1518). Appears the solution is to use the "black" profile, which can be set in setup.cfg or .pre-commit-config.yaml. This change adds the profile arg to the .pre-commit-config.yaml file
I also experienced conflicts between the two when using black as a profile. The commands that I run are:
In my case I had this in my pyproject.toml file:
and this as a pre-commit hook:
removing the keyword |
I also experienced conflicts. I found a solution that I haven't seen documented anywhere yet
the difference is the argument format of isort |
I didn't want to inject configuration via the command-line arguments so that filesystem-stored settings are honored.
|
This worked for me!
|
If using the VS Code extension for isort from Microsoft, add |
Otherwise, isort and black would fight about the line lengths of my import statements. Issue here: PyCQA/isort#1518
Hi.
I experience that black and isort undo eachothers changes when working on some of my files.
I am using the following two first steps in my
.pre-commit-config.yaml
:When I run
pre-commit run --all-files
, both black and isort report they are making changes.The changes result to the following formatting in my file
configs.py
:However, if I remove the
isort
-hook from the yaml file, the conflict stops.Then, I get the following output (as dictated by black alone):
How should I approach this? Am I using some wrong revision?
The text was updated successfully, but these errors were encountered: