10000 Merge pull request #629 from ghisvail/fix/issue-619 · nipype/pydra@11a6d68 · GitHub
[go: up one dir, main page]

Skip to content

Commit 11a6d68

Browse files
authored
Merge pull request #629 from ghisvail/fix/issue-619
FIX: Provide templated fields to cmdline only when requirements are met
2 parents 2be03da + 2ef6d4f commit 11a6d68

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

pydra/engine/helpers_file.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,17 @@ 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+
getattr(inputs, required_field) is not attr.NOTHING
601+
for required_field in field.metadata.get("requires", ())
602+
)
596603
]
604+
597605
dict_mod = {}
598606
for fld in fields_templ:
599607
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

pydra/engine/tests/test_workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4843,7 +4843,7 @@ def printer(a):
48434843
@pytest.mark.timeout(40)
48444844
def test_inner_outer_wf_duplicate(tmpdir):
48454845
"""checking if the execution gets stuck if there is an inner and outer workflows
4846-
thar run two nodes with the exact same inputs.
4846+
that run two nodes with the exact same inputs.
48474847
"""
48484848
task_list = ["First", "Second"]
48494849
start_list = [3]

pydra/utils/profiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class ResourceMonitor(threading.Thread):
12-
"""A thread to monitor a specific PID with a certain frequence to a file."""
12+
"""A thread to monitor a specific PID with a certain frequency to a file."""
1313

1414
def __init__(self, pid, interval=5, logdir=None, fname=None):
1515
"""

0 commit comments

Comments
 (0)
0