Files
Vijay Janapa Reddi cc0644c53d Keep book checks and HTML resources out of build output
- Concept-map and image-format checks skip _build, .quarto, and
  per-chapter _files trees, so stale local render output no longer
  fails the hooks; shared helper plus a regression test.
- Anchor HTML resource globs to the project root. Unanchored globs also
  matched earlier volumes' _build output, copying it into each new
  build (Vol I HTML reached 1.1 GB; Vol III drops from 283 MB to 60 MB).
2026-09-12 10:59:55 +02:00

26 lines
896 B
Python

"""Recognize generated trees that source checks must never scan.
A local render leaves build output and caches inside ``books/``: HTML and PDF
output under ``_build/``, Quarto caches under ``.quarto/``, and per-chapter
figure directories named ``<chapter>_files/``. Those trees hold stale copies
of sources and assets, so a check that walks them reports defects that do not
exist in the tracked content.
"""
from __future__ import annotations
from pathlib import Path
GENERATED_DIRS = frozenset(
{".quarto", "_build", "__pycache__", ".venv", "venv", "node_modules"}
)
def is_generated(path: Path, root: Path) -> bool:
"""True when *path* lies inside a generated tree below *root*."""
try:
parts = path.relative_to(root).parts[:-1]
except ValueError:
parts = path.parts[:-1]
return any(part in GENERATED_DIRS or part.endswith("_files") for part in parts)