runnable 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
runnable/__init__.py CHANGED
@@ -24,7 +24,18 @@ from runnable.interaction import (
24
24
  set_parameter,
25
25
  track_this,
26
26
  ) # noqa
27
- from runnable.sdk import Stub, Pipeline, Task, Parallel, Map, Catalog, Success, Fail # noqa
27
+ from runnable.sdk import (
28
+ Stub,
29
+ Pipeline,
30
+ Parallel,
31
+ Map,
32
+ Catalog,
33
+ Success,
34
+ Fail,
35
+ PythonTask,
36
+ NotebookTask,
37
+ ShellTask,
38
+ ) # noqa
28
39
 
29
40
 
30
41
  # TODO: Think of model registry as a central place to store models.
runnable/sdk.py CHANGED
@@ -3,9 +3,9 @@ from __future__ import annotations
3
3
  import logging
4
4
  import os
5
5
  from abc import ABC, abstractmethod
6
- from typing import Any, Dict, List, Optional, Union
6
+ from typing import Any, Callable, Dict, List, Optional, Union
7
7
 
8
- from pydantic import BaseModel, ConfigDict, Field, PrivateAttr, computed_field, field_validator, model_validator
8
+ from pydantic import BaseModel, ConfigDict, Field, PrivateAttr, computed_field, model_validator
9
9
  from rich import print
10
10
  from typing_extensions import Self
11
11
 
@@ -15,11 +15,8 @@ from runnable.nodes import TraversalNode
15
15
 
16
16
  logger = logging.getLogger(defaults.LOGGER_NAME)
17
17
 
18
- StepType = Union["Stub", "Task", "Success", "Fail", "Parallel", "Map"]
19
- TraversalTypes = Union["Stub", "Task", "Parallel", "Map"]
20
-
21
-
22
- ALLOWED_COMMAND_TYPES = ["shell", "python", "notebook"]
18
+ StepType = Union["Stub", "PythonTask", "NotebookTask", "ShellTask", "Success", "Fail", "Parallel", "Map"]
19
+ TraversalTypes = Union["Stub", "PythonTask", "NotebookTask", "ShellTask", "Parallel", "Map"]
23
20
 
24
21
 
25
22
  class Catalog(BaseModel):
@@ -106,10 +103,7 @@ class BaseTraversal(ABC, BaseModel):
106
103
  ...
107
104
 
108
105
 
109
- ## TODO: Add python task, shell task, and notebook task.
110
-
111
-
112
- class Task(BaseTraversal):
106
+ class BaseTask(BaseTraversal):
113
107
  """
114
108
  An execution node of the pipeline.
115
109
  Please refer to [concepts](concepts/task.md) for more information.
@@ -157,41 +151,166 @@ class Task(BaseTraversal):
157
151
 
158
152
  """
159
153
 
160
- command: str = Field(alias="command")
161
- command_type: str = Field(default="python")
162
154
  catalog: Optional[Catalog] = Field(default=None, alias="catalog")
163
155
  overrides: Dict[str, Any] = Field(default_factory=dict, alias="overrides")
164
156
 
157
+ def create_node(self) -> TaskNode:
158
+ if not self.next_node:
159
+ if not (self.terminate_with_failure or self.terminate_with_success):
160
+ raise AssertionError("A node not being terminated must have a user defined next node")
161
+
162
+ print(self.model_dump(exclude_none=True))
163
+ return TaskNode.parse_from_config(self.model_dump(exclude_none=True))
164
+
165
+
166
+ class PythonTask(BaseTask):
167
+ """
168
+ An execution node of the pipeline of python functions.
169
+ Please refer to [concepts](concepts/task.md) for more information.
170
+
171
+ Attributes:
172
+ name (str): The name of the node.
173
+ function (callable): The function to execute.
174
+ catalog (Optional[Catalog]): The catalog to sync data from/to.
175
+ Please see Catalog about the structure of the catalog.
176
+ overrides (Dict[str, Any]): Any overrides to the command.
177
+ Individual tasks can override the global configuration config by referring to the
178
+ specific override.
179
+
180
+ For example,
181
+ ### Global configuration
182
+ ```yaml
183
+ executor:
184
+ type: local-container
185
+ config:
186
+ docker_image: "runnable/runnable:latest"
187
+ overrides:
188
+ custom_docker_image:
189
+ docker_image: "runnable/runnable:custom"
190
+ ```
191
+ ### Task specific configuration
192
+ ```python
193
+ task = PythonTask(name="task", function="function'",
194
+ overrides={'local-container': custom_docker_image})
195
+ ```
196
+
197
+ terminate_with_failure (bool): Whether to terminate the pipeline with a failure after this node.
198
+ terminate_with_success (bool): Whether to terminate the pipeline with a success after this node.
199
+ on_failure (str): The name of the node to execute if the step fails.
200
+
201
+ """
202
+
203
+ function: Callable = Field(exclude=True)
204
+
205
+ @computed_field
206
+ def command_type(self) -> str:
207
+ return "python"
208
+
209
+ @computed_field
210
+ def command(self) -> str:
211
+ module = self.function.__module__
212
+ name = self.function.__name__
213
+
214
+ return f"{module}.{name}"
215
+
216
+
217
+ class NotebookTask(BaseTask):
218
+ """
219
+ An execution node of the pipeline of type notebook.
220
+ Please refer to [concepts](concepts/task.md) for more information.
221
+
222
+ Attributes:
223
+ name (str): The name of the node.
224
+ notebook: The path to the notebook
225
+ catalog (Optional[Catalog]): The catalog to sync data from/to.
226
+ Please see Catalog about the structure of the catalog.
227
+ returns: A list of the names of variables to return from the notebook.
228
+ overrides (Dict[str, Any]): Any overrides to the command.
229
+ Individual tasks can override the global configuration config by referring to the
230
+ specific override.
231
+
232
+ For example,
233
+ ### Global configuration
234
+ ```yaml
235
+ executor:
236
+ type: local-container
237
+ config:
238
+ docker_image: "runnable/runnable:latest"
239
+ overrides:
240
+ custom_docker_image:
241
+ docker_image: "runnable/runnable:custom"
242
+ ```
243
+ ### Task specific configuration
244
+ ```python
245
+ task = NotebookTask(name="task", notebook="evaluation.ipynb",
246
+ overrides={'local-container': custom_docker_image})
247
+ ```
248
+ notebook_output_path (Optional[str]): The path to save the notebook output.
249
+ Only used when command_type is 'notebook', defaults to command+_out.ipynb
250
+ optional_ploomber_args (Optional[Dict[str, Any]]): Any optional ploomber args.
251
+ Only used when command_type is 'notebook', defaults to {}
252
+
253
+ terminate_with_failure (bool): Whether to terminate the pipeline with a failure after this node.
254
+ terminate_with_success (bool): Whether to terminate the pipeline with a success after this node.
255
+ on_failure (str): The name of the node to execute if the step fails.
256
+
257
+ """
258
+
259
+ notebook: str = Field(alias="command")
260
+
165
261
  notebook_output_path: Optional[str] = Field(default=None, alias="notebook_output_path")
166
262
  optional_ploomber_args: Optional[Dict[str, Any]] = Field(default=None, alias="optional_ploomber_args")
167
- output_cell_tag: Optional[str] = Field(default=None, alias="output_cell_tag")
263
+ returns: List[str] = Field(default_factory=list, alias="returns")
168
264
 
169
- @field_validator("command_type", mode="before")
170
- @classmethod
171
- def validate_command_type(cls, value: str) -> str:
172
- if value not in ALLOWED_COMMAND_TYPES:
173
- raise ValueError(f"Invalid command_type: {value}")
174
- return value
265
+ @computed_field
266
+ def command_type(self) -> str:
267
+ return "notebook"
175
268
 
176
- @model_validator(mode="after")
177
- def check_notebook_args(self) -> "Task":
178
- if self.command_type != "notebook":
179
- assert (
180
- self.notebook_output_path is None
181
- ), "Only command_types of 'notebook' can be used with notebook_output_path"
182
269
 
183
- assert (
184
- self.optional_ploomber_args is None
185
- ), "Only command_types of 'notebook' can be used with optional_ploomber_args"
270
+ class ShellTask(BaseTask):
271
+ """
272
+ An execution node of the pipeline of type shell.
273
+ Please refer to [concepts](concepts/task.md) for more information.
186
274
 
187
- assert self.output_cell_tag is None, "Only command_types of 'notebook' can be used with output_cell_tag"
188
- return self
275
+ Attributes:
276
+ name (str): The name of the node.
277
+ command: The shell command to execute.
278
+ catalog (Optional[Catalog]): The catalog to sync data from/to.
279
+ Please see Catalog about the structure of the catalog.
280
+ returns: A list of the names of variables to capture from environment variables of shell.
281
+ overrides (Dict[str, Any]): Any overrides to the command.
282
+ Individual tasks can override the global configuration config by referring to the
283
+ specific override.
189
284
 
190
- def create_node(self) -> TaskNode:
191
- if not self.next_node:
192
- if not (self.terminate_with_failure or self.terminate_with_success):
193
- raise AssertionError("A node not being terminated must have a user defined next node")
194
- return TaskNode.parse_from_config(self.model_dump(exclude_none=True))
285
+ For example,
286
+ ### Global configuration
287
+ ```yaml
288
+ executor:
289
+ type: local-container
290
+ config:
291
+ docker_image: "runnable/runnable:latest"
292
+ overrides:
293
+ custom_docker_image:
294
+ docker_image: "runnable/runnable:custom"
295
+ ```
296
+ ### Task specific configuration
297
+ ```python
298
+ task = ShellTask(name="task", command="exit 0",
299
+ overrides={'local-container': custom_docker_image})
300
+ ```
301
+
302
+ terminate_with_failure (bool): Whether to terminate the pipeline with a failure after this node.
303
+ terminate_with_success (bool): Whether to terminate the pipeline with a success after this node.
304
+ on_failure (str): The name of the node to execute if the step fails.
305
+
306
+ """
307
+
308
+ command: str = Field(alias="command")
309
+ returns: List[str] = Field(default_factory=list, alias="returns")
310
+
311
+ @computed_field
312
+ def command_type(self) -> str:
313
+ return "shell"
195
314
 
196
315
 
197
316
  class Stub(BaseTraversal):
@@ -343,7 +462,8 @@ class Pipeline(BaseModel):
343
462
  A Pipeline is a directed acyclic graph of Steps that define a workflow.
344
463
 
345
464
  Attributes:
346
- steps (List[Stub | Task | Parallel | Map | Success | Fail]): A list of Steps that make up the Pipeline.
465
+ steps (List[Stub | PythonTask | NotebookTask | ShellTask | Parallel | Map | Success | Fail]):
466
+ A list of Steps that make up the Pipeline.
347
467
  start_at (Stub | Task | Parallel | Map): The name of the first Step in the Pipeline.
348
468
  name (str, optional): The name of the Pipeline. Defaults to "".
349
469
  description (str, optional): A description of the Pipeline. Defaults to "".
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: runnable
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: A Compute agnostic pipelining software
5
5
  Home-page: https://github.com/vijayvammi/runnable
6
6
  License: Apache-2.0
@@ -1,4 +1,4 @@
1
- runnable/__init__.py,sha256=6xTnI7ff5AT6QgEbzccgEag_4qVQsBRbrKqIIdtZn9k,847
1
+ runnable/__init__.py,sha256=v0QgHL7uvEWKecAOJ_bVYHYM9O5B4xCICCLZVBO6Ci8,923
2
2
  runnable/catalog.py,sha256=OUaQ73DWfTsMmq2sKlBn0aDz031mupladNGVuF3pWm0,3985
3
3
  runnable/cli.py,sha256=2NkFHfo1n1Aeq0gPO-SW_T_GsEY1qS1-IdoAJR_0Qhc,9800
4
4
  runnable/context.py,sha256=rP22KqTsLrnpVTe05W80W2jMoAFm8NfkVkYY49Mu2ZA,1025
@@ -58,12 +58,12 @@ runnable/names.py,sha256=vn92Kv9ANROYSZX6Z4z1v_WA3WiEdIYmG6KEStBFZug,8134
58
58
  runnable/nodes.py,sha256=7ztYtTf4GthbutwR56lDqu4ANDLrN5zHqJNvLD_PTOo,16458
59
59
  runnable/parameters.py,sha256=IT-7OUbYmRQuVtzAsG6L7Q4TkGaovmsQ4ErStcSXwmQ,6434
60
60
  runnable/pickler.py,sha256=rrFRc6SMrV6Pxd9r7aMtUou8z-HLL1un4QfH_non4XE,2679
61
- runnable/sdk.py,sha256=wtoSoSFsd-8NDK9qgOQD9rJBu5wqT-BRikJAyVaWPMo,17631
61
+ runnable/sdk.py,sha256=UVxXV-eYnWZnGKOsx7CA8gAI-ArOQAFdF_or_apauD0,22292
62
62
  runnable/secrets.py,sha256=dakb7WRloWVo-KpQp6Vy4rwFdGi58BTlT4OifQY106I,2324
63
63
  runnable/tasks.py,sha256=eG-L8mB5Kp4m-HChwvcZkXkueS9IA7VQ-tQKmr87lrQ,13604
64
64
  runnable/utils.py,sha256=jfgx2_lYCCKUASM7vEGZXdizRFg6EvV9pyZSlhhMKMk,19801
65
- runnable-0.3.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
66
- runnable-0.3.0.dist-info/METADATA,sha256=IgHtMhxwFvT0r2H7XPSP1lGzB1Pl7mzMsDDpxnsGBaU,16185
67
- runnable-0.3.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
68
- runnable-0.3.0.dist-info/entry_points.txt,sha256=wmEeo0n87KXEXxYLN6vzrd-690-1UhE0niJHMhz7f-o,1640
69
- runnable-0.3.0.dist-info/RECORD,,
65
+ runnable-0.4.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
66
+ runnable-0.4.0.dist-info/METADATA,sha256=1zNN1GWpwwS2VsHE5K2b34LknyPZmRt1kAHourIA_m8,16185
67
+ runnable-0.4.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
68
+ runnable-0.4.0.dist-info/entry_points.txt,sha256=wmEeo0n87KXEXxYLN6vzrd-690-1UhE0niJHMhz7f-o,1640
69
+ runnable-0.4.0.dist-info/RECORD,,