Skip to content

feat(show): add dependency group output#10945

Open
Yijian6 wants to merge 1 commit into
python-poetry:mainfrom
Yijian6:show-with-groups
Open

feat(show): add dependency group output#10945
Yijian6 wants to merge 1 commit into
python-poetry:mainfrom
Yijian6:show-with-groups

Conversation

@Yijian6

@Yijian6 Yijian6 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Pull Request Check List

Resolves: #8164

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

This adds a --with-groups option to poetry show so users can see which dependency groups each listed package belongs to without opening pyproject.toml or inspecting the lock file manually.

For text output, the command prints a group column after the package version. For JSON output, it adds a groups list. When lock-file group metadata is available, the command uses it so transitive packages can also be annotated; otherwise it falls back to the active root dependency groups. --tree --with-groups returns a clear error because tree output does not have a tabular group column.

Local checks:

.\.venv\Scripts\python.exe -m pytest tests\console\commands\test_show.py -q
.\.venv\Scripts\python.exe -m ruff check src\poetry\console\commands\show.py tests\console\commands\test_show.py
.\.venv\Scripts\python.exe -m ruff format --check src\poetry\console\commands\show.py tests\console\commands\test_show.py
.\.venv\Scripts\python.exe -m mypy src\poetry\console\commands\show.py
git diff --check

Breaking changes: None.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The new _package_groups helper relies on the private root._dependency_groups attribute; consider using a public API or adding an accessor on ProjectPackage so the command does not depend on internal implementation details of the package model.
  • When computing and displaying groups_length in _display_packages_information, you repeatedly call _format_groups for the same package name; you could precompute and cache the formatted group strings (e.g., formatted_groups[name]) to avoid duplicate work and simplify the width/printing logic.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `_package_groups` helper relies on the private `root._dependency_groups` attribute; consider using a public API or adding an accessor on `ProjectPackage` so the command does not depend on internal implementation details of the package model.
- When computing and displaying `groups_length` in `_display_packages_information`, you repeatedly call `_format_groups` for the same package name; you could precompute and cache the formatted group strings (e.g., `formatted_groups[name]`) to avoid duplicate work and simplify the width/printing logic.

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.

Suggestion: Add a command/option to the CLI to list groups

1 participant