27 lines
1.4 KiB
Python
27 lines
1.4 KiB
Python
import re
|
|
|
|
from markdown_text import sections
|
|
from todo_table import Item
|
|
|
|
|
|
def unreleased_entries(changelog: str) -> int | None:
|
|
"""How many top-level `- ` entries CHANGELOG.md holds under ## Unreleased; None without that section."""
|
|
found = sections(changelog).get("Unreleased")
|
|
return None if found is None else sum(line.startswith("- ") for line in found[0].splitlines())
|
|
|
|
|
|
def bundle_candidates(found: list[Item], first: Item) -> list[Item]:
|
|
"""The items of first's release, in the table's order, that a chunk taking first may take too: no question, and none blocked by an item outside first and these."""
|
|
candidates = {item.id for item in found if item.release == first.release and item.id != first.id and item.exempt != "question"}
|
|
held = {item.id for item in found}
|
|
while blocked := {item.id for item in found if item.id in candidates and (held & set(item.blocked_by)) - candidates - {first.id}}:
|
|
candidates -= blocked
|
|
return [item for item in found if item.id in candidates]
|
|
|
|
|
|
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."""
|
|
spans = dict.fromkeys(span.rstrip("/") for span in re.findall(r"`([^`\s]+)`", text))
|
|
held = ((span, sum(path == span or path.startswith(f"{span}/") for path in tracked)) for span in spans)
|
|
return [(span, count) for span, count in held if count]
|