From 86425526b6d90f21e19ad4320275bfda39b4cf38 Mon Sep 17 00:00:00 2001 From: Mark Veltzer Date: Sun, 9 Feb 2025 06:10:29 +0200 Subject: [PATCH] got ridd of pdflatex wrapper --- Makefile | 4 +- requirements.txt | 39 ++++---- scripts/wrapper_pdflatex.py | 183 ------------------------------------ 3 files changed, 22 insertions(+), 204 deletions(-) delete mode 100755 scripts/wrapper_pdflatex.py diff --git a/Makefile b/Makefile index 6c503ee..67d6302 100644 --- a/Makefile +++ b/Makefile @@ -90,10 +90,10 @@ debug: ############ # patterns # ############ -$(TEX_PDF): docs/%.pdf: src/tex/%.tex $(SK_TEX) scripts/wrapper_pdflatex.py scripts/wrapper_lacheck.py $(TEX_INC) +$(TEX_PDF): docs/%.pdf: src/tex/%.tex $(SK_TEX) scripts/wrapper_lacheck.py $(TEX_INC) $(info doing [$@]) $(Q)scripts/wrapper_lacheck.py $< - $(Q)scripts/wrapper_pdflatex.py $< $@ + $(Q)pymakehelper wrapper_pdflatex --input_file $< --output_file $@ $(SK_TEX): out/%.tex: %.sk scripts/wrapper_sketch.py $(info doing [$@]) $(Q)mkdir -p $(dir $@) diff --git a/requirements.txt b/requirements.txt index 93fda1a..70a6be9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,40 +1,40 @@ alabaster==1.0.0 -astroid==3.3.5 -attrs==24.2.0 -babel==2.16.0 +astroid==3.3.8 +attrs==25.1.0 +babel==2.17.0 BitVector==3.5.0 -certifi==2024.8.30 -charset-normalizer==3.4.0 +certifi==2025.1.31 +charset-normalizer==3.4.1 dill==0.3.9 docutils==0.21.2 -gitdb==4.0.11 -GitPython==3.1.43 +gitdb==4.0.12 +GitPython==3.1.44 idna==3.10 imagesize==1.4.1 -isort==5.13.2 -Jinja2==3.1.4 +isort==6.0.0 +Jinja2==3.1.5 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 logging_tree==1.10 -Mako==1.3.8 +Mako==1.3.9 MarkupSafe==3.0.2 mccabe==0.7.0 -numpy==2.1.3 +numpy==2.2.2 packaging==24.2 platformdirs==4.3.6 -pyclassifiers==0.0.14 -pydmt==0.3.18 +pyclassifiers==0.0.15 +pydmt==0.3.19 pyfakeuse==0.0.9 -Pygments==2.18.0 -pylint==3.3.2 +Pygments==2.19.1 +pylint==3.3.4 pylogconf==0.0.38 -pymakehelper==0.0.31 +pymakehelper==0.0.33 pytconf==0.1.18 PyYAML==6.0.2 -referencing==0.35.1 +referencing==0.36.2 requests==2.32.3 rpds-py==0.22.3 -smmap==5.0.1 +smmap==5.0.2 snowballstemmer==2.2.0 Sphinx==8.1.3 sphinxcontrib-applehelp==2.0.0 @@ -46,6 +46,7 @@ sphinxcontrib-serializinghtml==2.0.0 termcolor==2.5.0 tomlkit==0.13.2 tqdm==4.67.1 -urllib3==2.2.3 +typing_extensions==4.12.2 +urllib3==2.3.0 venv-run==0.2.0 yattag==1.16.1 diff --git a/scripts/wrapper_pdflatex.py b/scripts/wrapper_pdflatex.py deleted file mode 100755 index f819c15..0000000 --- a/scripts/wrapper_pdflatex.py +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env python - -""" -This is a script that runs pdflatex for us. -Why do we need this script ? -- to remove the output before we run pdflatex so that we will be sure that we start clean. -if pdflatex finds a file it will * reprocess * it and we dont want that, do we ? -- we need to run pdflatex twice to create indexes and more. -- pdf latex is way too verbose - we want to remove that output and only show it if there is -an error. -- in case we fail we want to make sure we remove the output. - -Maybe more reasons will follow... - -Take note of the argument we pass to pdflatex: -- -interaction=nonstopmode - this means that latex will not stop and enter interactive -mode to ask the user what to do about an error (what is this behaviour anyway ?!?). -- -halt-on-error - this means that latex will stop on error. -- -output-directory - this tells pdflatex where the output folder is. - -This python script is a rewrite of a similar script in perl. -""" - -import sys -import os -import os.path -import subprocess - - -def printout(filename: str, debug: bool): - """ - print to stdout a file content - this function is adjusted for the ugly output that pdflatex produces and so it - only prints the lines between lines starting with "!" (including the actual lines - starting with "!"). Apparently this is how pdflatex shows errors. Ugrrr... - """ - if debug: - print(f"printing [{filename}]", file=sys.stderr) - with open(filename, encoding="utf8") as stream: - inerr = False - for line in stream: - if inerr: - print(line, file=sys.stderr) - inerr = False - else: - if line.startswith("!"): - print(line, file=sys.stderr) - inerr = True - - -def unlink_check(filename: str, check: bool, doit: bool, debug: bool): - """ - this is a function that removes a file and can optionally die if there is a problem - """ - if doit: - if debug: - print(f"unlinking [{filename}]", file=sys.stderr) - if check: - os.unlink(filename) - else: - try: - os.unlink(filename) - except IOError: - pass - - -def chmod_check(filename:str, check: bool, debug: bool): - """ - this is a function that chmods a file and can optionally die if there is a problem - """ - if debug: - print(f"chmodding [{filename}]", file=sys.stderr) - if check: - os.chmod(filename, 0o444) - else: - try: - os.chmod(filename, 0o444) - except IOError: - pass - - -def my_call(args, debug: bool): - """ subprocess.check_call in my own style """ - if debug: - print(f"my_call args are [{args}]", file=sys.stderr) - if debug: - res = subprocess.check_call( - args, - ) - else: - res = subprocess.check_call( - args, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - ) - if debug: - print(f"my_call res is [{res}]", file=sys.stderr) - return res - - -def my_rename(old_filename: str, new_filename: str, check: bool, debug: bool): - """ - this is a function that renames a file and dies if there is a proble - """ - if debug: - print(f"my_rename [{old_filename, new_filename}]", file=sys.stderr) - if check: - os.rename(old_filename, new_filename) - else: - try: - os.rename(old_filename, new_filename) - except IOError: - pass - - -def main(): - """ main entry point """ - # do you want debugging... - debug = False - # remove the tmp file for output at the end of the run? (this should be yes - # unless you want junk files hanging around in /tmp...) - remove_tmp = True - # how many times to run pdflatex(1) ? - runs = 2 - # do you want to run the qpdf(1) post processing stage? - qpdf = True - - filename_input = sys.argv[1] - filename_output = sys.argv[2] - output_dir = os.path.dirname(filename_output) - output_base = os.path.splitext(filename_output)[0] - - args = [ - "pdflatex", - # "--shell-escape" - "-interaction=nonstopmode", - "-halt-on-error", - "-output-directory", - output_dir, - filename_input, - ] - if debug: - print(f"input is [{filename_input}]") - print(f"output is [{filename_output}") - print(f"cmd is [{args}") - # first remove the output (if it exists) - unlink_check( - filename_output, - True, - os.path.isfile(filename_output), - debug, - ) - # we need to run the command twice!!! (to generate the index and more) - for _ in range(runs): - my_call(args, debug) - unlink_check(output_base+".log", True, True, debug) - unlink_check(output_base+".out", False, True, debug) - unlink_check(output_base+".toc", False, True, debug) - unlink_check(output_base+".aux", True, True, debug) - unlink_check(output_base+".nav", False, True, debug) - unlink_check(output_base+".snm", False, True, debug) - unlink_check(output_base+".vrb", False, True, debug) - - if qpdf: - # move the output to the new place - tmp_output = filename_output+".tmp" - my_rename(filename_output, tmp_output, True, debug) - # I also had "--force-version=1.5" but it is not needed since I use pdflatex - # and pdftex with the right version there... - args = [ - "qpdf", - "--deterministic-id", - "--linearize", - tmp_output, - filename_output, - ] - my_call(args, debug) - if remove_tmp: - unlink_check(tmp_output, True, True, debug) - - -if __name__ == "__main__": - main()