Function
removepycache
(root: str | os.PathLike = ".")
Source from the content-addressed store, hash-verified
| 14 | |
| 15 | '''removepycache''' |
| 16 | def removepycache(root: str | os.PathLike = ".") -> int: |
| 17 | root_path, removed = Path(root).resolve(), 0 |
| 18 | for p in root_path.rglob("__pycache__"): |
| 19 | if p.is_dir(): |
| 20 | try: |
| 21 | shutil.rmtree(p) |
| 22 | removed += 1 |
| 23 | print(f"Removed: {p}") |
| 24 | except Exception as e: |
| 25 | print(f"Failed: {p} ({e})") |
| 26 | print(f"\nDone. Removed {removed} __pycache__ directories under {root_path}") |
| 27 | return removed |
| 28 | |
| 29 | |
| 30 | '''run''' |
Tested by
no test coverage detected