如何在诗歌和pyproject.toml中添加库的可选依赖项作为"额外"?



我正在使用pyprojectpoetry构建一个Python包。我的pyproject.toml看起来像这样:

[tool.poetry]
authors = ["test"]
description = ""
name = "test"
version = "0.1.0"
[tool.poetry.dependencies]
spacy = {extras = ["cuda113"], version = "^3.2.3"}
faiss-gpu = {version = "1.7.2", optional = true}
[tool.poetry.extras]
gpu = ["faiss-gpu"]

这成功地安装了faiss-gpu作为一个额外使用poetry install -E gpu

但是,只有在提供poetry install -E gpu时,我才想安装spacy[cuda113](GPU版本)。一个正常的poetry install应该只安装spacy(CPU版本)。

我尝试使用以下配置,但这使得所有spacy都是可选的,并且不安装它。只有spacy[cuda113](GPU版本)可选

[tool.poetry]
authors = ["test"]
description = ""
name = "test"
version = "0.1.0"
[tool.poetry.dependencies]
spacy = {extras = ["cuda113"], version = "^3.2.3", optional = true}
faiss-gpu = {version = "1.7.2", optional = true}
[tool.poetry.extras]
gpu = ["faiss-gpu", "spacy"]

是否有办法使spacy[cuda113]可选,但spacy作为必需的依赖?

试试:

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry]
authors = ["test"]
description = ""
name = "test"
version = "0.1.0"
[tool.poetry.dependencies]
python = "^3.10"
faiss-gpu = {version = "1.7.2", optional = true}
spacy = {extras = ["cuda113"], version = "^3.2.3", optional = true}
Spacy = "^3.2.3"
[tool.poetry.extras]
gpu = ["faiss-gpu", "spacy"]

它生成像这样的dist-info元数据行,就pip如何安装testtest[gpu]而言,这看起来是正确的:

Metadata-Version: 2.1
Name: test
Version: 0.1.0
Summary: 
Author: test
Requires-Python: >=3.10,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Provides-Extra: gpu
Requires-Dist: Spacy (>=3.2.3,<4.0.0)
Requires-Dist: faiss-gpu (==1.7.2); extra == "gpu"
Requires-Dist: spacy[cuda113] (>=3.2.3,<4.0.0); extra == "gpu"

免责声明:我认为我是依赖于bug和/或实现细节在诗歌的工作。请注意"空格"one_answers";Spacy"在依赖规范中。行序也很重要。

相关内容

  • 没有找到相关文章

最新更新