Delete tools/build_report.py
Browse files- tools/build_report.py +0 -92
tools/build_report.py
DELETED
|
@@ -1,92 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Build the self-contained English report, without executing the EDA notebook."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import argparse
|
| 7 |
-
import json
|
| 8 |
-
import re
|
| 9 |
-
import shutil
|
| 10 |
-
import subprocess
|
| 11 |
-
import tempfile
|
| 12 |
-
from pathlib import Path
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def check_assets(docs: Path) -> None:
|
| 16 |
-
"""Fail before TeX if a referenced archived figure or diagram is absent."""
|
| 17 |
-
text = (docs / "DRMHB.tex").read_text(encoding="utf-8")
|
| 18 |
-
paths = [docs / "anndata_workflow.tex", docs / "figures/skeleton.png"]
|
| 19 |
-
for slug in re.findall(r"\\edaplot\{[^}]+\}\{([^}]+)\}", text):
|
| 20 |
-
base = docs / "figures/eda" / slug
|
| 21 |
-
if not any(base.with_suffix(ext).is_file() for ext in (".pdf", ".png")):
|
| 22 |
-
raise FileNotFoundError(f"EDA figure not found: {base}")
|
| 23 |
-
sources = text + (docs / "anndata_workflow.tex").read_text(encoding="utf-8")
|
| 24 |
-
paths += [docs / item for item in re.findall(r"\\input\{([^}]+)\}", sources)]
|
| 25 |
-
for path in paths:
|
| 26 |
-
if not path.is_file():
|
| 27 |
-
raise FileNotFoundError(path)
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
def main() -> None:
|
| 31 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 32 |
-
parser.add_argument("--output", type=Path, help="Default: docs/DRMHB.pdf")
|
| 33 |
-
parser.add_argument(
|
| 34 |
-
"--build-dir", type=Path, help="Keep TeX logs/auxiliary files here"
|
| 35 |
-
)
|
| 36 |
-
args = parser.parse_args()
|
| 37 |
-
root = Path(__file__).resolve().parents[1]
|
| 38 |
-
docs = root / "docs"
|
| 39 |
-
output = (args.output or docs / "DRMHB.pdf").resolve()
|
| 40 |
-
if output.suffix.lower() != ".pdf":
|
| 41 |
-
parser.error("--output must be a PDF path")
|
| 42 |
-
if not shutil.which("latexmk") or not shutil.which("pdflatex"):
|
| 43 |
-
raise SystemExit(
|
| 44 |
-
"Install latexmk and a TeX distribution including TikZ and the packages in docs/DRMHB.tex"
|
| 45 |
-
)
|
| 46 |
-
check_assets(docs)
|
| 47 |
-
with tempfile.TemporaryDirectory(prefix="drmhb-report-") as temp:
|
| 48 |
-
build = args.build_dir.resolve() if args.build_dir else Path(temp)
|
| 49 |
-
build.mkdir(parents=True, exist_ok=True)
|
| 50 |
-
command = [
|
| 51 |
-
"latexmk",
|
| 52 |
-
"-pdf",
|
| 53 |
-
"-interaction=nonstopmode",
|
| 54 |
-
"-halt-on-error",
|
| 55 |
-
"-file-line-error",
|
| 56 |
-
f"-outdir={build}",
|
| 57 |
-
"DRMHB.tex",
|
| 58 |
-
]
|
| 59 |
-
run = subprocess.run(
|
| 60 |
-
command,
|
| 61 |
-
cwd=docs,
|
| 62 |
-
text=True,
|
| 63 |
-
stdout=subprocess.PIPE,
|
| 64 |
-
stderr=subprocess.STDOUT,
|
| 65 |
-
check=False,
|
| 66 |
-
)
|
| 67 |
-
(build / "build.log").write_text(run.stdout, encoding="utf-8")
|
| 68 |
-
print(run.stdout[-4000:])
|
| 69 |
-
if run.returncode:
|
| 70 |
-
raise SystemExit(f"LaTeX failed ({run.returncode}); log directory: {build}")
|
| 71 |
-
log = (build / "DRMHB.log").read_text(encoding="utf-8", errors="replace")
|
| 72 |
-
summary = {
|
| 73 |
-
"engine": "pdflatex",
|
| 74 |
-
"eda_executed": False,
|
| 75 |
-
"overfull_boxes": re.findall(r"Overfull[^\n]+", log),
|
| 76 |
-
"unresolved_references": "There were undefined references" in log,
|
| 77 |
-
"source": "docs/DRMHB.tex",
|
| 78 |
-
}
|
| 79 |
-
(build / "build_summary.json").write_text(json.dumps(summary, indent=2) + "\n")
|
| 80 |
-
if summary["overfull_boxes"] or summary["unresolved_references"]:
|
| 81 |
-
raise SystemExit(
|
| 82 |
-
f"Layout/reference errors remain; see {build / 'build_summary.json'}"
|
| 83 |
-
)
|
| 84 |
-
output.parent.mkdir(parents=True, exist_ok=True)
|
| 85 |
-
staged = output.with_name(output.name + ".tmp")
|
| 86 |
-
shutil.copy2(build / "DRMHB.pdf", staged)
|
| 87 |
-
staged.replace(output)
|
| 88 |
-
print(f"Report: {output} ({output.stat().st_size:,} bytes)")
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
if __name__ == "__main__":
|
| 92 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|