refact: planners accept only options in parameters

This commit is contained in:
2022-04-09 22:29:58 +02:00
parent 8c9d7bf9a2
commit dfcc48dd20
2 changed files with 65 additions and 24 deletions

View File

@@ -1,6 +1,10 @@
from bopytex.tasks import Task, activate_corr_on, compile_pdf, generate, join_pdfs
class PlannerMissingOption(Exception):
pass
def naming_template2source(template: str, metadatas: dict):
return metadatas["number"] + template[3:]
@@ -18,12 +22,25 @@ def naming_join(template):
def default_planner(
template: str,
subjects: list[dict],
corr: bool = False,
no_join: bool = False,
no_pdf: bool = False,
options: dict,
) -> list[Task]:
opt = {
"corr": False,
"no_join": False,
"no_pdf": False,
}
opt.update(options)
try:
template = opt["template"]
subjects = opt["subjects"]
corr = opt["corr"]
no_join = opt["no_join"]
no_pdf = opt["no_pdf"]
except KeyError:
raise PlannerMissingOption("An option is missing")
tasks = []
pdfs = []
@@ -61,10 +78,21 @@ def default_planner(
def only_corr_planner(
sources=[],
no_pdf: bool = False,
no_join: bool = False,
options: dict,
) -> list[Task]:
opt = {
"no_join": False,
"no_pdf": False,
}
opt.update(options)
try:
sources = opt["sources"]
no_join = opt["no_join"]
no_pdf = opt["no_pdf"]
except KeyError:
raise PlannerMissingOption("An option is missing")
tasks = []
corr_pdfs = []