-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump_code.py
More file actions
49 lines (40 loc) · 1.02 KB
/
dump_code.py
File metadata and controls
49 lines (40 loc) · 1.02 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
#!/usr/bin/env python3
from pathlib import Path
ROOT = Path(".").resolve()
OUT = Path("repo_dump.txt")
INCLUDE = {".py", ".toml", ".md"}
EXCLUDE_DIRS = {
".git",
".venv",
"__pycache__",
".pytest_cache",
".mypy_cache",
"dist",
"build",
}
EXCLUDE_FILES_SUFFIX = {".pyc"}
def should_skip(path: Path) -> bool:
if any(part in EXCLUDE_DIRS for part in path.parts):
return True
if path.suffix in EXCLUDE_FILES_SUFFIX:
return True
return False
files = []
for p in ROOT.rglob("*"):
if not p.is_file():
continue
if should_skip(p):
continue
if p.suffix not in INCLUDE:
continue
files.append(p)
files.sort()
with OUT.open("w", encoding="utf-8") as f:
for p in files:
rel = p.relative_to(ROOT)
f.write(f"\n\n# === {rel} ===\n\n")
try:
f.write(p.read_text(encoding="utf-8"))
except UnicodeDecodeError:
f.write("<binary or non-utf8 file skipped>\n")
print(f"Wrote {OUT} with {len(files)} files.")