Skip to content

Commit b35bc73

Browse files
committed
added support for tuple/list output_file_templates for options with multiple args (e.g. mrconvert --export_grad_fsl bvec.bvec bval.bval)
1 parent f4b08bf commit b35bc73

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pydra/engine/helpers_file.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def template_update_single(
162162
raise TypeError(
163163
f"type of '{field.name}' is Path, consider using Union[Path, bool]"
164164
)
165-
if inp_val_set is not attr.NOTHING and not isinstance(LazyField):
165+
if inp_val_set is not attr.NOTHING and not isinstance(inp_val_set, LazyField):
166166
inp_val_set = TypeParser(ty.Union.__getitem__(OUTPUT_TEMPLATE_TYPES))(
167167
inp_val_set
168168
)
@@ -202,16 +202,27 @@ def _template_formatting(field, inputs, inputs_dict_st):
202202
Allowing for multiple input values used in the template as longs as
203203
there is no more than one file (i.e. File, PathLike or string with extensions)
204204
"""
205-
from .specs import MultiInputObj, MultiOutputFile
206-
207205
# if a template is a function it has to be run first with the inputs as the only arg
208206
template = field.metadata["output_file_template"]
209207
if callable(template):
210208
template = template(inputs)
211209

212210
# as default, we assume that keep_extension is True
213-
keep_extension = field.metadata.get("keep_extension", True)
211+
if isinstance(template, (tuple, list)):
212+
formatted = [
213+
_string_template_formatting(field, t, inputs, inputs_dict_st)
214+
for t in template
215+
]
216+
else:
217+
assert isinstance(template, str)
218+
formatted = _string_template_formatting(field, template, inputs, inputs_dict_st)
219+
return formatted
214220

221+
222+
def _string_template_formatting(field, template, inputs, inputs_dict_st):
223+
from .specs import MultiInputObj, MultiOutputFile
224+
225+
keep_extension = field.metadata.get("keep_extension", True)
215226
inp_fields = re.findall(r"{\w+}", template)
216227
inp_fields_fl = re.findall(r"{\w+:[0-9.]+f}", template)
217228
inp_fields += [re.sub(":[0-9.]+f", "", el) for el in inp_fields_fl]

0 commit comments

Comments
 (0)