mecfs_bio.figures.orphan_pruning
Remove figure-manifest entries that no figure task produces, deleting their local files along the way.
This module backs the "I removed a figure task and want the figure system
to catch up" flow. We never prune a path that is still referenced from
documentation --- that would silently break the docs build. Instead,
prune_orphan_figures collects the conflicts and raises, leaving the
manifest and figure directory untouched until the user resolves them
(either by restoring the task to ALL_FIGURE_TASKS or by removing the
doc references).
Classes:
-
OrphanReferencedInDocsError–Raised when an orphan manifest path is still referenced by documentation.
Functions:
-
find_doc_references–Return every
.mdfile underdocs_dirwhose contents mention -
prune_orphan_figures–Drop manifest entries that no task in
figure_tasksproduces, and
Attributes:
-
logger–
OrphanReferencedInDocsError
Bases: ValueError
Raised when an orphan manifest path is still referenced by documentation.
find_doc_references
Return every .md file under docs_dir whose contents mention
rel_path as a substring.
Only .md files are scanned: .mdx files in this repo are
figure tables, not documentation pages, and are included from inside
.md files.
The figure paths in the manifest are relative to the figure directory
(docs/_figs). Every reference style in the repo ---
plotly_embed("docs/_figs/<rel_path>"),
include_file("docs/_figs/<rel_path>"),
, and
<iframe src="..._figs/<rel_path>"> --- contains the rel_path
verbatim (POSIX form), so a substring search is reliable.
Source code in mecfs_bio/figures/orphan_pruning.py
prune_orphan_figures
prune_orphan_figures(
manifest_path: Path,
docs_dir: Path,
fig_dir: Path,
figure_tasks: Sequence[Task],
) -> None
Drop manifest entries that no task in figure_tasks produces, and
delete the corresponding files under fig_dir.
The orphan check considers both manifest keys and files actually
present under fig_dir --- leftover files from a removed task may
not be in the committed manifest yet, but push_figures would
pick them up via its directory scan and the manifest-vs-task-list
validation would then fail.
For each orphan, docs_dir is scanned for references. If any orphan
is still referenced the function raises OrphanReferencedInDocsError
without mutating disk; the error distinguishes orphans whose local
file is also missing, since those require restoring the task before
the figure can be re-pulled.