digitalhub 0.8.1__py3-none-any.whl → 0.9.0b0__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 (128) hide show
  1. digitalhub/__init__.py +19 -2
  2. digitalhub/client/_base/api_builder.py +16 -0
  3. digitalhub/client/_base/client.py +31 -0
  4. digitalhub/client/api.py +2 -38
  5. digitalhub/client/dhcore/api_builder.py +100 -0
  6. digitalhub/client/dhcore/client.py +77 -24
  7. digitalhub/client/dhcore/enums.py +26 -0
  8. digitalhub/client/dhcore/env.py +2 -2
  9. digitalhub/client/dhcore/utils.py +17 -17
  10. digitalhub/client/local/api_builder.py +100 -0
  11. digitalhub/client/local/client.py +20 -0
  12. digitalhub/context/api.py +3 -38
  13. digitalhub/context/builder.py +10 -23
  14. digitalhub/context/context.py +20 -92
  15. digitalhub/entities/_base/context/entity.py +30 -22
  16. digitalhub/entities/_base/entity/_constructors/metadata.py +12 -1
  17. digitalhub/entities/_base/entity/_constructors/name.py +1 -1
  18. digitalhub/entities/_base/entity/_constructors/spec.py +1 -1
  19. digitalhub/entities/_base/entity/_constructors/status.py +3 -2
  20. digitalhub/entities/_base/entity/builder.py +6 -1
  21. digitalhub/entities/_base/entity/entity.py +30 -10
  22. digitalhub/entities/_base/entity/metadata.py +22 -0
  23. digitalhub/entities/_base/entity/spec.py +7 -2
  24. digitalhub/entities/_base/executable/entity.py +8 -8
  25. digitalhub/entities/_base/material/entity.py +48 -16
  26. digitalhub/entities/_base/material/status.py +0 -31
  27. digitalhub/entities/_base/material/utils.py +106 -0
  28. digitalhub/entities/_base/project/entity.py +341 -0
  29. digitalhub/entities/_base/unversioned/entity.py +1 -23
  30. digitalhub/entities/_base/versioned/entity.py +0 -25
  31. digitalhub/entities/_commons/enums.py +103 -0
  32. digitalhub/entities/_commons/utils.py +83 -0
  33. digitalhub/entities/_operations/processor.py +1747 -0
  34. digitalhub/entities/artifact/_base/builder.py +1 -1
  35. digitalhub/entities/artifact/_base/entity.py +1 -1
  36. digitalhub/entities/artifact/artifact/builder.py +2 -1
  37. digitalhub/entities/artifact/crud.py +46 -29
  38. digitalhub/entities/artifact/utils.py +62 -0
  39. digitalhub/entities/dataitem/_base/builder.py +1 -1
  40. digitalhub/entities/dataitem/_base/entity.py +6 -6
  41. digitalhub/entities/dataitem/crud.py +50 -66
  42. digitalhub/entities/dataitem/dataitem/builder.py +2 -1
  43. digitalhub/entities/dataitem/iceberg/builder.py +2 -1
  44. digitalhub/entities/dataitem/table/builder.py +2 -1
  45. digitalhub/entities/dataitem/table/entity.py +5 -10
  46. digitalhub/entities/dataitem/table/models.py +4 -5
  47. digitalhub/entities/dataitem/utils.py +137 -0
  48. digitalhub/entities/function/_base/builder.py +1 -1
  49. digitalhub/entities/function/_base/entity.py +5 -1
  50. digitalhub/entities/function/crud.py +36 -17
  51. digitalhub/entities/model/_base/builder.py +1 -1
  52. digitalhub/entities/model/_base/entity.py +1 -1
  53. digitalhub/entities/model/crud.py +46 -29
  54. digitalhub/entities/model/huggingface/builder.py +2 -1
  55. digitalhub/entities/model/huggingface/spec.py +4 -2
  56. digitalhub/entities/model/mlflow/builder.py +2 -1
  57. digitalhub/entities/model/mlflow/models.py +17 -9
  58. digitalhub/entities/model/mlflow/spec.py +6 -1
  59. digitalhub/entities/model/mlflow/utils.py +4 -2
  60. digitalhub/entities/model/model/builder.py +2 -1
  61. digitalhub/entities/model/sklearn/builder.py +2 -1
  62. digitalhub/entities/model/utils.py +62 -0
  63. digitalhub/entities/project/_base/builder.py +2 -2
  64. digitalhub/entities/project/_base/entity.py +82 -272
  65. digitalhub/entities/project/crud.py +110 -91
  66. digitalhub/entities/project/utils.py +35 -0
  67. digitalhub/entities/run/_base/builder.py +3 -1
  68. digitalhub/entities/run/_base/entity.py +52 -54
  69. digitalhub/entities/run/_base/spec.py +11 -7
  70. digitalhub/entities/run/crud.py +35 -17
  71. digitalhub/entities/secret/_base/builder.py +2 -2
  72. digitalhub/entities/secret/_base/entity.py +4 -10
  73. digitalhub/entities/secret/crud.py +36 -21
  74. digitalhub/entities/task/_base/builder.py +14 -14
  75. digitalhub/entities/task/_base/entity.py +6 -6
  76. digitalhub/entities/task/_base/models.py +29 -6
  77. digitalhub/entities/task/_base/spec.py +44 -13
  78. digitalhub/entities/task/_base/utils.py +18 -0
  79. digitalhub/entities/task/crud.py +35 -15
  80. digitalhub/entities/workflow/_base/builder.py +1 -1
  81. digitalhub/entities/workflow/_base/entity.py +14 -6
  82. digitalhub/entities/workflow/crud.py +36 -17
  83. digitalhub/factory/utils.py +1 -1
  84. digitalhub/readers/_base/reader.py +2 -2
  85. digitalhub/readers/_commons/enums.py +13 -0
  86. digitalhub/readers/api.py +3 -2
  87. digitalhub/readers/factory.py +12 -6
  88. digitalhub/readers/pandas/reader.py +20 -8
  89. digitalhub/runtimes/_base.py +0 -7
  90. digitalhub/stores/_base/store.py +53 -9
  91. digitalhub/stores/builder.py +5 -5
  92. digitalhub/stores/local/store.py +37 -2
  93. digitalhub/stores/remote/store.py +25 -3
  94. digitalhub/stores/s3/store.py +34 -7
  95. digitalhub/stores/sql/store.py +112 -45
  96. digitalhub/utils/exceptions.py +6 -0
  97. digitalhub/utils/file_utils.py +60 -2
  98. digitalhub/utils/generic_utils.py +45 -4
  99. digitalhub/utils/io_utils.py +18 -0
  100. digitalhub/utils/uri_utils.py +153 -15
  101. {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/METADATA +2 -2
  102. {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/RECORD +110 -113
  103. test/testkfp.py +4 -1
  104. digitalhub/datastores/_base/datastore.py +0 -85
  105. digitalhub/datastores/api.py +0 -37
  106. digitalhub/datastores/builder.py +0 -110
  107. digitalhub/datastores/local/datastore.py +0 -50
  108. digitalhub/datastores/remote/__init__.py +0 -0
  109. digitalhub/datastores/remote/datastore.py +0 -31
  110. digitalhub/datastores/s3/__init__.py +0 -0
  111. digitalhub/datastores/s3/datastore.py +0 -46
  112. digitalhub/datastores/sql/__init__.py +0 -0
  113. digitalhub/datastores/sql/datastore.py +0 -68
  114. digitalhub/entities/_base/api_utils.py +0 -620
  115. digitalhub/entities/_base/crud.py +0 -468
  116. digitalhub/entities/function/_base/models.py +0 -118
  117. digitalhub/entities/utils/__init__.py +0 -0
  118. digitalhub/entities/utils/api.py +0 -346
  119. digitalhub/entities/utils/entity_types.py +0 -19
  120. digitalhub/entities/utils/state.py +0 -31
  121. digitalhub/entities/utils/utils.py +0 -202
  122. /digitalhub/{context → entities/_base/project}/__init__.py +0 -0
  123. /digitalhub/{datastores → entities/_commons}/__init__.py +0 -0
  124. /digitalhub/{datastores/_base → entities/_operations}/__init__.py +0 -0
  125. /digitalhub/{datastores/local → readers/_commons}/__init__.py +0 -0
  126. {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/LICENSE.txt +0 -0
  127. {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/WHEEL +0 -0
  128. {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/top_level.txt +0 -0
@@ -2,14 +2,8 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
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
- )
12
- from digitalhub.entities.utils.entity_types import EntityTypes
5
+ from digitalhub.entities._commons.enums import EntityTypes
6
+ from digitalhub.entities._operations.processor import processor
13
7
  from digitalhub.utils.exceptions import EntityError
14
8
 
15
9
  if typing.TYPE_CHECKING:
@@ -59,7 +53,7 @@ def new_run(
59
53
  >>> kind="python+run",
60
54
  >>> task="task-string")
61
55
  """
62
- return new_context_entity(
56
+ return processor.create_context_entity(
63
57
  project=project,
64
58
  kind=kind,
65
59
  uuid=uuid,
@@ -101,7 +95,7 @@ def get_run(
101
95
  >>> obj = get_run("my-run-id"
102
96
  >>> project="my-project")
103
97
  """
104
- return get_unversioned_entity(
98
+ return processor.read_unversioned_entity(
105
99
  identifier,
106
100
  entity_type=ENTITY_TYPE,
107
101
  project=project,
@@ -130,7 +124,7 @@ def list_runs(project: str, **kwargs) -> list[Run]:
130
124
  >>> objs = list_runs(project="my-project")
131
125
  """
132
126
  # TODO more examples: search by function, latest for task and function
133
- return list_context_entities(
127
+ return processor.list_context_entities(
134
128
  project=project,
135
129
  entity_type=ENTITY_TYPE,
136
130
  **kwargs,
@@ -139,7 +133,7 @@ def list_runs(project: str, **kwargs) -> list[Run]:
139
133
 
140
134
  def import_run(file: str) -> Run:
141
135
  """
142
- Get object from file.
136
+ Import object from a YAML file and create a new object into the backend.
143
137
 
144
138
  Parameters
145
139
  ----------
@@ -155,7 +149,28 @@ def import_run(file: str) -> Run:
155
149
  -------
156
150
  >>> obj = import_run("my-run.yaml")
157
151
  """
158
- return import_context_entity(file)
152
+ return processor.import_context_entity(file)
153
+
154
+
155
+ def load_run(file: str) -> Run:
156
+ """
157
+ Load object from a YAML file and update an existing object into the backend.
158
+
159
+ Parameters
160
+ ----------
161
+ file : str
162
+ Path to YAML file.
163
+
164
+ Returns
165
+ -------
166
+ Run
167
+ Object instance.
168
+
169
+ Examples
170
+ --------
171
+ >>> obj = load_run("my-run.yaml")
172
+ """
173
+ return processor.load_context_entity(file)
159
174
 
160
175
 
161
176
  def update_run(entity: Run) -> Run:
@@ -176,7 +191,12 @@ def update_run(entity: Run) -> Run:
176
191
  --------
177
192
  >>> obj = update_run(obj)
178
193
  """
179
- return entity.save(update=True)
194
+ return processor.update_context_entity(
195
+ project=entity.project,
196
+ entity_type=entity.ENTITY_TYPE,
197
+ entity_id=entity.id,
198
+ entity_dict=entity.to_dict(),
199
+ )
180
200
 
181
201
 
182
202
  def delete_run(
@@ -208,12 +228,10 @@ def delete_run(
208
228
  """
209
229
  if not identifier.startswith("store://") and project is None:
210
230
  raise EntityError("Specify entity key or entity ID combined with project")
211
- return delete_entity(
231
+ return processor.delete_context_entity(
212
232
  identifier=identifier,
213
233
  entity_type=ENTITY_TYPE,
214
234
  project=project,
215
235
  entity_id=identifier,
216
236
  **kwargs,
217
237
  )
218
-
219
- # TODO read logs
@@ -1,10 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from digitalhub.entities._base.versioned.builder import VersionedBuilder
4
+ from digitalhub.entities._commons.enums import EntityKinds, EntityTypes
4
5
  from digitalhub.entities.secret._base.entity import Secret
5
6
  from digitalhub.entities.secret._base.spec import SecretSpec, SecretValidator
6
7
  from digitalhub.entities.secret._base.status import SecretStatus
7
- from digitalhub.entities.utils.entity_types import EntityTypes
8
8
 
9
9
 
10
10
  class SecretSecretBuilder(VersionedBuilder):
@@ -17,7 +17,7 @@ class SecretSecretBuilder(VersionedBuilder):
17
17
  ENTITY_SPEC_CLASS = SecretSpec
18
18
  ENTITY_SPEC_VALIDATOR = SecretValidator
19
19
  ENTITY_STATUS_CLASS = SecretStatus
20
- ENTITY_KIND = "secret"
20
+ ENTITY_KIND = EntityKinds.SECRET_SECRET.value
21
21
 
22
22
  def build(
23
23
  self,
@@ -2,9 +2,9 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.entities._base.api_utils import get_data_api, set_data_api
6
5
  from digitalhub.entities._base.versioned.entity import VersionedEntity
7
- from digitalhub.entities.utils.entity_types import EntityTypes
6
+ from digitalhub.entities._commons.enums import EntityTypes
7
+ from digitalhub.entities._operations.processor import processor
8
8
 
9
9
  if typing.TYPE_CHECKING:
10
10
  from digitalhub.entities._base.entity.metadata import Metadata
@@ -51,11 +51,8 @@ class Secret(VersionedEntity):
51
51
  -------
52
52
  None
53
53
  """
54
- if self._context().local:
55
- raise NotImplementedError("set_secret() is not implemented for local projects.")
56
-
57
54
  obj = {self.name: value}
58
- set_data_api(self.project, self.ENTITY_TYPE, obj)
55
+ processor.update_secret_data(self.project, self.ENTITY_TYPE, obj)
59
56
 
60
57
  def read_secret_value(self) -> dict:
61
58
  """
@@ -66,9 +63,6 @@ class Secret(VersionedEntity):
66
63
  str
67
64
  Value of the secret.
68
65
  """
69
- if self._context().local:
70
- raise NotImplementedError("read_secret() is not implemented for local projects.")
71
-
72
66
  params = {"keys": self.name}
73
- data = get_data_api(self.project, self.ENTITY_TYPE, params=params)
67
+ data = processor.read_secret_data(self.project, self.ENTITY_TYPE, params=params)
74
68
  return data[self.name]
@@ -2,16 +2,8 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.context.api import check_context
6
- from digitalhub.entities._base.crud import (
7
- delete_entity,
8
- get_context_entity_versions,
9
- get_versioned_entity,
10
- import_context_entity,
11
- list_context_entities,
12
- new_context_entity,
13
- )
14
- from digitalhub.entities.utils.entity_types import EntityTypes
5
+ from digitalhub.entities._commons.enums import EntityTypes
6
+ from digitalhub.entities._operations.processor import processor
15
7
  from digitalhub.utils.exceptions import EntityNotExistsError
16
8
 
17
9
  if typing.TYPE_CHECKING:
@@ -64,11 +56,9 @@ def new_secret(
64
56
  >>> name="my-secret",
65
57
  >>> secret_value="my-secret-value")
66
58
  """
67
- check_context(project)
68
-
69
59
  if secret_value is None:
70
60
  raise ValueError("secret_value must be provided.")
71
- obj: Secret = new_context_entity(
61
+ obj: Secret = processor.create_context_entity(
72
62
  project=project,
73
63
  name=name,
74
64
  kind="secret",
@@ -124,8 +114,7 @@ def get_secret(
124
114
  return secret
125
115
  else:
126
116
  raise EntityNotExistsError(f"Secret {identifier} not found.")
127
-
128
- return get_versioned_entity(
117
+ return processor.read_context_entity(
129
118
  identifier,
130
119
  entity_type=ENTITY_TYPE,
131
120
  project=project,
@@ -165,7 +154,7 @@ def get_secret_versions(
165
154
  >>> objs = get_secret_versions("my-secret-name",
166
155
  >>> project="my-project")
167
156
  """
168
- return get_context_entity_versions(
157
+ return processor.read_context_entity_versions(
169
158
  identifier,
170
159
  entity_type=ENTITY_TYPE,
171
160
  project=project,
@@ -193,7 +182,7 @@ def list_secrets(project: str, **kwargs) -> list[Secret]:
193
182
  --------
194
183
  >>> objs = list_secrets(project="my-project")
195
184
  """
196
- return list_context_entities(
185
+ return processor.list_context_entities(
197
186
  project=project,
198
187
  entity_type=ENTITY_TYPE,
199
188
  **kwargs,
@@ -202,7 +191,7 @@ def list_secrets(project: str, **kwargs) -> list[Secret]:
202
191
 
203
192
  def import_secret(file: str) -> Secret:
204
193
  """
205
- Import object from a YAML file.
194
+ Import object from a YAML file and create a new object into the backend.
206
195
 
207
196
  Parameters
208
197
  ----------
@@ -218,7 +207,28 @@ def import_secret(file: str) -> Secret:
218
207
  --------
219
208
  >>> obj = import_secret("my-secret.yaml")
220
209
  """
221
- return import_context_entity(file)
210
+ return processor.import_context_entity(file)
211
+
212
+
213
+ def load_secret(file: str) -> Secret:
214
+ """
215
+ Load object from a YAML file and update an existing object into the backend.
216
+
217
+ Parameters
218
+ ----------
219
+ file : str
220
+ Path to YAML file.
221
+
222
+ Returns
223
+ -------
224
+ Secret
225
+ Object instance.
226
+
227
+ Examples
228
+ --------
229
+ >>> obj = load_secret("my-secret.yaml")
230
+ """
231
+ return processor.load_context_entity(file)
222
232
 
223
233
 
224
234
  def update_secret(entity: Secret) -> Secret:
@@ -239,7 +249,12 @@ def update_secret(entity: Secret) -> Secret:
239
249
  --------
240
250
  >>> obj = update_secret(obj)
241
251
  """
242
- return entity.save(update=True)
252
+ return processor.update_context_entity(
253
+ project=entity.project,
254
+ entity_type=entity.ENTITY_TYPE,
255
+ entity_id=entity.id,
256
+ entity_dict=entity.to_dict(),
257
+ )
243
258
 
244
259
 
245
260
  def delete_secret(
@@ -280,7 +295,7 @@ def delete_secret(
280
295
  >>> project="my-project",
281
296
  >>> delete_all_versions=True)
282
297
  """
283
- return delete_entity(
298
+ return processor.delete_context_entity(
284
299
  identifier=identifier,
285
300
  entity_type=ENTITY_TYPE,
286
301
  project=project,
@@ -4,7 +4,7 @@ import typing
4
4
 
5
5
  from digitalhub.entities._base.runtime_entity.builder import EntityError, RuntimeEntityBuilder
6
6
  from digitalhub.entities._base.unversioned.builder import UnversionedBuilder
7
- from digitalhub.entities.utils.entity_types import EntityTypes
7
+ from digitalhub.entities._commons.enums import EntityTypes
8
8
 
9
9
  if typing.TYPE_CHECKING:
10
10
  from digitalhub.entities.task._base.entity import Task
@@ -23,7 +23,6 @@ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
23
23
  kind: str,
24
24
  uuid: str | None = None,
25
25
  labels: list[str] | None = None,
26
- function: str | None = None,
27
26
  **kwargs,
28
27
  ) -> Task:
29
28
  """
@@ -39,8 +38,6 @@ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
39
38
  ID of the object.
40
39
  labels : list[str]
41
40
  List of labels.
42
- function : str
43
- Name of the executable associated with the task.
44
41
  **kwargs : dict
45
42
  Spec keyword arguments.
46
43
 
@@ -49,10 +46,14 @@ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
49
46
  Task
50
47
  Object instance.
51
48
  """
52
- if function is None:
53
- raise EntityError("function must be provided")
49
+ # Check executable kind validity
50
+ fnc = kwargs.get("function", None)
51
+ wkf = kwargs.get("workflow", None)
52
+ executable = fnc if fnc is not None else wkf
53
+ if executable is None:
54
+ raise EntityError("Function or workflow must be provided")
55
+ self._check_kind_validity(executable)
54
56
 
55
- self._check_kind_validity(function)
56
57
  uuid = self.build_uuid(uuid)
57
58
  metadata = self.build_metadata(
58
59
  project=project,
@@ -60,7 +61,6 @@ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
60
61
  labels=labels,
61
62
  )
62
63
  spec = self.build_spec(
63
- function=function,
64
64
  **kwargs,
65
65
  )
66
66
  status = self.build_status()
@@ -73,19 +73,19 @@ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
73
73
  status=status,
74
74
  )
75
75
 
76
- def _check_kind_validity(self, function: str) -> None:
76
+ def _check_kind_validity(self, executable: str) -> None:
77
77
  """
78
78
  Check kind validity.
79
79
 
80
80
  Parameters
81
81
  ----------
82
- function : str
83
- Function string.
82
+ executable : str
83
+ Executable string.
84
84
 
85
85
  Returns
86
86
  -------
87
87
  None
88
88
  """
89
- function_kind = function.split("://")[0]
90
- if self.EXECUTABLE_KIND != function_kind:
91
- raise EntityError(f"Invalid task '{self.ENTITY_KIND}' for function kind '{function_kind}'")
89
+ exec_kind = executable.split("://")[0]
90
+ if self.EXECUTABLE_KIND != exec_kind:
91
+ raise EntityError(f"Invalid task '{self.ENTITY_KIND}' for executable kind '{exec_kind}'")
@@ -3,9 +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._commons.enums import EntityTypes
6
7
  from digitalhub.entities.run.crud import delete_run, get_run, new_run
7
- from digitalhub.entities.utils.entity_types import EntityTypes
8
- from digitalhub.factory.api import build_entity_from_params
8
+ from digitalhub.factory.api import get_entity_type_from_kind, get_executable_kind
9
9
 
10
10
  if typing.TYPE_CHECKING:
11
11
  from digitalhub.entities._base.entity.metadata import Metadata
@@ -62,6 +62,9 @@ class Task(UnversionedEntity):
62
62
  Run
63
63
  Run object.
64
64
  """
65
+ exec_kind = get_executable_kind(self.kind)
66
+ exec_type = get_entity_type_from_kind(exec_kind)
67
+ kwargs[exec_type] = getattr(self.spec, exec_type)
65
68
  return self.new_run(
66
69
  project=self.project,
67
70
  task=self._get_task_string(),
@@ -79,8 +82,7 @@ class Task(UnversionedEntity):
79
82
  str
80
83
  Task string.
81
84
  """
82
- splitted = self.spec.function.split("://")
83
- return f"{self.kind}://{splitted[1]}"
85
+ return f"{self.kind}://{self.project}/{self.id}"
84
86
 
85
87
  ##############################
86
88
  # CRUD Methods for Run
@@ -100,8 +102,6 @@ class Task(UnversionedEntity):
100
102
  Run
101
103
  Run object.
102
104
  """
103
- if kwargs["local_execution"]:
104
- return build_entity_from_params(**kwargs)
105
105
  return new_run(**kwargs)
106
106
 
107
107
  def get_run(self, entity_key: str) -> Run:
@@ -1,7 +1,17 @@
1
1
  from __future__ import annotations
2
2
 
3
- from pydantic import BaseModel, Field
4
- from typing_extensions import Literal
3
+ from enum import Enum
4
+
5
+ from pydantic import BaseModel, ConfigDict, Field
6
+
7
+
8
+ class VolumeType(Enum):
9
+ """
10
+ Volume type.
11
+ """
12
+
13
+ PERSISTENT_VOLUME_CLAIM = "persistent_volume_claim"
14
+ EMPTY_DIR = "empty_dir"
5
15
 
6
16
 
7
17
  class Volume(BaseModel):
@@ -9,7 +19,9 @@ class Volume(BaseModel):
9
19
  Volume model.
10
20
  """
11
21
 
12
- volume_type: Literal["persistent_volume_claim", "empty_dir"]
22
+ model_config = ConfigDict(use_enum_values=True)
23
+
24
+ volume_type: VolumeType
13
25
  """Volume type."""
14
26
 
15
27
  name: str
@@ -18,7 +30,7 @@ class Volume(BaseModel):
18
30
  mount_path: str
19
31
  """Volume mount path inside the container."""
20
32
 
21
- spec: dict[str, str]
33
+ spec: dict[str, str] = None
22
34
  """Volume spec."""
23
35
 
24
36
 
@@ -39,10 +51,10 @@ class ResourceItem(BaseModel):
39
51
  Resource item model.
40
52
  """
41
53
 
42
- requests: str = Field(default=None, regex=r"[\d]+|^([0-9])+([a-zA-Z])+$")
54
+ requests: str = Field(default=None, pattern=r"[\d]+|^([0-9])+([a-zA-Z])+$")
43
55
  """Resource requests."""
44
56
 
45
- limits: str = Field(default=None, regex=r"[\d]+|^([0-9])+([a-zA-Z])+$")
57
+ limits: str = Field(default=None, pattern=r"[\d]+|^([0-9])+([a-zA-Z])+$")
46
58
  """Resource limits."""
47
59
 
48
60
 
@@ -206,3 +218,14 @@ class CorePort(BaseModel):
206
218
 
207
219
  port: int
208
220
  target_port: int
221
+
222
+
223
+ class CoreServiceType(Enum):
224
+ """
225
+ CoreServiceType enum.
226
+ """
227
+
228
+ EXTERNAL_NAME = "ExternalName"
229
+ CLUSTER_IP = "ClusterIP"
230
+ NODE_PORT = "NodePort"
231
+ LOAD_BALANCER = "LoadBalancer"
@@ -7,27 +7,51 @@ from digitalhub.entities.task._base.models import K8s
7
7
  class TaskSpec(Spec):
8
8
  """TaskSpec specifications."""
9
9
 
10
- def __init__(self, function: str) -> None:
10
+
11
+ class TaskSpecFunction(TaskSpec):
12
+ """TaskSpecFunction specifications."""
13
+
14
+ def __init__(
15
+ self,
16
+ function: str,
17
+ node_selector: list[dict] | None = None,
18
+ volumes: list[dict] | None = None,
19
+ resources: dict | None = None,
20
+ affinity: dict | None = None,
21
+ tolerations: list[dict] | None = None,
22
+ envs: list[dict] | None = None,
23
+ secrets: list[str] | None = None,
24
+ profile: str | None = None,
25
+ **kwargs,
26
+ ) -> None:
11
27
  self.function = function
28
+ self.node_selector = node_selector
29
+ self.volumes = volumes
30
+ self.resources = resources
31
+ self.affinity = affinity
32
+ self.tolerations = tolerations
33
+ self.envs = envs
34
+ self.secrets = secrets
35
+ self.profile = profile
12
36
 
13
37
 
14
- class TaskSpecK8s(TaskSpec):
15
- """TaskSpecK8s specifications."""
38
+ class TaskSpecWorkflow(TaskSpec):
39
+ """TaskSpecWorkflow specifications."""
16
40
 
17
41
  def __init__(
18
42
  self,
19
- function: str,
20
- node_selector: dict | None = None,
21
- volumes: list | None = None,
43
+ workflow: str,
44
+ node_selector: list[dict] | None = None,
45
+ volumes: list[dict] | None = None,
22
46
  resources: dict | None = None,
23
47
  affinity: dict | None = None,
24
- tolerations: list | None = None,
25
- envs: list | None = None,
26
- secrets: list | None = None,
48
+ tolerations: list[dict] | None = None,
49
+ envs: list[dict] | None = None,
50
+ secrets: list[str] | None = None,
27
51
  profile: str | None = None,
28
52
  **kwargs,
29
53
  ) -> None:
30
- super().__init__(function)
54
+ self.workflow = workflow
31
55
  self.node_selector = node_selector
32
56
  self.volumes = volumes
33
57
  self.resources = resources
@@ -43,11 +67,18 @@ class TaskValidator(SpecValidator):
43
67
  TaskValidator validator.
44
68
  """
45
69
 
70
+
71
+ class TaskValidatorFunction(TaskValidator, K8s):
72
+ """
73
+ TaskValidatorFunction validator.
74
+ """
75
+
46
76
  function: str
47
- """Function string."""
48
77
 
49
78
 
50
- class TaskValidatorK8s(TaskValidator, K8s):
79
+ class TaskValidatorWorkflow(TaskValidator, K8s):
51
80
  """
52
- TaskValidatorK8s validator.
81
+ TaskValidatorWorkflow validator.
53
82
  """
83
+
84
+ workflow: str
@@ -0,0 +1,18 @@
1
+ from __future__ import annotations
2
+
3
+
4
+ def build_task_actions(kind_action_list: list[tuple[str, str]]) -> dict[str, str]:
5
+ """
6
+ Build task actions.
7
+
8
+ Parameters
9
+ ----------
10
+ kind_action_list : list[tuple[str, str]]
11
+ List of kind-action couples.
12
+
13
+ Returns
14
+ -------
15
+ dict[str, str]
16
+ Returns the task actions.
17
+ """
18
+ return [{"kind": kind, "action": action} for (kind, action) in kind_action_list]
@@ -2,14 +2,8 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
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
- )
12
- from digitalhub.entities.utils.entity_types import EntityTypes
5
+ from digitalhub.entities._commons.enums import EntityTypes
6
+ from digitalhub.entities._operations.processor import processor
13
7
  from digitalhub.utils.exceptions import EntityError
14
8
 
15
9
  if typing.TYPE_CHECKING:
@@ -56,7 +50,7 @@ def new_task(
56
50
  >>> kind="python+job",
57
51
  >>> function="function-string")
58
52
  """
59
- return new_context_entity(
53
+ return processor.create_context_entity(
60
54
  project=project,
61
55
  kind=kind,
62
56
  uuid=uuid,
@@ -97,7 +91,7 @@ def get_task(
97
91
  >>> obj = get_task("my-task-id"
98
92
  >>> project="my-project")
99
93
  """
100
- return get_unversioned_entity(
94
+ return processor.read_unversioned_entity(
101
95
  identifier,
102
96
  entity_type=ENTITY_TYPE,
103
97
  project=project,
@@ -125,7 +119,7 @@ def list_tasks(project: str, **kwargs) -> list[Task]:
125
119
  --------
126
120
  >>> objs = list_tasks(project="my-project")
127
121
  """
128
- return list_context_entities(
122
+ return processor.list_context_entities(
129
123
  project=project,
130
124
  entity_type=ENTITY_TYPE,
131
125
  **kwargs,
@@ -134,7 +128,7 @@ def list_tasks(project: str, **kwargs) -> list[Task]:
134
128
 
135
129
  def import_task(file: str) -> Task:
136
130
  """
137
- Get object from file.
131
+ Import object from a YAML file and create a new object into the backend.
138
132
 
139
133
  Parameters
140
134
  ----------
@@ -150,7 +144,28 @@ def import_task(file: str) -> Task:
150
144
  -------
151
145
  >>> obj = import_task("my-task.yaml")
152
146
  """
153
- return import_context_entity(file)
147
+ return processor.import_context_entity(file)
148
+
149
+
150
+ def load_task(file: str) -> Task:
151
+ """
152
+ Load object from a YAML file and update an existing object into the backend.
153
+
154
+ Parameters
155
+ ----------
156
+ file : str
157
+ Path to YAML file.
158
+
159
+ Returns
160
+ -------
161
+ Task
162
+ Object instance.
163
+
164
+ Examples
165
+ --------
166
+ >>> obj = load_task("my-task.yaml")
167
+ """
168
+ return processor.load_context_entity(file)
154
169
 
155
170
 
156
171
  def update_task(entity: Task) -> Task:
@@ -171,7 +186,12 @@ def update_task(entity: Task) -> Task:
171
186
  --------
172
187
  >>> obj = update_task(obj)
173
188
  """
174
- return entity.save(update=True)
189
+ return processor.update_context_entity(
190
+ project=entity.project,
191
+ entity_type=entity.ENTITY_TYPE,
192
+ entity_id=entity.id,
193
+ entity_dict=entity.to_dict(),
194
+ )
175
195
 
176
196
 
177
197
  def delete_task(
@@ -217,7 +237,7 @@ def delete_task(
217
237
  """
218
238
  if not identifier.startswith("store://"):
219
239
  raise EntityError("Task has no name. Use key instead.")
220
- return delete_entity(
240
+ return processor.delete_context_entity(
221
241
  identifier=identifier,
222
242
  entity_type=ENTITY_TYPE,
223
243
  project=project,
@@ -4,7 +4,7 @@ import typing
4
4
 
5
5
  from digitalhub.entities._base.runtime_entity.builder import RuntimeEntityBuilder
6
6
  from digitalhub.entities._base.versioned.builder import VersionedBuilder
7
- from digitalhub.entities.utils.entity_types import EntityTypes
7
+ from digitalhub.entities._commons.enums import EntityTypes
8
8
 
9
9
  if typing.TYPE_CHECKING:
10
10
  from digitalhub.entities.workflow._base.entity import Workflow