Source code for itasc.core.commit
"""The final-output commit contract.
The numbered stage dirs (``2_nucleus/``, ``3_cell/``) hold re-runnable *working*
label files; :func:`promote_labels` copies one up to a stable *committed* name in
the position base folder (``nucleus_labels.tif`` / ``cell_labels.tif``), the
downstream-stable output that discovery defaults to. :func:`commit_state` reports
where a position sits in that working-vs-committed split — the signal the
workflow widgets surface and the catalog status rail reads.
"""
from __future__ import annotations
import shutil
from pathlib import Path
import numpy as np
import tifffile
CommitState = str # one of: "missing" | "uncommitted" | "committed" | "stale"
[docs]
def commit_state(working: Path | str, committed: Path | str) -> CommitState:
"""Return the working-vs-committed state for one stage output.
* ``"missing"`` — no working file yet.
* ``"uncommitted"`` — working file exists but has not been committed.
* ``"committed"`` — committed copy is at least as new as the working file.
* ``"stale"`` — the working file was re-run after the last commit (strictly
newer), so the committed copy no longer reflects it.
"""
working = Path(working)
committed = Path(committed)
if not working.is_file():
return "missing"
if not committed.is_file():
return "uncommitted"
if working.stat().st_mtime > committed.stat().st_mtime:
return "stale"
return "committed"