refact: remove output to tasks
This commit is contained in:
parent
7b64dcf8d6
commit
480ced3259
@ -1,6 +1,6 @@
|
|||||||
""" Produce tasks to do
|
""" Produce tasks to do
|
||||||
|
|
||||||
It essentially place things at the right place and define the way that files are named.
|
It essentially place things at the right place.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
@ -11,7 +11,6 @@ class Task:
|
|||||||
action: str
|
action: str
|
||||||
args: dict
|
args: dict
|
||||||
deps: list
|
deps: list
|
||||||
output: str
|
|
||||||
|
|
||||||
|
|
||||||
def generate(template: str, meta: dict):
|
def generate(template: str, meta: dict):
|
||||||
@ -20,7 +19,6 @@ def generate(template: str, meta: dict):
|
|||||||
action="GENERATE",
|
action="GENERATE",
|
||||||
args=meta,
|
args=meta,
|
||||||
deps=[template],
|
deps=[template],
|
||||||
output=meta["subject"] + template[3:],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -30,7 +28,6 @@ def activate_corr_on(src: str):
|
|||||||
action="ACTIVATE_CORR",
|
action="ACTIVATE_CORR",
|
||||||
args={},
|
args={},
|
||||||
deps=[src],
|
deps=[src],
|
||||||
output="corr_" + src,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +37,6 @@ def compile_pdf(src: str):
|
|||||||
action="COMPILE",
|
action="COMPILE",
|
||||||
args={},
|
args={},
|
||||||
deps=[src],
|
deps=[src],
|
||||||
output=src[:-3] + "pdf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def join_pdfs(pdfs: list):
|
def join_pdfs(pdfs: list):
|
||||||
@ -49,7 +45,6 @@ def join_pdfs(pdfs: list):
|
|||||||
action="JOIN",
|
action="JOIN",
|
||||||
args={},
|
args={},
|
||||||
deps=pdfs,
|
deps=pdfs,
|
||||||
output="joined.pdf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -59,5 +54,4 @@ def clean(files: list):
|
|||||||
action="CLEAN",
|
action="CLEAN",
|
||||||
args={},
|
args={},
|
||||||
deps=files,
|
deps=files,
|
||||||
output=None
|
|
||||||
)
|
)
|
||||||
|
@ -25,5 +25,6 @@ class Scheduler:
|
|||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
task = self._tasks.pop()
|
task = self._tasks.pop()
|
||||||
self._done.append(task.output)
|
ans = self.dispatch(task)
|
||||||
return self.dispatch(task)
|
self._done.append(ans)
|
||||||
|
return ans
|
||||||
|
@ -7,7 +7,6 @@ def test_build_task_generate():
|
|||||||
assert task.action == "GENERATE"
|
assert task.action == "GENERATE"
|
||||||
assert task.args == {"subject": "01"}
|
assert task.args == {"subject": "01"}
|
||||||
assert task.deps == [template]
|
assert task.deps == [template]
|
||||||
assert task.output == "01_source.tex"
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_task_activate_corr_on():
|
def test_build_task_activate_corr_on():
|
||||||
@ -16,7 +15,6 @@ def test_build_task_activate_corr_on():
|
|||||||
assert task.action == "ACTIVATE_CORR"
|
assert task.action == "ACTIVATE_CORR"
|
||||||
assert task.args == {}
|
assert task.args == {}
|
||||||
assert task.deps == [src]
|
assert task.deps == [src]
|
||||||
assert task.output == "corr_source.tex"
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_task_compile():
|
def test_build_task_compile():
|
||||||
@ -25,7 +23,6 @@ def test_build_task_compile():
|
|||||||
assert task.action == "COMPILE"
|
assert task.action == "COMPILE"
|
||||||
assert task.args == {}
|
assert task.args == {}
|
||||||
assert task.deps == [src]
|
assert task.deps == [src]
|
||||||
assert task.output == "source.pdf"
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_task_join():
|
def test_build_task_join():
|
||||||
@ -34,7 +31,6 @@ def test_build_task_join():
|
|||||||
assert task.action == "JOIN"
|
assert task.action == "JOIN"
|
||||||
assert task.args == {}
|
assert task.args == {}
|
||||||
assert task.deps == pdfs
|
assert task.deps == pdfs
|
||||||
assert task.output == "joined.pdf"
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_task_compile():
|
def test_build_task_compile():
|
||||||
@ -43,4 +39,3 @@ def test_build_task_compile():
|
|||||||
assert task.action == "CLEAN"
|
assert task.action == "CLEAN"
|
||||||
assert task.args == {}
|
assert task.args == {}
|
||||||
assert task.deps == files
|
assert task.deps == files
|
||||||
assert task.output is None
|
|
||||||
|
@ -5,14 +5,14 @@ from bopytex.scheduler import Scheduler
|
|||||||
def test_schedule_append():
|
def test_schedule_append():
|
||||||
actions = {"DO": lambda _: "done"}
|
actions = {"DO": lambda _: "done"}
|
||||||
scheduler = Scheduler(actions)
|
scheduler = Scheduler(actions)
|
||||||
tasks = [Task(action="DO", args={}, deps=[], output="")]
|
tasks = [Task(action="DO", args={}, deps=[])]
|
||||||
scheduler.append(tasks)
|
scheduler.append(tasks)
|
||||||
assert scheduler.tasks == tasks
|
assert scheduler.tasks == tasks
|
||||||
|
|
||||||
def test_schedule_dispatch():
|
def test_schedule_dispatch():
|
||||||
actions = {"DO": lambda _: "done"}
|
actions = {"DO": lambda _: "done"}
|
||||||
scheduler = Scheduler(actions)
|
scheduler = Scheduler(actions)
|
||||||
task = Task(action="DO", args={}, deps=[], output="Nothing")
|
task = Task(action="DO", args={}, deps=[])
|
||||||
result = scheduler.dispatch(task)
|
result = scheduler.dispatch(task)
|
||||||
assert result == "done"
|
assert result == "done"
|
||||||
|
|
||||||
@ -20,8 +20,8 @@ def test_schedule_dispatch():
|
|||||||
def test_schedule_one_task():
|
def test_schedule_one_task():
|
||||||
actions = {"DO": lambda _: "done"}
|
actions = {"DO": lambda _: "done"}
|
||||||
scheduler = Scheduler(actions)
|
scheduler = Scheduler(actions)
|
||||||
scheduler.append([Task(action="DO", args={}, deps=[], output="Nothing")])
|
scheduler.append([Task(action="DO", args={}, deps=[])])
|
||||||
result = scheduler.__next__()
|
result = scheduler.__next__()
|
||||||
assert result == "done"
|
assert result == "done"
|
||||||
assert scheduler.tasks == []
|
assert scheduler.tasks == []
|
||||||
assert scheduler.done == ["Nothing"]
|
assert scheduler.done == ["done"]
|
||||||
|
Loading…
Reference in New Issue
Block a user