Hi again,
finally getting back to this. None of these elegantly solve a gripe I have with calling tasks directly...
Imagine
I have task A, B, C. Task A produces some targets as sub-tasks, task B
takes those and produces new sub-tasks from them, Task C takes these and
produces a third set of sub-tasks. Task A does not depend on previous
tasks. Task B depends on A and so calls task_A() again to get the
targets it produces. Task C depends on B and calls task_B(), which calls
task_A() yet again. The call chain grows quickly as I add more tasks
and they all depend on the tasks before them. My sources potentially
contain thousands of files within, so this is bound to be time
consuming...
I'm experimenting with memoization, the following works if you always produce sub-tasks instead of normal ones:
```
def memoize(func):
def memoized_generator(cache=[]):
if not cache:
cache[:] = [x for x in func()]
yield from cache
return memoized_generator
@memoize
def task_a():
print("a")
for i in [1, 2, 3]:
yield {
"name": i,
"actions": [f"echo hello{i} > hello{i}.txt"],
"targets": [f"hello{i}.txt"],
}
@memoize
def task_b():
print("b")
for i, subtask in enumerate(task_a()):
sources = subtask["targets"]
yield {
"name": i,
"actions": [f"echo {sources} > hellob{i}.txt"],
"targets": [f"hellob{i}.txt"],
}
@memoize
def task_c():
print("c")
for i, subtask in enumerate(task_b()):
sources = subtask["targets"]
yield {
"name": i,
"actions": [f"echo {sources} > helloc{i}.txt"],
"targets": [f"helloc{i}.txt"],
}
```
Output:
```
> doit
a
b
c
. a:1
. a:2
. a:3
. b:0
. b:1
. b:2
. c:0
. c:1
. c:2
```