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(cli): Support PEP 735 (Dependency Groups) #10130

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

Conversation

finswimmer
Copy link
Member

@finswimmer finswimmer commented Jan 31, 2025

Pull Request Check List

Requires: python-poetry/poetry-core#823
Resolves: #9751

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

Summary by Sourcery

Support PEP 735 by adding dependency groups to the pyproject.toml file.

New Features:

  • Added support for dependency groups, as described in PEP 735.

Tests:

  • Fixed failing tests due to dependency group changes.

Summary by Sourcery

Update dependency management to support PEP 735 (Dependency Groups).

New Features:

  • Introduce dependency groups, allowing for more granular control over dependency management.

Tests:

  • Fix failing tests due to dependency group changes.

Copy link

sourcery-ai bot commented Jan 31, 2025

Reviewer's Guide by Sourcery

This PR implements support for PEP 735 by introducing the new 'dependency-groups' section to handle dependency groups in pyproject.toml. The changes span across CLI commands, tests, documentation, and internal package handling. The implementation adds conditional logic to support both the legacy [tool.poetry.group] structure and the new [dependency-groups] format, with tests parameterized on the PEP735 flag to ensure correct behavior in both modes.

Sequence Diagram for Poetry Add Command with Dependency Groups

sequenceDiagram
    actor User
    participant CLI_Add as "Poetry Add Command"
    participant Config as "Pyproject.toml"
    participant Locker as "Locker"

    User->>CLI_Add: Run 'poetry add <package>' with group flag
    CLI_Add->>Config: Read configuration
    CLI_Add->>CLI_Add: Determine dependency group (MAIN group vs. dependency-groups)
    CLI_Add->>Config: Update dependency entry in project section or dependency-groups
    CLI_Add->>Locker: Update locker with new pyproject data
    CLI_Add->>Config: Write back updated configuration
    User->>CLI_Add: Command completes with success status
Loading

File-Level Changes

Change Details Files
Updated tests to handle both legacy and PEP 735 dependency group formats.
  • Parameterized tests in test_remove.py, test_add.py, and test_init.py to verify behavior under both pep_735 enabled and disabled scenarios.
  • Adjusted expected outputs in tests to check for changes in dependency section formatting based on the active mode.
  • Updated self command tests and plugin tests to reflect changes in dependency group handling.
tests/console/commands/test_remove.py
tests/console/commands/test_init.py
tests/console/commands/test_add.py
tests/console/commands/self/test_add_plugins.py
tests/console/commands/self/test_remove_plugins.py
tests/console/commands/self/utils.py
tests/console/commands/self/test_self_command.py
tests/test_factory.py
Modified CLI command implementations for adding and removing dependencies.
  • Updated the remove command (remove.py) to check and remove dependency entries from both 'tool.poetry.group' and 'dependency-groups' sections.
  • Enhanced the add command (add.py) to support writing new dependency constraints into the 'dependency-groups' section when a non-main group is specified.
  • Introduced conditional logic in both commands to work with the new PEP 735 format as well as maintain legacy behavior.
src/poetry/console/commands/remove.py
src/poetry/console/commands/add.py
Updated documentation to include PEP 735 dependency groups.
  • Modified managing-dependencies.md to show examples of declaring dependency groups using the new [dependency-groups] section.
  • Provided tabbed examples that demonstrate both PEP 735 style and legacy [tool.poetry.group] configurations.
docs/managing-dependencies.md
Enhanced internal tooling to support the new dependency groups.
  • Updated the self command (self_command.py) to preserve and write dependency groups when generating a system pyproject.
  • Modified layout.py to integrate the new 'dependency-groups' with existing project structure.
  • Refactored Factory code to introduce a legacy method for pyproject generation to maintain backward compatibility.
src/poetry/console/commands/self/self_command.py
src/poetry/layouts/layout.py
src/poetry/factory.py
pyproject.toml

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 finswimmer force-pushed the cli-pep-735 branch 2 times, most recently from f468fca to eeb4814 Compare January 31, 2025 12:41
@finswimmer
Copy link
Member Author

@sourcery-ai review

@finswimmer finswimmer added the impact/docs Contains or requires documentation changes label Jan 31, 2025
Copy link

github-actions bot commented Jan 31, 2025

Deploy preview for website ready!

✅ Preview
https://website-hpzzcr78w-python-poetry.vercel.app

Built with commit e522f40.
This pull request is being automatically deployed with vercel-action

Copy link
Member

@radoering radoering left a comment

Choose a reason for hiding this comment

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

Some feedback:

  • To satisfy the export tests, you can try to add poetry remove --lock poetry-core in
    poetry add --lock --group dev ../poetry
  • The support pep 735 commit is missing a test for remove and the tests in test_remove_plugins are still xfail. (If this is still on your todo list ignore the comment).

tests/console/commands/self/test_add_plugins.py Outdated Show resolved Hide resolved
docs/managing-dependencies.md Outdated Show resolved Hide resolved
docs/managing-dependencies.md Outdated Show resolved Hide resolved
@finswimmer finswimmer force-pushed the cli-pep-735 branch 2 times, most recently from 93e9c7e to 628c412 Compare February 2, 2025 13:40
@radoering radoering mentioned this pull request Feb 2, 2025
@finswimmer finswimmer force-pushed the cli-pep-735 branch 2 times, most recently from 720e60f to 727e441 Compare February 3, 2025 05:40
@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:

  • The remove command does not fully support the new dependency-groups format yet, as evidenced by the xfailed tests. This should be implemented before merging.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 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.

src/poetry/console/commands/add.py Show resolved Hide resolved
tests/console/commands/test_add.py Outdated Show resolved Hide resolved
tests/console/commands/test_add.py Show resolved Hide resolved
@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:

  • Extract the common dependency-group setup logic from tests into helper functions to reduce duplication in the if-else blocks.
  • Refactor the repeated type casts and handling of groups_content to improve code readability and maintainability.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 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.

@@ -152,14 +152,18 @@ def handle(self) -> int:
content: dict[str, Any] = self.poetry.file.read()
project_content = content.get("project", table())
poetry_content = content.get("tool", {}).get("poetry", table())
groups_content = content.get("dependency-groups")
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Consider defaulting groups_content to a dict.

While the removal command defaults groups_content to {} immediately, the add command obtains groups_content without a default value. Using a default (e.g. {} or an appropriate table) might avoid potential None-type issues and ensure consistency between commands.

Suggested change
groups_content = content.get("dependency-groups")
groups_content = content.get("dependency-groups", {})

@@ -27,14 +27,30 @@ are part of an implicit `main` group. Those dependencies are required by your pr
Beside the `main` dependencies, you might have dependencies that are only needed to test your project
Copy link

Choose a reason for hiding this comment

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

issue (typo): Typo: "Beside" should be "Besides".

Suggested change
Beside the `main` dependencies, you might have dependencies that are only needed to test your project
Besides the `main` dependencies, you might have dependencies that are only needed to test your project

@finswimmer finswimmer force-pushed the cli-pep-735 branch 3 times, most recently from bf31cc9 to db3ee35 Compare February 9, 2025 07:48
@finswimmer finswimmer requested review from a team and radoering February 9, 2025 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/docs Contains or requires documentation changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support PEP 735 – Dependency Groups in pyproject.toml
2 participants