-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathclean.py
More file actions
81 lines (67 loc) · 2.59 KB
/
Copy pathclean.py
File metadata and controls
81 lines (67 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import os
import shutil
from pathlib import Path
# --- Configuration ---
# Get the project's root directory (where this script is located)
# This makes the script runnable from anywhere, as long as it's found by python.
project_root = Path(__file__).parent.resolve()
# List of directories to remove completely.
# '.scikit-build' and 'build' contain the CMake cache — only remove for a full rebuild.
dirs_to_remove = [
'dist',
]
# Removing these forces a full CMake recompile of all C++ files.
cmake_dirs_to_remove = [
'.scikit-build',
'build',
]
# Glob pattern for other directories to remove.
glob_patterns_to_remove = [
'*.egg-info',
'*.so', # Add this if you want to clean up stray .so files in the root
'*.pyd', # Add this if you want to clean up stray .pyd files in the root
'**/gropt_wrapper*.pyd', # Remove all compiled wrapper binaries to ensure only one exists after rebuild
'**/gropt_wrapper*.so',
]
# Glob patterns for directories searched recursively under the project root.
recursive_glob_patterns_to_remove = [
'gropt/__pycache__',
]
# --- Main Execution ---
def main():
"""Find and removes build artifacts in the project root."""
import sys
full = '--full' in sys.argv
if full:
print('--- Starting FULL cleanup script (CMake cache will be removed) ---')
else:
print('--- Starting cleanup script ---')
all_dirs = dirs_to_remove + (cmake_dirs_to_remove if full else [])
# Remove specified directories
for dir_name in all_dirs:
path = project_root / dir_name
if path.is_dir():
print(f'Removing directory: {path.relative_to(project_root)}')
shutil.rmtree(path)
elif path.exists():
print(f'Removing file: {path.relative_to(project_root)}')
path.unlink()
# Remove directories/files matching glob patterns
for pattern in glob_patterns_to_remove:
for path in project_root.glob(pattern):
if path.is_dir():
print(f'Removing glob-matched directory: {path.relative_to(project_root)}')
shutil.rmtree(path)
elif path.is_file():
print(f'Removing glob-matched file: {path.relative_to(project_root)}')
path.unlink()
# Remove specific recursive paths
for pattern in recursive_glob_patterns_to_remove:
path = project_root / pattern
if path.is_dir():
print(f'Removing directory: {path.relative_to(project_root)}')
shutil.rmtree(path)
print('--- Cleanup finished successfully ---')
if __name__ == '__main__':
main()