Various HTML improvements

This commit is contained in:
sebastien committed 2026-11-03 10:02:10 +01:00
1 parent fd943696fb
commit 8c1fa0af57
16 files changed
+403 -45

No files matched your search

+14 -1
View File
@@ -38,6 +38,7 @@ def build_parser() -> argparse.ArgumentParser:
"directories, matching folders by their trailing copy ID"
),
)
parser.add_argument("--incremental", action="store_true", help="Skip unchanged return folders")
return parser
@@ -147,6 +148,7 @@ def update_named_return_answers(
def prepare_named_returns(
workspace: EvaluationWorkspace,
annotation_dir_name: str,
*, incremental: bool = False,
) -> ExitCode:
workspace.require_directories("Copies", annotation_dir_name)
workspace.return_dir.mkdir(parents=True, exist_ok=True)
@@ -198,6 +200,12 @@ def prepare_named_returns(
assigned_names.add(name)
destination = existing_returns.get(int(copy_id), workspace.return_dir / f"{safe_name} ({copy_id})")
output_name = destination.name.rsplit(" (", 1)[0]
from copienator.reviewed_cache import ReturnCache
cache = ReturnCache(workspace.root, source_folder, destination) if incremental else None
if cache and cache.unchanged():
print(f"Skipping unchanged return {destination.name}")
continue
copy_failed = False
destination.mkdir(parents=True, exist_ok=True)
try:
publish_answer_returns(workspace.root, source_folder, destination)
@@ -238,6 +246,9 @@ def prepare_named_returns(
file=sys.stderr,
)
had_errors = True
copy_failed = True
if cache and not copy_failed:
cache.remember()
unassigned = expected_names - assigned_names
if unassigned:
@@ -253,10 +264,11 @@ def run(
*,
annotation_dir: str,
update: bool = False,
incremental: bool = False,
) -> ExitCode:
if update:
return update_named_return_answers(workspace, annotation_dir)
return prepare_named_returns(workspace, annotation_dir)
return prepare_named_returns(workspace, annotation_dir, incremental=incremental)
def main(argv: Sequence[str] | None = None) -> int:
@@ -268,6 +280,7 @@ def main(argv: Sequence[str] | None = None) -> int:
workspace_from_args(args, repository=Path.cwd()),
annotation_dir=args.annotation_dir,
update=args.update,
incremental=args.incremental,
),
)
+10 -3
View File
@@ -25,16 +25,22 @@ from copienator.annotation_modifications import (
from copienator.filesystem import publish_file_sets
def run(workspace: EvaluationWorkspace, *, annotation_dir: str = "BGnot") -> ExitCode:
def run(workspace: EvaluationWorkspace, *, annotation_dir: str = "BGnot", incremental: bool = False) -> ExitCode:
workspace.require_files("labels", DRAFT)
workspace.require_directories("Copies", annotation_dir)
text = (workspace.root / DRAFT).read_text(encoding="utf-8")
instructions = read_instructions(text, annotation_dir)
validate_instructions(workspace.root, annotation_dir, instructions)
directory = workspace.root / annotation_dir
applied = directory / APPLIED
previous = read_instructions(applied.read_text(encoding="utf-8"), annotation_dir) if applied.exists() else []
if incremental and previous == instructions:
print("Skipping unchanged transfer instructions")
return ExitCode.SUCCESS
validate_instructions(workspace.root, annotation_dir, instructions)
copy_ids = sorted({item.copy_id for item in [*previous, *instructions]})
if incremental:
copy_ids = [cid for cid in copy_ids
if [i for i in previous if i.copy_id == cid] != [i for i in instructions if i.copy_id == cid]]
# Prepare every copy before publishing anything, including the applied file.
with TemporaryDirectory(prefix=".annotation-edits-", dir=directory) as temporary:
staging_root = Path(temporary)
@@ -61,12 +67,13 @@ def run(workspace: EvaluationWorkspace, *, annotation_dir: str = "BGnot") -> Exi
def build_parser():
parser = evaluation_parser("Modify reviewed answer bodies using annotation_modifications.txt")
parser.add_argument("--annotation-dir", choices=MODES, default="BGnot")
parser.add_argument("--incremental", action="store_true", help="Skip unchanged transfer instructions")
return parser
def main(argv: Sequence[str] | None = None) -> int:
return execute(build_parser(), argv, lambda args: run(
workspace_from_args(args), annotation_dir=args.annotation_dir))
workspace_from_args(args), annotation_dir=args.annotation_dir, incremental=args.incremental))
if __name__ == "__main__":
+16 -2
View File
@@ -5,9 +5,19 @@ from copienator.commands.reading_annotations import apply_actions_and_regenerate
from copienator.commands.reading_grouped_annotations import apply_actions_and_regenerate_grouped
def run(workspace: EvaluationWorkspace, mode: str):
def run(workspace: EvaluationWorkspace, mode: str, *, incremental: bool = False):
directories = sorted((p for p in (workspace.root / mode).glob('Copie*')
if p.is_dir() and p.name[5:].isdigit() and (p / 'score.json').is_file()))
from copienator.reviewed_cache import ReviewedReadCache
cache = ReviewedReadCache(workspace, mode, directories) if incremental else None
if cache:
pending = []
for directory in directories:
if cache.unchanged(directory.name[5:]):
print(f"Skipping unchanged {directory.name}", flush=True)
else:
pending.append(directory)
directories = pending
# Validate every snapshot before starting to publish any copy.
for directory in directories:
if not (directory / FILENAME).is_file():
@@ -29,10 +39,14 @@ def run(workspace: EvaluationWorkspace, mode: str):
print(log, flush=True)
if result != ExitCode.SUCCESS:
status = ExitCode.PARTIAL
elif cache:
# Rendering can normalize the saved snapshot; fingerprint the published inputs.
ReviewedReadCache(workspace, mode, [directory]).remember([cid])
return status
def main(argv=None):
parser = evaluation_parser('Regenerate from saved reviewed inputs without rescanning handwriting')
parser.add_argument('--annotation-dir', choices=('Bnot', 'BGnot'), required=True)
return execute(parser, argv, lambda args: run(workspace_from_args(args), args.annotation_dir))
parser.add_argument("--incremental", action="store_true", help="Skip unchanged copies")
return execute(parser, argv, lambda args: run(workspace_from_args(args), args.annotation_dir, incremental=args.incremental))