Skip to content

Commit 42f7894

Browse files
authored
Merge pull request #585 from tclose/explicit-out-files
Provide paths to ShellTask output files
2 parents f57d975 + eec510f commit 42f7894

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

pydra/engine/specs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ def collect_additional_outputs(self, inputs, output_dir, outputs):
450450
File,
451451
MultiOutputFile,
452452
Directory,
453+
Path,
453454
int,
454455
float,
455456
bool,
@@ -458,7 +459,12 @@ def collect_additional_outputs(self, inputs, output_dir, outputs):
458459
]:
459460
raise Exception("not implemented (collect_additional_output)")
460461
# assuming that field should have either default or metadata, but not both
461-
if (
462+
input_value = getattr(inputs, fld.name, attr.NOTHING)
463+
if input_value is not attr.NOTHING:
464+
if fld.type in (File, MultiOutputFile, Directory, Path):
465+
input_value = Path(input_value).absolute()
466+
additional_out[fld.name] = input_value
467+
elif (
462468
fld.default is None or fld.default == attr.NOTHING
463469
) and not fld.metadata: # TODO: is it right?
464470
raise AttributeError("File has to have default value or metadata")

pydra/engine/tests/test_shelltask.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,58 @@ def test_shell_cmd_inputspec_9c(tmpdir, plugin, results_function):
14141414
assert res.output.file_copy.parent == shelly.output_dir
14151415

14161416

1417+
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
1418+
def test_shell_cmd_inputspec_9d(tmpdir, plugin, results_function):
1419+
"""
1420+
providing output name explicitly by manually setting value in input_spec
1421+
(instead of using default provided byoutput_file_template in metadata)
1422+
"""
1423+
cmd = "cp"
1424+
file = tmpdir.mkdir("data_inp").join("file.txt")
1425+
file.write("content\n")
1426+
1427+
my_input_spec = SpecInfo(
1428+
name="Input",
1429+
fields=[
1430+
(
1431+
"file_orig",
1432+
attr.ib(
1433+
type=File,
1434+
metadata={"position": 2, "help_string": "new file", "argstr": ""},
1435+
),
1436+
),
1437+
(
1438+
"file_copy",
1439+
attr.ib(
1440+
type=str,
1441+
metadata={
1442+
"output_file_template": "{file_orig}_copy",
1443+
"help_string": "output file",
1444+
"argstr": "",
1445+
},
1446+
),
1447+
),
1448+
],
1449+
bases=(ShellSpec,),
1450+
)
1451+
1452+
shelly = ShellCommandTask(
1453+
name="shelly",
1454+
executable=cmd,
1455+
input_spec=my_input_spec,
1456+
file_orig=file,
1457+
file_copy="my_file_copy.txt",
1458+
cache_dir=tmpdir,
1459+
)
1460+
1461+
res = results_function(shelly, plugin)
1462+
assert res.output.stdout == ""
1463+
assert res.output.file_copy.exists()
1464+
assert res.output.file_copy.name == "my_file_copy.txt"
1465+
# checking if it's created in a good place
1466+
assert shelly.output_dir == res.output.file_copy.parent
1467+
1468+
14171469
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
14181470
def test_shell_cmd_inputspec_10(plugin, results_function, tmpdir):
14191471
"""using input_spec, providing list of files as an input"""

0 commit comments

Comments
 (0)