From 7f40b7c38f315555659b00b4143e12b647d82d41 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sat, 9 Apr 2022 15:42:00 +0200 Subject: [PATCH] feat: only_corr_planner --- bopytex/planner.py | 25 ++++++++++++++++++-- test/test_planner.py | 54 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/bopytex/planner.py b/bopytex/planner.py index 1d54f0e..0d38a78 100644 --- a/bopytex/planner.py +++ b/bopytex/planner.py @@ -62,6 +62,27 @@ def planner( def only_corr_planner( + sources=[], + no_pdf: bool = False, no_join: bool = False, - ): - pass +) -> list[Task]: + tasks = [] + corr_pdfs = [] + + for source in sources: + corr_source = naming_corr(source) + tasks.append(activate_corr_on(source, corr_source)) + + if not no_pdf: + corr_pdf = naming_source2pdf(corr_source) + tasks.append(compile_pdf(corr_source, corr_pdf)) + corr_pdfs.append(corr_pdf) + + if not no_join: + joined = "joined.pdf" + + if corr_pdfs: + corr_joined = naming_corr(joined) + tasks.append(join_pdfs(corr_pdfs, corr_joined)) + + return tasks diff --git a/test/test_planner.py b/test/test_planner.py index 0aaded4..9582726 100644 --- a/test/test_planner.py +++ b/test/test_planner.py @@ -1,4 +1,4 @@ -from bopytex.planner import planner +from bopytex.planner import only_corr_planner, planner from bopytex.tasks import Task @@ -23,6 +23,7 @@ def test_planner_generate(): ), ] + def test_planner_generate_compile(): tasks = planner( template="tpl_source.tex", @@ -56,6 +57,7 @@ def test_planner_generate_compile(): ), ] + def test_planner_generate_compile_join(): tasks = planner( template="tpl_source.tex", @@ -90,16 +92,17 @@ def test_planner_generate_compile_join(): action="JOIN", args={}, deps=["01_source.pdf", "02_source.pdf"], - output="joined_source.pdf" - ) + output="joined_source.pdf", + ), ] + def test_planner_generate_compile_corr(): tasks = planner( template="tpl_source.tex", subjects=[{"number": "01"}, {"number": "02"}], corr=1, - no_join=1 + no_join=1, ) assert tasks == [ Task( @@ -152,6 +155,7 @@ def test_planner_generate_compile_corr(): ), ] + def test_planner_generate_compile_corr_joined(): tasks = planner( template="tpl_source.tex", @@ -211,13 +215,49 @@ def test_planner_generate_compile_corr_joined(): action="JOIN", args={}, deps=["01_source.pdf", "02_source.pdf"], - output="joined_source.pdf" + output="joined_source.pdf", ), Task( action="JOIN", args={}, deps=["corr_01_source.pdf", "corr_02_source.pdf"], - output="corr_joined_source.pdf" - ) + output="corr_joined_source.pdf", + ), ] +def test_only_corr_planner(): + tasks = only_corr_planner( + sources = ["01_source.tex", "02_source.tex"], + ) + assert tasks == [ + Task( + action="ACTIVATE_CORR", + args={}, + deps=["01_source.tex"], + output="corr_01_source.tex", + ), + Task( + action="COMPILE", + args={}, + deps=["corr_01_source.tex"], + output="corr_01_source.pdf", + ), + Task( + action="ACTIVATE_CORR", + args={}, + deps=["02_source.tex"], + output="corr_02_source.tex", + ), + Task( + action="COMPILE", + args={}, + deps=["corr_02_source.tex"], + output="corr_02_source.pdf", + ), + Task( + action="JOIN", + args={}, + deps=["corr_01_source.pdf", "corr_02_source.pdf"], + output="corr_joined.pdf", + ), + ]