-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.py
More file actions
61 lines (51 loc) · 1.18 KB
/
Copy pathformat.py
File metadata and controls
61 lines (51 loc) · 1.18 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
# /// script
# requires-python = ">=3.13"
# dependencies = ["yapf==0.43.0"]
# ///
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
FORMAT_ROOTS = (
"dmdcontrol",
"tests",
"compat",
"debug_scripts",
"hannah_cam_code",
)
EXCLUDED_PARTS = {
".venv",
"__pycache__",
".pytest_cache",
".ruff_cache",
}
def _python_files() -> list[Path]:
files: list[Path] = []
for root_name in FORMAT_ROOTS:
root = Path(root_name)
if not root.exists():
continue
files.extend(
path for path in root.rglob("*.py")
if not any(part in EXCLUDED_PARTS for part in path.parts)
)
return sorted(files)
def main() -> int:
files = _python_files()
for path in files:
subprocess.run(
[
sys.executable,
"-m",
"yapf",
"--in-place",
"--style",
"pyproject.toml",
str(path),
],
check=True,
)
print(f"Formatted {len(files)} Python files.")
return 0
if __name__ == "__main__":
raise SystemExit(main())