gpt4 book ai didi

python - poetry管理的python>=3.5项目下如何使用python black formatter?

转载 作者:行者123 更新时间:2023-12-05 02:07:11 25 4
gpt4 key购买 nike

我用 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 formatter,与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 by poetry.

我该怎么办? (不想修改依赖到python>=3.6)

最佳答案

似乎有点晚了,但实际上你可以做你想做的,即使黑色只支持 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 不会提示,您也不会有任何问题,因为它是开发依赖项。

关于python - poetry管理的python>=3.5项目下如何使用python black formatter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62058120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com