Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(cycle-source): video-loop keeps a filled loop's cut with the fill off as cycle.source/, so video-cycle-align aligns it from there without the clip's frames, the same alignment as cutting it again
Soohong Kim0d1a71cb7041
diff --git a/sprite_gen/video/align.py b/sprite_gen/video/align.pyindex 798f441..22e0eae 100644--- a/sprite_gen/video/align.py+++ b/sprite_gen/video/align.py@@ -1000,27 +1000,23 @@ def _loop_files(loop_dir: Path) -> tuple[Path, dict[str, Any]]:return metas[0], meta-CUT_AGAIN_DIR = ".cycle.source.cut" # where a filled loop is cut again with the fill off, removed once staged---def filled(meta: dict[str, Any]) -> bool:- """Whether a cut's held cells were made again (`held_fill.made`, or `made` of the read after its repair)."""- held = meta.get("held_fill") or {}- return bool(held.get("made") or (held.get("again") or {}).get("made"))+CUT_AGAIN_DIR = loop_mod.CUT_AGAIN_DIR # where a filled loop is cut again with the fill off, removed once kept+filled = loop_mod.filled # whether a cut's held cells were made again, as its strip record saysdef unfilled_source(loop_dir: Path, meta_path: Path, meta: dict[str, Any]) -> dict[str, Any] | None:"""The frames an alignment reads are the cut as filmed: a loop never aligned whose held cells `video-loop` made again- (`filled`) is cut again from its frames as its report records it was asked (`loop.cut_again`), with the fill off, and- that cut is kept as `cycle.source/` (its strip and strip record beside its frames) — the alignment makes its frames- between from filmed frames, never from frames made between, and fills what it delivers at the end. What was done- (`cut_again`), or None where nothing was to do: a loop aligned before, one not filled, one whose `cycle.source/`- already holds its cut with the fill off. ValueError naming why it cannot be cut again (a report from before cuts- recorded what they were asked, frames moved away, another cut taken): cut it again with `--fill-held off`."""+ (`filled`) is aligned from its cut with the fill off, kept as `cycle.source/` (its strip and strip record beside its+ frames) — the alignment makes its frames between from filmed frames, never from frames made between, and fills what+ it delivers at the end. `video-loop` keeps that cut there as it cuts the loop (`loop.keep_unfilled`); where it is not+ there, the loop is cut again from its frames as its report records it was asked (`loop.cut_again`), with the fill off,+ and kept so. What was done (`cut_again`), or None where nothing was to do: a loop aligned before, one not filled, one+ whose `cycle.source/` already holds its cut with the fill off. ValueError naming why it cannot be cut again (a report+ from before cuts recorded what they were asked, frames moved away, another cut taken): carry the `cycle.source/`+ video-loop kept beside it, or cut it again with `--fill-held off`."""if "cycle_align" in meta or not filled(meta):return None- source = loop_dir / SOURCE_DIR- staged = source / meta_path.name+ staged = loop_dir / SOURCE_DIR / meta_path.nameif staged.is_file():try:if not filled(json.loads(staged.read_text(encoding="utf-8"))):@@ -1032,26 +1028,7 @@ def unfilled_source(loop_dir: Path, meta_path: Path, meta: dict[str, Any]) -> diraise ValueError("its held cells were made again (held_fill), and no report of its cut is beside it to cut it again ""with the fill off")report_path, report = found- work = loop_dir / CUT_AGAIN_DIR- shutil.rmtree(work, ignore_errors=True)- try:- try:- cut = loop_mod.cut_again(report, work, report_path=work / "cut.loop.report.json", fill_held="off")- except SystemExit as exc:- raise ValueError(f"cutting it again with the fill off failed: {exc}") from None- cut_meta = json.loads((work / meta_path.name).read_text(encoding="utf-8"))- was = meta.get("cycle_drawings") or {}- now = cut_meta.get("cycle_drawings") or {}- if (now.get("start"), now.get("length")) != (was.get("start"), was.get("length")):- raise ValueError(f"cut again with the fill off it took frames {now.get('start')}+{now.get('length')}, not "- f"{was.get('start')}+{was.get('length')}")- shutil.rmtree(source, ignore_errors=True)- (work / "cycle").rename(source)- shutil.copyfile(work / meta_path.name, staged)- strip = meta_path.name[: -len(".strip.json")] + ".strip.png"- shutil.copyfile(work / strip, source / strip)- finally:- shutil.rmtree(work, ignore_errors=True)+ cut = loop_mod.keep_unfilled(report, loop_dir, meta_path.name[: -len(".strip.json")], meta.get("cycle_drawings") or {})return {"report": str(report_path), "fill_held": "off", "cells": cut["strip"]["cycle_frames"],"made_before": (meta.get("held_fill") or {}).get("made", [])}@@ -1368,8 +1345,9 @@ def align_set(loop_dirs: list[Path], *, length: int | None = None, interpolate:clip's every cut as `video-loop` read them, `clip`): `same_foot` warn names such a loop in the warnings, refuse stopsthe set before anything is rewritten (the report written with `applied` false, `refused` same-foot).- The frames aligned are the cut as filmed: a loop whose held cells video-loop made again is cut again with the fill- off first (`unfilled_source`), or the set stops naming it. Each loop delivered is read at the end, its held cells made+ The frames aligned are the cut as filmed: a loop whose held cells video-loop made again is aligned from its cut with+ the fill off, as video-loop kept it in `cycle.source/` or else cut again first (`unfilled_source`), or the set stops+ naming it. Each loop delivered is read at the end, its held cells madebetween the poses beside them as video-loop fills a loop (`held_fill.fill`, `fill_held` auto; off delivers them asresampled), its record (`held_fill`) and kept holds (`holds`) replacing the cut's; and given at `out_fps` where oneis asked (`held_fill.upsample`, every loop the same number of cells)."""@@ -1419,8 +1397,9 @@ def align_set(loop_dirs: list[Path], *, length: int | None = None, interpolate:try:done = unfilled_source(d, meta_path, meta)except ValueError as exc:- raise SystemExit(f"video-cycle-align: {d}: {exc} — cut it again with `video-loop --fill-held off` and align that: "- "the alignment makes its frames between from frames as filmed (docs/loop-repair.md section 7)") from None+ raise SystemExit(f"video-cycle-align: {d}: {exc} — carry the {SOURCE_DIR}/ video-loop kept beside it (its cut with "+ "the fill off), or cut it again with `video-loop --fill-held off` and align that: the alignment "+ "makes its frames between from frames as filmed (docs/loop-repair.md section 7)") from Noneif done is not None:cut_again[i] = donesources = []@@ -1705,7 +1684,8 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:"they are made again as the frames between the poses beside them, as video-loop fills a loop ""(docs/loop-repair.md section 7), its first cell kept; a loop drawn on twos or threes, and a hold ""longer than three cells, are kept; with no RIFE the cells are delivered as resampled with a "- "warning. off: delivered as resampled. A loop whose held cells video-loop made again is cut again "+ "warning. off: delivered as resampled. A loop whose held cells video-loop made again is aligned "+ f"from its cut with the fill off, which video-loop keeps as {SOURCE_DIR}/, or else is cut again ""with the fill off from its report before it is aligned (or the set stops naming it)")parser.add_argument("--out-fps", type=float, metavar="F",help="give every loop of the set at F frames a second, above the loops' own rate, once aligned: each "diff --git a/sprite_gen/video/loop.py b/sprite_gen/video/loop.pyindex 32400f3..995890c 100644--- a/sprite_gen/video/loop.py+++ b/sprite_gen/video/loop.py@@ -154,6 +154,10 @@ SIZE_HOLD_MODES = ("auto", "off")# the kept one stale, so writing the cycle removes it: an alignment after a re-cut (say, once RIFE# is installed and the jumps are repaired) reads the new cut, not the old one.CYCLE_SOURCE_DIR = "cycle.source"+# A loop whose held cells the cut made again is cut again with the fill off, so an alignment aligns the cut as filmed, and+# that cut is kept as `cycle.source/` (`keep_unfilled`): by `video-loop` while the clip's frames are there, or else by+# `video-cycle-align`. The folder beside the loop it is cut in, removed once it is kept.+CUT_AGAIN_DIR = ".cycle.source.cut"# The strip as it was before `video-sway` (the Sway layer; old name `video-follow`) moved a region of it;# a later sway reads from it, and a new cut or alignment removes it (docs/video-pipeline.md section 6).# Its name, and the key the sway's record is written under, stay `follow` in this release: a consumer reads@@ -999,19 +1003,21 @@ def refuse(target: Path, out_dir: Path, name: str, report: dict[str, Any], *, cuwrite_loop_report(target, report)+def _finite(value: Any) -> Any:+ """`value` as the report holds it: a ratio that is not finite (a zero-motion one) as None."""+ if isinstance(value, float) and not math.isfinite(value):+ return None+ if isinstance(value, dict):+ return {key: _finite(item) for key, item in value.items()}+ if isinstance(value, (list, tuple)):+ return [_finite(item) for item in value]+ return value++def write_loop_report(target: Path, payload: dict[str, Any]) -> None:"""Strict JSON, including refusals with undefined (zero-motion) ratios."""- def finite(value: Any) -> Any:- if isinstance(value, float) and not math.isfinite(value):- return None- if isinstance(value, dict):- return {key: finite(item) for key, item in value.items()}- if isinstance(value, (list, tuple)):- return [finite(item) for item in value]- return value-target.parent.mkdir(parents=True, exist_ok=True)- atomic_write_text(target, json.dumps(finite(payload), ensure_ascii=False, indent=2, allow_nan=False) + "\n")+ atomic_write_text(target, json.dumps(_finite(payload), ensure_ascii=False, indent=2, allow_nan=False) + "\n")def resampled_cells(strip: Image.Image, meta: dict[str, Any], idx: list[int], length: int) -> list[Image.Image]:@@ -2434,6 +2440,65 @@ def cut_again(report: dict[str, Any], out_dir: Path, *, report_path: Path, **askcontacts=list(contacts) if contacts else None, **kw)+def filled(meta: dict[str, Any]) -> bool:+ """Whether a cut's held cells were made again (`held_fill.made`, or `made` of the read after its repair), as its strip+ record (`<name>.strip.json`) says."""+ held = meta.get("held_fill") or {}+ return bool(held.get("made") or (held.get("again") or {}).get("made"))+++def keep_unfilled(report: dict[str, Any], out_dir: Path, name: str, cut: dict[str, Any], **asked: Any) -> dict[str, Any]:+ """The cut `report` records made again from its frames with the fill off (`cut_again`, `asked` passed on), kept beside+ the loop in `out_dir` as `cycle.source/` — its frames, its strip and its strip record (`<name>.strip.json`), the cut+ as filmed that `video-cycle-align` aligns. `cut` is the loop's cut (its strip record's `cycle_drawings`), whose frames+ of the clip the cut again must take too. What the cut again returned; ValueError naming why it could not be+ (`cut_again`'s, a cut again that failed or took other frames), `cycle.source/` then left as it was."""+ work = out_dir / CUT_AGAIN_DIR+ shutil.rmtree(work, ignore_errors=True)+ try:+ try:+ again = cut_again(report, work, report_path=work / "cut.loop.report.json", fill_held="off", **asked)+ except SystemExit as exc:+ raise ValueError(f"cutting it again with the fill off failed: {exc}") from None+ record = f"{name}.strip.json"+ now = json.loads((work / record).read_text(encoding="utf-8")).get("cycle_drawings") or {}+ if (now.get("start"), now.get("length")) != (cut.get("start"), cut.get("length")):+ raise ValueError(f"cut again with the fill off it took frames {now.get('start')}+{now.get('length')}, not "+ f"{cut.get('start')}+{cut.get('length')}")+ # The strip and its record go beside its frames first, so `cycle.source/` appears whole or not at all.+ kept = work / "cycle"+ shutil.copyfile(work / record, kept / record)+ shutil.copyfile(work / f"{name}.strip.png", kept / f"{name}.strip.png")+ source = out_dir / CYCLE_SOURCE_DIR+ shutil.rmtree(source, ignore_errors=True)+ kept.rename(source)+ finally:+ shutil.rmtree(work, ignore_errors=True)+ return again+++def _keep_unfilled_here(report_base: dict[str, Any], frames_dir: Path, out_dir: Path, name: str,+ strip_meta: dict[str, Any], interpolate: rife_mod.Interpolate | None) -> dict[str, Any]:+ """A loop whose held cells this cut made again, cut again with the fill off while the clip's frames are here and kept+ as `cycle.source/` (`keep_unfilled`, from what this cut was asked as its report records it): an alignment of it then+ aligns the cut as filmed without the clip's frames. Its record (the report's `cycle_source`): kept, with the cells of+ the cut with the fill off and the cells made before; or not kept and why, said in a warning."""+ print(f"video-loop: {name}: its held cells were made again, so it is cut again with the fill off and that cut is kept "+ f"as {CYCLE_SOURCE_DIR}/ for video-cycle-align; the lines below until it is kept are that cut's", file=sys.stderr)+ # What the cut was asked, as its report holds it (`write_loop_report`): what an alignment reads to cut it again.+ asked = json.loads(json.dumps(_finite({"cut_args": report_base["cut_args"], "frames_dir": str(frames_dir)})))+ try:+ again = keep_unfilled(asked, out_dir, name, strip_meta["cycle_drawings"], interpolate=interpolate)+ except ValueError as exc:+ print(f"video-loop: warning: {name}: its held cells were made again and no cut with the fill off is kept beside it "+ f"({exc}): video-cycle-align cuts it again from the clip's frames, or stops on it without them "+ "(docs/loop-repair.md section 7)", file=sys.stderr)+ return {"kept": False, "why": str(exc)}+ print(f"video-loop: {name}: the cut with the fill off is kept as {CYCLE_SOURCE_DIR}/", file=sys.stderr)+ return {"kept": True, "dir": CYCLE_SOURCE_DIR, "fill_held": "off", "cells": again["strip"]["cycle_frames"],+ "made_before": strip_meta["held_fill"]["made"]}++def run_loop(frames_dir: Path, out_dir: Path, **options: Any) -> dict[str, Any]:"""Cut the loop (`_cut_loop`, which takes the options). The frames a size hold or the gait fallback scales backare written in folders of the run's own (`_Scratch`), removed however the run ends."""@@ -3445,6 +3510,10 @@ def _cut_loop(# The GIF or WebP could not be written (no img2webp) or failed its verification: nothing of the cut is handed over.refuse(target, out_dir, name, {**report_base, "status": "failed", "error": str(exc), "cycle": cycle}, cut_written=True)raise+ # A loop whose held cells were made again: the cut as filmed an alignment aligns, kept beside it while the clip's+ # frames are here (docs/loop-repair.md section 7). A cut at --out-fps is not aligned, nor one played once.+ if ring and out_fps is None and filled(strip_meta):+ report_base["cycle_source"] = _keep_unfilled_here(report_base, frames_dir, out_dir, name, strip_meta, interpolate)payload = {**report_base,@@ -3558,7 +3627,9 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:f"{held_fill_mod.HOLD_MAX} cells, the opening or closing pose of a cut played once, a loop's last ""cells and a cut drawn on twos or threes kept as filmed; off cuts them as filmed. Either way the report and the strip metadata record ""the held runs and the poses over the cells (`held_fill`, docs/loop-repair.md section 7); with no "- "RIFE installed the cells are shown as filmed, with a warning")+ "RIFE installed the cells are shown as filmed, with a warning. A loop at the clip's rate whose "+ f"cells auto made again is cut again with the fill off and that cut is kept as {CYCLE_SOURCE_DIR}/ "+ "for video-cycle-align, which then needs no clip's frames (the report's `cycle_source`)")parser.add_argument("--out-fps", type=float, default=None,help="give the cut at this rate, above the clip's (--fps): every cell at its own time, made by RIFE ""between the frames beside it — never a frame shown again. A loop keeps its cycle's seconds, a "@@ -3682,6 +3753,8 @@ def run(**kwargs: object) -> int:"held_runs": held["held_runs"], "made": held["made"],**({"unmade": held["unmade"]["cells"]} if "unmade" in held else {}),**({"out_fps": {k: held["out_fps"][k] for k in ("asked", "applied", "cells")}} if "out_fps" in held else {})}+ if "cycle_source" in payload:+ summary["cycle_source"] = payload["cycle_source"]if "root_motion" in payload:# Each air of a cut played once, as a person is told it: its seconds and its apex.summary["air"] = root_motion_mod.said(payload["root_motion"])diff --git a/tests/video/test_ghost_given_way.py b/tests/video/test_ghost_given_way.pyindex 2c9d59e..d45ead3 100644--- a/tests/video/test_ghost_given_way.py+++ b/tests/video/test_ghost_given_way.py@@ -392,13 +392,15 @@ def test_the_applications_walk_gives_a_small_filmed_ghost_way(tmp_path):# The binary's calls on the application's walk, by model (`rife.model_name()`): rife-v4.25's frame between held cells 32-# to 34 shows a neighbour's picture again, so it is refused (`held`), tried at another time and kept as filmed.-APP_RUNS = {"rife-v4.25": (10, 12), "rife-v4.6": 12}+# to 34 shows a neighbour's picture again, so it is refused (`held`), tried at another time and kept as filmed. Cells 13+# and 14 are made, so the walk is cut again with the fill off and kept as cycle.source/ (4.2.0), and that cut asks for+# the filmed ghost's frame between frames 0 and 2 again: two calls more than 4.1.0's on either model.+APP_RUNS = {"rife-v4.25": (12, 14), "rife-v4.6": 14}@pytest.mark.slow@pytest.mark.real_rife[email protected](900) # 8 to 10 calls of the binary at 280 x 221 (the held fill's frames between and the jump repair's): seconds on a GPU, minutes on a CPU's Vulkan driver[email protected](900) # 12 to 14 calls of the binary at 280 x 221 (the held fill's frames between, the jump repair's, and the jump repair's of the cut with the fill off): seconds on a GPU, minutes on a CPU's Vulkan driverdef test_real_rife_the_applications_walk_gives_a_small_filmed_ghost_way(tmp_path, rife_runs):"""B1b through the real RIFE, located as `video-loop` locates it."""report = _app_cut(tmp_path, None)diff --git a/tests/video/test_loop_prop_seam_held.py b/tests/video/test_loop_prop_seam_held.pyindex 1146733..dbc84b6 100644--- a/tests/video/test_loop_prop_seam_held.py+++ b/tests/video/test_loop_prop_seam_held.py@@ -453,10 +453,11 @@ def test_cycle_align_writes_a_loop_without_a_held_part_as_before(tmp_path, stafffor d in dirs:meta = json.loads((d / "loop.strip.json").read_text())assert set(meta) == STRIP_KEYS_2350 | SOURCE_KEYS_2390 | CLIP_FEET_KEYS | HELD_FILL_KEYS_3800 | NO_REPEAT_KEYS_400- # 4.0.0: a cut whose cells were made again after its repair (its read again) is cut again with the fill off- # before it is aligned, and the alignment says so (docs/loop-repair.md section 7).- again = {"cut_again"} if align.filled(cut) else set()- assert set(meta["cycle_align"]) == CYCLE_ALIGN_KEYS_2350 | CORRESPONDENCE_KEYS_2410 | GHOST_KEYS_2430 | BEAT_KEYS | again+ # 4.0.0: a cut whose cells were made again after its repair (its read again) is aligned from its cut with the fill+ # off; 4.2.0: video-loop keeps that cut beside it (`cycle_source`), so the alignment cuts nothing again and writes+ # no `cut_again` (docs/loop-repair.md section 7).+ assert not align.filled(cut) or report["cycle_source"]["kept"]+ assert set(meta["cycle_align"]) == CYCLE_ALIGN_KEYS_2350 | CORRESPONDENCE_KEYS_2410 | GHOST_KEYS_2430 | BEAT_KEYS# The cut's source stays as the cut wrote it: `cycle_align` says the cells were turned after it, so it# no longer names each cell's frame (docs/loop-comparison.md). The rebuilt strip names its own cells —# the same frames, turned, under the same crop.diff --git a/tests/video/test_no_repeat_default.py b/tests/video/test_no_repeat_default.pyindex f1ec37f..5921df6 100644--- a/tests/video/test_no_repeat_default.py+++ b/tests/video/test_no_repeat_default.py@@ -11,6 +11,7 @@ The interpolator is `Between`, a stand-in that draws the synthetic clip again atfrom __future__ import annotationsimport json+import shutilfrom pathlib import Pathimport pytest@@ -148,9 +149,15 @@ def test_an_aligned_set_whose_cuts_hold_a_picture_twice_delivers_none_shown_agaiassert any("held_fill" in c for c in meta["cycle_align"]["cells_from"])+def _cut_before_it_kept_its_source(d: Path) -> Path:+ """A filled loop as a video-loop from before it kept the cut with the fill off left it: no `cycle.source/`."""+ shutil.rmtree(d / align.SOURCE_DIR)+ return d++def test_the_alignment_cuts_a_filled_loop_again_with_the_fill_off_and_aligns_the_frames_as_filmed(tmp_path):clip = _held_clip()- dirs = [_cut(tmp_path, n, c, length=N + 1, interpolate=_between()) for n, c in (("A", clip), ("B", clip))]+ dirs = [_cut_before_it_kept_its_source(_cut(tmp_path, n, c, length=N + 1, interpolate=_between())) for n, c in (("A", clip), ("B", clip))]assert all(_meta(d)["held_fill"]["made"] == [6] for d in dirs) # video-loop on its own fills, a loop deliveredreport = align.align_set(dirs, interpolate=_between())for d, row in zip(dirs, report["loops"]):@@ -166,16 +173,91 @@ def test_the_alignment_cuts_a_filled_loop_again_with_the_fill_off_and_aligns_thedef test_a_filled_loop_whose_cut_cannot_be_made_again_stops_the_set_naming_it(tmp_path):clip = _held_clip()- dirs = [_cut(tmp_path, n, c, length=N + 1, interpolate=_between()) for n, c in (("A", clip), ("B", clip))]+ dirs = [_cut_before_it_kept_its_source(_cut(tmp_path, n, c, length=N + 1, interpolate=_between())) for n, c in (("A", clip), ("B", clip))]report_path = dirs[1] / "walk.loop.report.json"report = json.loads(report_path.read_text())report.pop("cut_args") # a report from before cuts recorded what they were askedreport_path.write_text(json.dumps(report))- with pytest.raises(SystemExit, match=r"no cut_args.*video-loop --fill-held off"):+ with pytest.raises(SystemExit, match=r"no cut_args.*carry the cycle.source/ video-loop kept.*video-loop --fill-held off"):align.align_set(dirs, interpolate=_between())assert not (dirs[1] / align.SOURCE_DIR / "walk.strip.json").exists()+def _aligned_files(d: Path) -> dict[str, bytes]:+ """What an alignment rewrote in a loop directory, and the cut it aligned (`cycle.source/`), byte for byte."""+ return {str(p.relative_to(d)): p.read_bytes() for p in sorted(d.rglob("*"))+ if p.is_file() and (p.parent.name in ("cycle", align.SOURCE_DIR) or p.suffix in (".png", ".gif", ".webp"))}+++def _aligned_meta(d: Path) -> dict:+ """The aligned strip's record, but for what the alignment itself cut again (`cut_again`, which names its report)."""+ meta = _meta(d)+ meta["cycle_align"].pop("cut_again", None)+ return meta+++def test_a_set_with_a_filled_direction_is_aligned_without_the_clip_s_frames_as_it_is_with_them(tmp_path):+ # An app that aligns a set elsewhere than it cut it holds each loop as video-loop left it, and none of its clip's+ # frames. Before, a set with a direction whose held cells video-loop made stopped there ("cut it again with+ # `video-loop --fill-held off`"): only the clip's frames could give the cut with the fill off.+ clip = _held_clip()+ cut = [_cut(tmp_path, "A", clip, length=N + 1, interpolate=_between()),+ _cut(tmp_path, "B", clip, length=N + 1, fill_held="off")]+ assert _meta(cut[0])["held_fill"]["made"] == [6] and _meta(cut[1])["held_fill"]["made"] == []+ # With the clip's frames and nothing kept beside the filled loop, the alignment cuts it again with the fill off.+ framed = [Path(shutil.copytree(d, tmp_path / "framed" / d.name)) for d in cut]+ shutil.rmtree(framed[0] / align.SOURCE_DIR, ignore_errors=True)+ by_cut = align.align_set(framed, interpolate=_between())+ assert by_cut["loops"][0]["cut_again"]["made_before"] == [6]+ # Without them: the loops as video-loop left them.+ held = [Path(shutil.copytree(d, tmp_path / "app" / d.name)) for d in cut]+ for name in ("A", "B"):+ shutil.rmtree(tmp_path / f"{name}-keyed")+ kept = align.align_set(held, interpolate=_between())+ assert all("cut_again" not in row for row in kept["loops"])+ for a, b in zip(framed, held):+ assert _aligned_files(a) == _aligned_files(b) and _aligned_meta(a) == _aligned_meta(b)+ assert (kept["length"], kept["lengths"]) == (by_cut["length"], by_cut["lengths"])+ assert all(_shown_again(_cells(d)) == [] for d in held)+++def test_video_loop_keeps_a_filled_loop_s_cut_with_the_fill_off_beside_it_and_an_unfilled_one_s_as_it_was(tmp_path):+ clip = _held_clip()+ filled = _cut(tmp_path, "A", clip, length=N + 1, interpolate=_between())+ unfilled = _cut(tmp_path, "B", walk(N + 6), length=N, interpolate=_between()) # no picture shown again: nothing made+ # The filled loop's cut with the fill off, as the alignment cut it from the clip's frames: frame 5 shown twice.+ report = json.loads((filled / "walk.loop.report.json").read_text())+ again = loop_mod.cut_again(report, tmp_path / "again", report_path=tmp_path / "again.json", fill_held="off")+ source = filled / align.SOURCE_DIR+ assert report["cycle_source"] == {"kept": True, "dir": align.SOURCE_DIR, "fill_held": "off",+ "cells": again["strip"]["cycle_frames"], "made_before": [6]}+ assert sorted(p.name for p in source.iterdir()) == [*(f"frame-{k:03d}.png" for k in range(N + 1)), "walk.strip.json", "walk.strip.png"]+ for name in [*(f"frame-{k:03d}.png" for k in range(N + 1))]:+ assert (source / name).read_bytes() == (tmp_path / "again" / "cycle" / name).read_bytes()+ for name in ("walk.strip.json", "walk.strip.png"):+ assert (source / name).read_bytes() == (tmp_path / "again" / name).read_bytes()+ assert not align.filled(json.loads((source / "walk.strip.json").read_text()))+ assert not (filled / loop_mod.CUT_AGAIN_DIR).exists()+ # The delivered loop is the filled one; a loop with nothing made, and one cut with the fill off, keep nothing.+ assert _shown_again(_cells(filled)) == []+ off = _cut(tmp_path, "C", clip, length=N + 1, fill_held="off")+ for d in (unfilled, off):+ assert not (d / align.SOURCE_DIR).exists() and "cycle_source" not in json.loads((d / "walk.loop.report.json").read_text())+++def test_a_filled_loop_whose_cut_with_the_fill_off_fails_is_delivered_and_says_why_nothing_is_kept(monkeypatch, tmp_path, capsys):+ def refused(report, out_dir, **asked):+ raise SystemExit("video-loop: refused for the test")++ monkeypatch.setattr(loop_mod, "cut_again", refused)+ d = _cut(tmp_path, "A", _held_clip(), length=N + 1, interpolate=_between())+ report = json.loads((d / "walk.loop.report.json").read_text())+ assert report["status"] == loop_mod.REPORT_PASSED and _meta(d)["held_fill"]["made"] == [6]+ assert report["cycle_source"] == {"kept": False, "why": "cutting it again with the fill off failed: video-loop: refused for the test"}+ assert not (d / align.SOURCE_DIR).exists() and not (d / loop_mod.CUT_AGAIN_DIR).exists()+ assert "no cut with the fill off is kept beside it" in capsys.readouterr().err++def test_an_aligned_set_asked_for_at_a_rate_of_its_own_is_given_frames_between_every_loop_alike(tmp_path):clip = walk(N + 6)dirs = [_cut(tmp_path, n, c, length=N, fill_held="off") for n, c in (("A", clip), ("B", clip))]