How to make isort black compatible. Original Question: isort conflicts with black?
See original GitHub issueHi.
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?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:33
- Comments:16 (3 by maintainers)
Top Results From Across the Web
Is it possible to run isort formatter from black command in python
isort helps to sort and format imports in your Python code. Black also formats imports, but in a different way from isort's defaults...
Read more >Using Black with other tools - Black 22.12.0 documentation
isort helps to sort and format imports in your Python code. Black also formats imports, but in a different way from isort's defaults...
Read more >Making isort compatible with black - A code to remember
The main difference between isort and black are on there points: the multi line mode; the trailing comma of the last import; the...
Read more >black · PyPI
Runtime support for Python 3.6 has been removed. Formatting 3.6 code will still be supported until further notice. Stable style. Fix a crash...
Read more >Coding style - Django documentation
If the error was with black or isort then the tool will go ahead and fix them for you. ... Use flake8 to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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
Thanks, this solution worked beautifully!