Skip to content

Commit 5c2af82

Browse files
committed
renamed TaskDef to Task
1 parent 44041fe commit 5c2af82

29 files changed

+315
-335
lines changed

pydra/design/base.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727

2828

2929
if ty.TYPE_CHECKING:
30-
from pydra.engine.specs import TaskDef, TaskOutputs
30+
from pydra.engine.specs import Task, TaskOutputs
3131

3232

3333
__all__ = [
3434
"Field",
3535
"Arg",
3636
"Out",
3737
"ensure_field_objects",
38-
"make_task_def",
38+
"make_task",
3939
]
4040

4141

@@ -89,7 +89,7 @@ class Requirement:
8989
default=None, converter=allowed_values_converter
9090
)
9191

92-
def satisfied(self, inputs: "TaskDef") -> bool:
92+
def satisfied(self, inputs: "Task") -> bool:
9393
"""Check if the requirement is satisfied by the inputs"""
9494
value = getattr(inputs, self.name)
9595
field = {f.name: f for f in list_fields(inputs)}[self.name]
@@ -157,7 +157,7 @@ class RequirementSet:
157157
converter=requirements_converter,
158158
)
159159

160-
def satisfied(self, inputs: "TaskDef") -> bool:
160+
def satisfied(self, inputs: "Task") -> bool:
161161
"""Check if all the requirements are satisfied by the inputs"""
162162
return all(req.satisfied(inputs) for req in self.requirements)
163163

@@ -203,7 +203,7 @@ def requires_converter(
203203

204204
@attrs.define(kw_only=True)
205205
class Field:
206-
"""Base class for input and output fields to task definitions
206+
"""Base class for input and output fields to tasks
207207
208208
Parameters
209209
----------
@@ -245,7 +245,7 @@ class Field:
245245
validator: ty.Callable[..., bool] | None = None
246246
hash_eq: bool = False
247247

248-
def requirements_satisfied(self, inputs: "TaskDef") -> bool:
248+
def requirements_satisfied(self, inputs: "Task") -> bool:
249249
"""Check if all the requirements are satisfied by the inputs"""
250250
return any(req.satisfied(inputs) for req in self.requires)
251251

@@ -264,7 +264,7 @@ def _requires_validator(self, _, value):
264264

265265
@attrs.define(kw_only=True)
266266
class Arg(Field):
267-
"""Base class for input fields of task definitions
267+
"""Base class for input fields of tasks
268268
269269
Parameters
270270
----------
@@ -303,7 +303,7 @@ class Arg(Field):
303303

304304
@attrs.define(kw_only=True, slots=False)
305305
class Out(Field):
306-
"""Base class for output fields of task definitions
306+
"""Base class for output fields of tasks
307307
308308
Parameters
309309
----------
@@ -328,7 +328,7 @@ class Out(Field):
328328

329329

330330
def extract_fields_from_class(
331-
spec_type: type["TaskDef"],
331+
spec_type: type["Task"],
332332
outputs_type: type["TaskOutputs"],
333333
klass: type,
334334
arg_type: type[Arg],
@@ -436,8 +436,8 @@ def get_fields(klass, field_type, auto_attribs, helps) -> dict[str, Field]:
436436
return inputs, outputs
437437

438438

439-
def make_task_def(
440-
spec_type: type["TaskDef"],
439+
def make_task(
440+
spec_type: type["Task"],
441441
out_type: type["TaskOutputs"],
442442
inputs: dict[str, Arg],
443443
outputs: dict[str, Out],
@@ -447,7 +447,7 @@ def make_task_def(
447447
outputs_bases: ty.Sequence[type] = (),
448448
xor: ty.Sequence[str | None] | ty.Sequence[ty.Sequence[str | None]] = (),
449449
):
450-
"""Create a task definition class and its outputs definition class from the
450+
"""Create a task class and its outputs class from the
451451
input and output fields provided to the decorator/function.
452452
453453
Modifies the class so that its attributes are converted from pydra fields to attrs fields
@@ -467,9 +467,9 @@ def make_task_def(
467467
name : str, optional
468468
The name of the class, by default
469469
bases : ty.Sequence[type], optional
470-
The base classes for the task definition class, by default ()
470+
The base classes for the task class, by default ()
471471
outputs_bases : ty.Sequence[type], optional
472-
The base classes for the outputs definition class, by default ()
472+
The base classes for the outputs class, by default ()
473473
xor: Sequence[str | None] | Sequence[Sequence[str | None]], optional
474474
Names of args that are exclusive mutually exclusive, which must include
475475
the name of the current field. If this list includes None, then none of the
@@ -509,14 +509,14 @@ def make_task_def(
509509
if name is None:
510510
raise ValueError("name must be provided if klass is not")
511511
bases = tuple(bases)
512-
# Ensure that TaskDef is a base class
512+
# Ensure that Task is a base class
513513
if not any(issubclass(b, spec_type) for b in bases):
514514
bases = bases + (spec_type,)
515515
# If building from a decorated class (as opposed to dynamically from a function
516516
# or shell-template), add any base classes not already in the bases tuple
517517
if klass is not None:
518518
bases += tuple(c for c in klass.__mro__ if c not in bases + (object,))
519-
# Create a new class with the TaskDef as a base class
519+
# Create a new class with the Task as a base class
520520
klass = types.new_class(
521521
name=name,
522522
bases=bases,
@@ -580,7 +580,7 @@ def make_outputs_spec(
580580
bases: ty.Sequence[type],
581581
spec_name: str,
582582
) -> type["TaskOutputs"]:
583-
"""Create an outputs definition class and its outputs definition class from the
583+
"""Create an outputs class and its outputs class from the
584584
output fields provided to the decorator/function.
585585
586586
Creates a new class with attrs fields and then calls `attrs.define` to create an
@@ -591,9 +591,9 @@ def make_outputs_spec(
591591
outputs : dict[str, Out]
592592
The output fields of the task
593593
bases : ty.Sequence[type], optional
594-
The base classes for the outputs definition class, by default ()
594+
The base classes for the outputs class, by default ()
595595
spec_name : str
596-
The name of the task definition class the outputs are for
596+
The name of the task class the outputs are for
597597
598598
Returns
599599
-------

pydra/design/python.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Arg,
77
Out,
88
ensure_field_objects,
9-
make_task_def,
9+
make_task,
1010
parse_doc_string,
1111
extract_function_inputs_and_outputs,
1212
check_explicit_fields_are_none,
@@ -21,7 +21,7 @@
2121

2222
@attrs.define
2323
class arg(Arg):
24-
"""Argument of a Python task definition
24+
"""Argument of a Python task
2525
2626
Parameters
2727
----------
@@ -56,7 +56,7 @@ class arg(Arg):
5656

5757
@attrs.define
5858
class out(Out):
59-
"""Output of a Python task definition
59+
"""Output of a Python task
6060
6161
Parameters
6262
----------
@@ -125,7 +125,7 @@ def define(
125125
Returns
126126
-------
127127
PythonTask
128-
The task definition class for the Python function
128+
The task class for the Python function
129129
"""
130130
from pydra.engine.specs import PythonTask, PythonOutputs
131131

@@ -175,7 +175,7 @@ def make(wrapped: ty.Callable | type) -> PythonTask:
175175
name="function", type=ty.Callable, default=function, hash_eq=True
176176
)
177177

178-
defn = make_task_def(
178+
defn = make_task(
179179
PythonTask,
180180
PythonOutputs,
181181
parsed_inputs,

pydra/design/shell.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
check_explicit_fields_are_none,
2121
extract_fields_from_class,
2222
ensure_field_objects,
23-
make_task_def,
23+
make_task,
2424
NO_DEFAULT,
2525
)
2626
from pydra.utils.typing import (
@@ -257,8 +257,8 @@ def define(
257257
name: str | None = None,
258258
xor: ty.Sequence[str | None] | ty.Sequence[ty.Sequence[str | None]] = (),
259259
) -> "ShellTask":
260-
"""Create a task definition for a shell command. Can be used either as a decorator on
261-
the "canonical" dataclass-form of a task definition or as a function that takes a
260+
"""Create a task for a shell command. Can be used either as a decorator on
261+
the "canonical" dataclass-form of a task or as a function that takes a
262262
"shell-command template string" of the form
263263
264264
```
@@ -430,7 +430,7 @@ def make(
430430
outpt.callable = GlobCallable(outpt.default)
431431
outpt.default = NO_DEFAULT
432432

433-
defn = make_task_def(
433+
defn = make_task(
434434
ShellTask,
435435
ShellOutputs,
436436
parsed_inputs,

pydra/design/tests/test_python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def func(a: int) -> float:
2626
python.arg(name="function", type=ty.Callable, hash_eq=True, default=func),
2727
]
2828
assert outputs == [python.out(name="out", type=float)]
29-
definition = SampleDef(a=1)
30-
outputs = definition(cache_dir=tmp_path)
29+
task = SampleDef(a=1)
30+
outputs = task(cache_dir=tmp_path)
3131
assert outputs.out == 2.0
3232
with pytest.raises(TypeError):
3333
SampleDef(a=1.5)

pydra/design/tests/test_workflow.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def MyTestWorkflow(a, b):
5252
constructor = MyTestWorkflow().constructor
5353
assert constructor.__name__ == "MyTestWorkflow"
5454

55-
# The constructor function is included as a part of the definition so it is
55+
# The constructor function is included as a part of the task so it is
5656
# included in the hash by default and can be overridden if needed. Not 100% sure
5757
# if this is a good idea or not
5858
assert list_fields(MyTestWorkflow) == [
@@ -143,7 +143,7 @@ def MyTestShellWorkflow(
143143

144144

145145
def test_workflow_canonical():
146-
"""Test class-based workflow definition"""
146+
"""Test class-based workflow task"""
147147

148148
# NB: We use PascalCase (i.e. class names) as it is translated into a class
149149

@@ -169,7 +169,7 @@ class Outputs(WorkflowOutputs):
169169
constructor = MyTestWorkflow().constructor
170170
assert constructor.__name__ == "constructor"
171171

172-
# The constructor function is included as a part of the definition so it is
172+
# The constructor function is included as a part of the task so it is
173173
# included in the hash by default and can be overridden if needed. Not 100% sure
174174
# if this is a good idea or not
175175
assert sorted(list_fields(MyTestWorkflow), key=attrgetter("name")) == [
@@ -236,7 +236,7 @@ def MyTestShellWorkflow(
236236
input_video=LazyOutField(node=mock_node, field="a_video", type=video.Mp4),
237237
watermark=LazyOutField(node=mock_node, field="a_watermark", type=image.Png),
238238
)
239-
Workflow.clear_cache(definition=MyTestShellWorkflow)
239+
Workflow.clear_cache(task=MyTestShellWorkflow)
240240
wf = Workflow.construct(workflow_spec)
241241
assert wf["add_watermark"].inputs.in_video == LazyInField(
242242
workflow=wf, field="input_video", type=video.Mp4, type_checked=True
@@ -458,7 +458,7 @@ def MyTestWorkflow(a: int, b: float, c: float) -> float:
458458
node=wf["NestedWorkflow"], field="out", type=float, type_checked=True
459459
)
460460
assert list(wf.node_names) == ["Divide", "NestedWorkflow"]
461-
nwf_spec = copy(wf["NestedWorkflow"]._definition)
461+
nwf_spec = copy(wf["NestedWorkflow"]._task)
462462
nwf_spec.a = 100.0
463463
nwf = Workflow.construct(nwf_spec)
464464
nwf.inputs.a == 100.0

pydra/design/workflow.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Arg,
77
Out,
88
ensure_field_objects,
9-
make_task_def,
9+
make_task,
1010
parse_doc_string,
1111
extract_function_inputs_and_outputs,
1212
check_explicit_fields_are_none,
@@ -15,7 +15,7 @@
1515

1616
if ty.TYPE_CHECKING:
1717
from pydra.engine.core import Workflow
18-
from pydra.engine.specs import TaskDef, TaskOutputs, WorkflowTask
18+
from pydra.engine.specs import Task, TaskOutputs, WorkflowTask
1919
from pydra.engine.environments import Environment
2020
from pydra.engine.specs import TaskHooks
2121

@@ -25,7 +25,7 @@
2525

2626
@attrs.define
2727
class arg(Arg):
28-
"""Argument of a workflow task definition
28+
"""Argument of a workflow task
2929
3030
Parameters
3131
----------
@@ -63,7 +63,7 @@ class arg(Arg):
6363

6464
@attrs.define
6565
class out(Out):
66-
"""Output of a workflow task definition
66+
"""Output of a workflow task
6767
6868
Parameters
6969
----------
@@ -111,7 +111,7 @@ def define(
111111
) -> "WorkflowTask":
112112
"""
113113
Create an interface for a function or a class. Can be used either as a decorator on
114-
a constructor function or the "canonical" dataclass-form of a task definition.
114+
a constructor function or the "canonical" dataclass-form of a task.
115115
116116
Parameters
117117
----------
@@ -130,15 +130,15 @@ def define(
130130
131131
Returns
132132
-------
133-
TaskDef
133+
Task
134134
The interface for the function or class.
135135
"""
136-
from pydra.engine.specs import TaskDef, WorkflowTask, WorkflowOutputs
136+
from pydra.engine.specs import Task, WorkflowTask, WorkflowOutputs
137137

138138
if lazy is None:
139139
lazy = []
140140

141-
def make(wrapped: ty.Callable | type) -> TaskDef:
141+
def make(wrapped: ty.Callable | type) -> Task:
142142
if inspect.isclass(wrapped):
143143
klass = wrapped
144144
constructor = klass.constructor
@@ -187,7 +187,7 @@ def make(wrapped: ty.Callable | type) -> TaskDef:
187187
for inpt_name in lazy:
188188
parsed_inputs[inpt_name].lazy = True
189189

190-
defn = make_task_def(
190+
defn = make_task(
191191
WorkflowTask,
192192
WorkflowOutputs,
193193
parsed_inputs,
@@ -225,7 +225,7 @@ def this() -> "Workflow":
225225

226226

227227
def add(
228-
task_def: "TaskDef[OutputsType]",
228+
task: "Task[OutputsType]",
229229
name: str | None = None,
230230
environment: "Environment | None" = None,
231231
hooks: "TaskHooks | None" = None,
@@ -234,10 +234,10 @@ def add(
234234
235235
Parameters
236236
----------
237-
task_def : TaskDef
237+
task : Task
238238
The definition of the task to add to the workflow as a node
239239
name : str, optional
240-
The name of the node, by default it will be the name of the task definition
240+
The name of the node, by default it will be the name of the task
241241
class
242242
environment : Environment, optional
243243
The environment to run the task in, such as the Docker or Singularity container,
@@ -248,9 +248,9 @@ def add(
248248
Returns
249249
-------
250250
Outputs
251-
The outputs definition of the node
251+
The outputs of the node
252252
"""
253-
return this().add(task_def, name=name, environment=environment, hooks=hooks)
253+
return this().add(task, name=name, environment=environment, hooks=hooks)
254254

255255

256256
U = ty.TypeVar("U")

0 commit comments

Comments
 (0)