Skip to content

Comments

canonicalize dependency group names#868

Merged
radoering merged 1 commit intopython-poetry:mainfrom
radoering:canonicalize-dependency-group-name
May 27, 2025
Merged

canonicalize dependency group names#868
radoering merged 1 commit intopython-poetry:mainfrom
radoering:canonicalize-dependency-group-name

Conversation

@radoering
Copy link
Member

@radoering radoering commented May 10, 2025

Closes: #852

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

Alternative to #852 with some small changes:

  • do not introduce CanonicalizedDict because in my opinion it is a bit overkill and I am not sure if would help to avoid errors or would be a source of new errors
  • normalize groups of a dependency
  • add test for dependency_group_names

Summary by Sourcery

Canonicalize dependency group names to provide case-insensitive and normalized handling of dependency groups across the package management system.

New Features:

  • Add support for case-insensitive dependency group name matching

Enhancements:

  • Normalize dependency group names using canonicalization
  • Introduce case-insensitive lookup for dependency groups

Tests:

  • Add tests to verify case-insensitive dependency group handling
  • Add tests for dependency group name normalization

@sourcery-ai
Copy link

sourcery-ai bot commented May 10, 2025

Reviewer's Guide

This PR implements canonicalization for dependency group names by consistently applying a normalization function (e.g., canonicalize_name) when group names are created or used. The DependencyGroup class now stores both a canonicalized name (for internal logic) and the original 'pretty' name. The Package class uses these canonicalized names for internal storage and normalizes group name inputs in its methods. Dependency objects also store associated group names in canonicalized form. This ensures consistent handling of group names like 'DevGroup' or 'dev_group' as 'dev-group' internally.

File-Level Changes

Change Details Files
Introduced system-wide canonicalization for dependency group names, ensuring consistent processing regardless of input casing or formatting (e.g., 'MyGroup', 'my_group' become 'my-group').
  • DependencyGroup constructor now canonicalizes its input name.
  • Dependency objects now store canonicalized group names.
  • Package methods now canonicalize input group names before processing.
src/poetry/core/packages/dependency_group.py
src/poetry/core/packages/package.py
src/poetry/core/packages/dependency.py
DependencyGroup now retains the original 'pretty' name while using a canonical name for internal operations; Package's internal group storage reflects this canonicalization.
  • Added pretty_name property to DependencyGroup to expose the original name.
  • Package._dependency_groups dictionary keys updated to use canonicalized NormalizedName type.
  • Package.dependency_group_names now returns a set of canonicalized names.
src/poetry/core/packages/dependency_group.py
src/poetry/core/packages/package.py
Enhanced test suite to validate dependency group name canonicalization across various scenarios.
  • Added new tests specifically for normalized name handling in Package and DependencyGroup.
  • Updated existing tests to use mixed-case and alternatively formatted group names.
tests/packages/test_package.py
tests/packages/test_dependency_group.py
tests/packages/test_dependency.py

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.

Hey @radoering - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 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.

@radoering radoering requested a review from a team May 10, 2025 12:23
Copy link
Contributor

@citelao citelao left a comment

Choose a reason for hiding this comment

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

I'm not sure I have enough context to give you a high-quality review, but I took a look and I think this change looks good!

@radoering radoering force-pushed the canonicalize-dependency-group-name branch from 3386a88 to 69dc4fc Compare May 14, 2025 16:25
@radoering radoering force-pushed the canonicalize-dependency-group-name branch from 69dc4fc to 1ba4009 Compare May 22, 2025 15:29
@radoering radoering merged commit 12f0e00 into python-poetry:main May 27, 2025
18 checks passed
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.

3 participants