Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support PEP 735 dependency groups #823

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

finswimmer
Copy link
Member

@finswimmer finswimmer commented Jan 21, 2025

Required-by: python-poetry/poetry#10130
Relates-to: python-poetry/poetry#9751

  • Added tests for changed code.
  • Updated documentation for changed code.

Summary by Sourcery

New Features:

  • Add support for PEP 735 dependency groups.

Summary by Sourcery

New Features:

  • Add support for PEP 735 dependency groups.

Copy link

sourcery-ai bot commented Jan 21, 2025

Reviewer's Guide by Sourcery

This PR implements support for PEP 735 dependency groups in Poetry. The changes enhance how dependency groups are retrieved from the project configuration, integrated into package dependency resolution, propagated through dependency creation methods, and validated. New tests and fixture files have also been added to ensure proper handling of both valid and invalid dependency groups.

Sequence diagram for dependency group initialization

sequenceDiagram
  participant Dev as Developer
  participant PP as PyProject
  participant F as Factory.configure_package
  participant P as Package
  participant DG as DependencyGroup
  participant D as Dependency

  Dev->>PP: Define dependency-groups in pyproject.toml
  PP->>F: Provide project data with dependency-groups and tool_poetry config
  F->>P: Call add_dependency_group for each group
  F->>DG: Create DependencyGroup(name, optional)
  DG->>P: Register group with package
  loop For each dependency constraint
      F->>D: Create dependency using create_from_pep_508(constraint, groups)
      D->>DG: Add dependency via add_dependency(dep)
  end
  Note over F,D: Dependency groups are now passed and propagated during dependency creation
Loading

Updated class diagram for Dependency and DependencyGroup

classDiagram
  class Package {
    +add_dependency_group(group)
    +has_dependency_group(group_name)
  }

  class DependencyGroup {
    +name: str
    +optional: bool
    +dependencies: list
    +add_dependency(dep)
  }

  class Dependency {
    <<abstract>>
    +groups: Iterable~str~
    +create_from_pep_508(name, relative_to, groups)
  }

  class VCSDependency {
    +groups: Iterable~str~
  }

  class URLDependency {
    +groups: Iterable~str~
  }

  class FileDependency {
    +groups: Iterable~str~
  }

  class DirectoryDependency {
    +groups: Iterable~str~
  }

  Package o-- "*" DependencyGroup : holds
  DependencyGroup "1" *-- "*" Dependency : contains
  Dependency <|-- VCSDependency
  Dependency <|-- URLDependency
  Dependency <|-- FileDependency
  Dependency <|-- DirectoryDependency
  note for Dependency "New attribute 'groups' to support PEP 735 dependency groups"
Loading

File-Level Changes

Change Details Files
Enhanced package configuration to support dependency groups.
  • Retrieved dependency groups from the pyproject configuration.
  • Passed dependency group information to the package dependency configuration function.
  • Iterated over dependency groups to create group-specific dependencies and add them to packages.
  • Updated the validation logic to replace error paths for dependency groups.
src/poetry/core/factory.py
Updated dependency creation methods to include group support.
  • Modified the create_from_pep_508 method to accept an optional groups parameter.
  • Propagated group information to VCSDependency, URLDependency, and file/directory dependency helpers.
  • Updated helper functions to support groups during dependency instantiation.
src/poetry/core/packages/dependency.py
Added new tests to verify dependency groups functionality.
  • Implemented tests to validate the creation and configuration of dependency groups, including optional flags and group assignments on dependencies.
  • Introduced tests to ensure proper error handling when invalid dependency group data is provided.
tests/test_factory.py
tests/fixtures/sample_project_with_groups_new/pyproject.toml
tests/fixtures/project_with_invalid_dependency_groups/pyproject.toml
tests/fixtures/sample_project_with_groups_new/README.rst
Introduced JSON schema for dependency groups validation.
  • Added a new dependency-groups schema to support configuration validation.
src/poetry/core/json/schemas/dependency-groups-schema.json

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@finswimmer
Copy link
Member Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @finswimmer - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please add documentation for the new dependency groups feature - this is a significant change that needs to be well documented for users
  • Link to the relevant issue number/tracking issue for PEP 735 implementation in the PR description
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@finswimmer finswimmer changed the title wip: poc pep 735 Support PEP 735 dependency groups Feb 5, 2025
@finswimmer
Copy link
Member Author

@sourcery-ai review

@finswimmer finswimmer changed the title Support PEP 735 dependency groups feat: Support PEP 735 dependency groups Feb 5, 2025
@finswimmer finswimmer requested a review from radoering February 5, 2025 08:09
@finswimmer
Copy link
Member Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @finswimmer - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider consolidating the two loops in _configure_package_dependencies that handle dependency groups (one for dependency-groups and one for tool.poetry.group) to reduce repeated logic.
  • If a dependency group exists in the pyproject data but lacks a corresponding tool.poetry.group entry, consider whether you want to apply default optional settings explicitly.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant