Spaces:
Sleeping
Sleeping
code: add generate_todo_md.py for TODO.md extraction
Browse files- scripts/generate_todo_md.py +67 -0
scripts/generate_todo_md.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Script to generate TODO.md by parsing all TODO-style comments using flake8-todos.
|
| 4 |
+
Run with: uv run python scripts/generate_todo_md.py
|
| 5 |
+
"""
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
REPO_ROOT = Path(__file__).parent.parent.resolve()
|
| 11 |
+
TODO_MD_PATH = REPO_ROOT / "TODO.md"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def run_flake8_todos():
|
| 15 |
+
"""Run flake8 with flake8-todos on all .py files in the repo."""
|
| 16 |
+
try:
|
| 17 |
+
result = subprocess.run(
|
| 18 |
+
[
|
| 19 |
+
sys.executable,
|
| 20 |
+
"-m",
|
| 21 |
+
"flake8",
|
| 22 |
+
"--select=TD",
|
| 23 |
+
str(REPO_ROOT),
|
| 24 |
+
],
|
| 25 |
+
capture_output=True,
|
| 26 |
+
text=True,
|
| 27 |
+
check=False,
|
| 28 |
+
)
|
| 29 |
+
return result.stdout.strip()
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"Error running flake8-todos: {e}")
|
| 32 |
+
sys.exit(1)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def parse_flake8_output(output):
|
| 36 |
+
"""Parse flake8-todos output into a list of TODOs."""
|
| 37 |
+
todos = []
|
| 38 |
+
for line in output.splitlines():
|
| 39 |
+
# Example: scripts/generate_todo_md.py:10:1: TD003 TODO: something
|
| 40 |
+
parts = line.split(":", 3)
|
| 41 |
+
if len(parts) == 4:
|
| 42 |
+
file_path, line_no, col_no, rest = parts
|
| 43 |
+
rest = rest.strip()
|
| 44 |
+
if rest.startswith("TD"): # e.g. TD003 TODO: ...
|
| 45 |
+
todos.append((file_path.strip(), line_no.strip(), rest))
|
| 46 |
+
return todos
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def write_todo_md(todos):
|
| 50 |
+
with open(TODO_MD_PATH, "w", encoding="utf-8") as f:
|
| 51 |
+
f.write("# 📝 TODOs in Codebase\n\n")
|
| 52 |
+
if not todos:
|
| 53 |
+
f.write("No TODOs found! 🎉\n")
|
| 54 |
+
return
|
| 55 |
+
for file_path, line_no, rest in todos:
|
| 56 |
+
f.write(f"- `{file_path}:{line_no}`: {rest}\n")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def main():
|
| 60 |
+
output = run_flake8_todos()
|
| 61 |
+
todos = parse_flake8_output(output)
|
| 62 |
+
write_todo_md(todos)
|
| 63 |
+
print(f"Wrote {len(todos)} TODOs to {TODO_MD_PATH}")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
if __name__ == "__main__":
|
| 67 |
+
main()
|