File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -458,7 +458,11 @@ def _command_pos_args(self, field):
458
458
cmd_add .append (argstr )
459
459
else :
460
460
sep = field .metadata .get ("sep" , " " )
461
- if argstr .endswith ("..." ) and isinstance (value , list ):
461
+ if (
462
+ argstr .endswith ("..." )
463
+ and isinstance (value , ty .Iterable )
464
+ and not isinstance (value , (str , bytes ))
465
+ ):
462
466
argstr = argstr .replace ("..." , "" )
463
467
# if argstr has a more complex form, with "{input_field}"
464
468
if "{" in argstr and "}" in argstr :
@@ -474,7 +478,9 @@ def _command_pos_args(self, field):
474
478
else :
475
479
# in case there are ... when input is not a list
476
480
argstr = argstr .replace ("..." , "" )
477
- if isinstance (value , list ):
481
+ if isinstance (value , ty .Iterable ) and not isinstance (
482
+ value , (str , bytes )
483
+ ):
478
484
cmd_el_str = sep .join ([str (val ) for val in value ])
479
485
value = cmd_el_str
480
486
# if argstr has a more complex form, with "{input_field}"
Original file line number Diff line number Diff line change @@ -1674,6 +1674,40 @@ def template_function(inputs):
1674
1674
assert shelly .output_dir == res .output .file_copy .parent
1675
1675
1676
1676
1677
+ def test_shell_cmd_inputspec_with_iterable ():
1678
+ """Test formatting of argstr with different iterable types."""
1679
+
1680
+ input_spec = SpecInfo (
1681
+ name = "Input" ,
1682
+ fields = [
1683
+ (
1684
+ "iterable_1" ,
1685
+ ty .Iterable [int ],
1686
+ {
1687
+ "help_string" : "iterable input 1" ,
1688
+ "argstr" : "--in1" ,
1689
+ },
1690
+ ),
1691
+ (
1692
+ "iterable_2" ,
1693
+ ty .Iterable [str ],
1694
+ {
1695
+ "help_string" : "iterable input 2" ,
1696
+ "argstr" : "--in2..." ,
1697
+ },
1698
+ ),
1699
+ ],
1700
+ bases = (ShellSpec ,),
1701
+ )
1702
+
1703
+ task = ShellCommandTask (name = "test" , input_spec = input_spec , executable = "test" )
1704
+
1705
+ for iterable_type in (list , tuple , set ):
1706
+ task .inputs .iterable_1 = iterable_type (range (3 ))
1707
+ task .inputs .iterable_2 = iterable_type (["bar" , "foo" ])
1708
+ assert task .cmdline == "test --in1 0 1 2 --in2 bar --in2 foo"
1709
+
1710
+
1677
1711
@pytest .mark .parametrize ("results_function" , [result_no_submitter , result_submitter ])
1678
1712
def test_shell_cmd_inputspec_copyfile_1 (plugin , results_function , tmpdir ):
1679
1713
"""shelltask changes a file in place,
You can’t perform that action at this time.
0 commit comments