Skip to content

feat(clean): group Python bytecode cleanup by project root#634

Merged
tw93 merged 1 commit intotw93:mainfrom
byronwang2005:feat/pycache
Mar 27, 2026
Merged

feat(clean): group Python bytecode cleanup by project root#634
tw93 merged 1 commit intotw93:mainfrom
byronwang2005:feat/pycache

Conversation

@byronwang2005
Copy link
Copy Markdown
Contributor

Summary

  • Group Python bytecode cache cleanup output by detected project root instead of printing one line per __pycache__ directory.
  • Preserve grouped dry-run export entries and skip/accounting behavior for protected or whitelisted Python cache directories.
  • Process project-cache scan results per scan root so output appears incrementally instead of arriving in one large batch.
  • Keep existing Next.js and Flutter project-cache cleanup behavior compatible with the new flow.

Safety Review

  • Does this change affect cleanup, uninstall, optimize, installer, remove, analyze delete, update, or install behavior?
  • Yes. It affects clean behavior for project cache cleanup, specifically Python __pycache__ handling and the timing/format of project-cache output.
  • Does this change affect path validation, protected directories, symlink handling, sudo boundaries, or release/install integrity?
  • It affects protected-directory and whitelist handling inside grouped Python cache cleanup.
  • New boundary/risk change:
  • Grouped Python cleanup now preserves the same protected-path and whitelist skip behavior as the previous per-directory flow by updating skip counters and writing SKIPPED operation logs.
  • Dry-run behavior is preserved by continuing to register/export concrete cleanup targets instead of only showing grouped summaries.
  • No changes were made to path validation rules, symlink handling, sudo boundaries, installer/release integrity, or destructive scope beyond the existing __pycache__ targets.

Tests

  • Automated tests run:
  • ./scripts/check.sh
  • ./scripts/test.sh (current repo still has unrelated existing failures in tests/cli.bats for mo status --json)
  • Targeted tests run during development:
  • bats tests/clean_system_caches.bats -f "clean_project_caches completes without errors"
  • bats tests/clean_system_caches.bats -f "clean_project_caches groups pycache directories by project root"
  • bats tests/clean_system_caches.bats -f "clean_project_caches pycache dry-run exports grouped targets and counts skips"
  • bats tests/clean_dev_caches.bats -f "clean_project_caches cleans flutter .dart_tool and build directories"
  • Manual checks:
  • Ran ./mo clean --dry-run globally and verified Python bytecode cleanup now prints grouped project-root summaries.
  • Inspected generated dry-run behavior and sampled real __pycache__ directories to confirm several 0B dry cases were due to empty cache directories, not size-calculation regression.

Safety-related changes

  • None.

@byronwang2005 byronwang2005 requested a review from tw93 as a code owner March 24, 2026 06:52
@byronwang2005
Copy link
Copy Markdown
Contributor Author

May close issue #633.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb249f5d92

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/clean/caches.sh
@tw93
Copy link
Copy Markdown
Owner

tw93 commented Mar 27, 2026

@byronwang2005 LGTM! This directly addresses a well-reported pain point (#633), grouping by project root turns 1000+ noisy lines into clean per-project summaries. The decomposition is solid and the existing safety checks (whitelist, protect path, dry-run) are all preserved.

A couple of minor things worth tidying up in a follow-up if you have time:

  • flush_python_bytecode_cache_group() is defined but never called — can be removed
  • The eval in flush_python_group_if_needed() works fine but could be simplified by passing array elements directly instead of the array name
  • rm -f on temp files is a minor convention deviation (project prefers safe_* helpers for all removals)

None of these are blockers. Thanks for tackling this one!

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.

2 participants