digitalhub 0.8.1__py3-none-any.whl → 0.9.0__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.
- digitalhub/__init__.py +19 -2
- digitalhub/client/_base/api_builder.py +16 -0
- digitalhub/client/_base/client.py +67 -0
- digitalhub/client/_base/key_builder.py +52 -0
- digitalhub/client/api.py +2 -38
- digitalhub/client/dhcore/api_builder.py +100 -0
- digitalhub/client/dhcore/client.py +81 -25
- digitalhub/client/dhcore/enums.py +27 -0
- digitalhub/client/dhcore/env.py +2 -2
- digitalhub/client/dhcore/key_builder.py +58 -0
- digitalhub/client/dhcore/utils.py +17 -17
- digitalhub/client/local/api_builder.py +100 -0
- digitalhub/client/local/client.py +22 -0
- digitalhub/client/local/key_builder.py +58 -0
- digitalhub/context/api.py +3 -38
- digitalhub/context/builder.py +10 -23
- digitalhub/context/context.py +20 -92
- digitalhub/entities/_base/context/entity.py +30 -22
- digitalhub/entities/_base/entity/_constructors/metadata.py +12 -1
- digitalhub/entities/_base/entity/_constructors/name.py +1 -1
- digitalhub/entities/_base/entity/_constructors/spec.py +1 -1
- digitalhub/entities/_base/entity/_constructors/status.py +3 -2
- digitalhub/entities/_base/entity/builder.py +6 -1
- digitalhub/entities/_base/entity/entity.py +32 -10
- digitalhub/entities/_base/entity/metadata.py +22 -0
- digitalhub/entities/_base/entity/spec.py +7 -2
- digitalhub/entities/_base/executable/entity.py +8 -8
- digitalhub/entities/_base/material/entity.py +49 -17
- digitalhub/entities/_base/material/status.py +0 -31
- digitalhub/entities/_base/material/utils.py +106 -0
- digitalhub/entities/_base/project/entity.py +341 -0
- digitalhub/entities/_base/unversioned/entity.py +3 -24
- digitalhub/entities/_base/versioned/entity.py +2 -26
- digitalhub/entities/_commons/enums.py +103 -0
- digitalhub/entities/_commons/utils.py +83 -0
- digitalhub/entities/_operations/processor.py +1873 -0
- digitalhub/entities/artifact/_base/builder.py +1 -1
- digitalhub/entities/artifact/_base/entity.py +1 -1
- digitalhub/entities/artifact/artifact/builder.py +2 -1
- digitalhub/entities/artifact/crud.py +46 -29
- digitalhub/entities/artifact/utils.py +62 -0
- digitalhub/entities/dataitem/_base/builder.py +1 -1
- digitalhub/entities/dataitem/_base/entity.py +6 -6
- digitalhub/entities/dataitem/crud.py +50 -66
- digitalhub/entities/dataitem/dataitem/builder.py +2 -1
- digitalhub/entities/dataitem/iceberg/builder.py +2 -1
- digitalhub/entities/dataitem/table/builder.py +2 -1
- digitalhub/entities/dataitem/table/entity.py +5 -10
- digitalhub/entities/dataitem/table/models.py +4 -5
- digitalhub/entities/dataitem/utils.py +137 -0
- digitalhub/entities/function/_base/builder.py +1 -1
- digitalhub/entities/function/_base/entity.py +6 -2
- digitalhub/entities/function/crud.py +36 -17
- digitalhub/entities/model/_base/builder.py +1 -1
- digitalhub/entities/model/_base/entity.py +1 -1
- digitalhub/entities/model/crud.py +46 -29
- digitalhub/entities/model/huggingface/builder.py +2 -1
- digitalhub/entities/model/huggingface/spec.py +4 -2
- digitalhub/entities/model/mlflow/builder.py +2 -1
- digitalhub/entities/model/mlflow/models.py +17 -9
- digitalhub/entities/model/mlflow/spec.py +6 -1
- digitalhub/entities/model/mlflow/utils.py +4 -2
- digitalhub/entities/model/model/builder.py +2 -1
- digitalhub/entities/model/sklearn/builder.py +2 -1
- digitalhub/entities/model/utils.py +62 -0
- digitalhub/entities/project/_base/builder.py +2 -2
- digitalhub/entities/project/_base/entity.py +82 -272
- digitalhub/entities/project/crud.py +110 -91
- digitalhub/entities/project/utils.py +35 -0
- digitalhub/entities/run/_base/builder.py +3 -1
- digitalhub/entities/run/_base/entity.py +52 -54
- digitalhub/entities/run/_base/spec.py +15 -7
- digitalhub/entities/run/crud.py +35 -17
- digitalhub/entities/secret/_base/builder.py +2 -2
- digitalhub/entities/secret/_base/entity.py +4 -10
- digitalhub/entities/secret/crud.py +36 -21
- digitalhub/entities/task/_base/builder.py +14 -14
- digitalhub/entities/task/_base/entity.py +21 -14
- digitalhub/entities/task/_base/models.py +35 -6
- digitalhub/entities/task/_base/spec.py +50 -13
- digitalhub/entities/task/_base/utils.py +18 -0
- digitalhub/entities/task/crud.py +35 -15
- digitalhub/entities/workflow/_base/builder.py +1 -1
- digitalhub/entities/workflow/_base/entity.py +22 -6
- digitalhub/entities/workflow/crud.py +36 -17
- digitalhub/factory/utils.py +1 -1
- digitalhub/readers/_base/reader.py +2 -2
- digitalhub/readers/_commons/enums.py +13 -0
- digitalhub/readers/api.py +3 -2
- digitalhub/readers/factory.py +12 -6
- digitalhub/readers/pandas/reader.py +20 -8
- digitalhub/runtimes/_base.py +0 -7
- digitalhub/runtimes/enums.py +12 -0
- digitalhub/stores/_base/store.py +59 -11
- digitalhub/stores/builder.py +5 -5
- digitalhub/stores/local/store.py +43 -4
- digitalhub/stores/remote/store.py +31 -5
- digitalhub/stores/s3/store.py +129 -48
- digitalhub/stores/sql/store.py +122 -47
- digitalhub/utils/exceptions.py +6 -0
- digitalhub/utils/file_utils.py +60 -2
- digitalhub/utils/generic_utils.py +45 -4
- digitalhub/utils/io_utils.py +18 -0
- digitalhub/utils/s3_utils.py +17 -0
- digitalhub/utils/uri_utils.py +153 -15
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0.dist-info}/LICENSE.txt +1 -1
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0.dist-info}/METADATA +3 -3
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0.dist-info}/RECORD +116 -114
- test/local/instances/test_validate.py +55 -0
- test/testkfp.py +4 -1
- digitalhub/datastores/_base/datastore.py +0 -85
- digitalhub/datastores/api.py +0 -37
- digitalhub/datastores/builder.py +0 -110
- digitalhub/datastores/local/datastore.py +0 -50
- digitalhub/datastores/remote/__init__.py +0 -0
- digitalhub/datastores/remote/datastore.py +0 -31
- digitalhub/datastores/s3/__init__.py +0 -0
- digitalhub/datastores/s3/datastore.py +0 -46
- digitalhub/datastores/sql/__init__.py +0 -0
- digitalhub/datastores/sql/datastore.py +0 -68
- digitalhub/entities/_base/api_utils.py +0 -620
- digitalhub/entities/_base/crud.py +0 -468
- digitalhub/entities/function/_base/models.py +0 -118
- digitalhub/entities/utils/__init__.py +0 -0
- digitalhub/entities/utils/api.py +0 -346
- digitalhub/entities/utils/entity_types.py +0 -19
- digitalhub/entities/utils/state.py +0 -31
- digitalhub/entities/utils/utils.py +0 -202
- /digitalhub/{context → entities/_base/project}/__init__.py +0 -0
- /digitalhub/{datastores → entities/_commons}/__init__.py +0 -0
- /digitalhub/{datastores/_base → entities/_operations}/__init__.py +0 -0
- /digitalhub/{datastores/local → readers/_commons}/__init__.py +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0.dist-info}/WHEEL +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0.dist-info}/top_level.txt +0 -0
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import typing
|
|
4
|
-
|
|
5
|
-
from digitalhub.client.api import build_client, get_client
|
|
6
|
-
from digitalhub.context.api import check_context
|
|
7
|
-
from digitalhub.entities._base.api_utils import (
|
|
8
|
-
delete_entity_api_ctx,
|
|
9
|
-
list_entity_api_ctx,
|
|
10
|
-
read_entity_api_base,
|
|
11
|
-
read_entity_api_ctx,
|
|
12
|
-
read_entity_api_ctx_versions,
|
|
13
|
-
)
|
|
14
|
-
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
15
|
-
from digitalhub.entities.utils.utils import parse_entity_key
|
|
16
|
-
from digitalhub.factory.api import build_entity_from_dict, build_entity_from_params
|
|
17
|
-
from digitalhub.utils.exceptions import ContextError, EntityAlreadyExistsError, EntityError, EntityNotExistsError
|
|
18
|
-
from digitalhub.utils.io_utils import read_yaml
|
|
19
|
-
|
|
20
|
-
if typing.TYPE_CHECKING:
|
|
21
|
-
from digitalhub.entities._base.context.entity import ContextEntity
|
|
22
|
-
from digitalhub.entities._base.executable.entity import ExecutableEntity
|
|
23
|
-
from digitalhub.entities._base.material.entity import MaterialEntity
|
|
24
|
-
from digitalhub.entities._base.unversioned.entity import UnversionedEntity
|
|
25
|
-
from digitalhub.entities._base.versioned.entity import VersionedEntity
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def _check_context(project: str) -> None:
|
|
29
|
-
"""
|
|
30
|
-
Check if the given project is in the context.
|
|
31
|
-
Otherwise try to get the project from remote.
|
|
32
|
-
|
|
33
|
-
Parameters
|
|
34
|
-
----------
|
|
35
|
-
project : str
|
|
36
|
-
Project name.
|
|
37
|
-
|
|
38
|
-
Returns
|
|
39
|
-
-------
|
|
40
|
-
None
|
|
41
|
-
"""
|
|
42
|
-
try:
|
|
43
|
-
check_context(project)
|
|
44
|
-
except ContextError:
|
|
45
|
-
try:
|
|
46
|
-
build_client()
|
|
47
|
-
client = get_client()
|
|
48
|
-
obj = read_entity_api_base(client, EntityTypes.PROJECT.value, project)
|
|
49
|
-
build_entity_from_dict(obj)
|
|
50
|
-
except EntityNotExistsError:
|
|
51
|
-
raise ContextError(f"Project '{project}' not found.")
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def _check_project_from_identifier(identifier: str, project: str | None = None) -> None:
|
|
55
|
-
"""
|
|
56
|
-
Check if the given project is in the context.
|
|
57
|
-
Otherwise try to get the project from remote.
|
|
58
|
-
|
|
59
|
-
Parameters
|
|
60
|
-
----------
|
|
61
|
-
identifier : str
|
|
62
|
-
Entity key (store://...) or entity name.
|
|
63
|
-
project : str
|
|
64
|
-
Project name.
|
|
65
|
-
|
|
66
|
-
Returns
|
|
67
|
-
-------
|
|
68
|
-
None
|
|
69
|
-
"""
|
|
70
|
-
if not identifier.startswith("store://"):
|
|
71
|
-
if project is None:
|
|
72
|
-
raise EntityError("Specify project if you do not specify entity key.")
|
|
73
|
-
|
|
74
|
-
else:
|
|
75
|
-
project, _, _, _, _ = parse_entity_key(identifier)
|
|
76
|
-
|
|
77
|
-
_check_context(project)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def new_context_entity(**kwargs) -> ContextEntity:
|
|
81
|
-
"""
|
|
82
|
-
Create a new object.
|
|
83
|
-
|
|
84
|
-
Parameters
|
|
85
|
-
----------
|
|
86
|
-
project : str
|
|
87
|
-
Project name.
|
|
88
|
-
kind : str
|
|
89
|
-
Kind the object.
|
|
90
|
-
uuid : str
|
|
91
|
-
ID of the object.
|
|
92
|
-
description : str
|
|
93
|
-
Description of the object (human readable).
|
|
94
|
-
labels : list[str]
|
|
95
|
-
List of labels.
|
|
96
|
-
embedded : bool
|
|
97
|
-
Flag to determine if object spec must be embedded in project spec.
|
|
98
|
-
|
|
99
|
-
Returns
|
|
100
|
-
-------
|
|
101
|
-
ContextEntity
|
|
102
|
-
Object instance.
|
|
103
|
-
"""
|
|
104
|
-
_check_context(kwargs["project"])
|
|
105
|
-
obj = build_entity_from_params(**kwargs)
|
|
106
|
-
obj.save()
|
|
107
|
-
return obj
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def get_versioned_entity(
|
|
111
|
-
identifier: str,
|
|
112
|
-
entity_type: str | None = None,
|
|
113
|
-
project: str | None = None,
|
|
114
|
-
entity_id: str | None = None,
|
|
115
|
-
**kwargs,
|
|
116
|
-
) -> VersionedEntity:
|
|
117
|
-
"""
|
|
118
|
-
Get object from backend.
|
|
119
|
-
|
|
120
|
-
Parameters
|
|
121
|
-
----------
|
|
122
|
-
identifier : str
|
|
123
|
-
Entity key (store://...) or entity name.
|
|
124
|
-
entity_type : str
|
|
125
|
-
Entity type.
|
|
126
|
-
project : str
|
|
127
|
-
Project name.
|
|
128
|
-
entity_id : str
|
|
129
|
-
Entity ID.
|
|
130
|
-
**kwargs : dict
|
|
131
|
-
Parameters to pass to the API call.
|
|
132
|
-
|
|
133
|
-
Returns
|
|
134
|
-
-------
|
|
135
|
-
VersionedEntity
|
|
136
|
-
Object instance.
|
|
137
|
-
"""
|
|
138
|
-
_check_project_from_identifier(identifier, project)
|
|
139
|
-
obj = read_entity_api_ctx(
|
|
140
|
-
identifier,
|
|
141
|
-
entity_type=entity_type,
|
|
142
|
-
project=project,
|
|
143
|
-
entity_id=entity_id,
|
|
144
|
-
**kwargs,
|
|
145
|
-
)
|
|
146
|
-
return build_entity_from_dict(obj)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
def get_unversioned_entity(
|
|
150
|
-
identifier: str,
|
|
151
|
-
entity_type: str | None = None,
|
|
152
|
-
project: str | None = None,
|
|
153
|
-
**kwargs,
|
|
154
|
-
) -> UnversionedEntity:
|
|
155
|
-
"""
|
|
156
|
-
Get object from backend.
|
|
157
|
-
|
|
158
|
-
Parameters
|
|
159
|
-
----------
|
|
160
|
-
entity_type : str
|
|
161
|
-
Entity type.
|
|
162
|
-
identifier : str
|
|
163
|
-
Entity key (store://...) or entity name.
|
|
164
|
-
project : str
|
|
165
|
-
Project name.
|
|
166
|
-
entity_id : str
|
|
167
|
-
Entity ID.
|
|
168
|
-
**kwargs : dict
|
|
169
|
-
Parameters to pass to the API call.
|
|
170
|
-
|
|
171
|
-
Returns
|
|
172
|
-
-------
|
|
173
|
-
UnversionedEntity
|
|
174
|
-
Object instance.
|
|
175
|
-
"""
|
|
176
|
-
_check_project_from_identifier(identifier, project)
|
|
177
|
-
|
|
178
|
-
obj = read_entity_api_ctx(
|
|
179
|
-
identifier,
|
|
180
|
-
entity_type=entity_type,
|
|
181
|
-
project=project,
|
|
182
|
-
**kwargs,
|
|
183
|
-
)
|
|
184
|
-
return build_entity_from_dict(obj)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
def get_material_entity(
|
|
188
|
-
identifier: str,
|
|
189
|
-
entity_type: str | None = None,
|
|
190
|
-
project: str | None = None,
|
|
191
|
-
entity_id: str | None = None,
|
|
192
|
-
**kwargs,
|
|
193
|
-
) -> MaterialEntity:
|
|
194
|
-
"""
|
|
195
|
-
Get object from backend.
|
|
196
|
-
|
|
197
|
-
Parameters
|
|
198
|
-
----------
|
|
199
|
-
identifier : str
|
|
200
|
-
Entity key (store://...) or entity name.
|
|
201
|
-
entity_type : str
|
|
202
|
-
Entity type.
|
|
203
|
-
project : str
|
|
204
|
-
Project name.
|
|
205
|
-
entity_id : str
|
|
206
|
-
Entity ID.
|
|
207
|
-
**kwargs : dict
|
|
208
|
-
Parameters to pass to the API call.
|
|
209
|
-
|
|
210
|
-
Returns
|
|
211
|
-
-------
|
|
212
|
-
MaterialEntity
|
|
213
|
-
Object instance.
|
|
214
|
-
"""
|
|
215
|
-
obj: MaterialEntity = get_versioned_entity(
|
|
216
|
-
identifier,
|
|
217
|
-
entity_type=entity_type,
|
|
218
|
-
project=project,
|
|
219
|
-
entity_id=entity_id,
|
|
220
|
-
**kwargs,
|
|
221
|
-
)
|
|
222
|
-
obj._get_files_info()
|
|
223
|
-
return obj
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
def get_context_entity_versions(
|
|
227
|
-
identifier: str,
|
|
228
|
-
entity_type: str | None = None,
|
|
229
|
-
project: str | None = None,
|
|
230
|
-
**kwargs,
|
|
231
|
-
) -> list[ContextEntity]:
|
|
232
|
-
"""
|
|
233
|
-
Get object versions from backend.
|
|
234
|
-
|
|
235
|
-
Parameters
|
|
236
|
-
----------
|
|
237
|
-
identifier : str
|
|
238
|
-
Entity key (store://...) or entity name.
|
|
239
|
-
entity_type : str
|
|
240
|
-
Entity type.
|
|
241
|
-
project : str
|
|
242
|
-
Project name.
|
|
243
|
-
**kwargs : dict
|
|
244
|
-
Parameters to pass to the API call.
|
|
245
|
-
|
|
246
|
-
Returns
|
|
247
|
-
-------
|
|
248
|
-
list[ContextEntity]
|
|
249
|
-
List of object instances.
|
|
250
|
-
"""
|
|
251
|
-
_check_project_from_identifier(identifier, project)
|
|
252
|
-
obj = read_entity_api_ctx_versions(
|
|
253
|
-
identifier,
|
|
254
|
-
entity_type=entity_type,
|
|
255
|
-
project=project,
|
|
256
|
-
**kwargs,
|
|
257
|
-
)
|
|
258
|
-
return [build_entity_from_dict(o) for o in obj]
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
def get_material_entity_versions(
|
|
262
|
-
identifier: str,
|
|
263
|
-
entity_type: str | None = None,
|
|
264
|
-
project: str | None = None,
|
|
265
|
-
**kwargs,
|
|
266
|
-
) -> list[MaterialEntity]:
|
|
267
|
-
"""
|
|
268
|
-
Get object versions from backend.
|
|
269
|
-
|
|
270
|
-
Parameters
|
|
271
|
-
----------
|
|
272
|
-
identifier : str
|
|
273
|
-
Entity key (store://...) or entity name.
|
|
274
|
-
entity_type : str
|
|
275
|
-
Entity type.
|
|
276
|
-
project : str
|
|
277
|
-
Project name.
|
|
278
|
-
**kwargs : dict
|
|
279
|
-
Parameters to pass to the API call.
|
|
280
|
-
|
|
281
|
-
Returns
|
|
282
|
-
-------
|
|
283
|
-
list[MaterialEntity]
|
|
284
|
-
List of object instances.
|
|
285
|
-
"""
|
|
286
|
-
_check_project_from_identifier(identifier, project)
|
|
287
|
-
objs = read_entity_api_ctx_versions(
|
|
288
|
-
identifier,
|
|
289
|
-
entity_type=entity_type,
|
|
290
|
-
project=project,
|
|
291
|
-
**kwargs,
|
|
292
|
-
)
|
|
293
|
-
objects = []
|
|
294
|
-
for o in objs:
|
|
295
|
-
entity: MaterialEntity = build_entity_from_dict(o)
|
|
296
|
-
entity._get_files_info()
|
|
297
|
-
objects.append(entity)
|
|
298
|
-
return objects
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
def list_context_entities(project: str, entity_type: str, **kwargs) -> list[ContextEntity]:
|
|
302
|
-
"""
|
|
303
|
-
List all latest version objects from backend.
|
|
304
|
-
|
|
305
|
-
Parameters
|
|
306
|
-
----------
|
|
307
|
-
project : str
|
|
308
|
-
Project name.
|
|
309
|
-
entity_type : str
|
|
310
|
-
Entity type.
|
|
311
|
-
**kwargs : dict
|
|
312
|
-
Parameters to pass to the API call.
|
|
313
|
-
|
|
314
|
-
Returns
|
|
315
|
-
-------
|
|
316
|
-
list[ContextEntity]
|
|
317
|
-
List of object instances.
|
|
318
|
-
"""
|
|
319
|
-
_check_context(project)
|
|
320
|
-
objs = list_entity_api_ctx(
|
|
321
|
-
project=project,
|
|
322
|
-
entity_type=entity_type,
|
|
323
|
-
**kwargs,
|
|
324
|
-
)
|
|
325
|
-
return [build_entity_from_dict(obj) for obj in objs]
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
def list_material_entities(
|
|
329
|
-
project: str,
|
|
330
|
-
entity_type: str,
|
|
331
|
-
**kwargs,
|
|
332
|
-
) -> list[MaterialEntity]:
|
|
333
|
-
"""
|
|
334
|
-
List all latest version objects from backend.
|
|
335
|
-
|
|
336
|
-
Parameters
|
|
337
|
-
----------
|
|
338
|
-
project : str
|
|
339
|
-
Project name.
|
|
340
|
-
entity_type : str
|
|
341
|
-
Entity type.
|
|
342
|
-
**kwargs : dict
|
|
343
|
-
Parameters to pass to the API call.
|
|
344
|
-
|
|
345
|
-
Returns
|
|
346
|
-
-------
|
|
347
|
-
list[MaterialEntity]
|
|
348
|
-
List of object instances.
|
|
349
|
-
"""
|
|
350
|
-
_check_context(project)
|
|
351
|
-
objs = list_entity_api_ctx(
|
|
352
|
-
project=project,
|
|
353
|
-
entity_type=entity_type,
|
|
354
|
-
**kwargs,
|
|
355
|
-
)
|
|
356
|
-
objects = []
|
|
357
|
-
for o in objs:
|
|
358
|
-
entity: MaterialEntity = build_entity_from_dict(o)
|
|
359
|
-
entity._get_files_info()
|
|
360
|
-
objects.append(entity)
|
|
361
|
-
return objects
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
def import_context_entity(file: str) -> ContextEntity:
|
|
365
|
-
"""
|
|
366
|
-
Get object from file.
|
|
367
|
-
|
|
368
|
-
Parameters
|
|
369
|
-
----------
|
|
370
|
-
file : str
|
|
371
|
-
Path to YAML file.
|
|
372
|
-
|
|
373
|
-
Returns
|
|
374
|
-
-------
|
|
375
|
-
ContextEntity
|
|
376
|
-
Object instance.
|
|
377
|
-
"""
|
|
378
|
-
dict_obj: dict = read_yaml(file)
|
|
379
|
-
|
|
380
|
-
_check_context(dict_obj["project"])
|
|
381
|
-
|
|
382
|
-
obj = build_entity_from_dict(dict_obj)
|
|
383
|
-
try:
|
|
384
|
-
obj.save()
|
|
385
|
-
except EntityAlreadyExistsError:
|
|
386
|
-
pass
|
|
387
|
-
return obj
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
def import_executable_entity(file: str) -> ExecutableEntity:
|
|
391
|
-
"""
|
|
392
|
-
Get object from file.
|
|
393
|
-
|
|
394
|
-
Parameters
|
|
395
|
-
----------
|
|
396
|
-
file : str
|
|
397
|
-
Path to YAML file.
|
|
398
|
-
|
|
399
|
-
Returns
|
|
400
|
-
-------
|
|
401
|
-
ExecutableEntity
|
|
402
|
-
Object instance.
|
|
403
|
-
"""
|
|
404
|
-
dict_obj: dict | list[dict] = read_yaml(file)
|
|
405
|
-
if isinstance(dict_obj, list):
|
|
406
|
-
exec_dict = dict_obj[0]
|
|
407
|
-
tsk_dicts = dict_obj[1:]
|
|
408
|
-
else:
|
|
409
|
-
exec_dict = dict_obj
|
|
410
|
-
tsk_dicts = []
|
|
411
|
-
|
|
412
|
-
_check_context(exec_dict["project"])
|
|
413
|
-
|
|
414
|
-
obj: ExecutableEntity = build_entity_from_dict(exec_dict)
|
|
415
|
-
|
|
416
|
-
obj.import_tasks(tsk_dicts)
|
|
417
|
-
|
|
418
|
-
try:
|
|
419
|
-
obj.save()
|
|
420
|
-
except EntityAlreadyExistsError:
|
|
421
|
-
pass
|
|
422
|
-
return obj
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
def delete_entity(
|
|
426
|
-
identifier: str,
|
|
427
|
-
entity_type: str | None = None,
|
|
428
|
-
project: str | None = None,
|
|
429
|
-
entity_id: str | None = None,
|
|
430
|
-
delete_all_versions: bool = False,
|
|
431
|
-
cascade: bool = True,
|
|
432
|
-
**kwargs,
|
|
433
|
-
) -> dict:
|
|
434
|
-
"""
|
|
435
|
-
Delete object from backend.
|
|
436
|
-
|
|
437
|
-
Parameters
|
|
438
|
-
----------
|
|
439
|
-
identifier : str
|
|
440
|
-
Entity key (store://...) or entity name.
|
|
441
|
-
entity_type : str
|
|
442
|
-
Entity type.
|
|
443
|
-
project : str
|
|
444
|
-
Project name.
|
|
445
|
-
entity_id : str
|
|
446
|
-
Entity ID.
|
|
447
|
-
delete_all_versions : bool
|
|
448
|
-
Delete all versions of the named entity. If True, use entity name instead of entity key as identifier.
|
|
449
|
-
cascade : bool
|
|
450
|
-
Cascade delete.
|
|
451
|
-
**kwargs : dict
|
|
452
|
-
Parameters to pass to the API call.
|
|
453
|
-
|
|
454
|
-
Returns
|
|
455
|
-
-------
|
|
456
|
-
dict
|
|
457
|
-
Response from backend.
|
|
458
|
-
"""
|
|
459
|
-
_check_project_from_identifier(identifier, project)
|
|
460
|
-
return delete_entity_api_ctx(
|
|
461
|
-
identifier=identifier,
|
|
462
|
-
entity_type=entity_type,
|
|
463
|
-
project=project,
|
|
464
|
-
entity_id=entity_id,
|
|
465
|
-
delete_all_versions=delete_all_versions,
|
|
466
|
-
cascade=cascade,
|
|
467
|
-
**kwargs,
|
|
468
|
-
)
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from abc import abstractmethod
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
from pydantic import BaseModel
|
|
7
|
-
|
|
8
|
-
from digitalhub.utils.exceptions import EntityError
|
|
9
|
-
from digitalhub.utils.generic_utils import decode_string
|
|
10
|
-
from digitalhub.utils.uri_utils import map_uri_scheme
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class SourceCodeStruct:
|
|
14
|
-
"""
|
|
15
|
-
Source code struct.
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
def __init__(
|
|
19
|
-
self,
|
|
20
|
-
source: str | None = None,
|
|
21
|
-
code: str | None = None,
|
|
22
|
-
base64: str | None = None,
|
|
23
|
-
handler: str | None = None,
|
|
24
|
-
lang: str | None = None,
|
|
25
|
-
) -> None:
|
|
26
|
-
self.source = source
|
|
27
|
-
self.code = code
|
|
28
|
-
self.base64 = base64
|
|
29
|
-
self.handler = handler
|
|
30
|
-
self.lang = lang
|
|
31
|
-
|
|
32
|
-
@staticmethod
|
|
33
|
-
@abstractmethod
|
|
34
|
-
def source_check(source: dict) -> dict:
|
|
35
|
-
"""
|
|
36
|
-
Check source.
|
|
37
|
-
|
|
38
|
-
Parameters
|
|
39
|
-
----------
|
|
40
|
-
source : dict
|
|
41
|
-
Source.
|
|
42
|
-
|
|
43
|
-
Returns
|
|
44
|
-
-------
|
|
45
|
-
dict
|
|
46
|
-
Checked source.
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
def show_source_code(self) -> str:
|
|
50
|
-
"""
|
|
51
|
-
Show source code.
|
|
52
|
-
|
|
53
|
-
Returns
|
|
54
|
-
-------
|
|
55
|
-
str
|
|
56
|
-
Source code.
|
|
57
|
-
"""
|
|
58
|
-
if self.code is not None:
|
|
59
|
-
return self.code
|
|
60
|
-
if self.base64 is not None:
|
|
61
|
-
try:
|
|
62
|
-
return decode_string(self.base64)
|
|
63
|
-
except Exception:
|
|
64
|
-
raise EntityError("Something got wrong during source code decoding.")
|
|
65
|
-
if (self.source is not None) and (map_uri_scheme(self.source) == "local"):
|
|
66
|
-
try:
|
|
67
|
-
return Path(self.source).read_text()
|
|
68
|
-
except Exception:
|
|
69
|
-
raise EntityError("Cannot access source code.")
|
|
70
|
-
return ""
|
|
71
|
-
|
|
72
|
-
def to_dict(self) -> dict:
|
|
73
|
-
"""
|
|
74
|
-
Convert to dictionary.
|
|
75
|
-
|
|
76
|
-
Returns
|
|
77
|
-
-------
|
|
78
|
-
dict
|
|
79
|
-
Dictionary representation of the object.
|
|
80
|
-
"""
|
|
81
|
-
dict_ = {}
|
|
82
|
-
if self.source is not None:
|
|
83
|
-
dict_["source"] = self.source
|
|
84
|
-
if self.base64 is not None:
|
|
85
|
-
dict_["base64"] = self.base64
|
|
86
|
-
if self.handler is not None:
|
|
87
|
-
dict_["handler"] = self.handler
|
|
88
|
-
if self.lang is not None:
|
|
89
|
-
dict_["lang"] = self.lang
|
|
90
|
-
|
|
91
|
-
return dict_
|
|
92
|
-
|
|
93
|
-
def __repr__(self) -> str:
|
|
94
|
-
return str(self.to_dict())
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
class SourceCodeValidator(BaseModel):
|
|
98
|
-
"""
|
|
99
|
-
Source code params.
|
|
100
|
-
"""
|
|
101
|
-
|
|
102
|
-
source: dict = None
|
|
103
|
-
"Source code details as dictionary"
|
|
104
|
-
|
|
105
|
-
code_src: str = None
|
|
106
|
-
"Pointer to source code"
|
|
107
|
-
|
|
108
|
-
handler: str = None
|
|
109
|
-
"Function entrypoint"
|
|
110
|
-
|
|
111
|
-
code: str = None
|
|
112
|
-
"Source code (plain text)"
|
|
113
|
-
|
|
114
|
-
base64: str = None
|
|
115
|
-
"Source code (base64 encoded)"
|
|
116
|
-
|
|
117
|
-
lang: str = None
|
|
118
|
-
"Source code language (hint)"
|
|
File without changes
|