Skip to content

Conversation

@daniel7an
Copy link

@daniel7an daniel7an commented Feb 9, 2026

Fixes #10703

The remove command never searched [project.optional-dependencies] or [tool.poetry.extras] sections, causing 'packages were not found' for optional deps.

Added _remove_optional_packages() to search both PEP 621 and legacy optional dependency sections, with cleanup of empty sections. Added two regression tests.

Summary by Sourcery

Handle removal of optional dependencies across both modern and legacy configuration formats when running the remove command.

Bug Fixes:

  • Ensure the remove command deletes packages from [project.optional-dependencies] and cleans up empty extras in that section.
  • Ensure the remove command deletes optional packages from [tool.poetry.extras] and corresponding optional entries in [tool.poetry.dependencies].

Tests:

  • Add regression tests verifying removal of optional dependencies defined via [project.optional-dependencies].
  • Add regression tests verifying removal of optional dependencies defined via legacy [tool.poetry.extras] and optional dependencies.

When running 'poetry remove <package>', optional dependencies declared in
[project.optional-dependencies] or [tool.poetry.extras] were not found,
causing a 'packages were not found' error.

This adds a _remove_optional_packages method that searches both PEP 621
optional-dependencies sections and legacy poetry extras/optional markers,
cleaning up empty sections after removal.

Fixes python-poetry#10703
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 9, 2026

🧙 Sourcery has finished reviewing your pull request!


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

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.

We failed to fetch the diff for pull request #10726

You can try again by commenting this pull request with @sourcery-ai review, or contact us for help.

@dimbleby
Copy link
Contributor

dimbleby commented Feb 10, 2026

what if a user wants to remove an optional dependency from one set of extras but not another? or from the main dependencies but not from extras?

I'm not convinced that everything has to be supported from the command line - just edit the pyproject.toml! - but if we start to go down this path there are lots more cases to think about.

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.

Cannot remove optional dependency

2 participants