Skip to content

Commit c032f87

Browse files
committed
fixing wildcard in outpute spec
1 parent 9176136 commit c032f87

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

pydra/engine/specs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import typing as ty
55
import inspect
66
import re
7+
from glob import glob
78

89
from .helpers_file import template_update_single
910

@@ -514,14 +515,13 @@ def _field_defaultvalue(self, fld, output_dir):
514515
default = Path(default)
515516

516517
default = output_dir / default
517-
518-
if "*" not in default.name:
518+
if "*" not in str(default):
519519
if default.exists():
520520
return default
521521
else:
522522
raise AttributeError(f"file {default} does not exist")
523523
else:
524-
all_files = list(Path(default.parent).expanduser().glob(default.name))
524+
all_files = [Path(el) for el in glob(str(default.expanduser()))]
525525
if len(all_files) > 1:
526526
return all_files
527527
elif len(all_files) == 1:

pydra/engine/tests/test_shelltask.py

+62-10
Original file line numberDiff line numberDiff line change
@@ -2585,6 +2585,58 @@ def test_shell_cmd_outputspec_3(plugin, results_function, tmpdir):
25852585

25862586
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
25872587
def test_shell_cmd_outputspec_4(plugin, results_function, tmpdir):
2588+
"""
2589+
customised output_spec, adding files to the output,
2590+
using a wildcard in default (in the directory name)
2591+
"""
2592+
cmd = ["mkdir", "tmp1", ";", "touch", "tmp1/newfile.txt"]
2593+
my_output_spec = SpecInfo(
2594+
name="Output",
2595+
fields=[("newfile", File, "tmp*/newfile.txt")],
2596+
bases=(ShellOutSpec,),
2597+
)
2598+
shelly = ShellCommandTask(
2599+
name="shelly", executable=cmd, output_spec=my_output_spec, cache_dir=tmpdir
2600+
)
2601+
2602+
res = results_function(shelly, plugin)
2603+
assert res.output.stdout == ""
2604+
assert res.output.newfile.exists()
2605+
2606+
2607+
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
2608+
def test_shell_cmd_outputspec_4a(plugin, results_function, tmpdir):
2609+
"""
2610+
customised output_spec, adding files to the output,
2611+
using a wildcard in default (in the directory name), should collect two files
2612+
"""
2613+
cmd = [
2614+
"mkdir",
2615+
"tmp1",
2616+
"tmp2",
2617+
";",
2618+
"touch",
2619+
"tmp1/newfile.txt",
2620+
"tmp2/newfile.txt",
2621+
]
2622+
my_output_spec = SpecInfo(
2623+
name="Output",
2624+
fields=[("newfile", File, "tmp*/newfile.txt")],
2625+
bases=(ShellOutSpec,),
2626+
)
2627+
shelly = ShellCommandTask(
2628+
name="shelly", executable=cmd, output_spec=my_output_spec, cache_dir=tmpdir
2629+
)
2630+
2631+
res = results_function(shelly, plugin)
2632+
assert res.output.stdout == ""
2633+
# newfile is a list
2634+
assert len(res.output.newfile) == 2
2635+
assert all([file.exists for file in res.output.newfile])
2636+
2637+
2638+
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
2639+
def test_shell_cmd_outputspec_5(plugin, results_function, tmpdir):
25882640
"""
25892641
customised output_spec, adding files to the output,
25902642
using a function to collect output, the function is saved in the field metadata
@@ -2613,7 +2665,7 @@ def gather_output(field, output_dir):
26132665

26142666

26152667
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
2616-
def test_shell_cmd_outputspec_4a(plugin, results_function):
2668+
def test_shell_cmd_outputspec_5a(plugin, results_function):
26172669
"""
26182670
customised output_spec, adding files to the output,
26192671
using a function to collect output, the function is saved in the field metadata
@@ -2639,7 +2691,7 @@ def gather_output(executable, output_dir):
26392691
assert all([file.exists for file in res.output.newfile])
26402692

26412693

2642-
def test_shell_cmd_outputspec_4b_error():
2694+
def test_shell_cmd_outputspec_5b_error():
26432695
"""
26442696
customised output_spec, adding files to the output,
26452697
using a function to collect output, the function is saved in the field metadata
@@ -2662,7 +2714,7 @@ def gather_output(executable, output_dir, ble):
26622714

26632715

26642716
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
2665-
def test_shell_cmd_outputspec_5(plugin, results_function, tmpdir):
2717+
def test_shell_cmd_outputspec_6(plugin, results_function, tmpdir):
26662718
"""
26672719
providing output name by providing output_file_template
26682720
(similar to the previous example, but not touching input_spec)
@@ -2700,7 +2752,7 @@ def test_shell_cmd_outputspec_5(plugin, results_function, tmpdir):
27002752
assert res.output.out1.exists()
27012753

27022754

2703-
def test_shell_cmd_outputspec_5a():
2755+
def test_shell_cmd_outputspec_6a():
27042756
"""
27052757
providing output name by providing output_file_template
27062758
(using shorter syntax)
@@ -2730,7 +2782,7 @@ def test_shell_cmd_outputspec_5a():
27302782

27312783

27322784
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
2733-
def test_shell_cmd_outputspec_6(tmpdir, plugin, results_function):
2785+
def test_shell_cmd_outputspec_7(tmpdir, plugin, results_function):
27342786
"""
27352787
providing output with output_file_name and using MultiOutputFile as a type.
27362788
the input field used in the template is a MultiInputObj, so it can be and is a list
@@ -2806,7 +2858,7 @@ def test_shell_cmd_outputspec_6(tmpdir, plugin, results_function):
28062858

28072859

28082860
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
2809-
def test_shell_cmd_outputspec_6a(tmpdir, plugin, results_function):
2861+
def test_shell_cmd_outputspec_7a(tmpdir, plugin, results_function):
28102862
"""
28112863
providing output with output_file_name and using MultiOutputFile as a type.
28122864
the input field used in the template is a MultiInputObj, but a single element is used
@@ -2881,7 +2933,7 @@ def test_shell_cmd_outputspec_6a(tmpdir, plugin, results_function):
28812933

28822934

28832935
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
2884-
def test_shell_cmd_outputspec_7a(tmpdir, plugin, results_function):
2936+
def test_shell_cmd_outputspec_8a(tmpdir, plugin, results_function):
28852937
"""
28862938
customised output_spec, adding int and str to the output,
28872939
requiring two callables with parameters stdout and stderr
@@ -2942,7 +2994,7 @@ def get_stderr(stderr):
29422994
assert res.output.stderr_field == f"stderr: {res.output.stderr}"
29432995

29442996

2945-
def test_shell_cmd_outputspec_7b_error():
2997+
def test_shell_cmd_outputspec_8b_error():
29462998
"""
29472999
customised output_spec, adding Int to the output,
29483000
requiring a function to collect output
@@ -2971,7 +3023,7 @@ def test_shell_cmd_outputspec_7b_error():
29713023

29723024

29733025
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
2974-
def test_shell_cmd_outputspec_7c(tmpdir, plugin, results_function):
3026+
def test_shell_cmd_outputspec_8c(tmpdir, plugin, results_function):
29753027
"""
29763028
customised output_spec, adding Directory to the output named by args
29773029
"""
@@ -3014,7 +3066,7 @@ def get_lowest_directory(directory_path):
30143066

30153067

30163068
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
3017-
def test_shell_cmd_outputspec_7d(tmpdir, plugin, results_function):
3069+
def test_shell_cmd_outputspec_8d(tmpdir, plugin, results_function):
30183070
"""
30193071
customised output_spec, adding Directory to the output named by input spec
30203072
"""

0 commit comments

Comments
 (0)