8000 FIX: Provide templated fields to cmdline only when requirements are met · nipype/pydra@785d373 · GitHub
[go: up one dir, main page]

Skip to content

Commit 785d373

Browse files
committed
FIX: Provide templated fields to cmdline only when requirements are met
1 parent 7b4837c commit 785d373

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

pydra/engine/helpers_file.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,19 @@ def template_update(inputs, output_dir, state_ind=None, map_copyfiles=None):
591591

592592
from .specs import attr_fields
593593

594+
# Collect templated inputs for which all requirements are satisfied.
594595
fields_templ = [
595-
fld for fld in attr_fields(inputs) if fld.metadata.get("output_file_template")
596+
field
597+
for field in attr_fields(inputs)
598+
if field.metadata.get("output_file_template")
599+
and all(
600+
[
601+
getattr(inputs, required_field) is not attr.NOTHING
602+
for required_field in field.metadata.get("requires", [])
603+
]
604+
)
596605
]
606+
597607
dict_mod = {}
598608
for fld in fields_templ:
599609
if fld.type not in [str, ty.Union[str, bool]]:

pydra/engine/tests/test_shelltask_inputspec.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,58 @@ def test_shell_cmd_inputs_template_10():
17211721
assert shelly.output_names == ["return_code", "stdout", "stderr", "outA"]
17221722

17231723

1724+
def test_shell_cmd_inputs_template_requires_1():
1725+
"""Given an input specification with a templated output file subject to required fields,
1726+
ensure the field is set only when all requirements are met."""
1727+
1728+
my_input_spec = SpecInfo(
1729+
name="Input",
1730+
fields=[
1731+
(
1732+
"in_file",
1733+
attr.ib(
1734+
type=str,
1735+
metadata={
1736+
"help_string": "input file",
1737+
"mandatory": True,
1738+
"argstr": "",
1739+
},
1740+
),
1741+
),
1742+
(
1743+
"with_tpl",
1744+
attr.ib(
1745+
type=bool,
1746+
metadata={"help_string": "enable template"},
1747+
),
1748+
),
1749+
(
1750+
"out_file",
1751+
attr.ib(
1752+
type=str,
1753+
metadata={
1754+
"help_string": "output file",
1755+
"argstr": "--tpl",
1756+
"output_file_template": "tpl.{in_file}",
1757+
"requires": {"with_tpl"},
1758+
},
1759+
),
1760+
),
1761+
],
1762+
bases=(ShellSpec,),
1763+
)
1764+
1765+
# When requirements are not met.
1766+
shelly = ShellCommandTask(
1767+
executable="cmd", input_spec=my_input_spec, in_file="in.file"
1768+
)
1769+
assert "--tpl" not in shelly.cmdline
1770+
1771+
# When requirements are met.
1772+
shelly.inputs.with_tpl = True
1773+
assert "tpl.in.file" in shelly.cmdline
1774+
1775+
17241776
def test_shell_cmd_inputs_template_function_1():
17251777
"""one input field uses output_file_template that is a simple function
17261778
this can be easily done by simple template as in test_shell_cmd_inputs_template_1

0 commit comments

Comments
 (0)
0