digitalhub 0.8.0b3__py3-none-any.whl → 0.8.0b5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of digitalhub might be problematic. Click here for more details.

Files changed (80) hide show
  1. digitalhub/__init__.py +3 -2
  2. digitalhub/client/dhcore/client.py +6 -1
  3. digitalhub/context/builder.py +1 -1
  4. digitalhub/context/context.py +1 -1
  5. digitalhub/entities/_base/entity/entity.py +2 -28
  6. digitalhub/entities/_base/unversioned/builder.py +66 -0
  7. digitalhub/entities/_base/unversioned/entity.py +0 -38
  8. digitalhub/entities/_base/versioned/builder.py +68 -0
  9. digitalhub/entities/_base/versioned/entity.py +0 -41
  10. digitalhub/entities/_builders/entity.py +37 -32
  11. digitalhub/entities/_builders/metadata.py +3 -10
  12. digitalhub/entities/_builders/spec.py +11 -21
  13. digitalhub/entities/_builders/status.py +8 -18
  14. digitalhub/entities/_builders/uuid.py +4 -11
  15. digitalhub/entities/artifact/_base/builder.py +86 -0
  16. digitalhub/entities/artifact/artifact/builder.py +18 -0
  17. digitalhub/entities/artifact/builder.py +15 -97
  18. digitalhub/entities/artifact/crud.py +1 -1
  19. digitalhub/entities/builders.py +63 -0
  20. digitalhub/entities/dataitem/_base/builder.py +86 -0
  21. digitalhub/entities/dataitem/builder.py +15 -108
  22. digitalhub/entities/dataitem/crud.py +3 -3
  23. digitalhub/entities/dataitem/dataitem/builder.py +18 -0
  24. digitalhub/entities/dataitem/iceberg/builder.py +18 -0
  25. digitalhub/entities/dataitem/table/builder.py +18 -0
  26. digitalhub/entities/function/_base/builder.py +78 -0
  27. digitalhub/entities/function/_base/entity.py +2 -2
  28. digitalhub/entities/function/builder.py +22 -57
  29. digitalhub/entities/function/crud.py +1 -1
  30. digitalhub/entities/model/_base/builder.py +86 -0
  31. digitalhub/entities/model/builder.py +15 -116
  32. digitalhub/entities/model/crud.py +1 -1
  33. digitalhub/entities/model/huggingface/builder.py +18 -0
  34. digitalhub/entities/model/mlflow/builder.py +18 -0
  35. digitalhub/entities/model/model/builder.py +18 -0
  36. digitalhub/entities/model/sklearn/builder.py +18 -0
  37. digitalhub/entities/project/_base/builder.py +128 -0
  38. digitalhub/entities/project/{project → _base}/entity.py +9 -51
  39. digitalhub/entities/project/builder.py +20 -51
  40. digitalhub/entities/project/crud.py +1 -1
  41. digitalhub/entities/run/_base/builder.py +73 -0
  42. digitalhub/entities/run/_base/entity.py +17 -152
  43. digitalhub/entities/run/builder.py +21 -47
  44. digitalhub/entities/run/crud.py +1 -1
  45. digitalhub/entities/secret/_base/builder.py +81 -0
  46. digitalhub/entities/secret/{secret → _base}/entity.py +2 -2
  47. digitalhub/entities/secret/builder.py +20 -62
  48. digitalhub/entities/secret/crud.py +2 -2
  49. digitalhub/entities/task/_base/builder.py +76 -0
  50. digitalhub/entities/task/builder.py +21 -44
  51. digitalhub/entities/task/crud.py +1 -1
  52. digitalhub/entities/workflow/_base/builder.py +78 -0
  53. digitalhub/entities/workflow/_base/entity.py +2 -2
  54. digitalhub/entities/workflow/builder.py +20 -60
  55. digitalhub/entities/workflow/crud.py +1 -1
  56. digitalhub/factory/factory.py +204 -0
  57. digitalhub/factory/utils.py +90 -0
  58. digitalhub/runtimes/builder.py +24 -41
  59. digitalhub/runtimes/kind_registry.py +14 -0
  60. digitalhub/runtimes/utils.py +28 -0
  61. digitalhub/utils/exceptions.py +6 -0
  62. digitalhub/utils/generic_utils.py +1 -1
  63. {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b5.dist-info}/METADATA +1 -1
  64. {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b5.dist-info}/RECORD +75 -57
  65. digitalhub/entities/_builders/factory.py +0 -44
  66. digitalhub/entities/registries.py +0 -48
  67. digitalhub/registry/models.py +0 -87
  68. digitalhub/registry/registry.py +0 -74
  69. digitalhub/registry/utils.py +0 -151
  70. /digitalhub/entities/project/{project → _base}/__init__.py +0 -0
  71. /digitalhub/entities/project/{project → _base}/spec.py +0 -0
  72. /digitalhub/entities/project/{project → _base}/status.py +0 -0
  73. /digitalhub/entities/secret/{secret → _base}/__init__.py +0 -0
  74. /digitalhub/entities/secret/{secret → _base}/spec.py +0 -0
  75. /digitalhub/entities/secret/{secret → _base}/status.py +0 -0
  76. /digitalhub/{registry → factory}/__init__.py +0 -0
  77. /digitalhub/runtimes/{base.py → _base.py} +0 -0
  78. {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b5.dist-info}/LICENSE.txt +0 -0
  79. {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b5.dist-info}/WHEEL +0 -0
  80. {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b5.dist-info}/top_level.txt +0 -0
@@ -13,10 +13,6 @@ from digitalhub.entities._base.crud import (
13
13
  update_entity_api_base,
14
14
  )
15
15
  from digitalhub.entities._base.entity.entity import Entity
16
- from digitalhub.entities._builders.metadata import build_metadata
17
- from digitalhub.entities._builders.name import build_name
18
- from digitalhub.entities._builders.spec import build_spec
19
- from digitalhub.entities._builders.status import build_status
20
16
  from digitalhub.entities.artifact.crud import (
21
17
  artifact_from_dict,
22
18
  delete_artifact,
@@ -92,10 +88,10 @@ if typing.TYPE_CHECKING:
92
88
  from digitalhub.entities.dataitem._base.entity import Dataitem
93
89
  from digitalhub.entities.function._base.entity import Function
94
90
  from digitalhub.entities.model._base.entity import Model
95
- from digitalhub.entities.project.project.spec import ProjectSpec
96
- from digitalhub.entities.project.project.status import ProjectStatus
91
+ from digitalhub.entities.project._base.spec import ProjectSpec
92
+ from digitalhub.entities.project._base.status import ProjectStatus
97
93
  from digitalhub.entities.run._base.entity import Run
98
- from digitalhub.entities.secret.secret.entity import Secret
94
+ from digitalhub.entities.secret._base.entity import Secret
99
95
  from digitalhub.entities.workflow._base.entity import Workflow
100
96
 
101
97
 
@@ -308,44 +304,6 @@ class Project(Entity):
308
304
  except EntityAlreadyExistsError:
309
305
  pass
310
306
 
311
- ##############################
312
- # Static interface methods
313
- ##############################
314
-
315
- @staticmethod
316
- def _parse_dict(obj: dict, validate: bool = True) -> dict:
317
- """
318
- Get dictionary and parse it to a valid entity dictionary.
319
-
320
- Parameters
321
- ----------
322
- entity : str
323
- Entity type.
324
- obj : dict
325
- Dictionary to parse.
326
-
327
- Returns
328
- -------
329
- dict
330
- A dictionary containing the attributes of the entity instance.
331
- """
332
- name = build_name(obj.get("name"))
333
- kind = obj.get("kind")
334
- metadata = build_metadata(kind, **obj.get("metadata", {}))
335
- spec = build_spec(kind, validate=validate, **obj.get("spec", {}))
336
- status = build_status(kind, **obj.get("status", {}))
337
- user = obj.get("user")
338
- local = obj.get("local", False)
339
- return {
340
- "name": name,
341
- "kind": kind,
342
- "metadata": metadata,
343
- "spec": spec,
344
- "status": status,
345
- "user": user,
346
- "local": local,
347
- }
348
-
349
307
  ##############################
350
308
  # Artifacts
351
309
  ##############################
@@ -371,7 +329,7 @@ class Project(Entity):
371
329
  kind : str
372
330
  Kind the object.
373
331
  uuid : str
374
- ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
332
+ ID of the object.
375
333
  description : str
376
334
  Description of the object (human readable).
377
335
  labels : list[str]
@@ -662,7 +620,7 @@ class Project(Entity):
662
620
  kind : str
663
621
  Kind the object.
664
622
  uuid : str
665
- ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
623
+ ID of the object.
666
624
  description : str
667
625
  Description of the object (human readable).
668
626
  labels : list[str]
@@ -966,7 +924,7 @@ class Project(Entity):
966
924
  kind : str
967
925
  Kind the object.
968
926
  uuid : str
969
- ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
927
+ ID of the object.
970
928
  description : str
971
929
  Description of the object (human readable).
972
930
  labels : list[str]
@@ -1257,7 +1215,7 @@ class Project(Entity):
1257
1215
  kind : str
1258
1216
  Kind the object.
1259
1217
  uuid : str
1260
- ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
1218
+ ID of the object.
1261
1219
  description : str
1262
1220
  Description of the object (human readable).
1263
1221
  labels : list[str]
@@ -1503,7 +1461,7 @@ class Project(Entity):
1503
1461
  kind : str
1504
1462
  Kind the object.
1505
1463
  uuid : str
1506
- ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
1464
+ ID of the object.
1507
1465
  description : str
1508
1466
  Description of the object (human readable).
1509
1467
  labels : list[str]
@@ -1747,7 +1705,7 @@ class Project(Entity):
1747
1705
  name : str
1748
1706
  Object name.
1749
1707
  uuid : str
1750
- ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
1708
+ ID of the object.
1751
1709
  description : str
1752
1710
  Description of the object (human readable).
1753
1711
  labels : list[str]
@@ -1,68 +1,33 @@
1
1
  from __future__ import annotations
2
2
 
3
- from digitalhub.entities._builders.metadata import build_metadata
4
- from digitalhub.entities._builders.name import build_name
5
- from digitalhub.entities._builders.spec import build_spec
6
- from digitalhub.entities._builders.status import build_status
7
- from digitalhub.entities.project.project.entity import Project
3
+ import typing
8
4
 
5
+ from digitalhub.factory.factory import factory
6
+ from digitalhub.utils.exceptions import BuilderError
9
7
 
10
- def project_from_parameters(
11
- name: str,
12
- kind: str,
13
- description: str | None = None,
14
- labels: list[str] | None = None,
15
- local: bool = False,
16
- context: str | None = None,
17
- **kwargs,
18
- ) -> Project:
8
+ if typing.TYPE_CHECKING:
9
+ from digitalhub.entities.project._base.entity import Project
10
+
11
+
12
+ def project_from_parameters(**kwargs) -> Project:
19
13
  """
20
14
  Create a new object.
21
15
 
22
16
  Parameters
23
17
  ----------
24
- name : str
25
- Object name.
26
- kind : str
27
- Kind the object.
28
- description : str
29
- Description of the object (human readable).
30
- labels : list[str]
31
- List of labels.
32
- local : bool
33
- If True, use local backend, if False use DHCore backend. Default to False.
34
- context : str
35
- The context local folder of the project.
36
- **kwargs : dict
37
- Spec keyword arguments.
18
+ **kwargs
19
+ Keyword arguments.
38
20
 
39
21
  Returns
40
22
  -------
41
23
  Project
42
24
  Object instance.
43
25
  """
44
- name = build_name(name)
45
- spec = build_spec(
46
- kind,
47
- context=context,
48
- **kwargs,
49
- )
50
- metadata = build_metadata(
51
- kind,
52
- project=name,
53
- name=name,
54
- description=description,
55
- labels=labels,
56
- )
57
- status = build_status(kind)
58
- return Project(
59
- name=name,
60
- kind=kind,
61
- metadata=metadata,
62
- spec=spec,
63
- status=status,
64
- local=local,
65
- )
26
+ try:
27
+ kind = kwargs["kind"]
28
+ except KeyError:
29
+ raise BuilderError("Missing 'kind' parameter.")
30
+ return factory.build_entity_from_params(kind, **kwargs)
66
31
 
67
32
 
68
33
  def project_from_dict(obj: dict) -> Project:
@@ -79,4 +44,8 @@ def project_from_dict(obj: dict) -> Project:
79
44
  Project
80
45
  Object instance.
81
46
  """
82
- return Project.from_dict(obj)
47
+ try:
48
+ kind = obj["kind"]
49
+ except KeyError:
50
+ raise BuilderError("Missing 'kind' parameter.")
51
+ return factory.build_entity_from_dict(kind, obj)
@@ -13,7 +13,7 @@ from digitalhub.utils.exceptions import BackendError, EntityError
13
13
  from digitalhub.utils.io_utils import read_yaml
14
14
 
15
15
  if typing.TYPE_CHECKING:
16
- from digitalhub.entities.project.project.entity import Project
16
+ from digitalhub.entities.project._base.entity import Project
17
17
 
18
18
 
19
19
  ENTITY_TYPE = EntityTypes.PROJECT.value
@@ -0,0 +1,73 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.unversioned.builder import UnversionedBuilder
6
+ from digitalhub.entities.utils.entity_types import EntityTypes
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from digitalhub.entities.run._base.entity import Run
10
+
11
+
12
+ class RunBuilder(UnversionedBuilder):
13
+ """
14
+ Run builder.
15
+ """
16
+
17
+ ENTITY_TYPE = EntityTypes.RUN.value
18
+
19
+ def build(
20
+ self,
21
+ project: str,
22
+ kind: str,
23
+ uuid: str | None = None,
24
+ labels: list[str] | None = None,
25
+ task: str | None = None,
26
+ local_execution: bool = False,
27
+ **kwargs,
28
+ ) -> Run:
29
+ """
30
+ Create a new object.
31
+
32
+ Parameters
33
+ ----------
34
+ project : str
35
+ Project name.
36
+ kind : str
37
+ Kind the object.
38
+ uuid : str
39
+ ID of the object.
40
+ labels : list[str]
41
+ List of labels.
42
+ task : str
43
+ Name of the task associated with the run.
44
+ local_execution : bool
45
+ Flag to determine if object has local execution.
46
+ **kwargs : dict
47
+ Spec keyword arguments.
48
+
49
+ Returns
50
+ -------
51
+ Run
52
+ Object instance.
53
+ """
54
+ uuid = self.build_uuid(uuid)
55
+ metadata = self.build_metadata(
56
+ project=project,
57
+ name=uuid,
58
+ labels=labels,
59
+ )
60
+ spec = self.build_spec(
61
+ task=task,
62
+ local_execution=local_execution,
63
+ **kwargs,
64
+ )
65
+ status = self.build_status()
66
+ return self.build_entity(
67
+ project=project,
68
+ uuid=uuid,
69
+ kind=kind,
70
+ metadata=metadata,
71
+ spec=spec,
72
+ status=status,
73
+ )
@@ -2,9 +2,6 @@ from __future__ import annotations
2
2
 
3
3
  import time
4
4
  import typing
5
- from typing import Any
6
-
7
- import requests
8
5
 
9
6
  from digitalhub.entities._base.crud import (
10
7
  list_entity_api_base,
@@ -15,21 +12,17 @@ from digitalhub.entities._base.crud import (
15
12
  stop_api,
16
13
  )
17
14
  from digitalhub.entities._base.unversioned.entity import UnversionedEntity
18
- from digitalhub.entities._builders.spec import build_spec
19
- from digitalhub.entities._builders.status import build_status
20
15
  from digitalhub.entities.utils.entity_types import EntityTypes
21
16
  from digitalhub.entities.utils.state import State
22
- from digitalhub.registry.registry import registry
23
- from digitalhub.runtimes.builder import build_runtime
17
+ from digitalhub.factory.factory import factory
24
18
  from digitalhub.utils.exceptions import EntityError
25
19
  from digitalhub.utils.logger import LOGGER
26
20
 
27
21
  if typing.TYPE_CHECKING:
28
22
  from digitalhub.entities._base.entity.metadata import Metadata
29
- from digitalhub.entities._base.material.entity import MaterialEntity
30
23
  from digitalhub.entities.run._base.spec import RunSpec
31
24
  from digitalhub.entities.run._base.status import RunStatus
32
- from digitalhub.runtimes.base import Runtime
25
+ from digitalhub.runtimes._base import Runtime
33
26
 
34
27
 
35
28
  class Run(UnversionedEntity):
@@ -70,7 +63,7 @@ class Run(UnversionedEntity):
70
63
  executable = self._get_executable(runtime)
71
64
  task = self._get_task(runtime)
72
65
  new_spec = runtime.build(executable, task, self.to_dict())
73
- self.spec = build_spec(
66
+ self.spec = factory.build_spec(
74
67
  self.kind,
75
68
  **new_spec,
76
69
  )
@@ -93,16 +86,15 @@ class Run(UnversionedEntity):
93
86
  self._set_state(State.RUNNING.value)
94
87
  self.save(update=True)
95
88
 
96
- # Try to get inputs if they exist
97
- try:
98
- self.spec.inputs = self.inputs(as_dict=True)
99
- except EntityError:
100
- pass
89
+ self._setup_execution()
101
90
 
102
91
  try:
103
92
  status = self._get_runtime().run(self.to_dict())
104
93
  except Exception as e:
105
94
  self.refresh()
95
+ import pdb
96
+
97
+ pdb.set_trace()
106
98
  if self.spec.local_execution:
107
99
  self._set_state(State.ERROR.value)
108
100
  self._set_message(str(e))
@@ -147,116 +139,6 @@ class Run(UnversionedEntity):
147
139
  LOGGER.info(f"Run {self.id} finished in {current:.2f} seconds.")
148
140
  return self
149
141
 
150
- def inputs(self, as_dict: bool = False) -> list[dict]:
151
- """
152
- Get inputs passed in spec as objects or as dictionaries.
153
-
154
- Parameters
155
- ----------
156
- as_dict : bool
157
- If True, return inputs as dictionaries.
158
-
159
- Returns
160
- -------
161
- list[dict]
162
- List of input objects.
163
- """
164
- try:
165
- return self.spec.get_inputs(as_dict=as_dict)
166
- except AttributeError:
167
- msg = f"Run of type {self.kind} has no inputs."
168
- raise EntityError(msg)
169
-
170
- def results(self) -> dict:
171
- """
172
- Get results from runtime execution.
173
-
174
- Returns
175
- -------
176
- dict
177
- Results.
178
- """
179
- try:
180
- return self.status.get_results()
181
- except AttributeError:
182
- msg = f"Run of type {self.kind} has no results."
183
- raise EntityError(msg)
184
-
185
- def result(self, key: str) -> Any:
186
- """
187
- Get result from runtime execution by key.
188
-
189
- Parameters
190
- ----------
191
- key : str
192
- Key of the result.
193
-
194
- Returns
195
- -------
196
- Any
197
- Result.
198
- """
199
- return self.results().get(key)
200
-
201
- def outputs(self, as_key: bool = False, as_dict: bool = False) -> dict:
202
- """
203
- Get run objects results.
204
-
205
- Parameters
206
- ----------
207
- as_key : bool
208
- If True, return results as keys.
209
- as_dict : bool
210
- If True, return results as dictionaries.
211
-
212
- Returns
213
- -------
214
- dict
215
- List of output objects.
216
- """
217
- try:
218
- return self.status.get_outputs(as_key=as_key, as_dict=as_dict)
219
- except AttributeError:
220
- msg = f"Run of type {self.kind} has no outputs."
221
- raise EntityError(msg)
222
-
223
- def output(self, key: str, as_key: bool = False, as_dict: bool = False) -> MaterialEntity | dict | str | None:
224
- """
225
- Get run object result by key.
226
-
227
- Parameters
228
- ----------
229
- key : str
230
- Key of the result.
231
- as_key : bool
232
- If True, return result as key.
233
- as_dict : bool
234
- If True, return result as dictionary.
235
-
236
- Returns
237
- -------
238
- Entity | dict | str | None
239
- Result.
240
- """
241
- return self.outputs(as_key=as_key, as_dict=as_dict).get(key)
242
-
243
- def values(self) -> dict:
244
- """
245
- Get values from runtime execution.
246
-
247
- Returns
248
- -------
249
- dict
250
- Values from backend.
251
- """
252
- try:
253
- value_list = getattr(self.spec, "values", [])
254
- value_list = value_list if value_list is not None else []
255
- return self.status.get_values(value_list)
256
- except AttributeError:
257
- msg = f"Run of type {self.kind} has no values."
258
- raise EntityError(msg)
259
-
260
142
  def logs(self) -> dict:
261
143
  """
262
144
  Get object from backend.
@@ -307,35 +189,18 @@ class Run(UnversionedEntity):
307
189
  # TODO verify the logic and order
308
190
  self.run()
309
191
 
310
- def invoke(self, **kwargs) -> requests.Response:
311
- """
312
- Invoke run.
192
+ ##############################
193
+ # Helpers
194
+ ##############################
313
195
 
314
- Parameters
315
- ----------
316
- kwargs
317
- Keyword arguments to pass to the request.
196
+ def _setup_execution(self) -> None:
197
+ """
198
+ Setup run execution. In base class, nothing to do.
318
199
 
319
200
  Returns
320
201
  -------
321
- requests.Response
322
- Response from service.
202
+ None
323
203
  """
324
- try:
325
- if not self._context().local and not self.spec.local_execution:
326
- local = False
327
- else:
328
- local = True
329
- if kwargs is None:
330
- kwargs = {}
331
- return self.status.invoke(local, **kwargs)
332
- except AttributeError:
333
- msg = f"Run of type {self.kind} has no invoke operation."
334
- raise EntityError(msg)
335
-
336
- ##############################
337
- # Helpers
338
- ##############################
339
204
 
340
205
  def _is_ready_to_run(self) -> bool:
341
206
  """
@@ -361,7 +226,7 @@ class Run(UnversionedEntity):
361
226
  -------
362
227
  None
363
228
  """
364
- self.status: RunStatus = build_status(self.kind, **status)
229
+ self.status: RunStatus = factory.build_status(self.kind, **status)
365
230
 
366
231
  def _set_state(self, state: str) -> None:
367
232
  """
@@ -402,7 +267,7 @@ class Run(UnversionedEntity):
402
267
  Runtime
403
268
  Runtime object.
404
269
  """
405
- return build_runtime(self.kind, self.project)
270
+ return factory.build_runtime(self.kind, self.project)
406
271
 
407
272
  def _get_executable(self, runtime: Runtime) -> dict:
408
273
  """
@@ -419,7 +284,7 @@ class Run(UnversionedEntity):
419
284
  Executable (function or workflow) from backend.
420
285
  """
421
286
  exec_kind = runtime.get_executable_kind()
422
- entity_type = registry.get_entity_type(exec_kind)
287
+ entity_type = factory.get_entity_type_from_builder(exec_kind)
423
288
  splitted = self.spec.task.split("/")
424
289
  exec_name = splitted[-1].split(":")[0]
425
290
  exec_id = splitted[-1].split(":")[1]
@@ -1,63 +1,33 @@
1
1
  from __future__ import annotations
2
2
 
3
- from digitalhub.entities._builders.metadata import build_metadata
4
- from digitalhub.entities._builders.spec import build_spec
5
- from digitalhub.entities._builders.status import build_status
6
- from digitalhub.entities._builders.uuid import build_uuid
7
- from digitalhub.entities.run._base.entity import Run
3
+ import typing
8
4
 
5
+ from digitalhub.factory.factory import factory
6
+ from digitalhub.utils.exceptions import BuilderError
9
7
 
10
- def run_from_parameters(
11
- project: str,
12
- kind: str,
13
- uuid: str | None = None,
14
- labels: list[str] | None = None,
15
- task: str | None = None,
16
- local_execution: bool = False,
17
- **kwargs,
18
- ) -> Run:
8
+ if typing.TYPE_CHECKING:
9
+ from digitalhub.entities.run._base.entity import Run
10
+
11
+
12
+ def run_from_parameters(**kwargs) -> Run:
19
13
  """
20
- Create run.
14
+ Create a new object.
21
15
 
22
16
  Parameters
23
17
  ----------
24
- project : str
25
- Project name.
26
- kind : str
27
- Kind the object.
28
- uuid : str
29
- ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
30
- labels : list[str]
31
- List of labels.
32
- task : str
33
- Name of the task associated with the run.
34
- local_execution : bool
35
- Flag to determine if object has local execution.
36
- **kwargs : dict
37
- Spec keyword arguments.
18
+ **kwargs
19
+ Keyword arguments.
38
20
 
39
21
  Returns
40
22
  -------
41
23
  Run
42
24
  Object instance.
43
25
  """
44
- uuid = build_uuid(uuid)
45
- metadata = build_metadata(
46
- kind=kind,
47
- project=project,
48
- name=uuid,
49
- labels=labels,
50
- )
51
- spec = build_spec(kind, task=task, local_execution=local_execution, **kwargs)
52
- status = build_status(kind)
53
- return Run(
54
- project=project,
55
- uuid=uuid,
56
- kind=kind,
57
- metadata=metadata,
58
- spec=spec,
59
- status=status,
60
- )
26
+ try:
27
+ kind = kwargs["kind"]
28
+ except KeyError:
29
+ raise BuilderError("Missing 'kind' parameter.")
30
+ return factory.build_entity_from_params(kind, **kwargs)
61
31
 
62
32
 
63
33
  def run_from_dict(obj: dict) -> Run:
@@ -74,4 +44,8 @@ def run_from_dict(obj: dict) -> Run:
74
44
  Run
75
45
  Object instance.
76
46
  """
77
- return Run.from_dict(obj)
47
+ try:
48
+ kind = obj["kind"]
49
+ except KeyError:
50
+ raise BuilderError("Missing 'kind' parameter.")
51
+ return factory.build_entity_from_dict(kind, obj)
@@ -35,7 +35,7 @@ def new_run(
35
35
  kind : str
36
36
  Kind the object.
37
37
  uuid : str
38
- ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
38
+ ID of the object.
39
39
  labels : list[str]
40
40
  List of labels.
41
41
  task : str