Feat: Organize script to work in CLI

This commit is contained in:
Bertrand Benjamin 2022-05-04 18:00:54 +02:00
parent 9d7f779f07
commit d9bd4ca5a1
5 changed files with 34 additions and 24 deletions

View File

@ -9,8 +9,7 @@ def bopytex(**options):
config["jinja2"]["environment"] = DEFAULT.jinja2_env config["jinja2"]["environment"] = DEFAULT.jinja2_env
orcherstre = orcherstrator( orcherstre = orcherstrator(
options, planner=DEFAULT.planner, dispatcher=DEFAULT.dispatcher config, planner=DEFAULT.planner, dispatcher=DEFAULT.dispatcher
) )
for message in orcherstre: for message in orcherstre:
print(message) yield message
assert message.status == 0

View File

@ -5,7 +5,7 @@
import click import click
import logging import logging
from bopytex.service import bopytex from bopytex.bopytex import bopytex
formatter = logging.Formatter("%(name)s :: %(levelname)s :: %(message)s") formatter = logging.Formatter("%(name)s :: %(levelname)s :: %(message)s")
steam_handler = logging.StreamHandler() steam_handler = logging.StreamHandler()
@ -21,7 +21,6 @@ logger.addHandler(steam_handler)
"template", "template",
type=click.Path(exists=True), type=click.Path(exists=True),
nargs=1, nargs=1,
# help="File with the template. The name should have the following form tpl_... .",
) )
@click.option( @click.option(
"-w", "-w",
@ -36,13 +35,6 @@ logger.addHandler(steam_handler)
default="", default="",
help="CSV containing list of students names", help="CSV containing list of students names",
) )
@click.option(
"-d",
"--dirty",
is_flag=True,
default=False,
help="Do not clean after compilation",
)
@click.option( @click.option(
"-n", "-n",
"--no-compile", "--no-compile",
@ -50,6 +42,13 @@ logger.addHandler(steam_handler)
default=False, default=False,
help="Do not compile source code", help="Do not compile source code",
) )
@click.option(
"-d",
"--dirty",
is_flag=True,
default=False,
help="Do not clean after compilation",
)
@click.option( @click.option(
"-q", "-q",
"--quantity_subjects", "--quantity_subjects",
@ -78,15 +77,15 @@ logger.addHandler(steam_handler)
default=False, default=False,
help="Create and compile correction while making subjects", help="Create and compile correction while making subjects",
) )
@click.option(
"-C",
"--crazy",
is_flag=True,
default=False,
help="Crazy mode. Tries and tries again until template feeding success!",
)
def new(**options): def new(**options):
bopytex(**options) for message in bopytex(**options):
try:
assert message.status == 0
except AssertionError:
logger.warning(message)
break
else:
logger.info(message.out)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -6,11 +6,10 @@ from ..message import SubprocessMessage
def latexmk(args: dict, deps, output): def latexmk(args: dict, deps, output):
compile_process = subprocess.Popen( compile_process = subprocess.Popen(
["latexmk", deps[0]], ["latexmk", "-f", deps[0]],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True universal_newlines=True
) )
#return SubprocessMessage(compile_process)
return Message(compile_process.wait(), list(compile_process.stdout), list(compile_process.stderr)) return Message(compile_process.wait(), list(compile_process.stdout), list(compile_process.stderr))

12
example/tpl_example.tex Normal file
View File

@ -0,0 +1,12 @@
% vim:ft=tex:
%
\documentclass[12pt]{article}
\title{Bopytex example -- {{ number }}}
\begin{document}
\maketitle
\end{document}

View File

@ -16,7 +16,7 @@ def template_path(tmp_path):
\\begin{document} \\begin{document}
First document. First document.
Subject {{ subject }} Subject {{ number }}
\\end{document} \\end{document}
""" """
) )
@ -43,7 +43,8 @@ def test_with_default_planner(template_path, jinja2_env, tmp_path):
}, },
} }
bopytex(**options) for message in bopytex(**options):
pass
assert Path("joined_source.pdf").exists() assert Path("joined_source.pdf").exists()