diff --git a/bopytex/actions.py b/bopytex/actions.py new file mode 100644 index 0000000..89805a4 --- /dev/null +++ b/bopytex/actions.py @@ -0,0 +1,27 @@ +def generate(): + pass + + +def compile(): + pass + + +def activate_corr(): + pass + + +def join_pdf(): + pass + + +def clean(): + pass + + +ACTIONS = { + "GENERATE": generate, + "COMPILE": compile, + "ACTIVATE_CORR": activate_corr, + "JOIN_PDF": join_pdf, + "clean": clean, +} diff --git a/bopytex/planner.py b/bopytex/planner.py new file mode 100644 index 0000000..0818129 --- /dev/null +++ b/bopytex/planner.py @@ -0,0 +1,63 @@ +""" Produce tasks to do + +It essentially place things at the right place and define the way that files are named. + +""" +from dataclasses import dataclass + + +@dataclass +class Task: + action: str + args: dict + deps: list + output: str + + +def generate(template: str, meta: dict): + """Create a task to generate a subject""" + return Task( + action="GENERATE", + args=meta, + deps=[template], + output=meta["subject"] + template[3:], + ) + + +def activate_corr_on(src: str): + """Create a task to activate correction for src""" + return Task( + action="ACTIVATE_CORR", + args={}, + deps=[src], + output="corr_" + src, + ) + + +def compile_pdf(src: str): + """Create a task to compile src""" + return Task( + action="COMPILE", + args={}, + deps=[src], + output=src[:-3] + "pdf" + ) + +def join_pdfs(pdfs: list): + """ Create task to join pdf together """ + return Task( + action="JOIN", + args={}, + deps=pdfs, + output="joined.pdf" + ) + + +def clean(files: list): + """ Create task to clean files""" + return Task( + action="CLEAN", + args={}, + deps=files, + output=None + ) diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_planner.py b/test/test_planner.py new file mode 100644 index 0000000..77b491c --- /dev/null +++ b/test/test_planner.py @@ -0,0 +1,46 @@ +from bopytex.planner import activate_corr_on, clean, compile_pdf, generate, join_pdfs + + +def test_build_task_generate(): + template = "tpl_source.tex" + task = generate(template, {"subject": "01"}) + assert task.action == "GENERATE" + assert task.args == {"subject": "01"} + assert task.deps == [template] + assert task.output == "01_source.tex" + + +def test_build_task_activate_corr_on(): + src = "source.tex" + task = activate_corr_on(src) + assert task.action == "ACTIVATE_CORR" + assert task.args == {} + assert task.deps == [src] + assert task.output == "corr_source.tex" + + +def test_build_task_compile(): + src = "source.tex" + task = compile_pdf(src) + assert task.action == "COMPILE" + assert task.args == {} + assert task.deps == [src] + assert task.output == "source.pdf" + + +def test_build_task_join(): + pdfs = [f"{i}_source.pdf" for i in range(3)] + task = join_pdfs(pdfs) + assert task.action == "JOIN" + assert task.args == {} + assert task.deps == pdfs + assert task.output == "joined.pdf" + + +def test_build_task_compile(): + files = ["source.aux", "source.log"] + task = clean(files) + assert task.action == "CLEAN" + assert task.args == {} + assert task.deps == files + assert task.output is None