Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
build_manual.py
Go to the documentation of this file.
1"""Build in an isolated directory so historical auxiliary files cannot interfere."""
2from pathlib import Path
3import argparse, shutil, subprocess, tempfile
4p=Path(__file__).resolve().parents[1]
5a=argparse.ArgumentParser();a.add_argument('--publish',action='store_true',help='copy successful PDF to manual_beta');args=a.parse_args()
6b=Path(tempfile.mkdtemp(prefix='modelib-manual-'))
7shutil.copy2(p/'MoDELib_manual.tex',b)
8shutil.copy2(p/'manual_cited.bib',b)
9for d in ['tex','figures']:shutil.copytree(p/d,b/d)
10log=b/'build-output.txt'
11with log.open('w') as f:
12 result=subprocess.run(['latexmk','-pdf','-interaction=nonstopmode','-halt-on-error','MoDELib_manual.tex'],cwd=b,stdout=f,stderr=subprocess.STDOUT)
13print('Build directory:',b)
14print('Build log:',log)
15if result.returncode:raise SystemExit(result.returncode)
16if args.publish:shutil.copy2(b/'MoDELib_manual.pdf',p/'MoDELib_manual.pdf')
17print('PDF:',p/'MoDELib_manual.pdf' if args.publish else b/'MoDELib_manual.pdf')