|
6 | 6 | "source": [ |
7 | 7 | "# Canonical task form\n", |
8 | 8 | "\n", |
9 | | - "Under the hood, all Python, shell and workflow task definitions generated by the\n", |
| 9 | + "Under the hood, all Python, shell and workflow tasks generated by the\n", |
10 | 10 | "`pydra.design.*.define` decorators/functions are translated to\n", |
11 | 11 | "[dataclasses](https://docs.python.org/3/library/dataclasses.html) by the\n", |
12 | 12 | "[Attrs](https://www.attrs.org/en/stable/). While the more compact syntax described\n", |
13 | 13 | "in the [Python-tasks](./4-python.html), [Shell-tasks](./5-shell.html) and [Workflow](./6-workflow.html)\n", |
14 | 14 | "tutorials is convenient when designing tasks for specific use cases, it is too magical\n", |
15 | | - "for linters follow. Therefore, when designing task definitions to be used by third\n", |
| 15 | + "for linters follow. Therefore, when designing tasks to be used by third\n", |
16 | 16 | "parties (e.g. `pydra-fsl`, `pydra-ants`) it is recommended to favour the, more\n", |
17 | 17 | "explicit, \"canonical\" dataclass form.\n", |
18 | 18 | "\n", |
|
26 | 26 | "cell_type": "markdown", |
27 | 27 | "metadata": {}, |
28 | 28 | "source": [ |
29 | | - "## Python-task definitions\n", |
| 29 | + "## Python-tasks\n", |
30 | 30 | "\n", |
31 | 31 | "Python tasks in dataclass form are decorated by `pydra.design.python.define`\n", |
32 | 32 | "with inputs listed as type annotations. Outputs are similarly defined in a nested class\n", |
33 | 33 | "called `Outputs`. The function to be executed should be a staticmethod called `function`.\n", |
34 | 34 | "Default values can also be set directly, as with Attrs classes.\n", |
35 | 35 | "\n", |
36 | 36 | "In order to allow static type-checkers to check the type of outputs of tasks added\n", |
37 | | - "to workflows, it is also necessary to explicitly extend from the `pydra.engine.specs.PythonDef`\n", |
| 37 | + "to workflows, it is also necessary to explicitly extend from the `pydra.engine.specs.PythonTask`\n", |
38 | 38 | "and `pydra.engine.specs.PythonOutputs` classes (they are otherwise set as bases by the\n", |
39 | | - "`define` method implicitly). Thus the \"canonical form\" of Python task definition is as\n", |
| 39 | + "`define` method implicitly). Thus the \"canonical form\" of Python task is as\n", |
40 | 40 | "follows" |
41 | 41 | ] |
42 | 42 | }, |
|
48 | 48 | "source": [ |
49 | 49 | "from pprint import pprint\n", |
50 | 50 | "from pydra.engine.helpers import fields_dict\n", |
51 | | - "from pydra.engine.specs import PythonDef, PythonOutputs\n", |
| 51 | + "from pydra.engine.specs import PythonTask, PythonOutputs\n", |
52 | 52 | "from pydra.design import python\n", |
53 | 53 | "\n", |
54 | 54 | "\n", |
55 | 55 | "@python.define\n", |
56 | | - "class CanonicalPythonDef(PythonDef[\"CanonicalPythonDef.Outputs\"]):\n", |
57 | | - " \"\"\"Canonical Python task definition class for testing\n", |
| 56 | + "class CanonicalPythonTask(PythonTask[\"CanonicalPythonTask.Outputs\"]):\n", |
| 57 | + " \"\"\"Canonical Python task class for testing\n", |
58 | 58 | "\n", |
59 | 59 | " Args:\n", |
60 | 60 | " a: First input\n", |
|
80 | 80 | " return a + b, a / b\n", |
81 | 81 | "\n", |
82 | 82 | "\n", |
83 | | - "pprint(fields_dict(CanonicalPythonDef))\n", |
84 | | - "pprint(fields_dict(CanonicalPythonDef.Outputs))" |
| 83 | + "pprint(fields_dict(CanonicalPythonTask))\n", |
| 84 | + "pprint(fields_dict(CanonicalPythonTask.Outputs))" |
85 | 85 | ] |
86 | 86 | }, |
87 | 87 | { |
|
102 | 102 | "\n", |
103 | 103 | "\n", |
104 | 104 | "@python.define\n", |
105 | | - "class CanonicalPythonDef(PythonDef[\"CanonicalPythonDef.Outputs\"]):\n", |
106 | | - " \"\"\"Canonical Python task definition class for testing\n", |
| 105 | + "class CanonicalPythonTask(PythonTask[\"CanonicalPythonTask.Outputs\"]):\n", |
| 106 | + " \"\"\"Canonical Python task class for testing\n", |
107 | 107 | "\n", |
108 | 108 | " Args:\n", |
109 | 109 | " a: First input\n", |
|
129 | 129 | " return a + b, a / b\n", |
130 | 130 | "\n", |
131 | 131 | "\n", |
132 | | - "pprint(fields_dict(CanonicalPythonDef))\n", |
133 | | - "pprint(fields_dict(CanonicalPythonDef.Outputs))" |
| 132 | + "pprint(fields_dict(CanonicalPythonTask))\n", |
| 133 | + "pprint(fields_dict(CanonicalPythonTask.Outputs))" |
134 | 134 | ] |
135 | 135 | }, |
136 | 136 | { |
137 | 137 | "cell_type": "markdown", |
138 | 138 | "metadata": {}, |
139 | 139 | "source": [ |
140 | | - "## Shell-task definitions\n", |
| 140 | + "## Shell-tasks\n", |
141 | 141 | "\n", |
142 | 142 | "The canonical form of shell tasks is the same as for Python tasks, except a string `executable`\n", |
143 | 143 | "attribute replaces the `function` staticmethod." |
|
153 | 153 | "from pathlib import Path\n", |
154 | 154 | "from fileformats import generic\n", |
155 | 155 | "from pydra.design import shell\n", |
156 | | - "from pydra.engine.specs import ShellDef, ShellOutputs\n", |
| 156 | + "from pydra.engine.specs import ShellTask, ShellOutputs\n", |
157 | 157 | "from pydra.utils.typing import MultiInputObj\n", |
158 | 158 | "\n", |
159 | 159 | "\n", |
160 | 160 | "@shell.define\n", |
161 | | - "class CpWithSize(ShellDef[\"CpWithSize.Outputs\"]):\n", |
| 161 | + "class CpWithSize(ShellTask[\"CpWithSize.Outputs\"]):\n", |
162 | 162 | "\n", |
163 | 163 | " executable = \"cp\"\n", |
164 | 164 | "\n", |
|
201 | 201 | "outputs": [], |
202 | 202 | "source": [ |
203 | 203 | "from pydra.design import python, workflow\n", |
204 | | - "from pydra.engine.specs import WorkflowDef, WorkflowOutputs\n", |
| 204 | + "from pydra.engine.specs import WorkflowTask, WorkflowOutputs\n", |
205 | 205 | "\n", |
206 | 206 | "\n", |
207 | | - "# Example python task definitions\n", |
| 207 | + "# Example python tasks\n", |
208 | 208 | "@python.define\n", |
209 | 209 | "def Add(a, b):\n", |
210 | 210 | " return a + b\n", |
|
216 | 216 | "\n", |
217 | 217 | "\n", |
218 | 218 | "@workflow.define\n", |
219 | | - "class CanonicalWorkflowDef(WorkflowDef[\"CanonicalWorkflowDef.Outputs\"]):\n", |
| 219 | + "class CanonicalWorkflowTask(WorkflowTask[\"CanonicalWorkflowTask.Outputs\"]):\n", |
220 | 220 | "\n", |
221 | 221 | " @staticmethod\n", |
222 | 222 | " def a_converter(value):\n", |
|
0 commit comments