Feat: activate solution worker

This commit is contained in:
Bertrand Benjamin 2022-07-19 18:09:17 +02:00
parent 177128afe2
commit 37d779c0ab
7 changed files with 32 additions and 9 deletions

View File

@ -1,6 +1,6 @@
#import jinja2 as j2
from bopytex.planner.generate_compile_join_planner import planner from bopytex.planner.generate_compile_join_planner import planner
from bopytex.worker import Dispatcher from bopytex.worker import Dispatcher
from bopytex.worker.activate_corr import activate_corr
from bopytex.worker.clean import clean from bopytex.worker.clean import clean
from bopytex.worker.compile import pdflatex from bopytex.worker.compile import pdflatex
from bopytex.worker.generate import generate from bopytex.worker.generate import generate
@ -8,12 +8,19 @@ from bopytex.worker.join_pdf import pdfjam
from bopytex.jinja2_env.texenv import texenv from bopytex.jinja2_env.texenv import texenv
jinja2 = { jinja2 = {
# "environment": j2.Environment(loader=j2.FileSystemLoader("./")),
"environment": texenv "environment": texenv
} }
dispatcher = Dispatcher( dispatcher = Dispatcher({
{"GENERATE": generate, "COMPILE": pdflatex, "JOIN": pdfjam, "CLEAN": clean} "GENERATE": generate,
) "COMPILE": pdflatex,
"JOIN": pdfjam,
"CLEAN": clean,
"ACTIVATE_CORR": activate_corr,
})
latex = {
"solution": r"solution/print = true",
"no_solution": r"solution/print = false",
}

View File

@ -1,4 +1,4 @@
from bopytex.tasks import Task, activate_corr_on, compile_pdf, generate, join_pdfs from bopytex.tasks import Task, activate_corr_on, compile_pdf, join_pdfs
import bopytex.planner.naming as naming import bopytex.planner.naming as naming
import os import os

View File

@ -80,7 +80,7 @@ def tasks_builder(
if corr: if corr:
corr_source = naming.corr(source) corr_source = naming.corr(source)
tasks.append(activate_corr_on(source, corr_source)) tasks.append(activate_corr_on(source, opt, corr_source))
if not no_pdf: if not no_pdf:
corr_pdf = naming.source2pdf(corr_source) corr_pdf = naming.source2pdf(corr_source)

View File

@ -24,11 +24,11 @@ def generate(template: str, meta: dict, output: str):
) )
def activate_corr_on(src: str, output: str): def activate_corr_on(src: str, meta:dict, output: str):
"""Create a task to activate correction for src""" """Create a task to activate correction for src"""
return Task( return Task(
action="ACTIVATE_CORR", action="ACTIVATE_CORR",
args={}, args=meta,
deps=[src], deps=[src],
output=output, output=output,
) )

View File

@ -0,0 +1,14 @@
from bopytex.message import Message
def activate_corr(args, deps, output):
no_solution = args["latex"]["no_solution"]
solution = args["latex"]["solution"]
with open(deps[0], "r") as input_f:
with open(output, "w") as output_f:
for line in input_f.readlines():
output_f.write(line.replace(no_solution, solution))
return Message(0, [f"ACTIVATE CORR - {deps[0]} to {output}"], [])

Binary file not shown.

View File

@ -4,6 +4,8 @@
\title{Bopytex with Mapytex example -- \Var{ number }} \title{Bopytex with Mapytex example -- \Var{ number }}
% solution/print = false
\begin{document} \begin{document}
\maketitle \maketitle