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:
repos:
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.5.4
hooks:
- id: isort
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:
from datetime import date
from cost_categories import (applsj, asjdfsi, bananana, sdjffsd, sjdifjsl,
sjdil, yoyoyoyoy)
from library_user import User
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):
from datetime import date
from cost_categories import (
applsj,
asjdfsi,
bananana,
sdjffsd,
sjdifjsl,
sjdil,
yoyoyoyoy,
)
from library_user import User
How should I approach this? Am I using some wrong revision?
you can choose the black profile in isort that should solve the conflict. You could include that in the .isort.cfg file in your repository.
@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:
[tool.isort]
profile = "black"
Alternatively, you could update your precommit to set the profile when running isort:
- repo: https://github.com/pycqa/isort
rev: 5.5.4
hooks:
- id: isort
args: ["--profile", "black"]
See: https://pycqa.github.io/isort/docs/configuration/config_files/
and: https://pycqa.github.io/isort/docs/configuration/profiles/
Hope this is helpful! Let us know if we were able to resolve your issue :).
Thanks!
~Timothy
Thanks, this solution worked beautifully!
- repo: https://github.com/pycqa/isort
rev: 5.5.4
hooks:
- id: isort
args: ["--profile", "black"]
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
Most helpful comment
@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/
and: https://pycqa.github.io/isort/docs/configuration/profiles/
Hope this is helpful! Let us know if we were able to resolve your issue :).
Thanks!
~Timothy