Skip to content

Commit 678924e

Browse files
authored
Merge pull request #379 from djarecka/fix/template_formatting
fixing template formatting
2 parents e168af4 + 937172f commit 678924e

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
@@ -1212,8 +1212,56 @@ def test_shell_cmd_inputspec_9(tmpdir, plugin, results_function):
12121212
assert shelly.output_dir == res.output.file_copy.parent
12131213

12141214

1215-
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
1215+
@pytest.mark.parametrize("results_function", [result_no_submitter])
12161216
def test_shell_cmd_inputspec_9a(tmpdir, plugin, results_function):
1217+
"""
1218+
providing output name using input_spec (output_file_template in metadata),
1219+
the template has a suffix, the extension of the file will be moved to the end
1220+
the change: input file has directory with a dot
1221+
"""
1222+
cmd = "cp"
1223+
file = tmpdir.mkdir("data.inp").join("file.txt")
1224+
file.write("content")
1225+
1226+
my_input_spec = SpecInfo(
1227+
name="Input",
1228+
fields=[
1229+
(
1230+
"file_orig",
1231+
attr.ib(
1232+
type=File,
1233+
metadata={"position": 2, "help_string": "new file", "argstr": ""},
1234+
),
1235+
),
1236+
(
1237+
"file_copy",
1238+
attr.ib(
1239+
type=str,
1240+
metadata={
1241+
"output_file_template": "{file_orig}_copy",
1242+
"help_string": "output file",
1243+
"argstr": "",
1244+
},
1245+
),
1246+
),
1247+
],
1248+
bases=(ShellSpec,),
1249+
)
1250+
1251+
shelly = ShellCommandTask(
1252+
name="shelly", executable=cmd, input_spec=my_input_spec, file_orig=file
1253+
)
1254+
1255+
res = results_function(shelly, plugin)
1256+
assert res.output.stdout == ""
1257+
assert res.output.file_copy.exists()
1258+
assert res.output.file_copy.name == "file_copy.txt"
1259+
# checking if it's created in a good place
1260+
assert shelly.output_dir == res.output.file_copy.parent
1261+
1262+
1263+
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
1264+
def test_shell_cmd_inputspec_9b(tmpdir, plugin, results_function):
12171265
"""
12181266
providing output name using input_spec (output_file_template in metadata)
12191267
and the keep_extension is set to False, so the extension is removed completely.
@@ -1263,7 +1311,7 @@ def test_shell_cmd_inputspec_9a(tmpdir, plugin, results_function):
12631311

12641312

12651313
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
1266-
def test_shell_cmd_inputspec_9b(tmpdir, plugin, results_function):
1314+
def test_shell_cmd_inputspec_9c(tmpdir, plugin, results_function):
12671315
"""
12681316
providing output name using input_spec (output_file_template in metadata)
12691317
and the keep_extension is set to False, so the extension is removed completely,

0 commit comments

Comments
 (0)