Optional dependencies currently look like this: Writing your pyproject.toml - Python Packaging User Guide
[project.optional-dependencies]
gui = ["PyQt5"]
cli = ["rich", "click"]
But a very common practise if for optional dependencies to refer to other optional dependencies, e.g.
[project.optional-dependencies]
gui = ["PyQt5"]
cli = ["rich", "click"]
all = ["PyQt5", "rich", "click"]
While this isn’t too cumbersome in this example, it can get exponentially out of control with lots of dependencies and lots of optional dependencies referring to other dependencies. If you look at a project like apache-airflow
they can’t specify their optional dependencies sensibly in their metadata so they dynamically build it with their build system.
My proposal, at a high level, would to be to allow optional dependencies to refer to other optional dependencies, like so:
[project.optional-dependencies]
gui = ["PyQt5"]
cli = ["rich", "click"]
all = ["$gui", "$cli"]
It would be up to the build system (or any tool that peeks directly at pyproject.toml
files) to recognize that this is referring to other groups and expand out the group. Circular dependencies would be strictly prohibited, but I don’t think there should be a requirement for the ordering to matter (e.g. in this example all
could be at the beginning).
This is a high level idea, the specification would need to be more precise, so not looking to bikeshed. I would like to gauge if this would be an idea that the relevant parties like, think is worthwhile, or it has been discussed before and I missed it.