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