From ac8fe3dfdd9bf64fa3464bd6d4802556f9ccb32a Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sun, 10 Apr 2022 16:27:12 +0200 Subject: [PATCH] Feat: latexmk worker to compile tex --- bopytex/worker/compile.py | 12 ++++++++++++ test/worker/test_compile.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 bopytex/worker/compile.py create mode 100644 test/worker/test_compile.py diff --git a/bopytex/worker/compile.py b/bopytex/worker/compile.py new file mode 100644 index 0000000..24a9531 --- /dev/null +++ b/bopytex/worker/compile.py @@ -0,0 +1,12 @@ +import subprocess + + +def latexmk(args: dict, deps, output): + compile_process = subprocess.Popen( + ["latexmk", deps[0]], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True + ) + yield from compile_process.stderr + diff --git a/test/worker/test_compile.py b/test/worker/test_compile.py new file mode 100644 index 0000000..7e1c96e --- /dev/null +++ b/test/worker/test_compile.py @@ -0,0 +1,35 @@ +import os + +from pathlib import Path +from bopytex.worker.compile import latexmk +import pytest + + +@pytest.fixture +def tex_path(tmp_path): + source = tmp_path / "source.tex" + with open(source, "w") as src: + src.write( + """ +\\documentclass{article} + +\\begin{document} +First document. This is a simple example, with no +extra parameters or packages included. +\\end{document} + """ + ) + return source + + +def test_compile(tex_path): + tmp_path = tex_path.parent + os.chdir(tmp_path) + + texfile = str(tex_path.name) + output = "source.pdf" + + for err in latexmk({}, [texfile], "source.pdf"): + assert 0 + + assert Path(output).exists