Show the size of the code each finished item names beside its S in score-outcomes

This commit is contained in:
2026-11-08 23:10:55 +01:00
parent 0a9a4dc159
commit 6176f72355
10 changed files with 150 additions and 42 deletions
+22
View File
@@ -0,0 +1,22 @@
"""The tracked files and folders an item's text names, each as a backticked span such as `bin/rank_todo.py` or `bin/`."""
import re
def named_paths(text: str, tracked: list[str]) -> list[tuple[str, int]]:
"""Each backticked span in text, in order and once, that names a tracked file or folder, with how many of the tracked files it holds: 1 for a file."""
held = ((span, sum(holds(span, path) for path in tracked)) for span in spans(text))
return [(span, count) for span, count in held if count]
def named_files(text: str, tracked: list[str]) -> list[str]:
"""Each tracked file that a backticked span in text names, itself or by a folder holding it, once, in tracked's order."""
named = spans(text)
return [path for path in tracked if any(holds(span, path) for span in named)]
def spans(text: str) -> list[str]:
return list(dict.fromkeys(span.removesuffix("/") for span in re.findall(r"`([^`\s]+)`", text)))
def holds(span: str, path: str) -> bool:
return path == span or path.startswith(f"{span}/")