Skip to content

Commit 69b72c9

Browse files
committed
debugging workflow and shell architecture refactoring
1 parent f639b21 commit 69b72c9

File tree

14 files changed

+656
-553
lines changed

14 files changed

+656
-553
lines changed

new-docs/source/tutorial/tst.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
from pathlib import Path
22
from tempfile import mkdtemp
3-
from fileformats.medimage import Nifti
3+
import shutil
4+
from fileformats.medimage import Nifti1
45
from pydra.tasks.mrtrix3.v3_0 import MrGrid
6+
from pydra.utils import user_cache_dir
57

68

79
if __name__ == "__main__":
810
test_dir = Path(mkdtemp())
911

12+
shutil.rmtree(user_cache_dir / "run-cache", ignore_errors=True)
13+
1014
nifti_dir = test_dir / "nifti"
1115
nifti_dir.mkdir()
1216

1317
for i in range(10):
14-
Nifti.sample(
18+
Nifti1.sample(
1519
nifti_dir, seed=i
1620
) # Create a dummy NIfTI file in the dest. directory
1721

1822
# Instantiate the task definition, "splitting" over all NIfTI files in the test directory
1923
# by splitting the "input" input field over all files in the directory
20-
mrgrid = MrGrid(voxel=(0.5, 0.5, 0.5)).split(input=nifti_dir.iterdir())
24+
mrgrid = MrGrid(voxel=(0.5, 0.5, 0.5)).split(in_file=nifti_dir.iterdir())
2125

2226
# Run the task to resample all NIfTI files
23-
outputs = mrgrid()
27+
outputs = mrgrid(worker="serial")
2428

2529
# Print the locations of the output files
26-
print("\n".join(str(p) for p in outputs.output))
30+
print("\n".join(str(p) for p in outputs.outputs))

new-docs/tst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
result = load_json(plugin="serial")
1212

1313
# Print the output interface of the of the task (LoadJson.Outputs)
14-
print(result.output)
14+
print(result.outputs)

pydra/design/base.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ def make_task_def(
388388
klass : type
389389
The class created using the attrs package
390390
"""
391-
from pydra.engine.specs import TaskDef
391+
from pydra.engine.specs import TaskDef, WorkflowDef
392+
from pydra.engine.core import Task, WorkflowTask
392393

393394
spec_type._check_arg_refs(inputs, outputs)
394395

@@ -399,6 +400,7 @@ def make_task_def(
399400
f"{reserved_names} are reserved and cannot be used for {spec_type} field names"
400401
)
401402
outputs_klass = make_outputs_spec(out_type, outputs, outputs_bases, name)
403+
task_type = WorkflowTask if issubclass(spec_type, WorkflowDef) else Task
402404
if klass is None or not issubclass(klass, spec_type):
403405
if name is None:
404406
raise ValueError("name must be provided if klass is not")
@@ -417,13 +419,19 @@ def make_task_def(
417419
name=name,
418420
bases=bases,
419421
kwds={},
420-
exec_body=lambda ns: ns.update({"Outputs": outputs_klass}),
422+
exec_body=lambda ns: ns.update(
423+
{
424+
"Outputs": outputs_klass,
425+
"Task": task_type,
426+
}
427+
),
421428
)
422429
else:
423430
# Ensure that the class has it's own annotations dict so we can modify it without
424431
# messing up other classes
425432
klass.__annotations__ = copy(klass.__annotations__)
426433
klass.Outputs = outputs_klass
434+
klass.Task = task_type
427435
# Now that we have saved the attributes in lists to be
428436
for arg in inputs.values():
429437
# If an outarg input then the field type should be Path not a FileSet
@@ -769,7 +777,11 @@ def extract_function_inputs_and_outputs(
769777
type_hints = ty.get_type_hints(function)
770778
input_types = {}
771779
input_defaults = {}
780+
has_varargs = False
772781
for p in sig.parameters.values():
782+
if p.kind is p.VAR_POSITIONAL or p.kind is p.VAR_KEYWORD:
783+
has_varargs = True
784+
continue
773785
input_types[p.name] = type_hints.get(p.name, ty.Any)
774786
if p.default is not inspect.Parameter.empty:
775787
input_defaults[p.name] = p.default
@@ -779,11 +791,12 @@ def extract_function_inputs_and_outputs(
779791
f"Input names ({inputs}) should not be provided when "
780792
"wrapping/decorating a function as "
781793
)
782-
if unrecognised := set(inputs) - set(input_types):
783-
raise ValueError(
784-
f"Unrecognised input names ({unrecognised}) not present in the signature "
785-
f"of the function {function!r}"
786-
)
794+
if not has_varargs:
795+
if unrecognised := set(inputs) - set(input_types):
796+
raise ValueError(
797+
f"Unrecognised input names ({unrecognised}) not present in the signature "
798+
f"of the function {function!r}"
799+
)
787800
for inpt_name, type_ in input_types.items():
788801
try:
789802
inpt = inputs[inpt_name]

pydra/design/workflow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def make(wrapped: ty.Callable | type) -> TaskDef:
170170
for inpt_name in lazy:
171171
parsed_inputs[inpt_name].lazy = True
172172

173-
interface = make_task_def(
173+
defn = make_task_def(
174174
WorkflowDef,
175175
WorkflowOutputs,
176176
parsed_inputs,
@@ -181,7 +181,7 @@ def make(wrapped: ty.Callable | type) -> TaskDef:
181181
outputs_bases=outputs_bases,
182182
)
183183

184-
return interface
184+
return defn
185185

186186
if wrapped is not None:
187187
if not isinstance(wrapped, (ty.Callable, type)):
@@ -198,7 +198,7 @@ def this() -> "Workflow":
198198
Workflow
199199
The workflow currently being constructed.
200200
"""
201-
from pydra.engine.workflow.base import Workflow
201+
from pydra.engine.core import Workflow
202202

203203
return Workflow.under_construction
204204

0 commit comments

Comments
 (0)