poetry icon indicating copy to clipboard operation
poetry copied to clipboard

feat: Add default-group-optionality configuration option

Open 3015pavan opened this issue 3 months ago • 2 comments

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-optionality boolean 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-optionality boolean config option to toggle default optionality of dependency groups

Enhancements:

  • Update GroupCommand to respect the default-group-optionality setting when determining which groups to install

Documentation:

  • Document the default-group-optionality option in the configuration guide with usage examples

Tests:

  • Add comprehensive tests for the new default-group-optionality behavior, including install scenarios and config commands

3015pavan avatar Nov 17 '25 17:11 3015pavan

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
  • Add default false value in Config.DEFAULTS
  • Include key in boolean normalizer set
  • Register key in config command validators
src/poetry/config/config.py
src/poetry/console/commands/config.py
Update group command to honor default-group-optionality
  • Fetch config value in non_optional_groups
  • Return empty non-optional set when option is enabled
src/poetry/console/commands/group_command.py
Document the default-group-optionality option
  • Add key description, environment variable, and examples
docs/configuration.md
Add and update tests for default-group-optionality
  • Update config listing and default value tests
  • Add integration tests for install command behavior
tests/console/commands/test_config.py
tests/config/test_config.py
tests/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-optionality configuration 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 review on 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 issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on 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 dismiss on 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 review to 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.

sourcery-ai[bot] avatar Nov 17 '25 17:11 sourcery-ai[bot]

Hey! I saw issue #10550 and thought this would be useful. Let me know if you'd like any changes! 😊

3015pavan avatar Nov 17 '25 17:11 3015pavan