运行 isort formatter from black command in python 是可能的吗

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

我喜欢从精心设计的 python 项目中获得灵感。

最后一个启发我的是poetry repository

我从那里抄了很多东西,但是这个 post 的主题是 black and isort

两者在pyproject.toml中配置良好:

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


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

并且格式在 Makefile 中配置为:

format: clean
    @poetry run black poetry/ tests/

我认为 运行ning make format 会 运行 black 这会在内部 运行 isort,但是当我 运行 isort .,之后它正确地格式化了导入语句。然后好像black没有运行isort.

问题:black运行isort是否在内部?

Question: does black run isort internally?

不,不是。

isorta profile = "black" 选项,使其符合黑方的标准。

poetry 存储库本身有一个 pre-commit hook defined here in .pre-commit-config.yaml 确保 isort 是 运行(以及其他几个工具)。

不,它不运行 isort。

如本文档所述,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.