Skip to content

Commit b8d61d5

Browse files
committed
debugged test_dockertask
1 parent 5e2f897 commit b8d61d5

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

pydra/design/shell.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import typing as ty
55
import re
66
from collections import defaultdict
7-
import shlex
87
import inspect
98
from copy import copy
109
import attrs
@@ -23,7 +22,7 @@
2322
make_task_def,
2423
NO_DEFAULT,
2524
)
26-
from pydra.utils.typing import is_fileset_or_union, MultiInputObj
25+
from pydra.utils.typing import is_fileset_or_union, MultiInputObj, non_optional_type
2726

2827
if ty.TYPE_CHECKING:
2928
from pydra.engine.specs import ShellDef
@@ -108,6 +107,7 @@ def _validate_sep(self, _, sep):
108107
tp = ty.get_args(self.type)[0]
109108
else:
110109
tp = self.type
110+
tp = non_optional_type(tp)
111111
origin = ty.get_origin(tp) or tp
112112
if (
113113
inspect.isclass(origin)
@@ -522,7 +522,7 @@ def parse_command_line_template(
522522
if isinstance(template, list):
523523
tokens = template
524524
else:
525-
tokens = shlex.split(template)
525+
tokens = template.split()
526526
executable = []
527527
start_args_index = 0
528528
for part in tokens:
@@ -631,7 +631,9 @@ def from_type_str(type_str) -> type:
631631
kwds["default"] = attrs.Factory(list)
632632
elif "=" in name:
633633
name, default = name.split("=")
634-
kwds["default"] = eval(default)
634+
kwds["default"] = (
635+
default[1:-1] if re.match(r"('|\").*\1", default) else eval(default)
636+
)
635637
elif "$" in name:
636638
name, path_template = name.split("$")
637639
kwds["path_template"] = path_template

pydra/design/tests/test_shell.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def test_interface_template_more_complex():
162162

163163
Cp = shell.define(
164164
(
165-
"cp <in_fs_objects:fs-object,...> <out|out_dir:directory> "
165+
"cp <in_fs_objects:fs-object+> <out|out_dir:directory> "
166166
"-R<recursive> "
167167
"--text-arg <text_arg?> "
168168
"--int-arg <int_arg:int?> "
@@ -187,7 +187,9 @@ def test_interface_template_more_complex():
187187
help=shell.EXECUTABLE_HELP_STRING,
188188
),
189189
shell.arg(
190-
name="in_fs_objects", type=MultiInputObj[FsObject], position=1, sep=" "
190+
name="in_fs_objects",
191+
type=MultiInputObj[FsObject],
192+
position=1,
191193
),
192194
output,
193195
shell.arg(name="recursive", argstr="-R", type=bool, default=False, position=3),
@@ -209,6 +211,7 @@ def test_interface_template_more_complex():
209211
name="tuple_arg",
210212
argstr="--tuple-arg",
211213
type=tuple[int, str] | None,
214+
sep=" ",
212215
default=None,
213216
position=6,
214217
),
@@ -245,7 +248,7 @@ def test_interface_template_with_overrides_and_optionals():
245248

246249
Cp = shell.define(
247250
(
248-
"cp <in_fs_objects:fs-object,...> <out|out_dir:directory> <out|out_file:file?> "
251+
"cp <in_fs_objects:fs-object+> <out|out_dir:directory> <out|out_file:file?> "
249252
"-R<recursive> "
250253
"--text-arg <text_arg> "
251254
"--int-arg <int_arg:int?> "
@@ -283,9 +286,7 @@ def test_interface_template_with_overrides_and_optionals():
283286
position=0,
284287
help=shell.EXECUTABLE_HELP_STRING,
285288
),
286-
shell.arg(
287-
name="in_fs_objects", type=MultiInputObj[FsObject], position=1, sep=" "
288-
),
289+
shell.arg(name="in_fs_objects", type=MultiInputObj[FsObject], position=1),
289290
shell.arg(
290291
name="recursive",
291292
argstr="-R",
@@ -307,6 +308,7 @@ def test_interface_template_with_overrides_and_optionals():
307308
argstr="--tuple-arg",
308309
type=tuple[int, str],
309310
position=5,
311+
sep=" ",
310312
),
311313
] + outargs + [ShellDef.additional_args]
312314
assert sorted_fields(Cp.Outputs) == outargs + [
@@ -332,7 +334,7 @@ def test_interface_template_with_defaults():
332334

333335
Cp = shell.define(
334336
(
335-
"cp <in_fs_objects:fs-object,...> <out|out_dir:directory> "
337+
"cp <in_fs_objects:fs-object+> <out|out_dir:directory> "
336338
"-R<recursive=True> "
337339
"--text-arg <text_arg='foo'> "
338340
"--int-arg <int_arg:int=99> "
@@ -356,9 +358,7 @@ def test_interface_template_with_defaults():
356358
position=0,
357359
help=shell.EXECUTABLE_HELP_STRING,
358360
),
359-
shell.arg(
360-
name="in_fs_objects", type=MultiInputObj[FsObject], position=1, sep=" "
361-
),
361+
shell.arg(name="in_fs_objects", type=MultiInputObj[FsObject], position=1),
362362
output,
363363
shell.arg(name="recursive", argstr="-R", type=bool, default=True, position=3),
364364
shell.arg(
@@ -371,6 +371,7 @@ def test_interface_template_with_defaults():
371371
type=tuple[int, str],
372372
default=(1, "bar"),
373373
position=6,
374+
sep=" ",
374375
),
375376
ShellDef.additional_args,
376377
]
@@ -400,7 +401,7 @@ def test_interface_template_with_type_overrides():
400401

401402
Cp = shell.define(
402403
(
403-
"cp <in_fs_objects:fs-object,...> <out|out_dir:directory> "
404+
"cp <in_fs_objects:fs-object+> <out|out_dir:directory> "
404405
"-R<recursive> "
405406
"--text-arg <text_arg> "
406407
"--int-arg <int_arg> "
@@ -425,9 +426,7 @@ def test_interface_template_with_type_overrides():
425426
position=0,
426427
help=shell.EXECUTABLE_HELP_STRING,
427428
),
428-
shell.arg(
429-
name="in_fs_objects", type=MultiInputObj[FsObject], position=1, sep=" "
430-
),
429+
shell.arg(name="in_fs_objects", type=MultiInputObj[FsObject], position=1),
431430
output,
432431
shell.arg(name="recursive", argstr="-R", type=bool, default=False, position=3),
433432
shell.arg(name="text_arg", argstr="--text-arg", type=str, position=4),
@@ -443,6 +442,7 @@ def test_interface_template_with_type_overrides():
443442
argstr="--tuple-arg",
444443
type=tuple[int, str],
445444
position=6,
445+
sep=" ",
446446
),
447447
ShellDef.additional_args,
448448
]

pydra/engine/core.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,17 @@ def add(
773773
OutputType
774774
The outputs definition of the node
775775
"""
776+
from pydra.engine.environments import Native
777+
776778
if name is None:
777779
name = type(task_def).__name__
778780
if name in self._nodes:
779781
raise ValueError(f"Node with name {name!r} already exists in the workflow")
780-
if environment and task_def._task_type != "shell":
782+
if (
783+
environment
784+
and not isinstance(environment, Native)
785+
and task_def._task_type != "shell"
786+
):
781787
raise ValueError(
782788
"Environments can only be used with 'shell' tasks not "
783789
f"{task_def._task_type!r} tasks ({task_def!r})"

pydra/engine/tests/test_dockertask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def Workflow(file):
545545

546546
wf = Workflow().split(file=[file_1, file_2])
547547

548-
outputs = wf()
548+
outputs = wf(cache_dir=tmp_path)
549549

550550
assert outputs.out[0].strip() == "hello from pydra"
551551
assert outputs.out[1].strip() == "have a nice one"
@@ -589,5 +589,5 @@ def Workflow(file):
589589

590590
wf = Workflow().split(file=[str(file_1), str(file_2)])
591591

592-
outputs = wf()
592+
outputs = wf(cache_dir=tmp_path)
593593
assert outputs.out == ["hello from pydra", "have a nice one"]

pydra/engine/tests/test_singularity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class Outputs(ShellOutputs):
390390
help="output file",
391391
)
392392

393-
singu = Singu(orig_file=str(file))
393+
singu = Singu(orig_file=file)
394394

395395
outputs = singu(environment=Singularity(image=image), cache_dir=tmp_path)
396396
assert outputs.stdout == ""

0 commit comments

Comments
 (0)