简体   繁体   English

如果请求包的特定附加功能,则安装依赖项的附加功能

[英]Install dependency’s extras if package’s specific extras is requested

My project has Celery as a dependency.我的项目有 Celery 作为依赖项。 It's a hard dependencies, ie.这是一个硬依赖,即。 my project can't live without it.我的项目离不开它。 However, it can use Redis as its backend, which my app doesn't need specifically.但是,它可以使用 Redis 作为后端,我的应用程序并不特别需要它。

I want my package to be set up so if a user installs dependencies with poetry install -E redis , it would install the redis block of Celery (as if it were specified in pyproject.toml as celery = { version="^4.4.0", extras=["redis"] } ).我希望设置我的 package,这样如果用户使用poetry install -E redis安装依赖项,它将安装 Celery 的redis块(就好像它在pyproject.toml中指定为celery = { version="^4.4.0", extras=["redis"] } )。

However, if a user uses a plain poetry install (without -E redis ), i don't want Celery's Redis dependencies (as if it were only specified as celery = "^4.4.0" ) to be installed.但是,如果用户使用普通poetry install (没有-E redis ),我不想安装 Celery 的 Redis 依赖项(就好像它只指定为celery = "^4.4.0" )。

Is there a way to put this into Poetry config?有没有办法将其放入 Poetry 配置中? Or should I track the optional requirements of celery[redis] and manually add them to my pyproject.toml file?或者我应该跟踪celery[redis]的可选要求并手动将它们添加到我的pyproject.toml文件中?

I already checked the Poetry documentation on this matter, but it doesn't offer a way to specify the same dependency ( celery in my case) with different options.我已经检查了有关此事的Poetry 文档,但它没有提供一种方法来指定具有不同选项的相同依赖项(在我的情况下为celery )。

This should work by defining redis as an optional extra , eg:这应该通过将redis定义为可选的 extra来工作,例如:

[tool.poetry]
name = "mypackage"
version = "0.1.0"
description = ""
authors = ["finswimmer <finswimmer@example.org>"]

[tool.poetry.dependencies]
python = "^3.6"
celery = "^4.4.7"
redis = { version = "^3.5.3", optional = true }

[tool.poetry.dev-dependencies]

[tool.poetry.extras]
redis = ["redis"]

[build-system]
requires = ["poetry>=1.0"]
build-backend = "poetry.masonry.api"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM