Last active
October 19, 2023 20:55
-
-
Save ml31415/98f8070dcb7682628df02521607b105b to your computer and use it in GitHub Desktop.
Clean up script for all temporary binaries and build artifacts, that might pile up within a python project and possibly disturb a clean execution.
This file contains 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
#!/usr/bin/env python3 | |
from shutil import rmtree | |
from sys import argv | |
from pathlib import Path | |
from typing import Iterable | |
DELETE_DIRS: set[str] = { | |
"build", | |
"dist", | |
"*.egg-info", | |
"**/__pycache__", | |
".hypothesis", | |
".pytest_cache", | |
".mypy_cache", | |
".cache", | |
".eggs" | |
} | |
DEFAULT_DIRS: list[str] = ["."] | |
def delete_path(path: Path, dry=False): | |
if path.is_dir(): | |
print("Deleting", path) | |
if not dry: | |
rmtree(path) | |
elif path.is_file(): | |
print("Deleting", path) | |
if not dry: | |
path.unlink(missing_ok=True) | |
def get_artifacts(path: Path) -> Iterable[Path]: | |
for pattern in DELETE_DIRS: | |
for artifact in path.glob(pattern): | |
yield artifact | |
def main(dry=False): | |
paths = argv[1:] or DEFAULT_DIRS | |
for path in paths: | |
for fpath in get_artifacts(Path(path)): | |
delete_path(fpath, dry=dry) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment