Rank, check and edit the plan at the paths the project's config names

This commit is contained in:
2026-11-13 00:38:52 +01:00
parent 2ca6fac1d4
commit 0a47b55c93
13 changed files with 246 additions and 87 deletions
+30 -23
View File
@@ -5,22 +5,23 @@ usage: todo-item add --release <version> --l <L> --e <E> --i <I> --s <S> [--move
todo-item finish <ID> [--changelog <bullet> | --no-changelog]
todo-item show <ID>
All three work on the todo.md in the current folder. add and finish also use the CHANGELOG.md beside it,
and read the docs/decisions.md beside it and the goals file that todo.md's project config names.
Run inside a checkout. All three work on the project's todo.md, and name its path in what they
print. add and finish also use its CHANGELOG.md, and read its docs/decisions.md and its goals file.
Each file sits where the project's config puts it, which `project-config` prints.
The cells take the format rank_todo.py --help states; the letter flags take upper case too, as --L.
add takes Next ID as the item's ID and raises Next ID by one. It writes the row, with the tagline
in bold and each | in it escaped, and the detail it reads from stdin, if any, under ## Details.
The detail may hold no ## or ### heading.
It prints `Filed item <ID>.` It doesn't write anything where ranking fails or scores the item under the bar.
It prints `Filed item <ID> in <todo.md's path>.` It doesn't write anything where ranking fails or scores the item under the bar.
finish removes the item's row and its detail. With --changelog it adds the bullet first under
CHANGELOG.md's ## Unreleased, or a ## heading that says unreleased, creating the section, or the
file, where missing. It refuses where that section holds ### subsections: add the bullet by hand.
Where CHANGELOG.md exists, finish needs --changelog or --no-changelog, so no bullet is left out by
mistake. It prints `Finished item <ID>.` It doesn't write anything while docs/decisions.md cites the item.
mistake. It prints `Finished item <ID> in <todo.md's path>.` It doesn't write anything while docs/decisions.md cites the item.
show reads only todo.md. It prints the items table's header and divider, item <ID>'s row, and its detail
show reads only todo.md. It prints `From <todo.md's path>:`, then the items table's header and divider, item <ID>'s row, and its detail
from its ### heading to the next item's, sub-headings included. It fails, saying so, where todo.md has
no row for <ID>.
@@ -35,6 +36,8 @@ import typing
from todo_item.edits import added, finished, shown, with_bullet
from release_plan.todo_table import BLOCKED_BY, MOVES
from failure import Failure
from project_config.main import located
from project_config.settings import ProjectConfig
from release_plan import plan_file, ranking
# Each score flag, as --l or --L, and the column it fills.
@@ -46,10 +49,13 @@ def main(argv: list[str], folder: pathlib.Path = pathlib.Path(), stdin: typing.T
print(__doc__.strip())
return 0
args = parser().parse_args(argv)
if args.command == "show":
done = show(args, folder)
config = located(str(folder), pathlib.Path.home())
if isinstance(config, Failure):
done: str | Failure = config
elif args.command == "show":
done = show(args, config.paths["plan"])
else:
done = add(args, folder, stdin) if args.command == "add" else finish(args, folder)
done = add(args, config, stdin) if args.command == "add" else finish(args, config)
if isinstance(done, Failure):
print(done.reason, file=sys.stderr)
return 1
@@ -78,19 +84,19 @@ def parser() -> argparse.ArgumentParser:
return parsed
def show(args: argparse.Namespace, folder: pathlib.Path) -> str | Failure:
todo = folder / "todo.md"
def show(args: argparse.Namespace, todo: pathlib.Path) -> str | Failure:
try:
return shown(todo.read_text(encoding="utf-8"), args.id)
found = shown(todo.read_text(encoding="utf-8"), args.id)
return found if isinstance(found, Failure) else f"From {todo}:\n\n{found}"
except OSError as failure:
return Failure(f"{todo}: {failure.strerror}")
except UnicodeDecodeError:
return Failure(f"{todo}: not UTF-8")
def add(args: argparse.Namespace, folder: pathlib.Path, stdin: typing.TextIO) -> str | Failure:
todo = folder / "todo.md"
texts = plan_file.read_all(todo)
def add(args: argparse.Namespace, config: ProjectConfig, stdin: typing.TextIO) -> str | Failure:
todo = config.paths["plan"]
texts = plan_file.read_all(todo, config)
if isinstance(texts, Failure):
return texts
named = {"Release": args.release, BLOCKED_BY: args.blocked_by, "Exempt": args.exempt, "Item": args.tagline, MOVES: args.moves}
@@ -107,12 +113,12 @@ def add(args: argparse.Namespace, folder: pathlib.Path, stdin: typing.TextIO) ->
if unwritten := plan_file.write(todo, ranked.text):
return unwritten
plan_file.print_report(todo, ranked)
return f"Filed item {id_}."
return f"Filed item {id_} in {todo}."
def finish(args: argparse.Namespace, folder: pathlib.Path) -> str | Failure:
todo, changelog = folder / "todo.md", folder / "CHANGELOG.md"
texts = finish_texts(args, todo, changelog)
def finish(args: argparse.Namespace, config: ProjectConfig) -> str | Failure:
todo, changelog = config.paths["plan"], config.paths["changelog"]
texts = finish_texts(args, config)
if isinstance(texts, Failure):
return Failure(f"not finished: {texts.reason}")
ranked, news = texts
@@ -121,14 +127,15 @@ def finish(args: argparse.Namespace, folder: pathlib.Path) -> str | Failure:
if news is not None and (unwritten := plan_file.write(changelog, news)):
return Failure(f"{unwritten.reason}; todo.md no longer holds item {args.id}, so add its bullet by hand")
plan_file.print_report(todo, ranked)
return f"Finished item {args.id}."
return f"Finished item {args.id} in {todo}."
def finish_texts(args: argparse.Namespace, todo: pathlib.Path, changelog: pathlib.Path) -> tuple[ranking.Ranked, str | None] | Failure:
"""What finish writes: todo ranked without item args.id, and changelog's new text, None where finish leaves it as is."""
def finish_texts(args: argparse.Namespace, config: ProjectConfig) -> tuple[ranking.Ranked, str | None] | Failure:
"""What finish writes: the plan ranked without item args.id, and the changelog's new text, None where finish leaves it as is."""
todo, changelog = config.paths["plan"], config.paths["changelog"]
if changelog.exists() and args.changelog is None and not args.no_changelog:
return Failure("CHANGELOG.md exists beside todo.md; pass --changelog <bullet>, or --no-changelog where the repo doesn't publish anything")
texts = plan_file.read_all(todo)
return Failure(f"{changelog} exists; pass --changelog <bullet>, or --no-changelog where the repo doesn't publish anything")
texts = plan_file.read_all(todo, config)
if isinstance(texts, Failure):
return texts
text = finished(texts[0], args.id)
+24 -7
View File
@@ -7,6 +7,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent))
from project_config.main import located
from project_config.test_project_config import configured
from release_plan.test_ranking import DECISIONS, README, TODO
from todo_item import edits, main
@@ -31,7 +32,7 @@ class TodoItem(unittest.TestCase):
temp = tempfile.TemporaryDirectory()
self.addCleanup(temp.cleanup)
self.folder = pathlib.Path(temp.name)
configured(self, self.folder)
self.config = configured(self, self.folder) / "config.toml"
self.todo = self.folder / "todo.md"
self.changelog = self.folder / "CHANGELOG.md"
(self.folder / "README.md").write_text(README)
@@ -52,7 +53,7 @@ class TodoItem(unittest.TestCase):
return raised.exception.code
def assert_ranked(self):
self.assertEqual(plan_file.check_failures(self.todo), [])
self.assertEqual(plan_file.check_failures(self.todo, located(str(self.folder), pathlib.Path.home())), [])
def details(self):
text = self.todo.read_text()
@@ -81,7 +82,7 @@ class BadArguments(TodoItem):
class Add(TodoItem):
def test_takes_next_id_and_raises_it(self):
self.assertEqual(self.run_main(*ADD)[:2], (0, "Filed item 6.\n"))
self.assertEqual(self.run_main(*ADD)[:2], (0, f"Filed item 6 in {self.todo}.\n"))
self.assertIn("`Next ID = 7`", self.todo.read_text())
def test_writes_the_row_with_the_tagline_bold_and_its_pipes_escaped(self):
@@ -151,7 +152,7 @@ class Add(TodoItem):
class Finish(TodoItem):
def test_removes_the_row(self):
self.assertEqual(self.run_main("finish", "3", "--no-changelog"), (0, "Finished item 3.\n", ""))
self.assertEqual(self.run_main("finish", "3", "--no-changelog"), (0, f"Finished item 3 in {self.todo}.\n", ""))
self.assertNotRegex(self.todo.read_text(), r"(?m)^\| 3 \|")
def test_removes_the_detail_and_keeps_the_others(self):
@@ -169,7 +170,7 @@ class Finish(TodoItem):
def test_adds_the_bullet_first_under_unreleased(self):
self.changelog.write_text(CHANGELOG)
self.assertEqual(self.run_main("finish", "3", "--changelog", "Runs are fast."), (0, "Finished item 3.\n", ""))
self.assertEqual(self.run_main("finish", "3", "--changelog", "Runs are fast."), (0, f"Finished item 3 in {self.todo}.\n", ""))
self.assertEqual(self.changelog.read_text(), "# Changelog\n\n## Unreleased\n\n- Runs are fast.\n- Older news.\n\n## 0.1.0\n\n- First.\n")
def test_creates_unreleased_above_the_first_release(self):
@@ -254,12 +255,28 @@ class Show(TodoItem):
def test_prints_the_header_the_row_and_the_detail(self):
row = next(line for line in self.todo.read_text().split("\n") if line.startswith("| 3 |"))
self.assertEqual(self.run_main("show", "3"), (0, f"{self.HEADER}{row}\n\n### 3. Make it fast, `a | b`.\n\nFast detail.\n", ""))
self.assertEqual(self.run_main("show", "3"), (0, f"From {self.todo}:\n\n{self.HEADER}{row}\n\n### 3. Make it fast, `a | b`.\n\nFast detail.\n", ""))
def test_works_on_the_plan_and_the_changelog_where_the_config_puts_them(self):
folder = self.config.parent
self.config.write_text(self.config.read_text().replace('"checkout:todo.md"', '"folder:todo.md"').replace('"checkout:CHANGELOG.md"', '"folder:news/CHANGELOG.md"').replace('"checkout:docs/decisions.md"', '"folder:decisions.md"'))
(folder / "decisions.md").write_text(DECISIONS)
self.todo.rename(folder / "todo.md")
self.todo.write_text("the project owners' own notes\n")
(folder / "news").mkdir()
(folder / "news" / "CHANGELOG.md").write_text("# Changelog\n")
self.assertEqual(self.run_main("show", "3")[1].split("\n")[0], f"From {folder}/todo.md:")
self.assertEqual(self.run_main(*ADD)[:2], (0, f"Filed item 6 in {folder}/todo.md.\n"))
self.assertEqual(self.run_main("finish", "3"), (1, "", f"not finished: {folder}/news/CHANGELOG.md exists; pass --changelog <bullet>, or --no-changelog where the repo doesn't publish anything\n"))
self.assertEqual(self.run_main("finish", "3", "--changelog", "Runs are fast."), (0, f"Finished item 3 in {folder}/todo.md.\n", ""))
self.assertIn("- Runs are fast.", (folder / "news" / "CHANGELOG.md").read_text())
self.assertEqual(self.todo.read_text(), "the project owners' own notes\n")
self.assertFalse(self.changelog.exists())
def test_prints_the_row_alone_where_the_item_has_no_detail(self):
code, out, err = self.run_main("show", "4")
self.assertEqual((code, err), (0, ""))
self.assertEqual(out.split("\n")[2:], ["| 4 | 0.1.0 | | security | **Rotate the leaked key.** | 3 | 3 | 5 | 9 | 2 | 2.1 by 1 | 12.3 |", ""])
self.assertEqual(out.split("\n")[4:], ["| 4 | 0.1.0 | | security | **Rotate the leaked key.** | 3 | 3 | 5 | 9 | 2 | 2.1 by 1 | 12.3 |", ""])
def test_prints_a_detail_with_a_sub_heading_whole_and_no_other_detail(self):
self.todo.write_text(self.todo.read_text().replace("Fast detail.\n", "Fast detail.\n\n### Why\n\nFast tail.\n"))