Skip to content

Commit ee88000

Browse files
committed
changed additional_args to be MultiInputObj[str] from list[str] type
1 parent 022c02a commit ee88000

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

new_file_2.txt

Whitespace-only changes.

newfile_tmp.txt

Whitespace-only changes.

pydra/engine/helpers_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def inputs_types_to_dict(name, inputs):
629629

630630

631631
def unwrap_splitter(
632-
splitter: ty.Union[str, ty.List[str], ty.Tuple[str, ...]]
632+
splitter: ty.Union[str, ty.List[str], ty.Tuple[str, ...]],
633633
) -> ty.Iterable[str]:
634634
"""Unwraps a splitter into a flat list of fields that are split over, i.e.
635635
[("a", "b"), "c"] -> ["a", "b", "c"]

pydra/engine/specs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import cloudpickle as cp
1919
from fileformats.generic import FileSet
2020
from pydra.utils.messenger import AuditFlag, Messenger
21-
from pydra.utils.typing import is_optional, optional_type
21+
from pydra.utils.typing import is_optional, optional_type, MultiInputObj
2222
from .helpers import (
2323
attrs_fields,
2424
attrs_values,
@@ -1039,11 +1039,10 @@ class ShellDef(TaskDef[ShellOutputsType]):
10391039

10401040
BASE_NAMES = ["additional_args"]
10411041

1042-
additional_args: list[str] = shell.arg(
1042+
additional_args: MultiInputObj[str] = shell.arg(
10431043
name="additional_args",
10441044
default=attrs.Factory(list),
1045-
type=list[str],
1046-
sep=" ",
1045+
type=MultiInputObj[str],
10471046
help="Additional free-form arguments to append to the end of the command.",
10481047
)
10491048

pydra/engine/tests/test_shelltask.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from glob import glob
21
import typing as ty
32
import os
43
import sys
@@ -7,7 +6,7 @@
76
import re
87
import stat
98
from pydra.engine.submitter import Submitter
10-
from pydra.design import shell, workflow
9+
from pydra.design import shell, workflow, python
1110
from pydra.engine.specs import (
1211
ShellOutputs,
1312
ShellDef,
@@ -248,8 +247,14 @@ def test_wf_shell_cmd_1(plugin, tmp_path):
248247

249248
@workflow.define
250249
def Workflow(cmd1, cmd2):
251-
shelly_pwd = workflow.add(shell.define(cmd1))
252-
shelly_ls = workflow.add(shell.define(cmd2, additional_args=shelly_pwd.stdout))
250+
shelly_pwd = workflow.add(shell.define(cmd1)())
251+
252+
@python.define
253+
def StripAndListify(x: str) -> list[str]:
254+
return [x.strip()]
255+
256+
listify = workflow.add(StripAndListify(x=shelly_pwd.stdout))
257+
shelly_ls = workflow.add(shell.define(cmd2)(additional_args=listify.out))
253258
return shelly_ls.stdout
254259

255260
wf = Workflow(cmd1="pwd", cmd2="ls")
@@ -1591,30 +1596,32 @@ def test_wf_shell_cmd_2(plugin_dask_opt, tmp_path):
15911596
class Shelly(ShellDef["Shelly.Outputs"]):
15921597
executable = "touch"
15931598

1599+
arg: str = shell.arg()
1600+
15941601
class Outputs(ShellOutputs):
15951602
out1: File = shell.outarg(
1596-
path_template="{args}",
1603+
path_template="{arg}",
15971604
help="output file",
15981605
)
15991606

1600-
@workflow.define
1601-
def Workflow(cmd, args):
1607+
@workflow.define(outputs=["out_f", "stdout"])
1608+
def Workflow(cmd, arg):
16021609

16031610
shelly = workflow.add(
16041611
Shelly(
16051612
executable=cmd,
1606-
additional_args=args,
1613+
arg=arg,
16071614
)
16081615
)
16091616

16101617
return shelly.out1, shelly.stdout
16111618

1612-
wf = Workflow(cmd="touch", args=File.mock("newfile.txt"))
1619+
wf = Workflow(cmd="touch", arg="newfile.txt")
16131620

1614-
with Submitter(plugin=plugin_dask_opt) as sub:
1621+
with Submitter(plugin=plugin_dask_opt, cache_dir=tmp_path) as sub:
16151622
res = sub(wf)
16161623

1617-
assert res.outputs.out == ""
1624+
assert res.outputs.stdout == ""
16181625
assert res.outputs.out_f.fspath.exists()
16191626
assert res.outputs.out_f.fspath.parent.parent == tmp_path
16201627

@@ -1628,25 +1635,27 @@ def test_wf_shell_cmd_2a(plugin, tmp_path):
16281635
class Shelly(ShellDef["Shelly.Outputs"]):
16291636
executable = "shelly"
16301637

1638+
arg: str = shell.arg()
1639+
16311640
class Outputs(ShellOutputs):
16321641
out1: File = shell.outarg(
1633-
path_template="{args}",
1642+
path_template="{arg}",
16341643
help="output file",
16351644
)
16361645

1637-
@workflow.define
1638-
def Workflow(cmd, args):
1646+
@workflow.define(outputs=["out_f", "out"])
1647+
def Workflow(cmd, arg):
16391648

16401649
shelly = workflow.add(
16411650
Shelly(
16421651
executable=cmd,
1643-
additional_args=args,
1652+
arg=arg,
16441653
)
16451654
)
16461655

16471656
return shelly.out1, shelly.stdout
16481657

1649-
wf = Workflow(cmd="touch", args=(File.mock("newfile.txt"),))
1658+
wf = Workflow(cmd="touch", arg="newfile.txt")
16501659

16511660
with Submitter(plugin="debug") as sub:
16521661
res = sub(wf)
@@ -1673,6 +1682,9 @@ class Outputs(ShellOutputs):
16731682

16741683
@shell.define
16751684
class Shelly2(ShellDef["Shelly2.Outputs"]):
1685+
1686+
executable = "shelly2"
1687+
16761688
orig_file: File = shell.arg(
16771689
position=1,
16781690
help="output file",
@@ -2491,7 +2503,7 @@ def test_shell_cmd_outputspec_wf_1(plugin, tmp_path):
24912503
@shell.define
24922504
class Shelly(ShellDef["Shelly.Outputs"]):
24932505

2494-
executable = "placeholder"
2506+
executable = "shelly"
24952507

24962508
class Outputs(ShellOutputs):
24972509
newfile: File = shell.outarg(path_template="newfile_tmp.txt")

0 commit comments

Comments
 (0)