poetry管理的python>=3.5项目下如何使用python black formatter?
How to use python black formatter under a project for python>=3.5 managed by poetry?
我用 Poetry 创建了一个 python 项目 "foo"。
这是pyproject.toml
的内容:
[tool.poetry]
name = "bar"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = ">=3.5"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
此包与 Python3.5 兼容。
我想要 black 格式化程序,它与 Python3.5 不兼容。
我觉得用Python>=3.6做开发是没问题的,就是装不上black formatter:
$ poetry add black --dev
[SolverProblemError]
The current project's Python requirement (>=3.5) is not compatible with some of the required packages Python requirement:
- black requires Python >=3.6
Because no versions of black match >19.10b0,<20.0
and black (19.10b0) requires Python >=3.6, black is forbidden.
So, because bar depends on black (^19.10b0), version solving failed.
所以我直接用pip
安装black:
$ poetry run pip install black
我不喜欢这种方式。我想装black
诗
我该怎么办? (不想修改依赖为python>=3.6
)
您需要编辑 pyproject.toml
中的 python 值:
[tool.poetry]
name = "bar"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = ">=3.6"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
好像有点晚了,其实black只支持也可以为所欲为Python >=3.6.2
在您的 pyproject.toml 中,您可以定义一个受限的依赖项,如 https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies
中所述
[tool.poetry.dependencies]
python = ">=3.5"
[tool.poetry.dev-dependencies]
black = {version = "^21.7b0", python = ">=3.6.2"}
Poetry 不会抱怨,您也不会有任何问题,因为它是开发依赖项。
我用 Poetry 创建了一个 python 项目 "foo"。
这是pyproject.toml
的内容:
[tool.poetry]
name = "bar"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = ">=3.5"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
此包与 Python3.5 兼容。 我想要 black 格式化程序,它与 Python3.5 不兼容。 我觉得用Python>=3.6做开发是没问题的,就是装不上black formatter:
$ poetry add black --dev
[SolverProblemError]
The current project's Python requirement (>=3.5) is not compatible with some of the required packages Python requirement:
- black requires Python >=3.6
Because no versions of black match >19.10b0,<20.0
and black (19.10b0) requires Python >=3.6, black is forbidden.
So, because bar depends on black (^19.10b0), version solving failed.
所以我直接用pip
安装black:
$ poetry run pip install black
我不喜欢这种方式。我想装black
诗
我该怎么办? (不想修改依赖为python>=3.6
)
您需要编辑 pyproject.toml
中的 python 值:
[tool.poetry]
name = "bar"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = ">=3.6"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
好像有点晚了,其实black只支持也可以为所欲为Python >=3.6.2
在您的 pyproject.toml 中,您可以定义一个受限的依赖项,如 https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies
中所述[tool.poetry.dependencies]
python = ">=3.5"
[tool.poetry.dev-dependencies]
black = {version = "^21.7b0", python = ">=3.6.2"}
Poetry 不会抱怨,您也不会有任何问题,因为它是开发依赖项。