digitalhub 0.8.0b7__py3-none-any.whl → 0.8.0b10__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 (59) 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/utils.py +1 -1
  5. digitalhub/context/api.py +93 -0
  6. digitalhub/context/builder.py +0 -84
  7. digitalhub/datastores/_base/datastore.py +2 -2
  8. digitalhub/datastores/api.py +37 -0
  9. digitalhub/datastores/builder.py +7 -31
  10. digitalhub/datastores/local/datastore.py +9 -1
  11. digitalhub/datastores/remote/datastore.py +8 -0
  12. digitalhub/datastores/s3/datastore.py +9 -1
  13. digitalhub/datastores/sql/datastore.py +9 -1
  14. digitalhub/entities/_base/api_utils.py +620 -0
  15. digitalhub/entities/_base/context/entity.py +2 -2
  16. digitalhub/entities/_base/crud.py +204 -408
  17. digitalhub/entities/_base/entity/entity.py +1 -1
  18. digitalhub/entities/_base/executable/entity.py +7 -6
  19. digitalhub/entities/_base/material/entity.py +2 -2
  20. digitalhub/entities/artifact/crud.py +16 -42
  21. digitalhub/entities/dataitem/crud.py +19 -45
  22. digitalhub/entities/dataitem/table/entity.py +1 -1
  23. digitalhub/entities/function/crud.py +13 -39
  24. digitalhub/entities/model/crud.py +15 -42
  25. digitalhub/entities/project/_base/entity.py +65 -38
  26. digitalhub/entities/project/crud.py +8 -8
  27. digitalhub/entities/run/_base/entity.py +1 -1
  28. digitalhub/entities/run/crud.py +17 -30
  29. digitalhub/entities/secret/_base/entity.py +1 -1
  30. digitalhub/entities/secret/crud.py +15 -27
  31. digitalhub/entities/task/_base/entity.py +3 -2
  32. digitalhub/entities/task/crud.py +17 -30
  33. digitalhub/entities/workflow/crud.py +13 -39
  34. digitalhub/factory/api.py +31 -25
  35. digitalhub/factory/factory.py +7 -5
  36. digitalhub/readers/_base/builder.py +26 -0
  37. digitalhub/readers/api.py +80 -0
  38. digitalhub/readers/factory.py +133 -0
  39. digitalhub/readers/pandas/builder.py +29 -0
  40. digitalhub/readers/pandas/{readers.py → reader.py} +1 -1
  41. digitalhub/stores/api.py +54 -0
  42. digitalhub/stores/builder.py +0 -46
  43. {digitalhub-0.8.0b7.dist-info → digitalhub-0.8.0b10.dist-info}/METADATA +1 -1
  44. {digitalhub-0.8.0b7.dist-info → digitalhub-0.8.0b10.dist-info}/RECORD +48 -50
  45. digitalhub/entities/artifact/builder.py +0 -51
  46. digitalhub/entities/dataitem/builder.py +0 -51
  47. digitalhub/entities/function/builder.py +0 -51
  48. digitalhub/entities/model/builder.py +0 -51
  49. digitalhub/entities/project/builder.py +0 -51
  50. digitalhub/entities/run/builder.py +0 -51
  51. digitalhub/entities/secret/builder.py +0 -51
  52. digitalhub/entities/task/builder.py +0 -51
  53. digitalhub/entities/workflow/builder.py +0 -51
  54. digitalhub/readers/builder.py +0 -54
  55. digitalhub/readers/registry.py +0 -15
  56. /digitalhub/readers/_base/{readers.py → reader.py} +0 -0
  57. {digitalhub-0.8.0b7.dist-info → digitalhub-0.8.0b10.dist-info}/LICENSE.txt +0 -0
  58. {digitalhub-0.8.0b7.dist-info → digitalhub-0.8.0b10.dist-info}/WHEEL +0 -0
  59. {digitalhub-0.8.0b7.dist-info → digitalhub-0.8.0b10.dist-info}/top_level.txt +0 -0
@@ -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
  ##############################
@@ -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(
@@ -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
 
@@ -2,17 +2,17 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.context.builder import check_context
5
+ from digitalhub.context.api import check_context
6
6
  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,
7
+ delete_entity,
8
+ get_context_entity_versions,
9
+ get_versioned_entity,
10
+ import_context_entity,
11
+ list_context_entities,
12
+ new_context_entity,
11
13
  )
12
- from digitalhub.entities.secret.builder import secret_from_dict, secret_from_parameters
13
14
  from digitalhub.entities.utils.entity_types import EntityTypes
14
- from digitalhub.utils.exceptions import EntityAlreadyExistsError, EntityNotExistsError
15
- from digitalhub.utils.io_utils import read_yaml
15
+ from digitalhub.utils.exceptions import EntityNotExistsError
16
16
 
17
17
  if typing.TYPE_CHECKING:
18
18
  from digitalhub.entities.secret._base.entity import Secret
@@ -68,8 +68,7 @@ def new_secret(
68
68
 
69
69
  if secret_value is None:
70
70
  raise ValueError("secret_value must be provided.")
71
-
72
- obj = secret_from_parameters(
71
+ obj: Secret = new_context_entity(
73
72
  project=project,
74
73
  name=name,
75
74
  kind="secret",
@@ -79,7 +78,6 @@ def new_secret(
79
78
  embedded=embedded,
80
79
  **kwargs,
81
80
  )
82
- obj.save()
83
81
  obj.set_secret_value(value=secret_value)
84
82
  return obj
85
83
 
@@ -127,14 +125,13 @@ def get_secret(
127
125
  else:
128
126
  raise EntityNotExistsError(f"Secret {identifier} not found.")
129
127
 
130
- obj = read_entity_api_ctx(
128
+ return get_versioned_entity(
131
129
  identifier,
132
- ENTITY_TYPE,
130
+ entity_type=ENTITY_TYPE,
133
131
  project=project,
134
132
  entity_id=entity_id,
135
133
  **kwargs,
136
134
  )
137
- return secret_from_dict(obj)
138
135
 
139
136
 
140
137
  def get_secret_versions(
@@ -168,13 +165,12 @@ def get_secret_versions(
168
165
  >>> objs = get_secret_versions("my-secret-name",
169
166
  >>> project="my-project")
170
167
  """
171
- obj = read_entity_api_ctx_versions(
168
+ return get_context_entity_versions(
172
169
  identifier,
173
170
  entity_type=ENTITY_TYPE,
174
171
  project=project,
175
172
  **kwargs,
176
173
  )
177
- return [secret_from_dict(o) for o in obj]
178
174
 
179
175
 
180
176
  def list_secrets(project: str, **kwargs) -> list[Secret]:
@@ -197,12 +193,11 @@ def list_secrets(project: str, **kwargs) -> list[Secret]:
197
193
  --------
198
194
  >>> objs = list_secrets(project="my-project")
199
195
  """
200
- objs = list_entity_api_ctx(
196
+ return list_context_entities(
201
197
  project=project,
202
198
  entity_type=ENTITY_TYPE,
203
199
  **kwargs,
204
200
  )
205
- return [secret_from_dict(obj) for obj in objs]
206
201
 
207
202
 
208
203
  def import_secret(file: str) -> Secret:
@@ -223,14 +218,7 @@ def import_secret(file: str) -> Secret:
223
218
  --------
224
219
  >>> obj = import_secret("my-secret.yaml")
225
220
  """
226
- dict_obj: dict = read_yaml(file)
227
- obj = secret_from_dict(dict_obj)
228
- try:
229
- obj.save()
230
- except EntityAlreadyExistsError:
231
- pass
232
- finally:
233
- return obj
221
+ return import_context_entity(file)
234
222
 
235
223
 
236
224
  def update_secret(entity: Secret) -> Secret:
@@ -292,7 +280,7 @@ def delete_secret(
292
280
  >>> project="my-project",
293
281
  >>> delete_all_versions=True)
294
282
  """
295
- return delete_entity_api_ctx(
283
+ return delete_entity(
296
284
  identifier=identifier,
297
285
  entity_type=ENTITY_TYPE,
298
286
  project=project,
@@ -3,8 +3,9 @@ from __future__ import annotations
3
3
  import typing
4
4
 
5
5
  from digitalhub.entities._base.unversioned.entity import UnversionedEntity
6
- from digitalhub.entities.run.crud import delete_run, get_run, new_run, run_from_parameters
6
+ from digitalhub.entities.run.crud import delete_run, get_run, new_run
7
7
  from digitalhub.entities.utils.entity_types import EntityTypes
8
+ from digitalhub.factory.api import build_entity_from_params
8
9
 
9
10
  if typing.TYPE_CHECKING:
10
11
  from digitalhub.entities._base.entity.metadata import Metadata
@@ -100,7 +101,7 @@ class Task(UnversionedEntity):
100
101
  Run object.
101
102
  """
102
103
  if kwargs["local_execution"]:
103
- return run_from_parameters(**kwargs)
104
+ return build_entity_from_params(**kwargs)
104
105
  return new_run(**kwargs)
105
106
 
106
107
  def get_run(self, entity_key: str) -> Run:
@@ -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.task.builder import task_from_dict, task_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.task._base.entity import Task
@@ -49,13 +52,11 @@ def new_task(
49
52
 
50
53
  Examples
51
54
  --------
52
- >>> obj = new_function(project="my-project",
53
- >>> name="my-function",
54
- >>> kind="python+task",
55
- >>> task="task-string"
55
+ >>> obj = new_task(project="my-project",
56
+ >>> kind="python+job",
57
+ >>> function="function-string")
56
58
  """
57
- check_context(project)
58
- obj = task_from_parameters(
59
+ return new_context_entity(
59
60
  project=project,
60
61
  kind=kind,
61
62
  uuid=uuid,
@@ -63,8 +64,6 @@ def new_task(
63
64
  function=function,
64
65
  **kwargs,
65
66
  )
66
- obj.save()
67
- return obj
68
67
 
69
68
 
70
69
  def get_task(
@@ -98,16 +97,12 @@ def get_task(
98
97
  >>> obj = get_task("my-task-id"
99
98
  >>> project="my-project")
100
99
  """
101
- if not identifier.startswith("store://"):
102
- raise EntityError("Task has no name. Use key instead.")
103
- obj = read_entity_api_ctx(
100
+ return get_unversioned_entity(
104
101
  identifier,
105
- ENTITY_TYPE,
102
+ entity_type=ENTITY_TYPE,
106
103
  project=project,
107
- entity_id=identifier,
108
104
  **kwargs,
109
105
  )
110
- return task_from_dict(obj)
111
106
 
112
107
 
113
108
  def list_tasks(project: str, **kwargs) -> list[Task]:
@@ -130,12 +125,11 @@ def list_tasks(project: str, **kwargs) -> list[Task]:
130
125
  --------
131
126
  >>> objs = list_tasks(project="my-project")
132
127
  """
133
- objs = list_entity_api_ctx(
128
+ return list_context_entities(
134
129
  project=project,
135
130
  entity_type=ENTITY_TYPE,
136
131
  **kwargs,
137
132
  )
138
- return [task_from_dict(obj) for obj in objs]
139
133
 
140
134
 
141
135
  def import_task(file: str) -> Task:
@@ -156,14 +150,7 @@ def import_task(file: str) -> Task:
156
150
  -------
157
151
  >>> obj = import_task("my-task.yaml")
158
152
  """
159
- dict_obj: dict = read_yaml(file)
160
- obj = task_from_dict(dict_obj)
161
- try:
162
- obj.save()
163
- except EntityAlreadyExistsError:
164
- pass
165
- finally:
166
- return obj
153
+ return import_context_entity(file)
167
154
 
168
155
 
169
156
  def update_task(entity: Task) -> Task:
@@ -230,7 +217,7 @@ def delete_task(
230
217
  """
231
218
  if not identifier.startswith("store://"):
232
219
  raise EntityError("Task has no name. Use key instead.")
233
- return delete_entity_api_ctx(
220
+ return delete_entity(
234
221
  identifier=identifier,
235
222
  entity_type=ENTITY_TYPE,
236
223
  project=project,