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
orcherstre = orcherstrator(
options, planner=DEFAULT.planner, dispatcher=DEFAULT.dispatcher
config, planner=DEFAULT.planner, dispatcher=DEFAULT.dispatcher
)
for message in orcherstre:
print(message)
assert message.status == 0
yield message

View File

@ -5,7 +5,7 @@
import click
import logging
from bopytex.service import bopytex
from bopytex.bopytex import bopytex
formatter = logging.Formatter("%(name)s :: %(levelname)s :: %(message)s")
steam_handler = logging.StreamHandler()
@ -21,7 +21,6 @@ logger.addHandler(steam_handler)
"template",
type=click.Path(exists=True),
nargs=1,
# help="File with the template. The name should have the following form tpl_... .",
)
@click.option(
"-w",
@ -36,13 +35,6 @@ logger.addHandler(steam_handler)
default="",
help="CSV containing list of students names",
)
@click.option(
"-d",
"--dirty",
is_flag=True,
default=False,
help="Do not clean after compilation",
)
@click.option(
"-n",
"--no-compile",
@ -50,6 +42,13 @@ logger.addHandler(steam_handler)
default=False,
help="Do not compile source code",
)
@click.option(
"-d",
"--dirty",
is_flag=True,
default=False,
help="Do not clean after compilation",
)
@click.option(
"-q",
"--quantity_subjects",
@ -78,15 +77,15 @@ logger.addHandler(steam_handler)
default=False,
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):
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__":

View File

@ -6,11 +6,10 @@ from ..message import SubprocessMessage
def latexmk(args: dict, deps, output):
compile_process = subprocess.Popen(
["latexmk", deps[0]],
["latexmk", "-f", deps[0]],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)
#return SubprocessMessage(compile_process)
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}
First document.
Subject {{ subject }}
Subject {{ number }}
\\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()