refactor: decompose run_remove to reduce cyclomatic complexity#526
Open
kasperjunge wants to merge 2 commits into
Open
refactor: decompose run_remove to reduce cyclomatic complexity#526kasperjunge wants to merge 2 commits into
kasperjunge wants to merge 2 commits into
Conversation
Defines the complexity-reduction task and acceptance criteria so the refactor iterations have a shared target to build toward. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
run_remove was the worst complexity outlier (radon CC 36, grade E). Its per-ref loop body is extracted into focused helpers (_resolve_dep, _remove_from_filesystem, the _resolve_package_cleanup trio, _process_ref, and a _RefRemoval result struct), leaving run_remove a thin loop. No behavior change; all functions now grade <= B (run_remove itself A 2). Adds seam-level tests for package child resolution and per-ref processing, plus a LOG.md and implementation diary for the iteration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
First iteration of the radon complexity-reduction task. Decomposes
run_remove(agr/commands/remove.py) — the codebase's worst complexity outlier — from CC 36 (grade E) down to CC 2 (A), with no behavior change.The per-
refloop body is extracted into focused, individually testable helpers:_RefRemovaldataclass — one ref's outcome (result + parallel candidate/kind lists for lockfile cleanup)._resolve_dep— handle parse + identifier candidates + dependency lookup._remove_from_filesystem/_remove_leaf_from_filesystem— filesystem removal, fanning out to package children._nested_packages_to_remove/_transitive_leaves_to_remove/_resolve_package_cleanup— package child resolution (split so each stays ≤ B)._uninstall_transitive_entries,_remove_from_config,_build_removal,_process_ref.run_removeis now a thin loop + finalization. All pre-existing helpers reused; pure decomposition.Tests
Added
TestResolvePackageCleanup(transitive leaf, nested package, shared-child retention, no-lockfile) andTestProcessRef(not-found, leaf removal, package transitive scheduling) totests/unit/test_remove.py. Existingrun_removeintegration tests retained as the behavior-preservation net.Verification
uvx radon cc agr/commands/remove.py -s: no function above grade B.uv run pytest: 1310 passed, 6 skipped.uv run ruff check .,ruff format --check,uv run ty check: clean.agr --help,agr remove --helpOK.A LOG.md and implementation diary document the iteration. Task definition and remaining acceptance criteria (add.py / package.py / config.py hotspots, sync.py split, xenon CI gate) are tracked under
tasks/2026-06-09-radon-complexity-reduction/.🤖 Generated with Claude Code