Spaces:
Sleeping
Sleeping
chore: Update TODO extraction script to use grep and clean up imports
Browse files- Replaced the flake8-todos based extraction with a grep-based approach in `generate_todo_md.py`.
- Updated the pre-commit hook to reflect the new script usage.
- Added TODO comments in `app.py` for future cleanup.
- Removed the old `scripts/generate_todo_md.py` file as it is no longer needed.
- TODO.md +4 -5
- app.py +4 -1
- generate_todo_md.py +16 -36
- pyproject.toml +6 -0
- scripts/generate_todo_md.py +0 -67
- scripts/pre-commit +2 -2
- uv.lock +0 -0
TODO.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
# π TODOs in Codebase
|
2 |
|
3 |
-
-
|
4 |
-
-
|
5 |
-
|
6 |
-
|
7 |
-
- `app.py:254`: TD003 Missing issue link for this TODO
|
|
|
1 |
# π TODOs in Codebase
|
2 |
|
3 |
+
- `./app.py:251:# TODO: Clean up imports.`
|
4 |
+
- `./app.py:254:# TODO: This should be fixed`
|
5 |
+
|
6 |
+
Keep up the great work! π
|
|
app.py
CHANGED
@@ -248,7 +248,10 @@ class ChainlitCallbackHandler(BaseCallbackHandler):
|
|
248 |
|
249 |
import time
|
250 |
|
251 |
-
#
|
|
|
|
|
|
|
252 |
|
253 |
|
254 |
@cl.on_message
|
|
|
248 |
|
249 |
import time
|
250 |
|
251 |
+
# TODO: Clean up imports.
|
252 |
+
|
253 |
+
|
254 |
+
# TODO: This should be fixed
|
255 |
|
256 |
|
257 |
@cl.on_message
|
generate_todo_md.py
CHANGED
@@ -1,65 +1,45 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
"""
|
3 |
-
Script to generate TODO.md by
|
4 |
-
Run with:
|
5 |
"""
|
6 |
import subprocess
|
7 |
-
import sys
|
8 |
from pathlib import Path
|
9 |
|
10 |
REPO_ROOT = Path(__file__).parent.resolve()
|
11 |
TODO_MD_PATH = REPO_ROOT / "TODO.md"
|
12 |
|
13 |
|
14 |
-
def
|
15 |
-
"""Run
|
16 |
try:
|
|
|
17 |
result = subprocess.run(
|
18 |
-
|
19 |
-
sys.executable,
|
20 |
-
"-m",
|
21 |
-
"ruff",
|
22 |
-
"check",
|
23 |
-
"--select=TD",
|
24 |
-
str(REPO_ROOT),
|
25 |
-
],
|
26 |
capture_output=True,
|
27 |
text=True,
|
28 |
-
|
|
|
29 |
)
|
30 |
-
return result.stdout.strip()
|
31 |
except Exception as e:
|
32 |
-
print(f"Error running
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
def parse_ruff_output(output):
|
37 |
-
"""Parse ruff output into a list of TODOs."""
|
38 |
-
todos = []
|
39 |
-
for line in output.splitlines():
|
40 |
-
# Example: app.py:251:1: TD001 TODO: ...
|
41 |
-
parts = line.split(":", 3)
|
42 |
-
if len(parts) == 4:
|
43 |
-
file_path, line_no, col_no, rest = parts
|
44 |
-
rest = rest.strip()
|
45 |
-
if rest.startswith("TD"): # e.g. TD001 TODO: ...
|
46 |
-
todos.append((file_path.strip(), line_no.strip(), rest))
|
47 |
-
return todos
|
48 |
|
49 |
|
50 |
def write_todo_md(todos):
|
51 |
with open(TODO_MD_PATH, "w", encoding="utf-8") as f:
|
52 |
f.write("# π TODOs in Codebase\n\n")
|
53 |
-
if not todos:
|
54 |
f.write("No TODOs found! π\n")
|
55 |
return
|
56 |
-
for
|
57 |
-
f.write(f"- `{
|
|
|
58 |
|
59 |
|
60 |
def main():
|
61 |
-
|
62 |
-
todos = parse_ruff_output(output)
|
63 |
write_todo_md(todos)
|
64 |
print(f"Wrote {len(todos)} TODOs to {TODO_MD_PATH}")
|
65 |
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
"""
|
3 |
+
Script to generate TODO.md by grepping for TODO/FIXME/HACK comments in Python files.
|
4 |
+
Run with: uvx python generate_todo_md.py
|
5 |
"""
|
6 |
import subprocess
|
|
|
7 |
from pathlib import Path
|
8 |
|
9 |
REPO_ROOT = Path(__file__).parent.resolve()
|
10 |
TODO_MD_PATH = REPO_ROOT / "TODO.md"
|
11 |
|
12 |
|
13 |
+
def run_grep_todos():
|
14 |
+
"""Run grep to find TODO/FIXME/HACK comments in all .py files using shell=True."""
|
15 |
try:
|
16 |
+
cmd = r'grep -rn "^\s*#\s*\(TODO\|FIXME\|HACK\)" --include="*.py" --exclude-dir=".venv" --exclude-dir=".git" .'
|
17 |
result = subprocess.run(
|
18 |
+
cmd,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
capture_output=True,
|
20 |
text=True,
|
21 |
+
shell=True,
|
22 |
+
cwd=REPO_ROOT,
|
23 |
)
|
24 |
+
return result.stdout.strip().splitlines()
|
25 |
except Exception as e:
|
26 |
+
print(f"Error running grep: {e}")
|
27 |
+
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
|
30 |
def write_todo_md(todos):
|
31 |
with open(TODO_MD_PATH, "w", encoding="utf-8") as f:
|
32 |
f.write("# π TODOs in Codebase\n\n")
|
33 |
+
if not todos or (len(todos) == 1 and todos[0] == ""):
|
34 |
f.write("No TODOs found! π\n")
|
35 |
return
|
36 |
+
for line in todos:
|
37 |
+
f.write(f"- `{line}`\n")
|
38 |
+
f.write("\nKeep up the great work! π\n")
|
39 |
|
40 |
|
41 |
def main():
|
42 |
+
todos = run_grep_todos()
|
|
|
43 |
write_todo_md(todos)
|
44 |
print(f"Wrote {len(todos)} TODOs to {TODO_MD_PATH}")
|
45 |
|
pyproject.toml
CHANGED
@@ -53,6 +53,8 @@ dependencies = [
|
|
53 |
"beautifulsoup4>=4.13.4",
|
54 |
"pathvalidate>=3.2.3",
|
55 |
"pydantic-settings>=2.9.1",
|
|
|
|
|
56 |
]
|
57 |
authors = [{ name = "Marko Budisic", email = "mbudisic@gmail.com" }]
|
58 |
license = "MIT"
|
@@ -88,8 +90,12 @@ web = [
|
|
88 |
[tool.ruff]
|
89 |
line-length = 79
|
90 |
target-version = "py311"
|
|
|
|
|
91 |
select = ["E", "F", "I", "N", "W"]
|
|
|
92 |
ignore = []
|
|
|
93 |
|
94 |
[tool.ruff.isort]
|
95 |
known-first-party = ["src"]
|
|
|
53 |
"beautifulsoup4>=4.13.4",
|
54 |
"pathvalidate>=3.2.3",
|
55 |
"pydantic-settings>=2.9.1",
|
56 |
+
"flake8-todos>=0.3.1",
|
57 |
+
"ruff>=0.11.0",
|
58 |
]
|
59 |
authors = [{ name = "Marko Budisic", email = "mbudisic@gmail.com" }]
|
60 |
license = "MIT"
|
|
|
90 |
[tool.ruff]
|
91 |
line-length = 79
|
92 |
target-version = "py311"
|
93 |
+
|
94 |
+
[tool.ruff.lint]
|
95 |
select = ["E", "F", "I", "N", "W"]
|
96 |
+
extend-select = ["TD"]
|
97 |
ignore = []
|
98 |
+
task-tags = ["TODO", "FIXME", "BUG", "HACK", "XXX"]
|
99 |
|
100 |
[tool.ruff.isort]
|
101 |
known-first-party = ["src"]
|
scripts/generate_todo_md.py
DELETED
@@ -1,67 +0,0 @@
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scripts/pre-commit
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
#!/bin/sh
|
2 |
-
# Manual pre-commit hook: Generates TODO.md using
|
3 |
# To install: cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
|
4 |
|
5 |
-
|
6 |
if [ -f TODO.md ]; then
|
7 |
git add TODO.md
|
8 |
fi
|
|
|
1 |
#!/bin/sh
|
2 |
+
# Manual pre-commit hook: Generates TODO.md using grep-based script and stages it.
|
3 |
# To install: cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
|
4 |
|
5 |
+
uvx python generate_todo_md.py
|
6 |
if [ -f TODO.md ]; then
|
7 |
git add TODO.md
|
8 |
fi
|
uv.lock
CHANGED
The diff for this file is too large to render.
See raw diff
|
|