5

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?

emonier
  • 293
  • 1
  • 3
  • 13

2 Answers2

3

Question: does black run isort internally?

No, it doesn't.

isort has a profile = "black" option that makes it adhere to Black's standards though.

The poetry repository itself has a pre-commit hook defined here in .pre-commit-config.yaml that makes sure isort is run (along with a couple of other tools).

AKX
  • 152,115
  • 15
  • 115
  • 172
1

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.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65