Skip to content

Commit 937172f

Browse files
committed
fixing template formatting - didnt work well if the directory had a dot in the name
1 parent 581545c commit 937172f

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

pydra/engine/helpers_file.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,12 @@ def _template_formatting(template, inputs_dict, keep_extension=True):
600600
fld_value = inputs_dict[fld_name]
601601
if fld_value is attr.NOTHING:
602602
return attr.NOTHING
603-
fld_value = str(fld_value) # in case it's a path
604-
filename, *ext = fld_value.split(".", maxsplit=1)
603+
fld_value_parent = Path(fld_value).parent
604+
fld_value_name = Path(fld_value).name
605+
606+
name, *ext = fld_value_name.split(".", maxsplit=1)
607+
filename = str(fld_value_parent / name)
608+
605609
# if keep_extension is False, the extensions are removed
606610
if keep_extension is False:
607611
ext = []

pydra/engine/tests/test_shelltask.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,8 +1162,56 @@ def test_shell_cmd_inputspec_9(tmpdir, plugin, results_function):
11621162
assert shelly.output_dir == res.output.file_copy.parent
11631163

11641164

1165-
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
1165+
@pytest.mark.parametrize("results_function", [result_no_submitter])
11661166
def test_shell_cmd_inputspec_9a(tmpdir, plugin, results_function):
1167+
"""
1168+
providing output name using input_spec (output_file_template in metadata),
1169+
the template has a suffix, the extension of the file will be moved to the end
1170+
the change: input file has directory with a dot
1171+
"""
1172+
cmd = "cp"
1173+
file = tmpdir.mkdir("data.inp").join("file.txt")
1174+
file.write("content")
1175+
1176+
my_input_spec = SpecInfo(
1177+
name="Input",
1178+
fields=[
1179+
(
1180+
"file_orig",
1181+
attr.ib(
1182+
type=File,
1183+
metadata={"position": 2, "help_string": "new file", "argstr": ""},
1184+
),
1185+
),
1186+
(
1187+
"file_copy",
1188+
attr.ib(
1189+
type=str,
1190+
metadata={
1191+
"output_file_template": "{file_orig}_copy",
1192+
"help_string": "output file",
1193+
"argstr": "",
1194+
},
1195+
),
1196+
),
1197+
],
1198+
bases=(ShellSpec,),
1199+
)
1200+
1201+
shelly = ShellCommandTask(
1202+
name="shelly", executable=cmd, input_spec=my_input_spec, file_orig=file
1203+
)
1204+
1205+
res = results_function(shelly, plugin)
1206+
assert res.output.stdout == ""
1207+
assert res.output.file_copy.exists()
1208+
assert res.output.file_copy.name == "file_copy.txt"
1209+
# checking if it's created in a good place
1210+
assert shelly.output_dir == res.output.file_copy.parent
1211+
1212+
1213+
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
1214+
def test_shell_cmd_inputspec_9b(tmpdir, plugin, results_function):
11671215
"""
11681216
providing output name using input_spec (output_file_template in metadata)
11691217
and the keep_extension is set to False, so the extension is removed completely.
@@ -1209,7 +1257,7 @@ def test_shell_cmd_inputspec_9a(tmpdir, plugin, results_function):
12091257

12101258

12111259
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
1212-
def test_shell_cmd_inputspec_9b(tmpdir, plugin, results_function):
1260+
def test_shell_cmd_inputspec_9c(tmpdir, plugin, results_function):
12131261
"""
12141262
providing output name using input_spec (output_file_template in metadata)
12151263
and the keep_extension is set to False, so the extension is removed completely,

0 commit comments

Comments
 (0)