Skip to content

Commit f2106f6

Browse files
authored
Merge pull request #466 from djarecka/fix/cmdline_sep_format
[fix] formatting cmdline for shelltask
2 parents bc71076 + 9176136 commit f2106f6

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

pydra/engine/task.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def _command_pos_args(self, field, state_ind, index):
433433
argstr_f = argstr_formatting(
434434
argstr, self.inputs, value_updates={field.name: val}
435435
)
436-
argstr_formatted_l.append(argstr_f)
436+
argstr_formatted_l.append(f" {argstr_f}")
437437
cmd_el_str = sep.join(argstr_formatted_l)
438438
else: # argstr has a simple form, e.g. "-f", or "--f"
439439
cmd_el_str = sep.join([f" {argstr} {val}" for val in value])
@@ -445,7 +445,8 @@ def _command_pos_args(self, field, state_ind, index):
445445
value = cmd_el_str
446446
# if argstr has a more complex form, with "{input_field}"
447447
if "{" in argstr and "}" in argstr:
448-
cmd_el_str = argstr_formatting(argstr, self.inputs)
448+
cmd_el_str = argstr.replace(f"{{{field.name}}}", str(value))
449+
cmd_el_str = argstr_formatting(cmd_el_str, self.inputs)
449450
else: # argstr has a simple form, e.g. "-f", or "--f"
450451
if value:
451452
cmd_el_str = f"{argstr} {value}"

pydra/engine/tests/test_shelltask_inputspec.py

+57-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,35 @@ def test_shell_cmd_inputs_list_sep_2():
441441
assert shelly.cmdline == "executable -v aaa,bbb,ccc"
442442

443443

444-
def test_shell_cmd_inputs_sep_3():
444+
def test_shell_cmd_inputs_list_sep_2a():
445+
"""providing list as an additional input:, sep, and argstr with f-string"""
446+
my_input_spec = SpecInfo(
447+
name="Input",
448+
fields=[
449+
(
450+
"inpA",
451+
attr.ib(
452+
type=str,
453+
metadata={
454+
"position": 1,
455+
"help_string": "inpA",
456+
"sep": ",",
457+
"argstr": "-v {inpA}",
458+
},
459+
),
460+
)
461+
],
462+
bases=(ShellSpec,),
463+
)
464+
465+
shelly = ShellCommandTask(
466+
executable="executable", inpA=["aaa", "bbb", "ccc"], input_spec=my_input_spec
467+
)
468+
# a flag is used once
469+
assert shelly.cmdline == "executable -v aaa,bbb,ccc"
470+
471+
472+
def test_shell_cmd_inputs_list_sep_3():
445473
"""providing list as an additional input:, sep, argstr with ..."""
446474
my_input_spec = SpecInfo(
447475
name="Input",
@@ -469,6 +497,34 @@ def test_shell_cmd_inputs_sep_3():
469497
assert shelly.cmdline == "executable -v aaa, -v bbb, -v ccc"
470498

471499

500+
def test_shell_cmd_inputs_list_sep_3a():
501+
"""providing list as an additional input:, sep, argstr with ... and f-string"""
502+
my_input_spec = SpecInfo(
503+
name="Input",
504+
fields=[
505+
(
506+
"inpA",
507+
attr.ib(
508+
type=str,
509+
metadata={
510+
"position": 1,
511+
"help_string": "inpA",
512+
"sep": ",",
513+
"argstr": "-v {inpA}...",
514+
},
515+
),
516+
)
517+
],
518+
bases=(ShellSpec,),
519+
)
520+
521+
shelly = ShellCommandTask(
522+
executable="executable", inpA=["aaa", "bbb", "ccc"], input_spec=my_input_spec
523+
)
524+
# a flag is repeated
525+
assert shelly.cmdline == "executable -v aaa, -v bbb, -v ccc"
526+
527+
472528
def test_shell_cmd_inputs_sep_4():
473529
"""providing 1-el list as an additional input:, sep, argstr with ...,"""
474530
my_input_spec = SpecInfo(

0 commit comments

Comments
 (0)