3

我用 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。我想要黑色格式化程序,它与 Python3.5 不兼容。我认为如果我使用 Python>=3.6 进行开发是没有问题的,但是我无法安装黑色格式化程序:

$ 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

$ poetry run pip install black

这种方式不适合我。我想black通过诗歌安装。

我应该怎么做?(我不想将依赖项修改为python>=3.6

4

2 回答 2

3

似乎有点晚了,但实际上你可以做你想做的事,即使黑色只支持 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"}

诗歌不会抱怨,你不会有任何问题,因为它是开发依赖。

于 2021-08-10T17:53:05.723 回答
2

您需要编辑您的 python 值pyproject.toml

[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"
于 2020-05-28T06:18:54.980 回答