Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Provide templated fields to cmdline only when requirements are met #629

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pydra/engine/helpers_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,17 @@ def template_update(inputs, output_dir, state_ind=None, map_copyfiles=None):

from .specs import attr_fields

# Collect templated inputs for which all requirements are satisfied.
fields_templ = [
fld for fld in attr_fields(inputs) if fld.metadata.get("output_file_template")
field
for field in attr_fields(inputs)
if field.metadata.get("output_file_template")
and all(
getattr(inputs, required_field) is not attr.NOTHING
for required_field in field.metadata.get("requires", ())
)
]

dict_mod = {}
for fld in fields_templ:
if fld.type not in [str, ty.Union[str, bool]]:
Expand Down
52 changes: 52 additions & 0 deletions pydra/engine/tests/test_shelltask_inputspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,58 @@ def test_shell_cmd_inputs_template_10():
assert shelly.output_names == ["return_code", "stdout", "stderr", "outA"]


def test_shell_cmd_inputs_template_requires_1():
"""Given an input specification with a templated output file subject to required fields,
ensure the field is set only when all requirements are met."""

my_input_spec = SpecInfo(
name="Input",
fields=[
(
"in_file",
attr.ib(
type=str,
metadata={
"help_string": "input file",
"mandatory": True,
"argstr": "",
},
),
),
(
"with_tpl",
attr.ib(
type=bool,
metadata={"help_string": "enable template"},
),
),
(
"out_file",
attr.ib(
type=str,
metadata={
"help_string": "output file",
"argstr": "--tpl",
"output_file_template": "tpl.{in_file}",
"requires": {"with_tpl"},
},
),
),
],
bases=(ShellSpec,),
)

# When requirements are not met.
shelly = ShellCommandTask(
executable="cmd", input_spec=my_input_spec, in_file="in.file"
)
assert "--tpl" not in shelly.cmdline

# When requirements are met.
shelly.inputs.with_tpl = True
assert "tpl.in.file" in shelly.cmdline


def test_shell_cmd_inputs_template_function_1():
"""one input field uses output_file_template that is a simple function
this can be easily done by simple template as in test_shell_cmd_inputs_template_1
Expand Down
2 changes: 1 addition & 1 deletion pydra/engine/tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4843,7 +4843,7 @@ def printer(a):
@pytest.mark.timeout(40)
def test_inner_outer_wf_duplicate(tmpdir):
"""checking if the execution gets stuck if there is an inner and outer workflows
thar run two nodes with the exact same inputs.
that run two nodes with the exact same inputs.
"""
task_list = ["First", "Second"]
start_list = [3]
Expand Down
2 changes: 1 addition & 1 deletion pydra/utils/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


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

def __init__(self, pid, interval=5, logdir=None, fname=None):
"""
Expand Down