Script: build.py

Komorebi Methodology

build.py

Download original file

This is the original source text. Reading it does not run or verify the program.

Read the typeset paper

Skip source text

1 """Rebuild the essay from sources. Requires Python 3.10+, matplotlib, numpy, and TeX Live.
2 
3 The exact-check script uses the Python standard library only.
4 No Lean installation is used or claimed by this build.
5 """
6 from __future__ import annotations
7 import shutil
8 import subprocess
9 import sys
10 from pathlib import Path
11 
12 ROOT = Path(__file__).resolve().parent
13 
14 
15 def run(args: list[str], log: Path | None = None) -> None:
16     if log is None:
17         subprocess.run(args, cwd=ROOT, check=True)
18     else:
19         with log.open('w', encoding='utf-8') as f:
20             subprocess.run(args, cwd=ROOT, check=True, stdout=f, stderr=subprocess.STDOUT)
21 
22 
23 def main() -> int:
24     if shutil.which('pdflatex') is None:
25         print('Missing pdflatex. Install TeX Live or MiKTeX with the packages listed in README.md.', file=sys.stderr)
26         return 2
27     (ROOT/'audit').mkdir(exist_ok=True)
28     try:
29         run([sys.executable, 'exact_checks.py'])
30         run([sys.executable, 'integrity_checks.py'])
31         run([sys.executable, 'figures.py'])
32         for i in range(1, 4):
33             run(['pdflatex', '-interaction=nonstopmode', '-halt-on-error', 'Komorebi_Methodology.tex'], ROOT/'audit'/f'build_pass_{i}.log')
34     except subprocess.CalledProcessError as exc:
35         print(f'Build failed in {exc.cmd}. Exit code: {exc.returncode}. See audit logs where available.', file=sys.stderr)
36         return exc.returncode or 1
37     log = (ROOT/'audit'/'build_pass_3.log').read_text(errors='replace')
38     issues = [line for line in log.splitlines() if any(key in line for key in ('Overfull', 'Underfull', 'LaTeX Warning:', 'Missing character:'))]
39     if issues:
40         print('PDF built, but typesetting review is required:\n'+'\n'.join(issues), file=sys.stderr)
41         return 1
42     print('Built Komorebi_Methodology.pdf; exact checks and final typesetting log passed.')
43     print('Render and visually review the PDF after any editorial changes.')
44     return 0
45 
46 if __name__ == '__main__':
47     raise SystemExit(main())

Back to source controls

Other PDFs for this work

Original file and source record

This copy matches the recorded source file. Its publication here does not change the work’s review status.

SHA-256: d295a07d7c80f5d96e887fe540dcf7832ef1cfe1c6c4e1d8fd044640e10efe46

Original source on GitHub

Back to Komorebi Methodology