Feat: service work but do nothing!
This commit is contained in:
parent
abd517b339
commit
3f1464f3f6
9
bopytex/planner/fake_planner.py
Normal file
9
bopytex/planner/fake_planner.py
Normal file
@ -0,0 +1,9 @@
|
||||
from bopytex.tasks import Task
|
||||
|
||||
|
||||
def simple(options: dict) -> list[Task]:
|
||||
"""Simple planner with options['quantity'] tasks and no dependencies"""
|
||||
return [
|
||||
Task("Do", args={"number": i}, deps=[], output=f"{i}")
|
||||
for i in range(options["quantity"])
|
||||
]
|
@ -5,75 +5,22 @@
|
||||
Producing then compiling templates
|
||||
"""
|
||||
|
||||
import csv
|
||||
import os
|
||||
from bopytex.actions import ACTIONS
|
||||
|
||||
from bopytex.planner import only_corr_planner, default_planner
|
||||
from bopytex.scheduler import Scheduler
|
||||
|
||||
|
||||
def build_subject_list_from_infos(infos: list[dict]) -> list[dict]:
|
||||
subjects = []
|
||||
digit = len(str(len(infos)))
|
||||
for i, infos in enumerate(infos):
|
||||
subjects.append({"number": str(i + 1).zfill(digit), **infos})
|
||||
return subjects
|
||||
|
||||
|
||||
def build_subject_list_from_qty(qty: int) -> list[dict]:
|
||||
subjects = []
|
||||
digit = len(str(qty))
|
||||
for i in range(qty):
|
||||
subjects.append({"number": str(i + 1).zfill(digit)})
|
||||
return subjects
|
||||
|
||||
|
||||
def build_subjects(students_csv, quantity_subjects):
|
||||
if students_csv:
|
||||
with open(students_csv, "r") as csv_file:
|
||||
infos = csv.DictReader(csv_file)
|
||||
return build_subject_list_from_infos(infos)
|
||||
|
||||
return build_subject_list_from_qty(quantity_subjects)
|
||||
|
||||
|
||||
def list_files(dir=".", accept=lambda _: True, reject=lambda _: False):
|
||||
tex_files = []
|
||||
for file in os.listdir(dir):
|
||||
if accept(file) and not reject(file):
|
||||
tex_files.append(file)
|
||||
return tex_files
|
||||
|
||||
|
||||
def bopytex(
|
||||
template: str,
|
||||
students_csv: str,
|
||||
quantity_subjects: int,
|
||||
corr: bool,
|
||||
only_corr: bool,
|
||||
no_join: bool,
|
||||
no_pdf: bool,
|
||||
def orcherstrator(
|
||||
options: dict,
|
||||
planner,
|
||||
actions: dict = ACTIONS,
|
||||
):
|
||||
tasks = planner(options)
|
||||
|
||||
if only_corr:
|
||||
tex_files = list_files(
|
||||
accept=lambda x: x.endswith(".tex"),
|
||||
reject=lambda x: x.startswith("tpl_"),
|
||||
)
|
||||
tasks = only_corr_planner(sources=tex_files, no_pdf=no_pdf, no_join=no_join)
|
||||
else:
|
||||
subjects = build_subjects(
|
||||
students_csv=students_csv, quantity_subjects=quantity_subjects
|
||||
)
|
||||
tasks = default_planner(template, subjects, corr, no_join, no_pdf)
|
||||
|
||||
scheduler = Scheduler([template])
|
||||
scheduler = Scheduler([options["template"]])
|
||||
scheduler.append(tasks)
|
||||
|
||||
for task in scheduler.backlog:
|
||||
pass
|
||||
for task in scheduler.backlog():
|
||||
yield task
|
||||
|
||||
|
||||
# -----------------------------
|
||||
|
@ -1,33 +1,10 @@
|
||||
from bopytex.service import build_subject_list_from_infos, build_subject_list_from_qty
|
||||
from bopytex.planner import fake_planner
|
||||
from bopytex.service import orcherstrator
|
||||
from bopytex.tasks import Task
|
||||
|
||||
|
||||
def test_build_subject_list_from_qty():
|
||||
subjects = build_subject_list_from_qty(10)
|
||||
assert subjects == [
|
||||
{"number": "01"},
|
||||
{"number": "02"},
|
||||
{"number": "03"},
|
||||
{"number": "04"},
|
||||
{"number": "05"},
|
||||
{"number": "06"},
|
||||
{"number": "07"},
|
||||
{"number": "08"},
|
||||
{"number": "09"},
|
||||
{"number": "10"},
|
||||
]
|
||||
|
||||
|
||||
def test_build_subject_list_from_infos():
|
||||
infos = [
|
||||
{"name": "test1", "date": "today"},
|
||||
{"name": "test2", "date": "tomorow"},
|
||||
]
|
||||
subjects = build_subject_list_from_infos(infos)
|
||||
assert subjects == [
|
||||
{"name": "test1", "date": "today", "number": "1"},
|
||||
{"name": "test2", "date": "tomorow", "number": "2"},
|
||||
]
|
||||
|
||||
|
||||
def test_bopytex():
|
||||
pass
|
||||
def test_service():
|
||||
options = {"quantity": 3, "template": "tpl_src.tex"}
|
||||
service = orcherstrator(options, fake_planner.simple)
|
||||
for i, task in enumerate(service):
|
||||
assert task == Task("Do", args={"number": i}, deps=[], output=f"{i}")
|
||||
|
Loading…
Reference in New Issue
Block a user