Skip to content

Conversation

@radoering
Copy link
Member

@radoering radoering commented May 10, 2025

Pull Request Check List

Requires: python-poetry/poetry-core#868

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

Summary by Sourcery

Normalize dependency group handling by canonicalizing group names across API, CLI, lock file parsing/dumping, and tests to ensure consistent use of packaging.utils.canonicalize_name.

Bug Fixes:

  • Normalize unnormalized dependency group names when loading from lock files

Enhancements:

  • Canonicalize dependency group names throughout the codebase using packaging.utils.canonicalize_name
  • Switch internal group representations to use NormalizedName in type annotations and data structures
  • Normalize CLI-specified and default dependency groups in console commands and installer

Build:

  • Update poetry-core dependency to track the latest git revision

Tests:

  • Refactor and extend tests to use canonicalized group constants and cover unnormalized group inputs

@sourcery-ai
Copy link

sourcery-ai bot commented May 10, 2025

Reviewer's Guide

This PR introduces consistent normalization of dependency group names across the codebase by using packaging.utils.canonicalize_name (NormalizedName) in type hints, data processing (locker, solver, transaction, transitive info), CLI commands, and tests, and updates the pyproject.toml to reference the poetry-core Git URL as required.

Updated Class Diagrams for Command Classes

classDiagram
    class GroupCommand {
        +activated_groups: set[NormalizedName]
    }
    class InstallCommand {
        +activated_groups: set[NormalizedName]
    }
    class SelfCommand {
        +ADDITIONAL_PACKAGE_GROUP: NormalizedName
        +activated_groups: set[NormalizedName]
    }
    class SelfShowCommand {
        +activated_groups: set[NormalizedName]
    }
    SelfCommand <|-- SelfShowCommand

    class SelfInstallCommand {
        +activated_groups: set[NormalizedName]
    }
    SelfCommand <|-- SelfInstallCommand
    InstallCommand <|-- SelfInstallCommand
Loading

Updated Class Diagram for TransitivePackageInfo

classDiagram
    class TransitivePackageInfo {
        +depth: int
        +groups: set[NormalizedName]
        +markers: dict[NormalizedName, BaseMarker]
        +get_marker(groups: Iterable[NormalizedName]) BaseMarker
    }
Loading

Updated Class Diagram for Locker

classDiagram
    class Locker {
        +locked_packages() dict[Package, TransitivePackageInfo]
        #_dump_package(package: Package, transitive_info: TransitivePackageInfo, dependencies: dict[str, list[str]]) Table
    }
Loading

Updated Class Diagram for Installer

classDiagram
    class Installer {
        -_groups: Iterable[NormalizedName] | None
        +only_groups(groups: Iterable[NormalizedName]) Installer
    }
Loading

Updated Class Diagram for Transaction

classDiagram
    class Transaction {
        +__init__(..., groups: set[NormalizedName] | None)
    }
Loading

Updated Class Diagram for PackageNode

classDiagram
    class PackageNode {
        +groups: frozenset[NormalizedName]
    }
Loading

File-Level Changes

Change Details Files
Normalize group names in core data processing to use canonicalize_name and NormalizedName
  • Import and apply canonicalize_name when reading and dumping group lists and markers
  • Update TransitivePackageInfo, Solver, and Transaction to use set[NormalizedName] and dict[NormalizedName, BaseMarker]
  • Canonicalize groups in Locker.locked_packages and dump logic before constructing TransitivePackageInfo
src/poetry/packages/locker.py
src/poetry/packages/transitive_package_info.py
src/poetry/puzzle/solver.py
src/poetry/puzzle/transaction.py
Normalize group names in CLI commands to return and process NormalizedName
  • Change activated_groups methods to return set[NormalizedName]
  • Canonicalize default, only, with, without group names before use
  • Adjust only_groups signature to accept NormalizedName
src/poetry/console/commands/group_command.py
src/poetry/console/commands/self/self_command.py
src/poetry/console/commands/self/show/__init__.py
src/poetry/console/commands/self/install.py
src/poetry/console/commands/install.py
src/poetry/installation/installer.py
Update tests to use canonicalized MAIN_GROUP/DEV_GROUP constants
  • Define MAIN_GROUP and DEV_GROUP via canonicalize_name at top of test modules
  • Replace literal "main"/"dev" group references with MAIN_GROUP, DEV_GROUP and canonicalize_name sets
  • Adjust assertions and TransitivePackageInfo instantiations to use NormalizedName keys
tests/puzzle/test_solver_internals.py
tests/packages/test_locker.py
tests/puzzle/test_transaction.py
tests/packages/test_transitive_package_info.py
tests/puzzle/test_solver.py
tests/installation/test_installer.py
Update poetry-core dependency in pyproject.toml to reference Git URL
  • Replace stable poetry-core version pin with git+https URL to python-poetry/poetry-core
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!

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

@radoering radoering marked this pull request as draft May 10, 2025 12:14
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 - here's some feedback:

  • The DEV_GROUP constant is defined locally in multiple test files; consider using a shared definition, possibly from poetry-core if appropriate, similar to MAIN_GROUP.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: 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.

@radoering
Copy link
Member Author

  • The DEV_GROUP constant is defined locally in multiple test files; consider using a shared definition, possibly from poetry-core if appropriate, similar to MAIN_GROUP.

I do not think it is worth it: While the name of the main group is really a constant, "dev" is not. It is just "coincidence" that multiple tests use the same arbitrary group name. Moving this one liner into a common module and replacing it by an import, is probably not worth it.

@radoering radoering requested a review from a team May 10, 2025 12:23
finswimmer
finswimmer previously approved these changes May 27, 2025
@radoering radoering force-pushed the normalize-dependency-group-names branch from 0c786c9 to a7cbe23 Compare May 27, 2025 15:53
@radoering radoering marked this pull request as ready for review May 27, 2025 15:59
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: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: 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.

@radoering radoering force-pushed the normalize-dependency-group-names branch from a7cbe23 to daa3f20 Compare May 27, 2025 16:13
@radoering radoering requested a review from finswimmer May 27, 2025 16:46
@radoering radoering merged commit dbad17e into python-poetry:main May 28, 2025
53 checks passed
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 28, 2025
@radoering radoering deleted the normalize-dependency-group-names branch December 13, 2025 17:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants