Skip to content

Commit c8b0f08

Browse files
authored
Merge pull request #447 from chasejohnson3/split_MultiInputFile
Handle Lazy MultiInputFiles
2 parents bbe0a28 + ed60a32 commit c8b0f08

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

pydra/engine/helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def ensure_list(obj, tuple2list=False):
6363
return list(obj)
6464
elif isinstance(obj, list):
6565
return obj
66+
elif isinstance(obj, LazyField):
67+
return obj
6668
return [obj]
6769

6870

pydra/engine/tests/test_shelltask_inputspec.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33
import pytest
44

55
from ..task import ShellCommandTask
6-
from ..specs import ShellOutSpec, ShellSpec, SpecInfo, File, MultiInputObj
6+
from ..specs import (
7+
ShellOutSpec,
8+
ShellSpec,
9+
SpecInfo,
10+
File,
11+
MultiInputObj,
12+
MultiInputFile,
13+
MultiOutputFile,
14+
)
715
from .utils import use_validator
16+
from ..core import Workflow
17+
from ..submitter import Submitter
818

919

1020
def test_shell_cmd_execargs_1():
@@ -1653,6 +1663,57 @@ def test_shell_cmd_inputs_template_10():
16531663
assert shelly.output_names == ["return_code", "stdout", "stderr", "outA"]
16541664

16551665

1666+
def test_shell_cmd_inputs_template_11():
1667+
input_fields = [
1668+
(
1669+
"inputFiles",
1670+
attr.ib(
1671+
type=MultiInputFile,
1672+
metadata={
1673+
"argstr": "--inputFiles ...",
1674+
"help_string": "The list of input image files to be segmented.",
1675+
},
1676+
),
1677+
)
1678+
]
1679+
1680+
output_fields = [
1681+
(
1682+
"outputFiles",
1683+
attr.ib(
1684+
type=MultiOutputFile,
1685+
metadata={
1686+
"help_string": "Corrected Output Images: should specify the same number of images as inputVolume, if only one element is given, then it is used as a file pattern where %s is replaced by the imageVolumeType, and %d by the index list location.",
1687+
"output_file_template": "{inputFiles}",
1688+
},
1689+
),
1690+
)
1691+
]
1692+
1693+
input_spec = SpecInfo(name="Input", fields=input_fields, bases=(ShellSpec,))
1694+
output_spec = SpecInfo(name="Output", fields=output_fields, bases=(ShellOutSpec,))
1695+
1696+
task = ShellCommandTask(
1697+
name="echoMultiple",
1698+
executable="echo",
1699+
input_spec=input_spec,
1700+
output_spec=output_spec,
1701+
)
1702+
wf = Workflow(name="wf", input_spec=["inputFiles"], inputFiles=["test1", "test2"])
1703+
1704+
task.inputs.inputFiles = wf.lzin.inputFiles
1705+
1706+
wf.add(task)
1707+
wf.set_output([("out", wf.echoMultiple.lzout.outputFiles)])
1708+
1709+
with Submitter(plugin="cf") as sub:
1710+
sub(wf)
1711+
result = wf.result()
1712+
1713+
for out_file in result.output.out:
1714+
assert out_file.name == "test1" or out_file.name == "test2"
1715+
1716+
16561717
# TODO: after deciding how we use requires/templates
16571718
def test_shell_cmd_inputs_di(tmpdir, use_validator):
16581719
""" example from #279 """

0 commit comments

Comments
 (0)