Skip to content

Commit

Permalink
CI: Copy latexusage.pdf to build root for TeX Live support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamievlin committed Aug 25, 2024
1 parent 55b30d7 commit 637926b
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions doc/build-latexusage-pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import pathlib
import sys
import shutil
import subprocess as sp


Expand All @@ -20,29 +21,50 @@ def parse_args():


def print_called_process_error(e: sp.CalledProcessError):
sys.stderr.write("Process stderr:\n")
sys.stderr.write(e.stderr)
sys.stderr.write("Process output:\n")
sys.stderr.write(e.stdout)
if e.stderr is not None:
sys.stderr.write("Process stderr:\n")
sys.stderr.write(e.stderr)

if e.stdout is not None:
sys.stderr.write("Process output:\n")
sys.stderr.write(e.stdout)
sys.stderr.flush()


def clean_artifacts(buildroot_path: pathlib.Path, latexusage_file_prefix: str):
if (buildroot_path / (latexusage_file_prefix + ".tex")).is_file():
os.remove((buildroot_path / (latexusage_file_prefix + ".tex")))
for asyartifacts in buildroot_path.glob("latexusage-*"):
os.remove(asyartifacts)
for exts in ["pre", "aux", "out"]:
with contextlib.suppress(FileNotFoundError):
os.remove(buildroot_path / (latexusage_file_prefix + "." + exts))


def run_pdflatex(
pdflatex_exec: str, buildroot_path: pathlib.Path, latexusage_name: str
):
sp.run(
[pdflatex_exec, latexusage_name + ".tex"],
text=True,
cwd=buildroot_path,
check=True,
)


def main():
args = parse_args()
buildroot_path = pathlib.Path(args.build_dir)
clean_artifacts(buildroot_path, args.latexusage_name)
pdflatex_base_args = [
args.pdflatex_executable,
f"-output-directory={str(buildroot_path)}",
]

# copy latexusage.pdf to build root, since TeX Live has some issues with
# out of source builds

shutil.copy2(
pathlib.Path(args.latexusage_source_dir) / (args.latexusage_name + ".tex"),
buildroot_path / (args.latexusage_name + ".tex"),
)

asy_base_dir = pathlib.Path(args.asy_base_dir)
asy_base_args = [
args.asy_executable,
Expand All @@ -57,14 +79,9 @@ def main():
str(buildroot_path) + os.path.sep,
]

latexusage_src_file = pathlib.Path(args.latexusage_source_dir) / (
args.latexusage_name + ".tex"
)

try:
# first pdflatex run
sp.run(pdflatex_base_args + [str(latexusage_src_file)], check=True, text=True)

run_pdflatex(args.pdflatex_executable, buildroot_path, args.latexusage_name)
# asy run
for asyfile in buildroot_path.glob("latexusage-*.asy"):
sp.run(
Expand All @@ -75,7 +92,7 @@ def main():
)

# second pdflatex run
sp.run(pdflatex_base_args + [str(latexusage_src_file)], check=True, text=True)
run_pdflatex(args.pdflatex_executable, buildroot_path, args.latexusage_name)
except sp.CalledProcessError as e:
print_called_process_error(e)
raise
Expand Down

0 comments on commit 637926b

Please sign in to comment.