digitalhub 0.8.0b7__py3-none-any.whl → 0.8.0b11__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 (70) hide show
  1. digitalhub/__init__.py +1 -1
  2. digitalhub/client/api.py +63 -0
  3. digitalhub/client/builder.py +0 -55
  4. digitalhub/client/dhcore/client.py +39 -11
  5. digitalhub/client/dhcore/utils.py +1 -1
  6. digitalhub/client/local/client.py +1 -1
  7. digitalhub/context/api.py +93 -0
  8. digitalhub/context/builder.py +0 -84
  9. digitalhub/datastores/_base/datastore.py +2 -2
  10. digitalhub/datastores/api.py +37 -0
  11. digitalhub/datastores/builder.py +7 -31
  12. digitalhub/datastores/local/datastore.py +9 -1
  13. digitalhub/datastores/remote/datastore.py +8 -0
  14. digitalhub/datastores/s3/datastore.py +9 -1
  15. digitalhub/datastores/sql/datastore.py +9 -1
  16. digitalhub/entities/_base/api_utils.py +620 -0
  17. digitalhub/entities/_base/context/entity.py +2 -2
  18. digitalhub/entities/_base/crud.py +204 -408
  19. digitalhub/entities/_base/entity/entity.py +1 -1
  20. digitalhub/entities/_base/executable/entity.py +7 -6
  21. digitalhub/entities/_base/material/entity.py +2 -2
  22. digitalhub/entities/_base/runtime_entity/builder.py +11 -0
  23. digitalhub/entities/artifact/_base/builder.py +1 -1
  24. digitalhub/entities/artifact/crud.py +17 -43
  25. digitalhub/entities/dataitem/_base/builder.py +1 -1
  26. digitalhub/entities/dataitem/crud.py +20 -46
  27. digitalhub/entities/dataitem/table/entity.py +1 -1
  28. digitalhub/entities/function/_base/builder.py +1 -1
  29. digitalhub/entities/function/crud.py +14 -40
  30. digitalhub/entities/model/_base/builder.py +1 -1
  31. digitalhub/entities/model/crud.py +16 -43
  32. digitalhub/entities/project/_base/entity.py +71 -44
  33. digitalhub/entities/project/crud.py +8 -8
  34. digitalhub/entities/run/_base/builder.py +21 -1
  35. digitalhub/entities/run/_base/entity.py +1 -1
  36. digitalhub/entities/run/crud.py +17 -30
  37. digitalhub/entities/secret/_base/entity.py +1 -1
  38. digitalhub/entities/secret/crud.py +16 -28
  39. digitalhub/entities/task/_base/builder.py +22 -1
  40. digitalhub/entities/task/_base/entity.py +3 -2
  41. digitalhub/entities/task/crud.py +17 -30
  42. digitalhub/entities/workflow/_base/builder.py +1 -1
  43. digitalhub/entities/workflow/crud.py +14 -40
  44. digitalhub/factory/api.py +31 -25
  45. digitalhub/factory/factory.py +7 -5
  46. digitalhub/readers/_base/builder.py +26 -0
  47. digitalhub/readers/api.py +80 -0
  48. digitalhub/readers/factory.py +133 -0
  49. digitalhub/readers/pandas/builder.py +29 -0
  50. digitalhub/readers/pandas/{readers.py → reader.py} +1 -1
  51. digitalhub/stores/api.py +54 -0
  52. digitalhub/stores/builder.py +0 -46
  53. digitalhub/utils/io_utils.py +38 -2
  54. {digitalhub-0.8.0b7.dist-info → digitalhub-0.8.0b11.dist-info}/METADATA +1 -1
  55. {digitalhub-0.8.0b7.dist-info → digitalhub-0.8.0b11.dist-info}/RECORD +59 -61
  56. digitalhub/entities/artifact/builder.py +0 -51
  57. digitalhub/entities/dataitem/builder.py +0 -51
  58. digitalhub/entities/function/builder.py +0 -51
  59. digitalhub/entities/model/builder.py +0 -51
  60. digitalhub/entities/project/builder.py +0 -51
  61. digitalhub/entities/run/builder.py +0 -51
  62. digitalhub/entities/secret/builder.py +0 -51
  63. digitalhub/entities/task/builder.py +0 -51
  64. digitalhub/entities/workflow/builder.py +0 -51
  65. digitalhub/readers/builder.py +0 -54
  66. digitalhub/readers/registry.py +0 -15
  67. /digitalhub/readers/_base/{readers.py → reader.py} +0 -0
  68. {digitalhub-0.8.0b7.dist-info → digitalhub-0.8.0b11.dist-info}/LICENSE.txt +0 -0
  69. {digitalhub-0.8.0b7.dist-info → digitalhub-0.8.0b11.dist-info}/WHEEL +0 -0
  70. {digitalhub-0.8.0b7.dist-info → digitalhub-0.8.0b11.dist-info}/top_level.txt +0 -0
@@ -2,19 +2,17 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.context.builder import check_context
6
5
  from digitalhub.entities._base.crud import (
7
- delete_entity_api_ctx,
8
- list_entity_api_ctx,
9
- read_entity_api_ctx,
10
- read_entity_api_ctx_versions,
6
+ delete_entity,
7
+ get_material_entity,
8
+ get_material_entity_versions,
9
+ import_context_entity,
10
+ list_material_entities,
11
+ new_context_entity,
11
12
  )
12
13
  from digitalhub.entities._base.entity._constructors.uuid import build_uuid
13
- from digitalhub.entities.model.builder import model_from_dict, model_from_parameters
14
14
  from digitalhub.entities.utils.entity_types import EntityTypes
15
15
  from digitalhub.entities.utils.utils import build_log_path_from_source, eval_local_source
16
- from digitalhub.utils.exceptions import EntityAlreadyExistsError
17
- from digitalhub.utils.io_utils import read_yaml
18
16
 
19
17
  if typing.TYPE_CHECKING:
20
18
  from digitalhub.entities.model._base.entity import Model
@@ -30,7 +28,7 @@ def new_model(
30
28
  uuid: str | None = None,
31
29
  description: str | None = None,
32
30
  labels: list[str] | None = None,
33
- embedded: bool = True,
31
+ embedded: bool = False,
34
32
  path: str | None = None,
35
33
  **kwargs,
36
34
  ) -> Model:
@@ -70,8 +68,7 @@ def new_model(
70
68
  >>> kind="model",
71
69
  >>> path="s3://my-bucket/my-key")
72
70
  """
73
- check_context(project)
74
- obj = model_from_parameters(
71
+ return new_context_entity(
75
72
  project=project,
76
73
  name=name,
77
74
  kind=kind,
@@ -82,8 +79,6 @@ def new_model(
82
79
  path=path,
83
80
  **kwargs,
84
81
  )
85
- obj.save()
86
- return obj
87
82
 
88
83
 
89
84
  def log_model(
@@ -171,16 +166,13 @@ def get_model(
171
166
  >>> project="my-project",
172
167
  >>> entity_id="my-model-id")
173
168
  """
174
- obj = read_entity_api_ctx(
175
- identifier,
176
- ENTITY_TYPE,
169
+ return get_material_entity(
170
+ identifier=identifier,
171
+ entity_type=ENTITY_TYPE,
177
172
  project=project,
178
173
  entity_id=entity_id,
179
174
  **kwargs,
180
175
  )
181
- entity = model_from_dict(obj)
182
- entity._get_files_info()
183
- return entity
184
176
 
185
177
 
186
178
  def get_model_versions(
@@ -214,18 +206,12 @@ def get_model_versions(
214
206
  >>> objs = get_model_versions("my-model-name",
215
207
  >>> project="my-project")
216
208
  """
217
- objs = read_entity_api_ctx_versions(
218
- identifier,
209
+ return get_material_entity_versions(
210
+ identifier=identifier,
219
211
  entity_type=ENTITY_TYPE,
220
212
  project=project,
221
213
  **kwargs,
222
214
  )
223
- objects = []
224
- for o in objs:
225
- entity = model_from_dict(o)
226
- entity._get_files_info()
227
- objects.append(entity)
228
- return objects
229
215
 
230
216
 
231
217
  def list_models(project: str, **kwargs) -> list[Model]:
@@ -248,17 +234,11 @@ def list_models(project: str, **kwargs) -> list[Model]:
248
234
  --------
249
235
  >>> objs = list_models(project="my-project")
250
236
  """
251
- objs = list_entity_api_ctx(
237
+ return list_material_entities(
252
238
  project=project,
253
239
  entity_type=ENTITY_TYPE,
254
240
  **kwargs,
255
241
  )
256
- objects = []
257
- for o in objs:
258
- entity = model_from_dict(o)
259
- entity._get_files_info()
260
- objects.append(entity)
261
- return objects
262
242
 
263
243
 
264
244
  def import_model(file: str) -> Model:
@@ -279,14 +259,7 @@ def import_model(file: str) -> Model:
279
259
  --------
280
260
  >>> obj = import_model("my-model.yaml")
281
261
  """
282
- dict_obj: dict = read_yaml(file)
283
- obj = model_from_dict(dict_obj)
284
- try:
285
- obj.save()
286
- except EntityAlreadyExistsError:
287
- pass
288
- finally:
289
- return obj
262
+ return import_context_entity(file)
290
263
 
291
264
 
292
265
  def update_model(entity: Model) -> Model:
@@ -348,7 +321,7 @@ def delete_model(
348
321
  >>> project="my-project",
349
322
  >>> delete_all_versions=True)
350
323
  """
351
- return delete_entity_api_ctx(
324
+ return delete_entity(
352
325
  identifier=identifier,
353
326
  entity_type=ENTITY_TYPE,
354
327
  project=project,
@@ -4,17 +4,17 @@ import typing
4
4
  from pathlib import Path
5
5
  from typing import Any
6
6
 
7
- from digitalhub.client.builder import get_client
8
- from digitalhub.context.builder import set_context
9
- from digitalhub.entities._base.crud import (
7
+ from digitalhub.client.api import get_client
8
+ from digitalhub.context.api import set_context
9
+ from digitalhub.entities._base.api_utils import (
10
10
  create_entity_api_base,
11
11
  read_entity_api_base,
12
12
  read_entity_api_ctx,
13
13
  update_entity_api_base,
14
14
  )
15
+ from digitalhub.entities._base.crud import import_context_entity, import_executable_entity
15
16
  from digitalhub.entities._base.entity.entity import Entity
16
17
  from digitalhub.entities.artifact.crud import (
17
- artifact_from_dict,
18
18
  delete_artifact,
19
19
  get_artifact,
20
20
  get_artifact_versions,
@@ -25,7 +25,6 @@ from digitalhub.entities.artifact.crud import (
25
25
  update_artifact,
26
26
  )
27
27
  from digitalhub.entities.dataitem.crud import (
28
- dataitem_from_dict,
29
28
  delete_dataitem,
30
29
  get_dataitem,
31
30
  get_dataitem_versions,
@@ -37,7 +36,6 @@ from digitalhub.entities.dataitem.crud import (
37
36
  )
38
37
  from digitalhub.entities.function.crud import (
39
38
  delete_function,
40
- function_from_dict,
41
39
  get_function,
42
40
  get_function_versions,
43
41
  import_function,
@@ -52,7 +50,6 @@ from digitalhub.entities.model.crud import (
52
50
  import_model,
53
51
  list_models,
54
52
  log_model,
55
- model_from_dict,
56
53
  new_model,
57
54
  update_model,
58
55
  )
@@ -75,8 +72,8 @@ from digitalhub.entities.workflow.crud import (
75
72
  list_workflows,
76
73
  new_workflow,
77
74
  update_workflow,
78
- workflow_from_dict,
79
75
  )
76
+ from digitalhub.factory.api import build_entity_from_dict
80
77
  from digitalhub.utils.exceptions import BackendError, EntityAlreadyExistsError, EntityError
81
78
  from digitalhub.utils.generic_utils import get_timestamp
82
79
  from digitalhub.utils.io_utils import write_yaml
@@ -95,31 +92,6 @@ if typing.TYPE_CHECKING:
95
92
  from digitalhub.entities.workflow._base.entity import Workflow
96
93
 
97
94
 
98
- ARTIFACTS = EntityTypes.ARTIFACT.value + "s"
99
- FUNCTIONS = EntityTypes.FUNCTION.value + "s"
100
- WORKFLOWS = EntityTypes.WORKFLOW.value + "s"
101
- DATAITEMS = EntityTypes.DATAITEM.value + "s"
102
- MODELS = EntityTypes.MODEL.value + "s"
103
-
104
- CTX_ENTITIES = [ARTIFACTS, FUNCTIONS, WORKFLOWS, DATAITEMS, MODELS]
105
-
106
- FROM_DICT_MAP = {
107
- ARTIFACTS: artifact_from_dict,
108
- FUNCTIONS: function_from_dict,
109
- WORKFLOWS: workflow_from_dict,
110
- DATAITEMS: dataitem_from_dict,
111
- MODELS: model_from_dict,
112
- }
113
-
114
- IMPORT_MAP = {
115
- ARTIFACTS: import_artifact,
116
- FUNCTIONS: import_function,
117
- WORKFLOWS: import_workflow,
118
- DATAITEMS: import_dataitem,
119
- MODELS: import_model,
120
- }
121
-
122
-
123
95
  class Project(Entity):
124
96
  """
125
97
  A class representing a project.
@@ -253,7 +225,7 @@ class Project(Entity):
253
225
  Updatated project object in dictionary format with referenced entities.
254
226
  """
255
227
  # Cycle over entity types
256
- for entity_type in CTX_ENTITIES:
228
+ for entity_type in self._get_entity_types():
257
229
  # Entity types are stored as a list of entities
258
230
  for idx, entity in enumerate(obj.get("spec", {}).get(entity_type, [])):
259
231
  # Export entity if not embedded is in metadata, else do nothing
@@ -262,7 +234,7 @@ class Project(Entity):
262
234
  obj_dict: dict = read_entity_api_ctx(entity["key"])
263
235
 
264
236
  # Create from dict (not need to new method, we do not save to backend)
265
- ent = FROM_DICT_MAP[entity_type](obj_dict)
237
+ ent = build_entity_from_dict(obj_dict)
266
238
 
267
239
  # Export and stor ref in object metadata inside project
268
240
  pth = ent.export()
@@ -279,8 +251,10 @@ class Project(Entity):
279
251
  -------
280
252
  None
281
253
  """
254
+ entity_types = self._get_entity_types()
255
+
282
256
  # Cycle over entity types
283
- for entity_type in CTX_ENTITIES:
257
+ for entity_type in entity_types:
284
258
  # Entity types are stored as a list of entities
285
259
  for entity in getattr(self.spec, entity_type, []):
286
260
  entity_metadata = entity["metadata"]
@@ -292,7 +266,12 @@ class Project(Entity):
292
266
  # Import entity from local ref
293
267
  if map_uri_scheme(ref) == "local":
294
268
  try:
295
- IMPORT_MAP[entity_type](ref)
269
+ # Artifacts, Dataitems and Models
270
+ if entity_type in entity_types[:3]:
271
+ import_context_entity(ref)
272
+ # Functions and Workflows
273
+ elif entity_type in entity_types[3:]:
274
+ import_executable_entity(ref)
296
275
  except FileNotFoundError:
297
276
  msg = f"File not found: {ref}."
298
277
  raise EntityError(msg)
@@ -300,10 +279,54 @@ class Project(Entity):
300
279
  # If entity is embedded, create it and try to save
301
280
  elif embedded:
302
281
  try:
303
- FROM_DICT_MAP[entity_type](entity).save()
282
+ build_entity_from_dict(entity).save()
304
283
  except EntityAlreadyExistsError:
305
284
  pass
306
285
 
286
+ def _get_entity_types(self) -> list[str]:
287
+ """
288
+ Get entity types.
289
+
290
+ Returns
291
+ -------
292
+ list
293
+ Entity types.
294
+ """
295
+ return [
296
+ f"{EntityTypes.ARTIFACT.value}s",
297
+ f"{EntityTypes.DATAITEM.value}s",
298
+ f"{EntityTypes.MODEL.value}s",
299
+ f"{EntityTypes.FUNCTION.value}s",
300
+ f"{EntityTypes.WORKFLOW.value}s",
301
+ ]
302
+
303
+ def run(self, workflow: str | None = "main", **kwargs) -> Run:
304
+ """
305
+ Run workflow project.
306
+
307
+ Parameters
308
+ ----------
309
+ workflow : str
310
+ Workflow name.
311
+ **kwargs : dict
312
+ Keyword arguments passed to workflow.run().
313
+
314
+ Returns
315
+ -------
316
+ Run
317
+ Run instance.
318
+ """
319
+ self.refresh()
320
+ for i in self.spec.workflows:
321
+ if i["name"] == workflow or i["key"] == workflow:
322
+ workflow = build_entity_from_dict(i)
323
+ break
324
+ else:
325
+ msg = f"Workflow {workflow} not found."
326
+ raise EntityError(msg)
327
+
328
+ return workflow.run(**kwargs)
329
+
307
330
  ##############################
308
331
  # Artifacts
309
332
  ##############################
@@ -315,7 +338,7 @@ class Project(Entity):
315
338
  uuid: str | None = None,
316
339
  description: str | None = None,
317
340
  labels: list[str] | None = None,
318
- embedded: bool = True,
341
+ embedded: bool = False,
319
342
  path: str | None = None,
320
343
  **kwargs,
321
344
  ) -> Artifact:
@@ -606,7 +629,7 @@ class Project(Entity):
606
629
  uuid: str | None = None,
607
630
  description: str | None = None,
608
631
  labels: list[str] | None = None,
609
- embedded: bool = True,
632
+ embedded: bool = False,
610
633
  path: str | None = None,
611
634
  **kwargs,
612
635
  ) -> Dataitem:
@@ -910,7 +933,7 @@ class Project(Entity):
910
933
  uuid: str | None = None,
911
934
  description: str | None = None,
912
935
  labels: list[str] | None = None,
913
- embedded: bool = True,
936
+ embedded: bool = False,
914
937
  path: str | None = None,
915
938
  **kwargs,
916
939
  ) -> Model:
@@ -1202,7 +1225,7 @@ class Project(Entity):
1202
1225
  uuid: str | None = None,
1203
1226
  description: str | None = None,
1204
1227
  labels: list[str] | None = None,
1205
- embedded: bool = True,
1228
+ embedded: bool = False,
1206
1229
  **kwargs,
1207
1230
  ) -> Function:
1208
1231
  """
@@ -1448,7 +1471,7 @@ class Project(Entity):
1448
1471
  uuid: str | None = None,
1449
1472
  description: str | None = None,
1450
1473
  labels: list[str] | None = None,
1451
- embedded: bool = True,
1474
+ embedded: bool = False,
1452
1475
  **kwargs,
1453
1476
  ) -> Workflow:
1454
1477
  """
@@ -1693,7 +1716,7 @@ class Project(Entity):
1693
1716
  uuid: str | None = None,
1694
1717
  description: str | None = None,
1695
1718
  labels: list[str] | None = None,
1696
- embedded: bool = True,
1719
+ embedded: bool = False,
1697
1720
  secret_value: str | None = None,
1698
1721
  **kwargs,
1699
1722
  ) -> Secret:
@@ -2016,3 +2039,7 @@ class Project(Entity):
2016
2039
  **kwargs,
2017
2040
  )
2018
2041
  self.refresh()
2042
+
2043
+ ##############################
2044
+ # Project methods
2045
+ ##############################
@@ -4,11 +4,11 @@ import importlib.util as imputil
4
4
  import typing
5
5
  from pathlib import Path
6
6
 
7
- from digitalhub.client.builder import build_client, get_client
8
- from digitalhub.context.builder import delete_context
9
- from digitalhub.entities._base.crud import delete_entity_api_base, read_entity_api_base, update_entity_api_base
10
- from digitalhub.entities.project.builder import project_from_dict, project_from_parameters
7
+ from digitalhub.client.api import build_client, get_client
8
+ from digitalhub.context.api import delete_context
9
+ from digitalhub.entities._base.api_utils import delete_entity_api_base, read_entity_api_base, update_entity_api_base
11
10
  from digitalhub.entities.utils.entity_types import EntityTypes
11
+ from digitalhub.factory.api import build_entity_from_dict, build_entity_from_params
12
12
  from digitalhub.utils.exceptions import BackendError, EntityError
13
13
  from digitalhub.utils.io_utils import read_yaml
14
14
 
@@ -63,7 +63,7 @@ def new_project(
63
63
  build_client(local, config)
64
64
  if context is None:
65
65
  context = name
66
- obj = project_from_parameters(
66
+ obj = build_entity_from_params(
67
67
  name=name,
68
68
  kind="project",
69
69
  description=description,
@@ -112,7 +112,7 @@ def get_project(
112
112
  client = get_client(local)
113
113
  obj = read_entity_api_base(client, ENTITY_TYPE, name, **kwargs)
114
114
  obj["local"] = local
115
- project = project_from_dict(obj)
115
+ project = build_entity_from_dict(obj)
116
116
  return _setup_project(project, setup_kwargs)
117
117
 
118
118
 
@@ -148,7 +148,7 @@ def import_project(
148
148
  build_client(local, config)
149
149
  dict_obj: dict = read_yaml(file)
150
150
  dict_obj["local"] = local
151
- obj = project_from_dict(dict_obj)
151
+ obj = build_entity_from_dict(dict_obj)
152
152
  obj = _setup_project(obj, setup_kwargs)
153
153
 
154
154
  # Import related entities
@@ -278,7 +278,7 @@ def update_project(entity: Project, local: bool = False, **kwargs) -> Project:
278
278
  """
279
279
  client = get_client(local)
280
280
  obj = update_entity_api_base(client, ENTITY_TYPE, entity.name, entity.to_dict(), **kwargs)
281
- return project_from_dict(obj)
281
+ return build_entity_from_dict(obj)
282
282
 
283
283
 
284
284
  def delete_project(
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.entities._base.runtime_entity.builder import RuntimeEntityBuilder
5
+ from digitalhub.entities._base.runtime_entity.builder import RuntimeEntityBuilder, EntityError
6
6
  from digitalhub.entities._base.unversioned.builder import UnversionedBuilder
7
7
  from digitalhub.entities.utils.entity_types import EntityTypes
8
8
 
@@ -52,6 +52,9 @@ class RunBuilder(UnversionedBuilder, RuntimeEntityBuilder):
52
52
  Run
53
53
  Object instance.
54
54
  """
55
+ if task is None:
56
+ raise EntityError("Missing task in run spec")
57
+ self._check_kind_validity(task)
55
58
  uuid = self.build_uuid(uuid)
56
59
  metadata = self.build_metadata(
57
60
  project=project,
@@ -72,3 +75,20 @@ class RunBuilder(UnversionedBuilder, RuntimeEntityBuilder):
72
75
  spec=spec,
73
76
  status=status,
74
77
  )
78
+
79
+ def _check_kind_validity(self, task: str) -> None:
80
+ """
81
+ Check kind validity.
82
+
83
+ Parameters
84
+ ----------
85
+ task : str
86
+ Task string.
87
+
88
+ Returns
89
+ -------
90
+ None
91
+ """
92
+ task_kind = task.split("://")[0]
93
+ if task_kind not in self.get_all_kinds():
94
+ raise EntityError(f"Invalid run '{self.ENTITY_KIND}' for task kind '{task_kind}'")
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  import time
4
4
  import typing
5
5
 
6
- from digitalhub.entities._base.crud import (
6
+ from digitalhub.entities._base.api_utils import (
7
7
  list_entity_api_base,
8
8
  list_entity_api_ctx,
9
9
  logs_api,
@@ -2,12 +2,15 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.context.builder import check_context
6
- from digitalhub.entities._base.crud import delete_entity_api_ctx, list_entity_api_ctx, read_entity_api_ctx
7
- from digitalhub.entities.run.builder import run_from_dict, run_from_parameters
5
+ from digitalhub.entities._base.crud import (
6
+ delete_entity,
7
+ get_unversioned_entity,
8
+ import_context_entity,
9
+ list_context_entities,
10
+ new_context_entity,
11
+ )
8
12
  from digitalhub.entities.utils.entity_types import EntityTypes
9
- from digitalhub.utils.exceptions import EntityAlreadyExistsError, EntityError
10
- from digitalhub.utils.io_utils import read_yaml
13
+ from digitalhub.utils.exceptions import EntityError
11
14
 
12
15
  if typing.TYPE_CHECKING:
13
16
  from digitalhub.entities.run._base.entity import Run
@@ -52,13 +55,11 @@ def new_run(
52
55
 
53
56
  Examples
54
57
  --------
55
- >>> obj = new_function(project="my-project",
56
- >>> name="my-function",
57
- >>> kind="python+run",
58
- >>> task="task-string"
58
+ >>> obj = new_run(project="my-project",
59
+ >>> kind="python+run",
60
+ >>> task="task-string")
59
61
  """
60
- check_context(project)
61
- obj = run_from_parameters(
62
+ return new_context_entity(
62
63
  project=project,
63
64
  kind=kind,
64
65
  uuid=uuid,
@@ -67,8 +68,6 @@ def new_run(
67
68
  local_execution=local_execution,
68
69
  **kwargs,
69
70
  )
70
- obj.save()
71
- return obj
72
71
 
73
72
 
74
73
  def get_run(
@@ -102,16 +101,12 @@ def get_run(
102
101
  >>> obj = get_run("my-run-id"
103
102
  >>> project="my-project")
104
103
  """
105
- if not identifier.startswith("store://") and project is None:
106
- raise EntityError("Specify entity key or entity ID combined with project")
107
- obj = read_entity_api_ctx(
104
+ return get_unversioned_entity(
108
105
  identifier,
109
- ENTITY_TYPE,
106
+ entity_type=ENTITY_TYPE,
110
107
  project=project,
111
- entity_id=identifier,
112
108
  **kwargs,
113
109
  )
114
- return run_from_dict(obj)
115
110
 
116
111
 
117
112
  def list_runs(project: str, **kwargs) -> list[Run]:
@@ -135,12 +130,11 @@ def list_runs(project: str, **kwargs) -> list[Run]:
135
130
  >>> objs = list_runs(project="my-project")
136
131
  """
137
132
  # TODO more examples: search by function, latest for task and function
138
- objs = list_entity_api_ctx(
133
+ return list_context_entities(
139
134
  project=project,
140
135
  entity_type=ENTITY_TYPE,
141
136
  **kwargs,
142
137
  )
143
- return [run_from_dict(obj) for obj in objs]
144
138
 
145
139
 
146
140
  def import_run(file: str) -> Run:
@@ -161,14 +155,7 @@ def import_run(file: str) -> Run:
161
155
  -------
162
156
  >>> obj = import_run("my-run.yaml")
163
157
  """
164
- dict_obj: dict = read_yaml(file)
165
- obj = run_from_dict(dict_obj)
166
- try:
167
- obj.save()
168
- except EntityAlreadyExistsError:
169
- pass
170
- finally:
171
- return obj
158
+ return import_context_entity(file)
172
159
 
173
160
 
174
161
  def update_run(entity: Run) -> Run:
@@ -221,7 +208,7 @@ def delete_run(
221
208
  """
222
209
  if not identifier.startswith("store://") and project is None:
223
210
  raise EntityError("Specify entity key or entity ID combined with project")
224
- return delete_entity_api_ctx(
211
+ return delete_entity(
225
212
  identifier=identifier,
226
213
  entity_type=ENTITY_TYPE,
227
214
  project=project,
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.entities._base.crud import get_data_api, set_data_api
5
+ from digitalhub.entities._base.api_utils import get_data_api, set_data_api
6
6
  from digitalhub.entities._base.versioned.entity import VersionedEntity
7
7
  from digitalhub.entities.utils.entity_types import EntityTypes
8
8