Is it possible to run isort formatter from black command in python

Viewed 2533

I like to get inspiration from well designed python projects.

The last one that inspired me was the poetry repository.

I copied a lot from that, but the subject of this post are black and isort.

Both are well configured in pyproject.toml:

[tool.isort]
profile = "black"
...
known_first_party = "poetry"


[tool.black]
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
...
)/
'''

and formatting is configured in the Makefileas:

format: clean
    @poetry run black poetry/ tests/

I thought that running make format would run blackwhich would internally run isort, but when I ran isort ., it correctly formated the import statements afterwards. It then seems black did not run isort.

Question: does black run isort internally?

2 Answers

No, it doesn't run isort.

As noted in this document, Using Black with other tools:

isort

isort helps to sort and format imports in your Python code. Black also formats imports, but in a different way from isort's defaults which leads to conflicting changes.

Related