我正在使用pyproject
和poetry
构建一个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如何安装test
和test[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"在依赖规范中。行序也很重要。