digitalhub 0.8.0b0__py3-none-any.whl → 0.8.0b2__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 (159) hide show
  1. digitalhub/__init__.py +62 -94
  2. digitalhub/client/__init__.py +0 -0
  3. digitalhub/client/builder.py +105 -0
  4. digitalhub/client/objects/__init__.py +0 -0
  5. digitalhub/client/objects/base.py +56 -0
  6. digitalhub/client/objects/dhcore.py +681 -0
  7. digitalhub/client/objects/local.py +533 -0
  8. digitalhub/context/__init__.py +0 -0
  9. digitalhub/context/builder.py +178 -0
  10. digitalhub/context/context.py +136 -0
  11. digitalhub/datastores/__init__.py +0 -0
  12. digitalhub/datastores/builder.py +134 -0
  13. digitalhub/datastores/objects/__init__.py +0 -0
  14. digitalhub/datastores/objects/base.py +85 -0
  15. digitalhub/datastores/objects/local.py +42 -0
  16. digitalhub/datastores/objects/remote.py +23 -0
  17. digitalhub/datastores/objects/s3.py +38 -0
  18. digitalhub/datastores/objects/sql.py +60 -0
  19. digitalhub/entities/__init__.py +0 -0
  20. digitalhub/entities/_base/__init__.py +0 -0
  21. digitalhub/entities/_base/api.py +346 -0
  22. digitalhub/entities/_base/base.py +82 -0
  23. digitalhub/entities/_base/crud.py +610 -0
  24. digitalhub/entities/_base/entity/__init__.py +0 -0
  25. digitalhub/entities/_base/entity/base.py +132 -0
  26. digitalhub/entities/_base/entity/context.py +118 -0
  27. digitalhub/entities/_base/entity/executable.py +380 -0
  28. digitalhub/entities/_base/entity/material.py +214 -0
  29. digitalhub/entities/_base/entity/unversioned.py +87 -0
  30. digitalhub/entities/_base/entity/versioned.py +94 -0
  31. digitalhub/entities/_base/metadata.py +59 -0
  32. digitalhub/entities/_base/spec/__init__.py +0 -0
  33. digitalhub/entities/_base/spec/base.py +58 -0
  34. digitalhub/entities/_base/spec/material.py +22 -0
  35. digitalhub/entities/_base/state.py +31 -0
  36. digitalhub/entities/_base/status/__init__.py +0 -0
  37. digitalhub/entities/_base/status/base.py +32 -0
  38. digitalhub/entities/_base/status/material.py +49 -0
  39. digitalhub/entities/_builders/__init__.py +0 -0
  40. digitalhub/entities/_builders/metadata.py +60 -0
  41. digitalhub/entities/_builders/name.py +31 -0
  42. digitalhub/entities/_builders/spec.py +43 -0
  43. digitalhub/entities/_builders/status.py +62 -0
  44. digitalhub/entities/_builders/uuid.py +33 -0
  45. digitalhub/entities/artifact/__init__.py +0 -0
  46. digitalhub/entities/artifact/builder.py +133 -0
  47. digitalhub/entities/artifact/crud.py +358 -0
  48. digitalhub/entities/artifact/entity/__init__.py +0 -0
  49. digitalhub/entities/artifact/entity/_base.py +39 -0
  50. digitalhub/entities/artifact/entity/artifact.py +9 -0
  51. digitalhub/entities/artifact/spec.py +39 -0
  52. digitalhub/entities/artifact/status.py +15 -0
  53. digitalhub/entities/dataitem/__init__.py +0 -0
  54. digitalhub/entities/dataitem/builder.py +144 -0
  55. digitalhub/entities/dataitem/crud.py +395 -0
  56. digitalhub/entities/dataitem/entity/__init__.py +0 -0
  57. digitalhub/entities/dataitem/entity/_base.py +75 -0
  58. digitalhub/entities/dataitem/entity/dataitem.py +9 -0
  59. digitalhub/entities/dataitem/entity/iceberg.py +7 -0
  60. digitalhub/entities/dataitem/entity/table.py +125 -0
  61. digitalhub/entities/dataitem/models.py +62 -0
  62. digitalhub/entities/dataitem/spec.py +61 -0
  63. digitalhub/entities/dataitem/status.py +38 -0
  64. digitalhub/entities/entity_types.py +19 -0
  65. digitalhub/entities/function/__init__.py +0 -0
  66. digitalhub/entities/function/builder.py +86 -0
  67. digitalhub/entities/function/crud.py +305 -0
  68. digitalhub/entities/function/entity.py +101 -0
  69. digitalhub/entities/function/models.py +118 -0
  70. digitalhub/entities/function/spec.py +81 -0
  71. digitalhub/entities/function/status.py +9 -0
  72. digitalhub/entities/model/__init__.py +0 -0
  73. digitalhub/entities/model/builder.py +152 -0
  74. digitalhub/entities/model/crud.py +358 -0
  75. digitalhub/entities/model/entity/__init__.py +0 -0
  76. digitalhub/entities/model/entity/_base.py +34 -0
  77. digitalhub/entities/model/entity/huggingface.py +9 -0
  78. digitalhub/entities/model/entity/mlflow.py +90 -0
  79. digitalhub/entities/model/entity/model.py +9 -0
  80. digitalhub/entities/model/entity/sklearn.py +9 -0
  81. digitalhub/entities/model/models.py +26 -0
  82. digitalhub/entities/model/spec.py +146 -0
  83. digitalhub/entities/model/status.py +33 -0
  84. digitalhub/entities/project/__init__.py +0 -0
  85. digitalhub/entities/project/builder.py +82 -0
  86. digitalhub/entities/project/crud.py +350 -0
  87. digitalhub/entities/project/entity.py +2060 -0
  88. digitalhub/entities/project/spec.py +50 -0
  89. digitalhub/entities/project/status.py +9 -0
  90. digitalhub/entities/registries.py +48 -0
  91. digitalhub/entities/run/__init__.py +0 -0
  92. digitalhub/entities/run/builder.py +77 -0
  93. digitalhub/entities/run/crud.py +232 -0
  94. digitalhub/entities/run/entity.py +461 -0
  95. digitalhub/entities/run/spec.py +153 -0
  96. digitalhub/entities/run/status.py +114 -0
  97. digitalhub/entities/secret/__init__.py +0 -0
  98. digitalhub/entities/secret/builder.py +93 -0
  99. digitalhub/entities/secret/crud.py +294 -0
  100. digitalhub/entities/secret/entity.py +73 -0
  101. digitalhub/entities/secret/spec.py +35 -0
  102. digitalhub/entities/secret/status.py +9 -0
  103. digitalhub/entities/task/__init__.py +0 -0
  104. digitalhub/entities/task/builder.py +74 -0
  105. digitalhub/entities/task/crud.py +241 -0
  106. digitalhub/entities/task/entity.py +135 -0
  107. digitalhub/entities/task/models.py +199 -0
  108. digitalhub/entities/task/spec.py +51 -0
  109. digitalhub/entities/task/status.py +9 -0
  110. digitalhub/entities/utils.py +184 -0
  111. digitalhub/entities/workflow/__init__.py +0 -0
  112. digitalhub/entities/workflow/builder.py +91 -0
  113. digitalhub/entities/workflow/crud.py +304 -0
  114. digitalhub/entities/workflow/entity.py +77 -0
  115. digitalhub/entities/workflow/spec.py +15 -0
  116. digitalhub/entities/workflow/status.py +9 -0
  117. digitalhub/readers/__init__.py +0 -0
  118. digitalhub/readers/builder.py +54 -0
  119. digitalhub/readers/objects/__init__.py +0 -0
  120. digitalhub/readers/objects/base.py +70 -0
  121. digitalhub/readers/objects/pandas.py +207 -0
  122. digitalhub/readers/registry.py +15 -0
  123. digitalhub/registry/__init__.py +0 -0
  124. digitalhub/registry/models.py +87 -0
  125. digitalhub/registry/registry.py +74 -0
  126. digitalhub/registry/utils.py +150 -0
  127. digitalhub/runtimes/__init__.py +0 -0
  128. digitalhub/runtimes/base.py +164 -0
  129. digitalhub/runtimes/builder.py +53 -0
  130. digitalhub/runtimes/kind_registry.py +170 -0
  131. digitalhub/stores/__init__.py +0 -0
  132. digitalhub/stores/builder.py +257 -0
  133. digitalhub/stores/objects/__init__.py +0 -0
  134. digitalhub/stores/objects/base.py +189 -0
  135. digitalhub/stores/objects/local.py +230 -0
  136. digitalhub/stores/objects/remote.py +143 -0
  137. digitalhub/stores/objects/s3.py +563 -0
  138. digitalhub/stores/objects/sql.py +328 -0
  139. digitalhub/utils/__init__.py +0 -0
  140. digitalhub/utils/data_utils.py +127 -0
  141. digitalhub/utils/env_utils.py +123 -0
  142. digitalhub/utils/exceptions.py +55 -0
  143. digitalhub/utils/file_utils.py +204 -0
  144. digitalhub/utils/generic_utils.py +207 -0
  145. digitalhub/utils/git_utils.py +148 -0
  146. digitalhub/utils/io_utils.py +79 -0
  147. digitalhub/utils/logger.py +17 -0
  148. digitalhub/utils/uri_utils.py +56 -0
  149. {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/METADATA +27 -12
  150. digitalhub-0.8.0b2.dist-info/RECORD +161 -0
  151. test/test_crud_artifacts.py +1 -1
  152. test/test_crud_dataitems.py +1 -1
  153. test/test_crud_functions.py +1 -1
  154. test/test_crud_runs.py +1 -1
  155. test/test_crud_tasks.py +1 -1
  156. digitalhub-0.8.0b0.dist-info/RECORD +0 -14
  157. {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/LICENSE.txt +0 -0
  158. {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/WHEEL +0 -0
  159. {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/top_level.txt +0 -0
File without changes
@@ -0,0 +1,93 @@
1
+ from __future__ import annotations
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._builders.uuid import build_uuid
8
+ from digitalhub.entities.secret.entity import Secret
9
+
10
+
11
+ def secret_from_parameters(
12
+ project: str,
13
+ name: str,
14
+ kind: str,
15
+ uuid: str | None = None,
16
+ description: str | None = None,
17
+ labels: list[str] | None = None,
18
+ embedded: bool = True,
19
+ **kwargs,
20
+ ) -> Secret:
21
+ """
22
+ Create a new object.
23
+
24
+ Parameters
25
+ ----------
26
+ project : str
27
+ Project name.
28
+ name : str
29
+ Object name.
30
+ kind : str
31
+ Kind the object.
32
+ uuid : str
33
+ ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
34
+ labels : list[str]
35
+ List of labels.
36
+ description : str
37
+ Description of the object (human readable).
38
+ embedded : bool
39
+ Flag to determine if object spec must be embedded in project spec.
40
+ **kwargs : dict
41
+ Spec keyword arguments.
42
+
43
+ Returns
44
+ -------
45
+ Secret
46
+ Object instance.
47
+ """
48
+ name = build_name(name)
49
+ uuid = build_uuid(uuid)
50
+ metadata = build_metadata(
51
+ kind,
52
+ project=project,
53
+ name=name,
54
+ version=uuid,
55
+ description=description,
56
+ labels=labels,
57
+ embedded=embedded,
58
+ )
59
+ path = f"kubernetes://dhcore-proj-secrets-{project}/{name}"
60
+ provider = "kubernetes"
61
+ spec = build_spec(
62
+ kind,
63
+ path=path,
64
+ provider=provider,
65
+ **kwargs,
66
+ )
67
+ status = build_status(kind)
68
+ return Secret(
69
+ project=project,
70
+ name=name,
71
+ uuid=uuid,
72
+ kind=kind,
73
+ metadata=metadata,
74
+ spec=spec,
75
+ status=status,
76
+ )
77
+
78
+
79
+ def secret_from_dict(obj: dict) -> Secret:
80
+ """
81
+ Create a new object from dictionary.
82
+
83
+ Parameters
84
+ ----------
85
+ obj : dict
86
+ Dictionary to create object from.
87
+
88
+ Returns
89
+ -------
90
+ Secret
91
+ Object instance.
92
+ """
93
+ return Secret.from_dict(obj)
@@ -0,0 +1,294 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.context.builder import check_context
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,
11
+ )
12
+ from digitalhub.entities.entity_types import EntityTypes
13
+ from digitalhub.entities.secret.builder import secret_from_dict, secret_from_parameters
14
+ from digitalhub.utils.exceptions import EntityAlreadyExistsError
15
+ from digitalhub.utils.io_utils import read_yaml
16
+
17
+ if typing.TYPE_CHECKING:
18
+ from digitalhub.entities.secret.entity import Secret
19
+
20
+
21
+ ENTITY_TYPE = EntityTypes.SECRET.value
22
+
23
+
24
+ def new_secret(
25
+ project: str,
26
+ name: str,
27
+ uuid: str | None = None,
28
+ description: str | None = None,
29
+ labels: list[str] | None = None,
30
+ embedded: bool = True,
31
+ secret_value: str | None = None,
32
+ **kwargs,
33
+ ) -> Secret:
34
+ """
35
+ Create a new object.
36
+
37
+ Parameters
38
+ ----------
39
+ project : str
40
+ Project name.
41
+ name : str
42
+ Object name.
43
+ uuid : str
44
+ ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
45
+ description : str
46
+ Description of the object (human readable).
47
+ labels : list[str]
48
+ List of labels.
49
+ embedded : bool
50
+ Flag to determine if object spec must be embedded in project spec.
51
+ secret_value : str
52
+ Value of the secret.
53
+ **kwargs : dict
54
+ Spec keyword arguments.
55
+
56
+ Returns
57
+ -------
58
+ Secret
59
+ Object instance.
60
+
61
+ Examples
62
+ --------
63
+ >>> obj = new_secret(project="my-project",
64
+ >>> name="my-secret",
65
+ >>> secret_value="my-secret-value")
66
+ """
67
+ check_context(project)
68
+
69
+ if secret_value is None:
70
+ raise ValueError("secret_value must be provided.")
71
+
72
+ obj = secret_from_parameters(
73
+ project=project,
74
+ name=name,
75
+ kind="secret",
76
+ uuid=uuid,
77
+ description=description,
78
+ labels=labels,
79
+ embedded=embedded,
80
+ **kwargs,
81
+ )
82
+ obj.save()
83
+ obj.set_secret_value(value=secret_value)
84
+ return obj
85
+
86
+
87
+ def get_secret(
88
+ identifier: str,
89
+ project: str | None = None,
90
+ entity_id: str | None = None,
91
+ **kwargs,
92
+ ) -> Secret:
93
+ """
94
+ Get object from backend.
95
+
96
+ Parameters
97
+ ----------
98
+ identifier : str
99
+ Entity key (store://...) or entity name.
100
+ project : str
101
+ Project name.
102
+ entity_id : str
103
+ Entity ID.
104
+ **kwargs : dict
105
+ Parameters to pass to the API call.
106
+
107
+ Returns
108
+ -------
109
+ Secret
110
+ Object instance.
111
+
112
+ Examples
113
+ --------
114
+ Using entity key:
115
+ >>> obj = get_secret("store://my-secret-key")
116
+
117
+ Using entity name:
118
+ >>> obj = get_secret("my-secret-name"
119
+ >>> project="my-project",
120
+ >>> entity_id="my-secret-id")
121
+ """
122
+ obj = read_entity_api_ctx(
123
+ identifier,
124
+ ENTITY_TYPE,
125
+ project=project,
126
+ entity_id=entity_id,
127
+ **kwargs,
128
+ )
129
+ return secret_from_dict(obj)
130
+
131
+
132
+ def get_secret_versions(
133
+ identifier: str,
134
+ project: str | None = None,
135
+ **kwargs,
136
+ ) -> list[Secret]:
137
+ """
138
+ Get object versions from backend.
139
+
140
+ Parameters
141
+ ----------
142
+ identifier : str
143
+ Entity key (store://...) or entity name.
144
+ project : str
145
+ Project name.
146
+ **kwargs : dict
147
+ Parameters to pass to the API call.
148
+
149
+ Returns
150
+ -------
151
+ list[Secret]
152
+ List of object instances.
153
+
154
+ Examples
155
+ --------
156
+ Using entity key:
157
+ >>> objs = get_secret_versions("store://my-secret-key")
158
+
159
+ Using entity name:
160
+ >>> objs = get_secret_versions("my-secret-name",
161
+ >>> project="my-project")
162
+ """
163
+ obj = read_entity_api_ctx_versions(
164
+ identifier,
165
+ entity_type=ENTITY_TYPE,
166
+ project=project,
167
+ **kwargs,
168
+ )
169
+ return [secret_from_dict(o) for o in obj]
170
+
171
+
172
+ def list_secrets(project: str, **kwargs) -> list[Secret]:
173
+ """
174
+ List all latest version objects from backend.
175
+
176
+ Parameters
177
+ ----------
178
+ project : str
179
+ Project name.
180
+ **kwargs : dict
181
+ Parameters to pass to the API call.
182
+
183
+ Returns
184
+ -------
185
+ list[Secret]
186
+ List of object instances.
187
+
188
+ Examples
189
+ --------
190
+ >>> objs = list_secrets(project="my-project")
191
+ """
192
+ objs = list_entity_api_ctx(
193
+ project=project,
194
+ entity_type=ENTITY_TYPE,
195
+ **kwargs,
196
+ )
197
+ return [secret_from_dict(obj) for obj in objs]
198
+
199
+
200
+ def import_secret(file: str) -> Secret:
201
+ """
202
+ Import object from a YAML file.
203
+
204
+ Parameters
205
+ ----------
206
+ file : str
207
+ Path to YAML file.
208
+
209
+ Returns
210
+ -------
211
+ Secret
212
+ Object instance.
213
+
214
+ Examples
215
+ --------
216
+ >>> obj = import_secret("my-secret.yaml")
217
+ """
218
+ dict_obj: dict = read_yaml(file)
219
+ obj = secret_from_dict(dict_obj)
220
+ try:
221
+ obj.save()
222
+ except EntityAlreadyExistsError:
223
+ pass
224
+ finally:
225
+ return obj
226
+
227
+
228
+ def update_secret(entity: Secret) -> Secret:
229
+ """
230
+ Update object. Note that object spec are immutable.
231
+
232
+ Parameters
233
+ ----------
234
+ entity : Secret
235
+ Object to update.
236
+
237
+ Returns
238
+ -------
239
+ Secret
240
+ Entity updated.
241
+
242
+ Examples
243
+ --------
244
+ >>> obj = update_secret(obj)
245
+ """
246
+ return entity.save(update=True)
247
+
248
+
249
+ def delete_secret(
250
+ identifier: str,
251
+ project: str | None = None,
252
+ entity_id: str | None = None,
253
+ delete_all_versions: bool = False,
254
+ **kwargs,
255
+ ) -> dict:
256
+ """
257
+ Delete object from backend.
258
+
259
+ Parameters
260
+ ----------
261
+ identifier : str
262
+ Entity key (store://...) or entity name.
263
+ project : str
264
+ Project name.
265
+ entity_id : str
266
+ Entity ID.
267
+ delete_all_versions : bool
268
+ Delete all versions of the named entity. If True, use entity name instead of entity key as identifier.
269
+ **kwargs : dict
270
+ Parameters to pass to the API call.
271
+
272
+ Returns
273
+ -------
274
+ dict
275
+ Response from backend.
276
+
277
+ Examples
278
+ --------
279
+ If delete_all_versions is False:
280
+ >>> obj = delete_secret("store://my-secret-key")
281
+
282
+ Otherwise:
283
+ >>> obj = delete_secret("my-secret-name"
284
+ >>> project="my-project",
285
+ >>> delete_all_versions=True)
286
+ """
287
+ return delete_entity_api_ctx(
288
+ identifier=identifier,
289
+ entity_type=ENTITY_TYPE,
290
+ project=project,
291
+ entity_id=entity_id,
292
+ delete_all_versions=delete_all_versions,
293
+ **kwargs,
294
+ )
@@ -0,0 +1,73 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.crud import get_data_api, set_data_api
6
+ from digitalhub.entities._base.entity.versioned import VersionedEntity
7
+ from digitalhub.entities.entity_types import EntityTypes
8
+
9
+ if typing.TYPE_CHECKING:
10
+ from digitalhub.entities._base.metadata import Metadata
11
+ from digitalhub.entities.secret.spec import SecretSpec
12
+ from digitalhub.entities.secret.status import SecretStatus
13
+
14
+
15
+ class Secret(VersionedEntity):
16
+ """
17
+ A class representing a secret.
18
+ """
19
+
20
+ ENTITY_TYPE = EntityTypes.SECRET.value
21
+
22
+ def __init__(
23
+ self,
24
+ project: str,
25
+ name: str,
26
+ uuid: str,
27
+ kind: str,
28
+ metadata: Metadata,
29
+ spec: SecretSpec,
30
+ status: SecretStatus,
31
+ user: str | None = None,
32
+ ) -> None:
33
+ super().__init__(project, name, uuid, kind, metadata, spec, status, user)
34
+ self.spec: SecretSpec
35
+ self.status: SecretStatus
36
+
37
+ ##############################
38
+ # Secret methods
39
+ ##############################
40
+
41
+ def set_secret_value(self, value: str) -> None:
42
+ """
43
+ Update the secret value with a new one.
44
+
45
+ Parameters
46
+ ----------
47
+ value : str
48
+ Value of the secret.
49
+
50
+ Returns
51
+ -------
52
+ None
53
+ """
54
+ if self._context().local:
55
+ raise NotImplementedError("set_secret() is not implemented for local projects.")
56
+
57
+ obj = {self.name: value}
58
+ set_data_api(self.project, self.ENTITY_TYPE, obj)
59
+
60
+ def read_secret_value(self) -> dict:
61
+ """
62
+ Read the secret value from backend.
63
+
64
+ Returns
65
+ -------
66
+ str
67
+ Value of the secret.
68
+ """
69
+ if self._context().local:
70
+ raise NotImplementedError("read_secret() is not implemented for local projects.")
71
+
72
+ params = {"keys": self.name}
73
+ return get_data_api(self.project, self.ENTITY_TYPE, params=params)
@@ -0,0 +1,35 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.spec.base import Spec, SpecParams
4
+
5
+
6
+ class SecretSpec(Spec):
7
+ """
8
+ Secret specifications.
9
+ """
10
+
11
+ def __init__(self, path: str | None = None, provider: str | None = None, **kwargs) -> None:
12
+ """
13
+ Constructor.
14
+
15
+ Parameters
16
+ ----------
17
+ path : str
18
+ Path to the secret.
19
+ provider : str
20
+ Provider of the secret.
21
+ """
22
+ self.path = path
23
+ self.provider = provider
24
+
25
+
26
+ class SecretParams(SpecParams):
27
+ """
28
+ Secret parameters.
29
+ """
30
+
31
+ path: str = None
32
+ """Path to the secret."""
33
+
34
+ provider: str = None
35
+ """Provider of the secret."""
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.status.base import Status
4
+
5
+
6
+ class SecretStatus(Status):
7
+ """
8
+ Status class for secret entities.
9
+ """
File without changes
@@ -0,0 +1,74 @@
1
+ from __future__ import annotations
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.task.entity import Task
8
+
9
+
10
+ def task_from_parameters(
11
+ project: str,
12
+ kind: str,
13
+ uuid: str | None = None,
14
+ labels: list[str] | None = None,
15
+ function: str | None = None,
16
+ **kwargs,
17
+ ) -> Task:
18
+ """
19
+ Create a new object.
20
+
21
+ Parameters
22
+ ----------
23
+ project : str
24
+ Project name.
25
+ kind : str
26
+ Kind the object.
27
+ uuid : str
28
+ ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
29
+ labels : list[str]
30
+ List of labels.
31
+ function : str
32
+ Name of the executable associated with the task.
33
+ **kwargs : dict
34
+ Spec keyword arguments.
35
+
36
+ Returns
37
+ -------
38
+ Task
39
+ Object instance.
40
+ """
41
+ uuid = build_uuid(uuid)
42
+ metadata = build_metadata(
43
+ kind=kind,
44
+ project=project,
45
+ name=uuid,
46
+ labels=labels,
47
+ )
48
+ spec = build_spec(kind, function=function, **kwargs)
49
+ status = build_status(kind)
50
+ return Task(
51
+ project=project,
52
+ uuid=uuid,
53
+ kind=kind,
54
+ metadata=metadata,
55
+ spec=spec,
56
+ status=status,
57
+ )
58
+
59
+
60
+ def task_from_dict(obj: dict) -> Task:
61
+ """
62
+ Create a new object from dictionary.
63
+
64
+ Parameters
65
+ ----------
66
+ obj : dict
67
+ Dictionary representation of Task.
68
+
69
+ Returns
70
+ -------
71
+ Task
72
+ Object instance.
73
+ """
74
+ return Task.from_dict(obj)