My project has Celery as a dependency. 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.
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"] }
).
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.
Is there a way to put this into Poetry config? Or should I track the optional requirements of celery[redis]
and manually add them to my pyproject.toml
file?
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.
This should work by defining redis
as an optional extra , eg:
[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"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.