Skip to content

fix(clean): reduce Python bytecode output spam#672

Open
sebastianbreguel wants to merge 3 commits intotw93:mainfrom
sebastianbreguel:fix/python-bytecode-spam
Open

fix(clean): reduce Python bytecode output spam#672
sebastianbreguel wants to merge 3 commits intotw93:mainfrom
sebastianbreguel:fix/python-bytecode-spam

Conversation

@sebastianbreguel
Copy link
Copy Markdown
Contributor

@sebastianbreguel sebastianbreguel commented Apr 2, 2026

Summary

Fixes the output spam and performance issue when mo clean encounters many __pycache__ directories.

Users reported 3000+ lines of Python bytecode cache · X, 1 dirs, 0 B output and 10-15 minute runtimes (#633). The root causes were: (1) empty __pycache__ dirs left from previous cleanups still being processed, and (2) the scan traversing conda/pip site-packages trees with thousands of package __pycache__ dirs.

Changes

1. Skip empty __pycache__ dirs at scan time

scan_project_cache_root now checks whether each __pycache__ directory contains .pyc or .pyo files before including it in the results. Empty dirs (left over from previous cleanups or created by tooling) are silently skipped.

2. Prune conda and site-packages from scan tree

Added miniconda3, anaconda3, miniforge3, mambaforge, and site-packages to the find prune list. These directories contain __pycache__ dirs from installed Python packages — cleaning them would break installed packages, and traversing them was the main cause of 10-15 minute scan times.

Visual preview

Before (from #633):

  ✓ Python bytecode cache · dev, 1 dirs, 0 B
  ✓ Python bytecode cache · dev, 1 dirs, 0 B
  ✓ Python bytecode cache · dev, 1 dirs, 0 B
  ... (3000+ lines, 10-15 minutes)

After:

  ✓ Python bytecode cache · my-project, 4 dirs, 1.2 MB
  ✓ Python bytecode cache · another-app, 2 dirs, 256 KB

Only projects with actual bytecode files produce output.

What changed

File Change
lib/clean/caches.sh Filter empty __pycache__ in scan_project_cache_root; add conda/site-packages to prune list
tests/clean_system_caches.bats 2 new tests: empty pycache skipping, conda/site-packages pruning

Test plan

  • bats tests/clean_system_caches.bats — all 18 tests pass (2 new + 16 existing)
  • Empty __pycache__ dirs excluded from scan results
  • conda/site-packages paths pruned from scan tree
  • Existing pycache grouping, dry-run export, and whitelist tests unaffected
  • No regressions in project cache detection (configured roots, auto-detect, GOPATH-style)

Closes #633

Filter out __pycache__ directories that contain no .pyc/.pyo files
at scan time. These empty dirs produce 0 B output lines that spam
the terminal when running mo clean.

Closes tw93#633
Add miniconda3, anaconda3, miniforge3, mambaforge, and site-packages
to the find prune list in scan_project_cache_root. These directories
contain thousands of __pycache__ dirs from installed packages that
should not be cleaned, and traversing them causes 10-15 minute scans.
@sebastianbreguel sebastianbreguel requested a review from tw93 as a code owner April 2, 2026 14:57
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.

[BUG] Consistent Issue of 100s of Python Bytecode Cleanups

1 participant