digitalhub 0.8.0b3__py3-none-any.whl → 0.8.0b4__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 +3 -2
- digitalhub/client/dhcore/client.py +6 -1
- digitalhub/context/builder.py +1 -1
- digitalhub/context/context.py +1 -1
- digitalhub/entities/_base/entity/entity.py +2 -28
- digitalhub/entities/_base/unversioned/builder.py +66 -0
- digitalhub/entities/_base/unversioned/entity.py +0 -38
- digitalhub/entities/_base/versioned/builder.py +68 -0
- digitalhub/entities/_base/versioned/entity.py +0 -41
- digitalhub/entities/_builders/entity.py +37 -32
- digitalhub/entities/_builders/metadata.py +3 -10
- digitalhub/entities/_builders/spec.py +11 -21
- digitalhub/entities/_builders/status.py +8 -18
- digitalhub/entities/_builders/uuid.py +4 -11
- digitalhub/entities/artifact/_base/builder.py +86 -0
- digitalhub/entities/artifact/artifact/builder.py +18 -0
- digitalhub/entities/artifact/builder.py +15 -97
- digitalhub/entities/artifact/crud.py +1 -1
- digitalhub/entities/builders.py +63 -0
- digitalhub/entities/dataitem/_base/builder.py +86 -0
- digitalhub/entities/dataitem/builder.py +15 -108
- digitalhub/entities/dataitem/crud.py +3 -3
- digitalhub/entities/dataitem/dataitem/builder.py +18 -0
- digitalhub/entities/dataitem/iceberg/builder.py +18 -0
- digitalhub/entities/dataitem/table/builder.py +18 -0
- digitalhub/entities/function/_base/builder.py +78 -0
- digitalhub/entities/function/_base/entity.py +2 -2
- digitalhub/entities/function/builder.py +22 -57
- digitalhub/entities/function/crud.py +1 -1
- digitalhub/entities/model/_base/builder.py +86 -0
- digitalhub/entities/model/builder.py +15 -116
- digitalhub/entities/model/crud.py +1 -1
- digitalhub/entities/model/huggingface/builder.py +18 -0
- digitalhub/entities/model/mlflow/builder.py +18 -0
- digitalhub/entities/model/model/builder.py +18 -0
- digitalhub/entities/model/sklearn/builder.py +18 -0
- digitalhub/entities/project/_base/builder.py +128 -0
- digitalhub/entities/project/{project → _base}/entity.py +9 -51
- digitalhub/entities/project/builder.py +20 -51
- digitalhub/entities/project/crud.py +1 -1
- digitalhub/entities/run/_base/builder.py +73 -0
- digitalhub/entities/run/_base/entity.py +6 -149
- digitalhub/entities/run/builder.py +21 -47
- digitalhub/entities/run/crud.py +1 -1
- digitalhub/entities/secret/_base/builder.py +81 -0
- digitalhub/entities/secret/{secret → _base}/entity.py +2 -2
- digitalhub/entities/secret/builder.py +20 -62
- digitalhub/entities/secret/crud.py +2 -2
- digitalhub/entities/task/_base/builder.py +76 -0
- digitalhub/entities/task/builder.py +21 -44
- digitalhub/entities/task/crud.py +1 -1
- digitalhub/entities/workflow/_base/builder.py +78 -0
- digitalhub/entities/workflow/_base/entity.py +2 -2
- digitalhub/entities/workflow/builder.py +20 -60
- digitalhub/entities/workflow/crud.py +1 -1
- digitalhub/factory/factory.py +204 -0
- digitalhub/factory/utils.py +90 -0
- digitalhub/runtimes/builder.py +24 -41
- digitalhub/runtimes/kind_registry.py +14 -0
- digitalhub/runtimes/utils.py +28 -0
- digitalhub/utils/exceptions.py +6 -0
- digitalhub/utils/generic_utils.py +1 -1
- {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b4.dist-info}/METADATA +1 -1
- {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b4.dist-info}/RECORD +75 -57
- digitalhub/entities/_builders/factory.py +0 -44
- digitalhub/entities/registries.py +0 -48
- digitalhub/registry/models.py +0 -87
- digitalhub/registry/registry.py +0 -74
- digitalhub/registry/utils.py +0 -151
- /digitalhub/entities/project/{project → _base}/__init__.py +0 -0
- /digitalhub/entities/project/{project → _base}/spec.py +0 -0
- /digitalhub/entities/project/{project → _base}/status.py +0 -0
- /digitalhub/entities/secret/{secret → _base}/__init__.py +0 -0
- /digitalhub/entities/secret/{secret → _base}/spec.py +0 -0
- /digitalhub/entities/secret/{secret → _base}/status.py +0 -0
- /digitalhub/{registry → factory}/__init__.py +0 -0
- /digitalhub/runtimes/{base.py → _base.py} +0 -0
- {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b4.dist-info}/LICENSE.txt +0 -0
- {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b4.dist-info}/WHEEL +0 -0
- {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b4.dist-info}/top_level.txt +0 -0
|
@@ -13,10 +13,6 @@ from digitalhub.entities._base.crud import (
|
|
|
13
13
|
update_entity_api_base,
|
|
14
14
|
)
|
|
15
15
|
from digitalhub.entities._base.entity.entity import Entity
|
|
16
|
-
from digitalhub.entities._builders.metadata import build_metadata
|
|
17
|
-
from digitalhub.entities._builders.name import build_name
|
|
18
|
-
from digitalhub.entities._builders.spec import build_spec
|
|
19
|
-
from digitalhub.entities._builders.status import build_status
|
|
20
16
|
from digitalhub.entities.artifact.crud import (
|
|
21
17
|
artifact_from_dict,
|
|
22
18
|
delete_artifact,
|
|
@@ -92,10 +88,10 @@ if typing.TYPE_CHECKING:
|
|
|
92
88
|
from digitalhub.entities.dataitem._base.entity import Dataitem
|
|
93
89
|
from digitalhub.entities.function._base.entity import Function
|
|
94
90
|
from digitalhub.entities.model._base.entity import Model
|
|
95
|
-
from digitalhub.entities.project.
|
|
96
|
-
from digitalhub.entities.project.
|
|
91
|
+
from digitalhub.entities.project._base.spec import ProjectSpec
|
|
92
|
+
from digitalhub.entities.project._base.status import ProjectStatus
|
|
97
93
|
from digitalhub.entities.run._base.entity import Run
|
|
98
|
-
from digitalhub.entities.secret.
|
|
94
|
+
from digitalhub.entities.secret._base.entity import Secret
|
|
99
95
|
from digitalhub.entities.workflow._base.entity import Workflow
|
|
100
96
|
|
|
101
97
|
|
|
@@ -308,44 +304,6 @@ class Project(Entity):
|
|
|
308
304
|
except EntityAlreadyExistsError:
|
|
309
305
|
pass
|
|
310
306
|
|
|
311
|
-
##############################
|
|
312
|
-
# Static interface methods
|
|
313
|
-
##############################
|
|
314
|
-
|
|
315
|
-
@staticmethod
|
|
316
|
-
def _parse_dict(obj: dict, validate: bool = True) -> dict:
|
|
317
|
-
"""
|
|
318
|
-
Get dictionary and parse it to a valid entity dictionary.
|
|
319
|
-
|
|
320
|
-
Parameters
|
|
321
|
-
----------
|
|
322
|
-
entity : str
|
|
323
|
-
Entity type.
|
|
324
|
-
obj : dict
|
|
325
|
-
Dictionary to parse.
|
|
326
|
-
|
|
327
|
-
Returns
|
|
328
|
-
-------
|
|
329
|
-
dict
|
|
330
|
-
A dictionary containing the attributes of the entity instance.
|
|
331
|
-
"""
|
|
332
|
-
name = build_name(obj.get("name"))
|
|
333
|
-
kind = obj.get("kind")
|
|
334
|
-
metadata = build_metadata(kind, **obj.get("metadata", {}))
|
|
335
|
-
spec = build_spec(kind, validate=validate, **obj.get("spec", {}))
|
|
336
|
-
status = build_status(kind, **obj.get("status", {}))
|
|
337
|
-
user = obj.get("user")
|
|
338
|
-
local = obj.get("local", False)
|
|
339
|
-
return {
|
|
340
|
-
"name": name,
|
|
341
|
-
"kind": kind,
|
|
342
|
-
"metadata": metadata,
|
|
343
|
-
"spec": spec,
|
|
344
|
-
"status": status,
|
|
345
|
-
"user": user,
|
|
346
|
-
"local": local,
|
|
347
|
-
}
|
|
348
|
-
|
|
349
307
|
##############################
|
|
350
308
|
# Artifacts
|
|
351
309
|
##############################
|
|
@@ -371,7 +329,7 @@ class Project(Entity):
|
|
|
371
329
|
kind : str
|
|
372
330
|
Kind the object.
|
|
373
331
|
uuid : str
|
|
374
|
-
ID of the object
|
|
332
|
+
ID of the object.
|
|
375
333
|
description : str
|
|
376
334
|
Description of the object (human readable).
|
|
377
335
|
labels : list[str]
|
|
@@ -662,7 +620,7 @@ class Project(Entity):
|
|
|
662
620
|
kind : str
|
|
663
621
|
Kind the object.
|
|
664
622
|
uuid : str
|
|
665
|
-
ID of the object
|
|
623
|
+
ID of the object.
|
|
666
624
|
description : str
|
|
667
625
|
Description of the object (human readable).
|
|
668
626
|
labels : list[str]
|
|
@@ -966,7 +924,7 @@ class Project(Entity):
|
|
|
966
924
|
kind : str
|
|
967
925
|
Kind the object.
|
|
968
926
|
uuid : str
|
|
969
|
-
ID of the object
|
|
927
|
+
ID of the object.
|
|
970
928
|
description : str
|
|
971
929
|
Description of the object (human readable).
|
|
972
930
|
labels : list[str]
|
|
@@ -1257,7 +1215,7 @@ class Project(Entity):
|
|
|
1257
1215
|
kind : str
|
|
1258
1216
|
Kind the object.
|
|
1259
1217
|
uuid : str
|
|
1260
|
-
ID of the object
|
|
1218
|
+
ID of the object.
|
|
1261
1219
|
description : str
|
|
1262
1220
|
Description of the object (human readable).
|
|
1263
1221
|
labels : list[str]
|
|
@@ -1503,7 +1461,7 @@ class Project(Entity):
|
|
|
1503
1461
|
kind : str
|
|
1504
1462
|
Kind the object.
|
|
1505
1463
|
uuid : str
|
|
1506
|
-
ID of the object
|
|
1464
|
+
ID of the object.
|
|
1507
1465
|
description : str
|
|
1508
1466
|
Description of the object (human readable).
|
|
1509
1467
|
labels : list[str]
|
|
@@ -1747,7 +1705,7 @@ class Project(Entity):
|
|
|
1747
1705
|
name : str
|
|
1748
1706
|
Object name.
|
|
1749
1707
|
uuid : str
|
|
1750
|
-
ID of the object
|
|
1708
|
+
ID of the object.
|
|
1751
1709
|
description : str
|
|
1752
1710
|
Description of the object (human readable).
|
|
1753
1711
|
labels : list[str]
|
|
@@ -1,68 +1,33 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
|
|
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.project.project.entity import Project
|
|
3
|
+
import typing
|
|
8
4
|
|
|
5
|
+
from digitalhub.factory.factory import factory
|
|
6
|
+
from digitalhub.utils.exceptions import BuilderError
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
local: bool = False,
|
|
16
|
-
context: str | None = None,
|
|
17
|
-
**kwargs,
|
|
18
|
-
) -> Project:
|
|
8
|
+
if typing.TYPE_CHECKING:
|
|
9
|
+
from digitalhub.entities.project._base.entity import Project
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def project_from_parameters(**kwargs) -> Project:
|
|
19
13
|
"""
|
|
20
14
|
Create a new object.
|
|
21
15
|
|
|
22
16
|
Parameters
|
|
23
17
|
----------
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
kind : str
|
|
27
|
-
Kind the object.
|
|
28
|
-
description : str
|
|
29
|
-
Description of the object (human readable).
|
|
30
|
-
labels : list[str]
|
|
31
|
-
List of labels.
|
|
32
|
-
local : bool
|
|
33
|
-
If True, use local backend, if False use DHCore backend. Default to False.
|
|
34
|
-
context : str
|
|
35
|
-
The context local folder of the project.
|
|
36
|
-
**kwargs : dict
|
|
37
|
-
Spec keyword arguments.
|
|
18
|
+
**kwargs
|
|
19
|
+
Keyword arguments.
|
|
38
20
|
|
|
39
21
|
Returns
|
|
40
22
|
-------
|
|
41
23
|
Project
|
|
42
24
|
Object instance.
|
|
43
25
|
"""
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
)
|
|
50
|
-
metadata = build_metadata(
|
|
51
|
-
kind,
|
|
52
|
-
project=name,
|
|
53
|
-
name=name,
|
|
54
|
-
description=description,
|
|
55
|
-
labels=labels,
|
|
56
|
-
)
|
|
57
|
-
status = build_status(kind)
|
|
58
|
-
return Project(
|
|
59
|
-
name=name,
|
|
60
|
-
kind=kind,
|
|
61
|
-
metadata=metadata,
|
|
62
|
-
spec=spec,
|
|
63
|
-
status=status,
|
|
64
|
-
local=local,
|
|
65
|
-
)
|
|
26
|
+
try:
|
|
27
|
+
kind = kwargs["kind"]
|
|
28
|
+
except KeyError:
|
|
29
|
+
raise BuilderError("Missing 'kind' parameter.")
|
|
30
|
+
return factory.build_entity_from_params(kind, **kwargs)
|
|
66
31
|
|
|
67
32
|
|
|
68
33
|
def project_from_dict(obj: dict) -> Project:
|
|
@@ -79,4 +44,8 @@ def project_from_dict(obj: dict) -> Project:
|
|
|
79
44
|
Project
|
|
80
45
|
Object instance.
|
|
81
46
|
"""
|
|
82
|
-
|
|
47
|
+
try:
|
|
48
|
+
kind = obj["kind"]
|
|
49
|
+
except KeyError:
|
|
50
|
+
raise BuilderError("Missing 'kind' parameter.")
|
|
51
|
+
return factory.build_entity_from_dict(kind, obj)
|
|
@@ -13,7 +13,7 @@ from digitalhub.utils.exceptions import BackendError, EntityError
|
|
|
13
13
|
from digitalhub.utils.io_utils import read_yaml
|
|
14
14
|
|
|
15
15
|
if typing.TYPE_CHECKING:
|
|
16
|
-
from digitalhub.entities.project.
|
|
16
|
+
from digitalhub.entities.project._base.entity import Project
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
ENTITY_TYPE = EntityTypes.PROJECT.value
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._base.unversioned.builder import UnversionedBuilder
|
|
6
|
+
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
7
|
+
|
|
8
|
+
if typing.TYPE_CHECKING:
|
|
9
|
+
from digitalhub.entities.run._base.entity import Run
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RunBuilder(UnversionedBuilder):
|
|
13
|
+
"""
|
|
14
|
+
Run builder.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
ENTITY_TYPE = EntityTypes.RUN.value
|
|
18
|
+
|
|
19
|
+
def build(
|
|
20
|
+
self,
|
|
21
|
+
project: str,
|
|
22
|
+
kind: str,
|
|
23
|
+
uuid: str | None = None,
|
|
24
|
+
labels: list[str] | None = None,
|
|
25
|
+
task: str | None = None,
|
|
26
|
+
local_execution: bool = False,
|
|
27
|
+
**kwargs,
|
|
28
|
+
) -> Run:
|
|
29
|
+
"""
|
|
30
|
+
Create a new object.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
project : str
|
|
35
|
+
Project name.
|
|
36
|
+
kind : str
|
|
37
|
+
Kind the object.
|
|
38
|
+
uuid : str
|
|
39
|
+
ID of the object.
|
|
40
|
+
labels : list[str]
|
|
41
|
+
List of labels.
|
|
42
|
+
task : str
|
|
43
|
+
Name of the task associated with the run.
|
|
44
|
+
local_execution : bool
|
|
45
|
+
Flag to determine if object has local execution.
|
|
46
|
+
**kwargs : dict
|
|
47
|
+
Spec keyword arguments.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
Run
|
|
52
|
+
Object instance.
|
|
53
|
+
"""
|
|
54
|
+
uuid = self.build_uuid(uuid)
|
|
55
|
+
metadata = self.build_metadata(
|
|
56
|
+
project=project,
|
|
57
|
+
name=uuid,
|
|
58
|
+
labels=labels,
|
|
59
|
+
)
|
|
60
|
+
spec = self.build_spec(
|
|
61
|
+
task=task,
|
|
62
|
+
local_execution=local_execution,
|
|
63
|
+
**kwargs,
|
|
64
|
+
)
|
|
65
|
+
status = self.build_status()
|
|
66
|
+
return self.build_entity(
|
|
67
|
+
project=project,
|
|
68
|
+
uuid=uuid,
|
|
69
|
+
kind=kind,
|
|
70
|
+
metadata=metadata,
|
|
71
|
+
spec=spec,
|
|
72
|
+
status=status,
|
|
73
|
+
)
|
|
@@ -2,9 +2,6 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import time
|
|
4
4
|
import typing
|
|
5
|
-
from typing import Any
|
|
6
|
-
|
|
7
|
-
import requests
|
|
8
5
|
|
|
9
6
|
from digitalhub.entities._base.crud import (
|
|
10
7
|
list_entity_api_base,
|
|
@@ -15,21 +12,17 @@ from digitalhub.entities._base.crud import (
|
|
|
15
12
|
stop_api,
|
|
16
13
|
)
|
|
17
14
|
from digitalhub.entities._base.unversioned.entity import UnversionedEntity
|
|
18
|
-
from digitalhub.entities._builders.spec import build_spec
|
|
19
|
-
from digitalhub.entities._builders.status import build_status
|
|
20
15
|
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
21
16
|
from digitalhub.entities.utils.state import State
|
|
22
|
-
from digitalhub.
|
|
23
|
-
from digitalhub.runtimes.builder import build_runtime
|
|
17
|
+
from digitalhub.factory.factory import factory
|
|
24
18
|
from digitalhub.utils.exceptions import EntityError
|
|
25
19
|
from digitalhub.utils.logger import LOGGER
|
|
26
20
|
|
|
27
21
|
if typing.TYPE_CHECKING:
|
|
28
22
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
29
|
-
from digitalhub.entities._base.material.entity import MaterialEntity
|
|
30
23
|
from digitalhub.entities.run._base.spec import RunSpec
|
|
31
24
|
from digitalhub.entities.run._base.status import RunStatus
|
|
32
|
-
from digitalhub.runtimes.
|
|
25
|
+
from digitalhub.runtimes._base import Runtime
|
|
33
26
|
|
|
34
27
|
|
|
35
28
|
class Run(UnversionedEntity):
|
|
@@ -70,7 +63,7 @@ class Run(UnversionedEntity):
|
|
|
70
63
|
executable = self._get_executable(runtime)
|
|
71
64
|
task = self._get_task(runtime)
|
|
72
65
|
new_spec = runtime.build(executable, task, self.to_dict())
|
|
73
|
-
self.spec = build_spec(
|
|
66
|
+
self.spec = factory.build_spec(
|
|
74
67
|
self.kind,
|
|
75
68
|
**new_spec,
|
|
76
69
|
)
|
|
@@ -147,116 +140,6 @@ class Run(UnversionedEntity):
|
|
|
147
140
|
LOGGER.info(f"Run {self.id} finished in {current:.2f} seconds.")
|
|
148
141
|
return self
|
|
149
142
|
|
|
150
|
-
def inputs(self, as_dict: bool = False) -> list[dict]:
|
|
151
|
-
"""
|
|
152
|
-
Get inputs passed in spec as objects or as dictionaries.
|
|
153
|
-
|
|
154
|
-
Parameters
|
|
155
|
-
----------
|
|
156
|
-
as_dict : bool
|
|
157
|
-
If True, return inputs as dictionaries.
|
|
158
|
-
|
|
159
|
-
Returns
|
|
160
|
-
-------
|
|
161
|
-
list[dict]
|
|
162
|
-
List of input objects.
|
|
163
|
-
"""
|
|
164
|
-
try:
|
|
165
|
-
return self.spec.get_inputs(as_dict=as_dict)
|
|
166
|
-
except AttributeError:
|
|
167
|
-
msg = f"Run of type {self.kind} has no inputs."
|
|
168
|
-
raise EntityError(msg)
|
|
169
|
-
|
|
170
|
-
def results(self) -> dict:
|
|
171
|
-
"""
|
|
172
|
-
Get results from runtime execution.
|
|
173
|
-
|
|
174
|
-
Returns
|
|
175
|
-
-------
|
|
176
|
-
dict
|
|
177
|
-
Results.
|
|
178
|
-
"""
|
|
179
|
-
try:
|
|
180
|
-
return self.status.get_results()
|
|
181
|
-
except AttributeError:
|
|
182
|
-
msg = f"Run of type {self.kind} has no results."
|
|
183
|
-
raise EntityError(msg)
|
|
184
|
-
|
|
185
|
-
def result(self, key: str) -> Any:
|
|
186
|
-
"""
|
|
187
|
-
Get result from runtime execution by key.
|
|
188
|
-
|
|
189
|
-
Parameters
|
|
190
|
-
----------
|
|
191
|
-
key : str
|
|
192
|
-
Key of the result.
|
|
193
|
-
|
|
194
|
-
Returns
|
|
195
|
-
-------
|
|
196
|
-
Any
|
|
197
|
-
Result.
|
|
198
|
-
"""
|
|
199
|
-
return self.results().get(key)
|
|
200
|
-
|
|
201
|
-
def outputs(self, as_key: bool = False, as_dict: bool = False) -> dict:
|
|
202
|
-
"""
|
|
203
|
-
Get run objects results.
|
|
204
|
-
|
|
205
|
-
Parameters
|
|
206
|
-
----------
|
|
207
|
-
as_key : bool
|
|
208
|
-
If True, return results as keys.
|
|
209
|
-
as_dict : bool
|
|
210
|
-
If True, return results as dictionaries.
|
|
211
|
-
|
|
212
|
-
Returns
|
|
213
|
-
-------
|
|
214
|
-
dict
|
|
215
|
-
List of output objects.
|
|
216
|
-
"""
|
|
217
|
-
try:
|
|
218
|
-
return self.status.get_outputs(as_key=as_key, as_dict=as_dict)
|
|
219
|
-
except AttributeError:
|
|
220
|
-
msg = f"Run of type {self.kind} has no outputs."
|
|
221
|
-
raise EntityError(msg)
|
|
222
|
-
|
|
223
|
-
def output(self, key: str, as_key: bool = False, as_dict: bool = False) -> MaterialEntity | dict | str | None:
|
|
224
|
-
"""
|
|
225
|
-
Get run object result by key.
|
|
226
|
-
|
|
227
|
-
Parameters
|
|
228
|
-
----------
|
|
229
|
-
key : str
|
|
230
|
-
Key of the result.
|
|
231
|
-
as_key : bool
|
|
232
|
-
If True, return result as key.
|
|
233
|
-
as_dict : bool
|
|
234
|
-
If True, return result as dictionary.
|
|
235
|
-
|
|
236
|
-
Returns
|
|
237
|
-
-------
|
|
238
|
-
Entity | dict | str | None
|
|
239
|
-
Result.
|
|
240
|
-
"""
|
|
241
|
-
return self.outputs(as_key=as_key, as_dict=as_dict).get(key)
|
|
242
|
-
|
|
243
|
-
def values(self) -> dict:
|
|
244
|
-
"""
|
|
245
|
-
Get values from runtime execution.
|
|
246
|
-
|
|
247
|
-
Returns
|
|
248
|
-
-------
|
|
249
|
-
dict
|
|
250
|
-
Values from backend.
|
|
251
|
-
"""
|
|
252
|
-
try:
|
|
253
|
-
value_list = getattr(self.spec, "values", [])
|
|
254
|
-
value_list = value_list if value_list is not None else []
|
|
255
|
-
return self.status.get_values(value_list)
|
|
256
|
-
except AttributeError:
|
|
257
|
-
msg = f"Run of type {self.kind} has no values."
|
|
258
|
-
raise EntityError(msg)
|
|
259
|
-
|
|
260
143
|
def logs(self) -> dict:
|
|
261
144
|
"""
|
|
262
145
|
Get object from backend.
|
|
@@ -307,32 +190,6 @@ class Run(UnversionedEntity):
|
|
|
307
190
|
# TODO verify the logic and order
|
|
308
191
|
self.run()
|
|
309
192
|
|
|
310
|
-
def invoke(self, **kwargs) -> requests.Response:
|
|
311
|
-
"""
|
|
312
|
-
Invoke run.
|
|
313
|
-
|
|
314
|
-
Parameters
|
|
315
|
-
----------
|
|
316
|
-
kwargs
|
|
317
|
-
Keyword arguments to pass to the request.
|
|
318
|
-
|
|
319
|
-
Returns
|
|
320
|
-
-------
|
|
321
|
-
requests.Response
|
|
322
|
-
Response from service.
|
|
323
|
-
"""
|
|
324
|
-
try:
|
|
325
|
-
if not self._context().local and not self.spec.local_execution:
|
|
326
|
-
local = False
|
|
327
|
-
else:
|
|
328
|
-
local = True
|
|
329
|
-
if kwargs is None:
|
|
330
|
-
kwargs = {}
|
|
331
|
-
return self.status.invoke(local, **kwargs)
|
|
332
|
-
except AttributeError:
|
|
333
|
-
msg = f"Run of type {self.kind} has no invoke operation."
|
|
334
|
-
raise EntityError(msg)
|
|
335
|
-
|
|
336
193
|
##############################
|
|
337
194
|
# Helpers
|
|
338
195
|
##############################
|
|
@@ -361,7 +218,7 @@ class Run(UnversionedEntity):
|
|
|
361
218
|
-------
|
|
362
219
|
None
|
|
363
220
|
"""
|
|
364
|
-
self.status: RunStatus = build_status(self.kind, **status)
|
|
221
|
+
self.status: RunStatus = factory.build_status(self.kind, **status)
|
|
365
222
|
|
|
366
223
|
def _set_state(self, state: str) -> None:
|
|
367
224
|
"""
|
|
@@ -402,7 +259,7 @@ class Run(UnversionedEntity):
|
|
|
402
259
|
Runtime
|
|
403
260
|
Runtime object.
|
|
404
261
|
"""
|
|
405
|
-
return build_runtime(self.kind, self.project)
|
|
262
|
+
return factory.build_runtime(self.kind, self.project)
|
|
406
263
|
|
|
407
264
|
def _get_executable(self, runtime: Runtime) -> dict:
|
|
408
265
|
"""
|
|
@@ -419,7 +276,7 @@ class Run(UnversionedEntity):
|
|
|
419
276
|
Executable (function or workflow) from backend.
|
|
420
277
|
"""
|
|
421
278
|
exec_kind = runtime.get_executable_kind()
|
|
422
|
-
entity_type =
|
|
279
|
+
entity_type = factory.get_entity_type_from_builder(exec_kind)
|
|
423
280
|
splitted = self.spec.task.split("/")
|
|
424
281
|
exec_name = splitted[-1].split(":")[0]
|
|
425
282
|
exec_id = splitted[-1].split(":")[1]
|
|
@@ -1,63 +1,33 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
|
|
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.run._base.entity import Run
|
|
3
|
+
import typing
|
|
8
4
|
|
|
5
|
+
from digitalhub.factory.factory import factory
|
|
6
|
+
from digitalhub.utils.exceptions import BuilderError
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
task: str | None = None,
|
|
16
|
-
local_execution: bool = False,
|
|
17
|
-
**kwargs,
|
|
18
|
-
) -> Run:
|
|
8
|
+
if typing.TYPE_CHECKING:
|
|
9
|
+
from digitalhub.entities.run._base.entity import Run
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def run_from_parameters(**kwargs) -> Run:
|
|
19
13
|
"""
|
|
20
|
-
Create
|
|
14
|
+
Create a new object.
|
|
21
15
|
|
|
22
16
|
Parameters
|
|
23
17
|
----------
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
kind : str
|
|
27
|
-
Kind the object.
|
|
28
|
-
uuid : str
|
|
29
|
-
ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
|
|
30
|
-
labels : list[str]
|
|
31
|
-
List of labels.
|
|
32
|
-
task : str
|
|
33
|
-
Name of the task associated with the run.
|
|
34
|
-
local_execution : bool
|
|
35
|
-
Flag to determine if object has local execution.
|
|
36
|
-
**kwargs : dict
|
|
37
|
-
Spec keyword arguments.
|
|
18
|
+
**kwargs
|
|
19
|
+
Keyword arguments.
|
|
38
20
|
|
|
39
21
|
Returns
|
|
40
22
|
-------
|
|
41
23
|
Run
|
|
42
24
|
Object instance.
|
|
43
25
|
"""
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
labels=labels,
|
|
50
|
-
)
|
|
51
|
-
spec = build_spec(kind, task=task, local_execution=local_execution, **kwargs)
|
|
52
|
-
status = build_status(kind)
|
|
53
|
-
return Run(
|
|
54
|
-
project=project,
|
|
55
|
-
uuid=uuid,
|
|
56
|
-
kind=kind,
|
|
57
|
-
metadata=metadata,
|
|
58
|
-
spec=spec,
|
|
59
|
-
status=status,
|
|
60
|
-
)
|
|
26
|
+
try:
|
|
27
|
+
kind = kwargs["kind"]
|
|
28
|
+
except KeyError:
|
|
29
|
+
raise BuilderError("Missing 'kind' parameter.")
|
|
30
|
+
return factory.build_entity_from_params(kind, **kwargs)
|
|
61
31
|
|
|
62
32
|
|
|
63
33
|
def run_from_dict(obj: dict) -> Run:
|
|
@@ -74,4 +44,8 @@ def run_from_dict(obj: dict) -> Run:
|
|
|
74
44
|
Run
|
|
75
45
|
Object instance.
|
|
76
46
|
"""
|
|
77
|
-
|
|
47
|
+
try:
|
|
48
|
+
kind = obj["kind"]
|
|
49
|
+
except KeyError:
|
|
50
|
+
raise BuilderError("Missing 'kind' parameter.")
|
|
51
|
+
return factory.build_entity_from_dict(kind, obj)
|
digitalhub/entities/run/crud.py
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities._base.versioned.builder import VersionedBuilder
|
|
4
|
+
from digitalhub.entities.secret._base.entity import Secret
|
|
5
|
+
from digitalhub.entities.secret._base.spec import SecretSpec, SecretValidator
|
|
6
|
+
from digitalhub.entities.secret._base.status import SecretStatus
|
|
7
|
+
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SecretSecretBuilder(VersionedBuilder):
|
|
11
|
+
"""
|
|
12
|
+
SecretSecretBuilder builder.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
ENTITY_TYPE = EntityTypes.SECRET.value
|
|
16
|
+
ENTITY_CLASS = Secret
|
|
17
|
+
ENTITY_SPEC_CLASS = SecretSpec
|
|
18
|
+
ENTITY_SPEC_VALIDATOR = SecretValidator
|
|
19
|
+
ENTITY_STATUS_CLASS = SecretStatus
|
|
20
|
+
ENTITY_KIND = "secret"
|
|
21
|
+
|
|
22
|
+
def build(
|
|
23
|
+
self,
|
|
24
|
+
kind: str,
|
|
25
|
+
project: str,
|
|
26
|
+
name: str,
|
|
27
|
+
uuid: str | None = None,
|
|
28
|
+
description: str | None = None,
|
|
29
|
+
labels: list[str] | None = None,
|
|
30
|
+
**kwargs,
|
|
31
|
+
) -> Secret:
|
|
32
|
+
"""
|
|
33
|
+
Create a new object.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
project : str
|
|
38
|
+
Project name.
|
|
39
|
+
name : str
|
|
40
|
+
Object name.
|
|
41
|
+
kind : str
|
|
42
|
+
Kind the object.
|
|
43
|
+
uuid : str
|
|
44
|
+
ID of the object.
|
|
45
|
+
description : str
|
|
46
|
+
Description of the object (human readable).
|
|
47
|
+
labels : list[str]
|
|
48
|
+
List of labels.
|
|
49
|
+
**kwargs : dict
|
|
50
|
+
Spec keyword arguments.
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
Secret
|
|
55
|
+
Object instance.
|
|
56
|
+
"""
|
|
57
|
+
name = self.build_name(name)
|
|
58
|
+
uuid = self.build_uuid(uuid)
|
|
59
|
+
metadata = self.build_metadata(
|
|
60
|
+
project=project,
|
|
61
|
+
name=name,
|
|
62
|
+
description=description,
|
|
63
|
+
labels=labels,
|
|
64
|
+
)
|
|
65
|
+
path = f"kubernetes://dhcore-proj-secrets-{project}/{name}"
|
|
66
|
+
provider = "kubernetes"
|
|
67
|
+
spec = self.build_spec(
|
|
68
|
+
path=path,
|
|
69
|
+
provider=provider,
|
|
70
|
+
**kwargs,
|
|
71
|
+
)
|
|
72
|
+
status = self.build_status()
|
|
73
|
+
return self.build_entity(
|
|
74
|
+
project=project,
|
|
75
|
+
name=name,
|
|
76
|
+
uuid=uuid,
|
|
77
|
+
kind=kind,
|
|
78
|
+
metadata=metadata,
|
|
79
|
+
spec=spec,
|
|
80
|
+
status=status,
|
|
81
|
+
)
|