Skip to content

Commit

Permalink
Recursively flatten target collections in fetch_output handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Nov 18, 2022
1 parent dc8a78e commit 4230365
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions law/task/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def fetch_task_output(task, max_depth=0, mode=None, target_dir=".", include_exte
continue

# skip missing targets
if not isinstance(output, TargetCollection) and stat is None:
if stat is None and not isinstance(output, TargetCollection):
print(ooffset + colored("not existing, skip", "yellow"))
continue

Expand Down Expand Up @@ -500,12 +500,18 @@ def fetch_task_output(task, max_depth=0, mode=None, target_dir=".", include_exte
if target_choice == "n":
print(ooffset + colored("skipped", "yellow"))
continue
else:
if isinstance(output, TargetCollection):
to_fetch = list(output._flat_target_list)

# flatten all target collections
to_fetch_flat = []
while to_fetch:
t = to_fetch.pop(0)
if isinstance(t, TargetCollection):
to_fetch[:0] = list(t._flat_target_list)
else:
to_fetch_flat.append(t)

# actual copy
for outp in to_fetch:
for outp in to_fetch_flat:
if not callable(getattr(outp, "copy_to_local", None)):
continue

Expand Down

0 comments on commit 4230365

Please sign in to comment.