doc: add docstring and typehints

This commit is contained in:
Bertrand Benjamin 2022-04-09 21:23:28 +02:00
parent 03482d4b3d
commit 1f0547c1ac

View File

@ -16,11 +16,13 @@ class Scheduler:
self._tasks = []
@property
def tasks(self):
def tasks(self) -> list[Task]:
""" list all the tasks """
return self._tasks
@property
def doable_tasks(self):
def doable_tasks(self) -> list[Task]:
""" list all doable tasks """
return [
task
for task in self.tasks
@ -28,15 +30,17 @@ class Scheduler:
]
@property
def all_deps(self):
def all_deps(self) -> list[str]:
""" List dependencies of all tasks """
return {d for task in self.tasks for d in task.deps}
@property
def all_output(self):
def all_output(self) -> list[str]:
""" List ouput of all tasks """
return {task.output for task in self.tasks}
@property
def done(self):
def done(self) -> list[str]:
return self._done
def append(self, tasks: list[Task]):
@ -54,24 +58,14 @@ class Scheduler:
return self.next()
def next(self):
undoable = []
try:
task = self._tasks.pop(0)
task = self.doable_tasks[0]
except IndexError:
raise StopIteration
while not all([d in self.done for d in task.deps]):
undoable.append(task)
try:
task = self._tasks.pop(0)
except IndexError:
self.append(undoable)
raise StopIteration
self.append(undoable)
ans = self.dispatch(task)
self._done.append(task.output)
self._tasks.remove(task)
return ans
def run(self):