Skip to content

Commit

Permalink
Merge pull request #466 from djarecka/fix/cmdline_sep_format
Browse files Browse the repository at this point in the history
[fix] formatting cmdline for shelltask
  • Loading branch information
djarecka authored May 14, 2021
2 parents bc71076 + 9176136 commit f2106f6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pydra/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def _command_pos_args(self, field, state_ind, index):
argstr_f = argstr_formatting(
argstr, self.inputs, value_updates={field.name: val}
)
argstr_formatted_l.append(argstr_f)
argstr_formatted_l.append(f" {argstr_f}")
cmd_el_str = sep.join(argstr_formatted_l)
else: # argstr has a simple form, e.g. "-f", or "--f"
cmd_el_str = sep.join([f" {argstr} {val}" for val in value])
Expand All @@ -445,7 +445,8 @@ def _command_pos_args(self, field, state_ind, index):
value = cmd_el_str
# if argstr has a more complex form, with "{input_field}"
if "{" in argstr and "}" in argstr:
cmd_el_str = argstr_formatting(argstr, self.inputs)
cmd_el_str = argstr.replace(f"{{{field.name}}}", str(value))
cmd_el_str = argstr_formatting(cmd_el_str, self.inputs)
else: # argstr has a simple form, e.g. "-f", or "--f"
if value:
cmd_el_str = f"{argstr} {value}"
Expand Down
58 changes: 57 additions & 1 deletion pydra/engine/tests/test_shelltask_inputspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,35 @@ def test_shell_cmd_inputs_list_sep_2():
assert shelly.cmdline == "executable -v aaa,bbb,ccc"


def test_shell_cmd_inputs_sep_3():
def test_shell_cmd_inputs_list_sep_2a():
"""providing list as an additional input:, sep, and argstr with f-string"""
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"inpA",
attr.ib(
type=str,
metadata={
"position": 1,
"help_string": "inpA",
"sep": ",",
"argstr": "-v {inpA}",
},
),
)
],
bases=(ShellSpec,),
)

shelly = ShellCommandTask(
executable="executable", inpA=["aaa", "bbb", "ccc"], input_spec=my_input_spec
)
# a flag is used once
assert shelly.cmdline == "executable -v aaa,bbb,ccc"


def test_shell_cmd_inputs_list_sep_3():
"""providing list as an additional input:, sep, argstr with ..."""
my_input_spec = SpecInfo(
name="Input",
Expand Down Expand Up @@ -469,6 +497,34 @@ def test_shell_cmd_inputs_sep_3():
assert shelly.cmdline == "executable -v aaa, -v bbb, -v ccc"


def test_shell_cmd_inputs_list_sep_3a():
"""providing list as an additional input:, sep, argstr with ... and f-string"""
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"inpA",
attr.ib(
type=str,
metadata={
"position": 1,
"help_string": "inpA",
"sep": ",",
"argstr": "-v {inpA}...",
},
),
)
],
bases=(ShellSpec,),
)

shelly = ShellCommandTask(
executable="executable", inpA=["aaa", "bbb", "ccc"], input_spec=my_input_spec
)
# a flag is repeated
assert shelly.cmdline == "executable -v aaa, -v bbb, -v ccc"


def test_shell_cmd_inputs_sep_4():
"""providing 1-el list as an additional input:, sep, argstr with ...,"""
my_input_spec = SpecInfo(
Expand Down

0 comments on commit f2106f6

Please sign in to comment.