In pyproject.toml, I can define extra_requires via [project.optional-dependencies].…
- User
In pyproject.toml, I can define extra_requires via
[project.optional-dependencies]. Suppose I define two such extrasextraa = ["package1", "package2"]andextrab = ["package1", "package3"]. Is there a convenient way to create an "all" extras that would include both of there without repeating the list of packages? - Assistant
Short answer
No.
The PEP-621 syntax that[project.optional-dependencies]follows only allows every key to map to a literal list of requirement strings.
It does not let one extra “include” another or express set operations such as unions, so you would have to spell the packages out again:[project.optional-dependencies] extraa = ["package1", "package2"] extrab = ["package1", "package3"] all = ["package1", "package2", "package3"] # duplicated on purposeWork-arounds / remarks
• Users can always install several extras at once (
pip install myproj[extraa,extrab]), so an “all” extra isn’t strictly required.• If you really want to keep the list in one place, you’d need a build-time solution outside the spec, e.g.
– generate thepyproject.tomlwith a script,
– or use a build backend that offers its own metadata hooks (Hatch, Flit, etc.) to compute an extra dynamically.
Such tricks are backend-specific and won’t work in plain staticpyproject.toml.In standard
pyproject.tomlalone, duplication is unavoidable.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.