From 268ae012362111e18e60fac60a3bd938a9ee1862 Mon Sep 17 00:00:00 2001 From: desilo-hanyul <95674196+hanyul-ryu@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:34:28 +0900 Subject: [PATCH] Create clean.py add clean.py --- clean.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 clean.py diff --git a/clean.py b/clean.py new file mode 100644 index 0000000..e3d0162 --- /dev/null +++ b/clean.py @@ -0,0 +1,29 @@ +import pathlib +import shutil + + +def clean_project(): + """ + Remove common build directories and *.so files in a Python project. + """ + # Directories to remove + dirs_to_remove = [ + "__pycache__", ".pytest_cache", + "build", "*.egg-info", # "dist", + ] + # File patterns to remove + files_to_remove = ["*.so"] + + for path in pathlib.Path(".").rglob("*"): + # Remove specified directories + if path.is_dir() and any(path.match(d) for d in dirs_to_remove): + shutil.rmtree(path, ignore_errors=True) + print(f"Removed directory: {path}") + # Remove specified files + elif path.is_file() and any(path.match(f) for f in files_to_remove): + path.unlink() + print(f"Removed file: {path}") + + +if __name__ == "__main__": + clean_project()