diff --git a/Dockerfile b/Dockerfile index c76e34c..343f5a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,5 +12,5 @@ COPY bopytex/ /src/bopytex COPY setup.py /src/ RUN pip install -e /src -COPY example /example +COPY example/simple /example WORKDIR /example diff --git a/Dockerfile.mapytex b/Dockerfile.mapytex new file mode 100644 index 0000000..5a5a910 --- /dev/null +++ b/Dockerfile.mapytex @@ -0,0 +1,17 @@ +FROM python:3.11-rc-slim + +RUN apt-get update +RUN apt-get install -y texlive texlive-extra-utils + +RUN apt-get install -y python3-dev +COPY requirements.txt /tmp/ +RUN pip install -r /tmp/requirements.txt +RUN pip install mapytex + +RUN mkdir -p /src/bopytex +COPY bopytex/ /src/bopytex +COPY setup.py /src/ +RUN pip install -e /src + +COPY example/mapytex /example +WORKDIR /example diff --git a/bopytex/worker/compile.py b/bopytex/worker/compile.py index 641122c..5813337 100644 --- a/bopytex/worker/compile.py +++ b/bopytex/worker/compile.py @@ -22,4 +22,4 @@ def curstomtex(command: str, options: str): latexmk = curstomtex("latexmk", "-f") -pdflatex = curstomtex("pdflatex", "--inteactions=nonstopmode") +pdflatex = curstomtex("pdflatex", "--interaction=nonstopmode") diff --git a/bopytex/worker/generate.py b/bopytex/worker/generate.py index b6a9cf3..02a12b0 100644 --- a/bopytex/worker/generate.py +++ b/bopytex/worker/generate.py @@ -9,13 +9,10 @@ def generate(args, deps, output): try: with open(output, "w") as out: - out.write(tpl2tex(template, metas=args)) + fed = template.render(args) + out.write(fed) return Message(0, [f"GENERATE - {deps[0]} to {output}"], []) except Exception as e: - return Message(0, [], [e]) - - -def tpl2tex(template: Template, metas: dict = {}) -> str: - return template.render(metas) + return Message(1, [], [e]) diff --git a/example/mapytex/bopytex_config.py b/example/mapytex/bopytex_config.py new file mode 100644 index 0000000..1fa0584 --- /dev/null +++ b/example/mapytex/bopytex_config.py @@ -0,0 +1,7 @@ +from mapytex import Expression + +from bopytex.jinja2_env.texenv import texenv + +jinja2 = { + "environment": texenv, +} diff --git a/example/mapytex/tpl_example.tex b/example/mapytex/tpl_example.tex new file mode 100644 index 0000000..48b3339 --- /dev/null +++ b/example/mapytex/tpl_example.tex @@ -0,0 +1,17 @@ +% vim:ft=tex: +% +\documentclass[12pt]{article} + +\title{Bopytex with Mapytex example -- \Var{ number }} + +\begin{document} + +\maketitle + +%- set e = Expression.random("{a} + {b}") +\Var{e} + +\Var{e.simplify()} + + +\end{document} diff --git a/example/tpl_example.tex b/example/simple/tpl_example.tex similarity index 100% rename from example/tpl_example.tex rename to example/simple/tpl_example.tex diff --git a/test/worker/test_generate.py b/test/worker/test_generate.py index 015f322..bcdd319 100644 --- a/test/worker/test_generate.py +++ b/test/worker/test_generate.py @@ -1,16 +1,9 @@ import os import jinja2 -from bopytex.worker.generate import generate, tpl2tex +from bopytex.worker.generate import generate import pytest -def test_tpl2tex(): - tpl = "Plop {{a}}" - jinja2_tpl = jinja2.Template(tpl) - fed = tpl2tex(jinja2_tpl, metas={"a": 1}) - assert fed == "Plop 1" - - @pytest.fixture def jinja2_env(tmp_path): templateEnv = jinja2.Environment(loader=jinja2.FileSystemLoader(tmp_path))