Rank, check and edit the plan at the paths the project's config names
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
"""todo.md on disk: read it with the project files ranking reads, then rank or check it, write it back, and print what ranking reports."""
|
||||
"""todo.md on disk: read it with the files ranking reads, at the paths the project's config names, then rank or check it, write it back, and print what ranking reports."""
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from failure import Failure
|
||||
from project_config.main import goals_file
|
||||
from review_rules.comprehension_history import HISTORY
|
||||
from project_config.settings import ProjectConfig
|
||||
from release_plan.ranking import rank, Ranked
|
||||
from records.file_writes import replace_file
|
||||
|
||||
|
||||
def rank_file(todo: pathlib.Path) -> Ranked | Failure:
|
||||
def rank_file(todo: pathlib.Path, config: ProjectConfig) -> Ranked | Failure:
|
||||
"""Rank todo in place: rank what read_all reads, write todo where that changed it, and print the notes and under-bar lines on stderr."""
|
||||
texts = read_all(todo)
|
||||
texts = read_all(todo, config)
|
||||
if isinstance(texts, Failure):
|
||||
return texts
|
||||
ranked = rank(*texts)
|
||||
@@ -29,9 +28,9 @@ def print_report(todo: pathlib.Path, ranked: Ranked) -> None:
|
||||
print(f"{todo}: {line}", file=sys.stderr)
|
||||
|
||||
|
||||
def check_failures(todo: pathlib.Path) -> list[str]:
|
||||
def check_failures(todo: pathlib.Path, config: ProjectConfig) -> list[str]:
|
||||
"""Why --check fails on todo, empty when it passes."""
|
||||
texts = read_all(todo)
|
||||
texts = read_all(todo, config)
|
||||
if isinstance(texts, Failure):
|
||||
return [texts.reason]
|
||||
ranked = rank(*texts)
|
||||
@@ -41,16 +40,12 @@ def check_failures(todo: pathlib.Path) -> list[str]:
|
||||
return unranked + [f"{todo}: {line}" for line in ranked.under_bar]
|
||||
|
||||
|
||||
def read_all(todo: pathlib.Path) -> tuple[str, str, str, str] | Failure:
|
||||
"""todo.md, the goals file its project's config names, and its docs/decisions.md and docs/comprehension-history.md. The last two are empty when missing; a missing todo.md, config or goals file is a Failure."""
|
||||
def read_all(todo: pathlib.Path, config: ProjectConfig) -> tuple[str, str, str, str] | Failure:
|
||||
"""todo, the plan, then the goals file, the decision log and the comprehension history that config names. The last two are empty when missing; a missing plan or goals file is a Failure."""
|
||||
plan = read(todo, "every project keeps a todo.md, and rank_todo.py --help shows one")
|
||||
if isinstance(plan, Failure):
|
||||
return plan
|
||||
# Looked up after todo.md is read, so a mistyped path fails naming todo.md, not in git's words.
|
||||
goals = goals_file(str(todo.parent), pathlib.Path.home())
|
||||
if isinstance(goals, Failure):
|
||||
return goals
|
||||
goals_text, decisions, history = read(goals, "rank_todo.py weighs goals from the file the project's config names as goals-and-audience"), read(todo.parent / "docs" / "decisions.md", None), read(todo.parent / HISTORY, None)
|
||||
goals_text, decisions, history = read(config.paths["goals-and-audience"], "rank_todo.py weighs goals from the file the project's config names as goals-and-audience"), read(config.paths["decisions"], None), read(config.paths["comprehension-history"], None)
|
||||
if isinstance(goals_text, Failure):
|
||||
return goals_text
|
||||
if isinstance(decisions, Failure):
|
||||
|
||||
Reference in New Issue
Block a user