poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Allow setting default optionality for dependency groups

Open jaredahern opened this issue 5 months ago • 1 comments

Issue Kind

Brand new capability

Description

Now that PEP 735 [dependency-groups] is supported, the [tool.poetry.group.GROUPNAME] tables can largely be omitted from pyproject.toml. However, it appears that in Poetry 2.2.0 they continue to have the same behavior as in previous versions, defaulting to optional = false. This is a reasonable choice, but given the ease by which (e.g.) a single group can be defined and requested for installation via command line, package developers may wish to declare most or all groups optional.

To accomplish this, propose defining a Boolean tool.poetry.default-group-optionality key in the configuration, itself having a default false value. This would expose and allow configuration of the default value for optional for all groups.

Alternatively, perhaps this key could be under tool.poetry.group somehow, but it is not immediately clear how it would be differentiated from a group name. Additionally, there may well be a clearer key name.

Impact

This would allow package developers to fully omit the [tool.poetry.group.GROUPNAME] tables from their pyproject.toml config. For configs with a large number of optional dependency groups, changing the default optionality could eliminate substantial extra complexity.

For comparison, I believe that pip only installs specifically-requested groups (see https://pip.pypa.io/en/latest/user_guide/#dependency-groups).

This change should be backwards compatible.

Workarounds

Specify the following for each optional group:

[tool.poetry.group.GROUPNAME]
optional = true

jaredahern avatar Sep 14 '25 18:09 jaredahern

Conceivable. I just wonder if there are enough users who would use such a feature or if it is too rare of a use case so that the maintainance effort is not worth it.

radoering avatar Sep 19 '25 21:09 radoering