Skip to content

Commit

Permalink
allowing for any position of the shelltask input field (not excluding…
Browse files Browse the repository at this point in the history
… 0); allowing for position duplication in the input spec as long as one value only is provided
  • Loading branch information
djarecka committed Feb 19, 2021
1 parent 6177c68 commit d364375
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
32 changes: 20 additions & 12 deletions pydra/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ def _command_args_single(self, state_ind, ind=None):
"bindings",
]:
continue
elif getattr(self.inputs, f.name) is attr.NOTHING and not f.metadata.get(
"readonly"
):
continue
elif f.name == "executable":
pos_args.append(
self._command_shelltask_executable(
Expand Down Expand Up @@ -424,18 +428,22 @@ def _command_pos_args(self, field, state_ind, ind):
if pos is None:
# position will be set at the end
pass
elif not isinstance(pos, int):
raise Exception(f"position should be an integer, but {pos} given")
elif pos == 0:
raise Exception(f"position can't be 0")
elif pos < 0: # position -1 is for args
pos = pos - 1
# checking if the position is not already used
elif pos in self._positions_provided:
raise Exception(
f"{field.name} can't have provided position, {pos} is already used"
)
self._positions_provided.append(pos)
else:
if not isinstance(pos, int):
raise Exception(f"position should be an integer, but {pos} given")
# checking if the position is not already used
if pos in self._positions_provided:
raise Exception(
f"{field.name} can't have provided position, {pos} is already used"
)
else:
self._positions_provided.append(pos)

if pos >= 0:
pos = pos + 1 # position 0 is for executable
else: # pos < 0:
pos = pos - 1 # position -1 is for args

value = self._field_value(
field=field, state_ind=state_ind, ind=ind, check_file=True
)
Expand Down
33 changes: 32 additions & 1 deletion pydra/engine/tests/test_shelltask_inputspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,44 @@ def test_shell_cmd_inputs_2_err():
)

shelly = ShellCommandTask(
executable="executable", inpA="inp1", inpB="inp1", input_spec=my_input_spec
executable="executable", inpA="inp1", inpB="inp2", input_spec=my_input_spec
)
with pytest.raises(Exception) as e:
shelly.cmdline
assert "1 is already used" in str(e.value)


def test_shell_cmd_inputs_2_noerr():
""" additional inputs with provided positions
(duplication of teh position doesn't lead to error, since only one field has value)
"""
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"inpA",
attr.ib(
type=str,
metadata={"position": 1, "help_string": "inpA", "argstr": ""},
),
),
(
"inpB",
attr.ib(
type=str,
metadata={"position": 1, "help_string": "inpB", "argstr": ""},
),
),
],
bases=(ShellSpec,),
)

shelly = ShellCommandTask(
executable="executable", inpA="inp1", input_spec=my_input_spec
)
shelly.cmdline


def test_shell_cmd_inputs_3():
""" additional inputs: positive pos, negative pos and no pos """
my_input_spec = SpecInfo(
Expand Down

0 comments on commit d364375

Please sign in to comment.