Repository navigation
Conversation
…moved Without a group specified, poetry remove deletes empty dependency groups from pyproject.toml even when nothing was removed from them. The cleanup blocks in the remove-from-all-groups path were gated on the sections being empty after the removal loop, which is also true for groups that were empty before the command and unrelated to the removed packages. This silently dropped unrelated [dependency-groups] entries (and empty legacy [tool.poetry.group.*] tables) and, when those groups were included by others, cascaded into deleting the referencing groups as well. Gate the per-group cleanup on the packages actually removed from that group, matching the single-group path, which already preserves unrelated empty groups (test_remove_preserves_unrelated_empty_groups).
Linked issuesChecked at commit a1c9982 #11232 poetry remove (without --group) silently deletes unrelated empty dependency groups · 3 of 3 met
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. If the removal result is misreported, an empty group could remain in the project's configuration after the command; it can be removed manually, but reverting the code will not restore or clean up configuration already written.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Check List
Resolves: #11232
Why / Problem
Without
--group,poetry removedeletes dependency groups that were empty before the command and unrelated to the removed packages — the cleanup blocks in the remove-from-all-groups path (src/poetry/console/commands/remove.py,group is Nonebranch) run for every group whose sections are empty after the loop, which is also true for already-empty unrelated groups. Both declaration styles are affected:if not standard_section and group_name in groups_content: del groups_content[group_name]if not poetry_section and "dependencies" in poetry_groups_content.get(group_name, {})The single-group path already preserves unrelated empty groups (see
test_remove_preserves_unrelated_empty_groupsonmain), so the remove-from-all-groups path violating that contract is a sibling-path inconsistency, not a design question.What changed
Capture what
_remove_packagesactually removed per group and gate the per-group cleanup blocks on it (removed_in_group). Nothing else changes: a group whose last dependency was genuinely removed is still deleted, and the include-reference cleanup still runs for it. Deliberately not touched: the single-group path and the_remove_references_to_groupcascade, which already behave as intended.Bug fix verification
Red on
main(18668c8), both parametrized variants of the new test:End-to-end on a real project (
dependencies = ["six"],[dependency-groups] docs = []):With
docs = []included bydev = [{ include-group = "docs" }]: before, both groups were deleted; after, both are preserved.Validation / Testing
pytest tests/console/commands/test_remove.py: 40 passed before → 42 passed after (2 new parametrized cases).pytest tests/console: 1008 passed / 3 failed, identical to the clean-mainbaseline on this machine (env/test_info.py::test_env_info_displays_complete_info,debug/test_info.py::test_debug_info_displays_complete_info,test_init.py::test_empty_license— pre-existing, unrelated).ruff check --no-fix+ruff format --diff(0.17.4): clean.mypy src/poetry/console/commands/remove.pyandmypy tests/console/commands/test_remove.py: clean.