feat: Add default-group-optionality configuration option
This commit implements a new configuration option default-group-optionality that allows users to treat all dependency groups as optional by default.
When set to true, Poetry will only install the implicit main group by default, and other groups must be explicitly requested using --with or --only flags. This eliminates the need to mark each group as optional = true in pyproject.toml for projects with many optional dependency groups.
Changes:
- Add
default-group-optionalityboolean config option (default: false) - Modify GroupCommand.non_optional_groups to respect the configuration
- Add comprehensive tests for the new functionality
- Update documentation with usage examples
Fixes #10550
Pull Request Check List
Resolves: #issue-number-here
- [x] Added tests for changed code.
- [x] Updated documentation for changed code.
Summary by Sourcery
Add a new default-group-optionality configuration option to allow treating all dependency groups as optional by default and update related command logic, documentation, and tests.
New Features:
- Introduce
default-group-optionalityboolean config option to toggle default optionality of dependency groups
Enhancements:
- Update GroupCommand to respect the
default-group-optionalitysetting when determining which groups to install
Documentation:
- Document the
default-group-optionalityoption in the configuration guide with usage examples
Tests:
- Add comprehensive tests for the new
default-group-optionalitybehavior, including install scenarios and config commands
Reviewer's Guide
Introduces a new default-group-optionality boolean setting that makes all dependency groups optional by default, updates GroupCommand to respect this option, extends configuration handling and documentation, and adds tests covering the new behavior.
Class diagram for updated configuration handling (Config class)
classDiagram
class Config {
+bool default-group-optionality = False
+__init__(use_environment: bool)
+_get_normalizer(name: str)
}
Class diagram for updated GroupCommand logic
classDiagram
class GroupCommand {
+non_optional_groups: set[str]
}
GroupCommand --> Config : uses
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Introduce default-group-optionality configuration key |
|
src/poetry/config/config.pysrc/poetry/console/commands/config.py |
| Update group command to honor default-group-optionality |
|
src/poetry/console/commands/group_command.py |
| Document the default-group-optionality option |
|
docs/configuration.md |
| Add and update tests for default-group-optionality |
|
tests/console/commands/test_config.pytests/config/test_config.pytests/console/commands/test_default_group_optionality.py |
Assessment against linked issues
| Issue | Objective | Addressed | Explanation |
|---|---|---|---|
| https://github.com/python-poetry/poetry/issues/10550 | Implement a configuration option (e.g., tool.poetry.default-group-optionality) to allow users to set the default optionality for dependency groups. | ✅ | |
| https://github.com/python-poetry/poetry/issues/10550 | Ensure that when the configuration option is enabled, all dependency groups (except the implicit main group) are treated as optional by default, so that only explicitly requested groups are installed. | ✅ | |
| https://github.com/python-poetry/poetry/issues/10550 | Update documentation and add tests to cover the new configuration option and its behavior. | ✅ |
Possibly linked issues
-
#10550: The PR implements the
default-group-optionalityconfiguration option to allow treating all dependency groups as optional by default, as proposed in the issue.
Tips and commands
Interacting with Sourcery
-
Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
-
Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. -
Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. -
Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. -
Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. -
Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. -
Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Hey! I saw issue #10550 and thought this would be useful. Let me know if you'd like any changes! 😊