digitalhub 0.8.0b6__py3-none-any.whl → 0.8.0b10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of digitalhub might be problematic. Click here for more details.
- digitalhub/__init__.py +1 -1
- digitalhub/client/api.py +63 -0
- digitalhub/client/builder.py +0 -55
- digitalhub/client/dhcore/utils.py +1 -1
- digitalhub/context/api.py +93 -0
- digitalhub/context/builder.py +0 -84
- digitalhub/datastores/_base/datastore.py +2 -2
- digitalhub/datastores/api.py +37 -0
- digitalhub/datastores/builder.py +7 -31
- digitalhub/datastores/local/datastore.py +9 -1
- digitalhub/datastores/remote/datastore.py +8 -0
- digitalhub/datastores/s3/datastore.py +9 -1
- digitalhub/datastores/sql/datastore.py +9 -1
- digitalhub/entities/_base/api_utils.py +620 -0
- digitalhub/entities/_base/context/entity.py +2 -2
- digitalhub/entities/_base/crud.py +204 -408
- digitalhub/entities/_base/entity/entity.py +1 -1
- digitalhub/entities/_base/entity/status.py +12 -1
- digitalhub/entities/_base/executable/entity.py +7 -6
- digitalhub/entities/_base/material/entity.py +2 -2
- digitalhub/entities/artifact/crud.py +16 -42
- digitalhub/entities/dataitem/crud.py +19 -45
- digitalhub/entities/dataitem/table/entity.py +1 -1
- digitalhub/entities/function/crud.py +13 -39
- digitalhub/entities/model/crud.py +15 -42
- digitalhub/entities/project/_base/entity.py +65 -38
- digitalhub/entities/project/crud.py +8 -8
- digitalhub/entities/run/_base/entity.py +1 -14
- digitalhub/entities/run/_base/spec.py +0 -103
- digitalhub/entities/run/_base/status.py +0 -105
- digitalhub/entities/run/crud.py +17 -30
- digitalhub/entities/secret/_base/builder.py +1 -1
- digitalhub/entities/secret/_base/entity.py +1 -1
- digitalhub/entities/secret/crud.py +15 -27
- digitalhub/entities/task/_base/entity.py +3 -2
- digitalhub/entities/task/crud.py +17 -30
- digitalhub/entities/utils/utils.py +18 -0
- digitalhub/entities/workflow/crud.py +13 -39
- digitalhub/factory/api.py +31 -25
- digitalhub/factory/factory.py +7 -5
- digitalhub/readers/_base/builder.py +26 -0
- digitalhub/readers/api.py +80 -0
- digitalhub/readers/factory.py +133 -0
- digitalhub/readers/pandas/builder.py +29 -0
- digitalhub/readers/pandas/{readers.py → reader.py} +1 -1
- digitalhub/stores/api.py +54 -0
- digitalhub/stores/builder.py +0 -46
- {digitalhub-0.8.0b6.dist-info → digitalhub-0.8.0b10.dist-info}/METADATA +1 -1
- {digitalhub-0.8.0b6.dist-info → digitalhub-0.8.0b10.dist-info}/RECORD +53 -55
- digitalhub/entities/artifact/builder.py +0 -51
- digitalhub/entities/dataitem/builder.py +0 -51
- digitalhub/entities/function/builder.py +0 -51
- digitalhub/entities/model/builder.py +0 -51
- digitalhub/entities/project/builder.py +0 -51
- digitalhub/entities/run/builder.py +0 -51
- digitalhub/entities/secret/builder.py +0 -51
- digitalhub/entities/task/builder.py +0 -51
- digitalhub/entities/workflow/builder.py +0 -51
- digitalhub/readers/builder.py +0 -54
- digitalhub/readers/registry.py +0 -15
- /digitalhub/readers/_base/{readers.py → reader.py} +0 -0
- {digitalhub-0.8.0b6.dist-info → digitalhub-0.8.0b10.dist-info}/LICENSE.txt +0 -0
- {digitalhub-0.8.0b6.dist-info → digitalhub-0.8.0b10.dist-info}/WHEEL +0 -0
- {digitalhub-0.8.0b6.dist-info → digitalhub-0.8.0b10.dist-info}/top_level.txt +0 -0
|
@@ -4,17 +4,17 @@ import typing
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from typing import Any
|
|
6
6
|
|
|
7
|
-
from digitalhub.client.
|
|
8
|
-
from digitalhub.context.
|
|
9
|
-
from digitalhub.entities._base.
|
|
7
|
+
from digitalhub.client.api import get_client
|
|
8
|
+
from digitalhub.context.api import set_context
|
|
9
|
+
from digitalhub.entities._base.api_utils import (
|
|
10
10
|
create_entity_api_base,
|
|
11
11
|
read_entity_api_base,
|
|
12
12
|
read_entity_api_ctx,
|
|
13
13
|
update_entity_api_base,
|
|
14
14
|
)
|
|
15
|
+
from digitalhub.entities._base.crud import import_context_entity, import_executable_entity
|
|
15
16
|
from digitalhub.entities._base.entity.entity import Entity
|
|
16
17
|
from digitalhub.entities.artifact.crud import (
|
|
17
|
-
artifact_from_dict,
|
|
18
18
|
delete_artifact,
|
|
19
19
|
get_artifact,
|
|
20
20
|
get_artifact_versions,
|
|
@@ -25,7 +25,6 @@ from digitalhub.entities.artifact.crud import (
|
|
|
25
25
|
update_artifact,
|
|
26
26
|
)
|
|
27
27
|
from digitalhub.entities.dataitem.crud import (
|
|
28
|
-
dataitem_from_dict,
|
|
29
28
|
delete_dataitem,
|
|
30
29
|
get_dataitem,
|
|
31
30
|
get_dataitem_versions,
|
|
@@ -37,7 +36,6 @@ from digitalhub.entities.dataitem.crud import (
|
|
|
37
36
|
)
|
|
38
37
|
from digitalhub.entities.function.crud import (
|
|
39
38
|
delete_function,
|
|
40
|
-
function_from_dict,
|
|
41
39
|
get_function,
|
|
42
40
|
get_function_versions,
|
|
43
41
|
import_function,
|
|
@@ -52,7 +50,6 @@ from digitalhub.entities.model.crud import (
|
|
|
52
50
|
import_model,
|
|
53
51
|
list_models,
|
|
54
52
|
log_model,
|
|
55
|
-
model_from_dict,
|
|
56
53
|
new_model,
|
|
57
54
|
update_model,
|
|
58
55
|
)
|
|
@@ -75,8 +72,8 @@ from digitalhub.entities.workflow.crud import (
|
|
|
75
72
|
list_workflows,
|
|
76
73
|
new_workflow,
|
|
77
74
|
update_workflow,
|
|
78
|
-
workflow_from_dict,
|
|
79
75
|
)
|
|
76
|
+
from digitalhub.factory.api import build_entity_from_dict
|
|
80
77
|
from digitalhub.utils.exceptions import BackendError, EntityAlreadyExistsError, EntityError
|
|
81
78
|
from digitalhub.utils.generic_utils import get_timestamp
|
|
82
79
|
from digitalhub.utils.io_utils import write_yaml
|
|
@@ -95,31 +92,6 @@ if typing.TYPE_CHECKING:
|
|
|
95
92
|
from digitalhub.entities.workflow._base.entity import Workflow
|
|
96
93
|
|
|
97
94
|
|
|
98
|
-
ARTIFACTS = EntityTypes.ARTIFACT.value + "s"
|
|
99
|
-
FUNCTIONS = EntityTypes.FUNCTION.value + "s"
|
|
100
|
-
WORKFLOWS = EntityTypes.WORKFLOW.value + "s"
|
|
101
|
-
DATAITEMS = EntityTypes.DATAITEM.value + "s"
|
|
102
|
-
MODELS = EntityTypes.MODEL.value + "s"
|
|
103
|
-
|
|
104
|
-
CTX_ENTITIES = [ARTIFACTS, FUNCTIONS, WORKFLOWS, DATAITEMS, MODELS]
|
|
105
|
-
|
|
106
|
-
FROM_DICT_MAP = {
|
|
107
|
-
ARTIFACTS: artifact_from_dict,
|
|
108
|
-
FUNCTIONS: function_from_dict,
|
|
109
|
-
WORKFLOWS: workflow_from_dict,
|
|
110
|
-
DATAITEMS: dataitem_from_dict,
|
|
111
|
-
MODELS: model_from_dict,
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
IMPORT_MAP = {
|
|
115
|
-
ARTIFACTS: import_artifact,
|
|
116
|
-
FUNCTIONS: import_function,
|
|
117
|
-
WORKFLOWS: import_workflow,
|
|
118
|
-
DATAITEMS: import_dataitem,
|
|
119
|
-
MODELS: import_model,
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
95
|
class Project(Entity):
|
|
124
96
|
"""
|
|
125
97
|
A class representing a project.
|
|
@@ -253,7 +225,7 @@ class Project(Entity):
|
|
|
253
225
|
Updatated project object in dictionary format with referenced entities.
|
|
254
226
|
"""
|
|
255
227
|
# Cycle over entity types
|
|
256
|
-
for entity_type in
|
|
228
|
+
for entity_type in self._get_entity_types():
|
|
257
229
|
# Entity types are stored as a list of entities
|
|
258
230
|
for idx, entity in enumerate(obj.get("spec", {}).get(entity_type, [])):
|
|
259
231
|
# Export entity if not embedded is in metadata, else do nothing
|
|
@@ -262,7 +234,7 @@ class Project(Entity):
|
|
|
262
234
|
obj_dict: dict = read_entity_api_ctx(entity["key"])
|
|
263
235
|
|
|
264
236
|
# Create from dict (not need to new method, we do not save to backend)
|
|
265
|
-
ent =
|
|
237
|
+
ent = build_entity_from_dict(obj_dict)
|
|
266
238
|
|
|
267
239
|
# Export and stor ref in object metadata inside project
|
|
268
240
|
pth = ent.export()
|
|
@@ -279,8 +251,10 @@ class Project(Entity):
|
|
|
279
251
|
-------
|
|
280
252
|
None
|
|
281
253
|
"""
|
|
254
|
+
entity_types = self._get_entity_types()
|
|
255
|
+
|
|
282
256
|
# Cycle over entity types
|
|
283
|
-
for entity_type in
|
|
257
|
+
for entity_type in entity_types:
|
|
284
258
|
# Entity types are stored as a list of entities
|
|
285
259
|
for entity in getattr(self.spec, entity_type, []):
|
|
286
260
|
entity_metadata = entity["metadata"]
|
|
@@ -292,7 +266,12 @@ class Project(Entity):
|
|
|
292
266
|
# Import entity from local ref
|
|
293
267
|
if map_uri_scheme(ref) == "local":
|
|
294
268
|
try:
|
|
295
|
-
|
|
269
|
+
# Artifacts, Dataitems and Models
|
|
270
|
+
if entity_type in entity_types[:3]:
|
|
271
|
+
import_context_entity(ref)
|
|
272
|
+
# Functions and Workflows
|
|
273
|
+
elif entity_type in entity_types[3:]:
|
|
274
|
+
import_executable_entity(ref)
|
|
296
275
|
except FileNotFoundError:
|
|
297
276
|
msg = f"File not found: {ref}."
|
|
298
277
|
raise EntityError(msg)
|
|
@@ -300,10 +279,54 @@ class Project(Entity):
|
|
|
300
279
|
# If entity is embedded, create it and try to save
|
|
301
280
|
elif embedded:
|
|
302
281
|
try:
|
|
303
|
-
|
|
282
|
+
build_entity_from_dict(entity).save()
|
|
304
283
|
except EntityAlreadyExistsError:
|
|
305
284
|
pass
|
|
306
285
|
|
|
286
|
+
def _get_entity_types(self) -> list[str]:
|
|
287
|
+
"""
|
|
288
|
+
Get entity types.
|
|
289
|
+
|
|
290
|
+
Returns
|
|
291
|
+
-------
|
|
292
|
+
list
|
|
293
|
+
Entity types.
|
|
294
|
+
"""
|
|
295
|
+
return [
|
|
296
|
+
f"{EntityTypes.ARTIFACT.value}s",
|
|
297
|
+
f"{EntityTypes.DATAITEM.value}s",
|
|
298
|
+
f"{EntityTypes.MODEL.value}s",
|
|
299
|
+
f"{EntityTypes.FUNCTION.value}s",
|
|
300
|
+
f"{EntityTypes.WORKFLOW.value}s",
|
|
301
|
+
]
|
|
302
|
+
|
|
303
|
+
def run(self, workflow: str | None = "main", **kwargs) -> Run:
|
|
304
|
+
"""
|
|
305
|
+
Run workflow project.
|
|
306
|
+
|
|
307
|
+
Parameters
|
|
308
|
+
----------
|
|
309
|
+
workflow : str
|
|
310
|
+
Workflow name.
|
|
311
|
+
**kwargs : dict
|
|
312
|
+
Keyword arguments passed to workflow.run().
|
|
313
|
+
|
|
314
|
+
Returns
|
|
315
|
+
-------
|
|
316
|
+
Run
|
|
317
|
+
Run instance.
|
|
318
|
+
"""
|
|
319
|
+
self.refresh()
|
|
320
|
+
for i in self.spec.workflows:
|
|
321
|
+
if i["name"] == workflow or i["key"] == workflow:
|
|
322
|
+
workflow = build_entity_from_dict(i)
|
|
323
|
+
break
|
|
324
|
+
else:
|
|
325
|
+
msg = f"Workflow {workflow} not found."
|
|
326
|
+
raise EntityError(msg)
|
|
327
|
+
|
|
328
|
+
return workflow.run(**kwargs)
|
|
329
|
+
|
|
307
330
|
##############################
|
|
308
331
|
# Artifacts
|
|
309
332
|
##############################
|
|
@@ -2016,3 +2039,7 @@ class Project(Entity):
|
|
|
2016
2039
|
**kwargs,
|
|
2017
2040
|
)
|
|
2018
2041
|
self.refresh()
|
|
2042
|
+
|
|
2043
|
+
##############################
|
|
2044
|
+
# Project methods
|
|
2045
|
+
##############################
|
|
@@ -4,11 +4,11 @@ import importlib.util as imputil
|
|
|
4
4
|
import typing
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
|
|
7
|
-
from digitalhub.client.
|
|
8
|
-
from digitalhub.context.
|
|
9
|
-
from digitalhub.entities._base.
|
|
10
|
-
from digitalhub.entities.project.builder import project_from_dict, project_from_parameters
|
|
7
|
+
from digitalhub.client.api import build_client, get_client
|
|
8
|
+
from digitalhub.context.api import delete_context
|
|
9
|
+
from digitalhub.entities._base.api_utils import delete_entity_api_base, read_entity_api_base, update_entity_api_base
|
|
11
10
|
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
11
|
+
from digitalhub.factory.api import build_entity_from_dict, build_entity_from_params
|
|
12
12
|
from digitalhub.utils.exceptions import BackendError, EntityError
|
|
13
13
|
from digitalhub.utils.io_utils import read_yaml
|
|
14
14
|
|
|
@@ -63,7 +63,7 @@ def new_project(
|
|
|
63
63
|
build_client(local, config)
|
|
64
64
|
if context is None:
|
|
65
65
|
context = name
|
|
66
|
-
obj =
|
|
66
|
+
obj = build_entity_from_params(
|
|
67
67
|
name=name,
|
|
68
68
|
kind="project",
|
|
69
69
|
description=description,
|
|
@@ -112,7 +112,7 @@ def get_project(
|
|
|
112
112
|
client = get_client(local)
|
|
113
113
|
obj = read_entity_api_base(client, ENTITY_TYPE, name, **kwargs)
|
|
114
114
|
obj["local"] = local
|
|
115
|
-
project =
|
|
115
|
+
project = build_entity_from_dict(obj)
|
|
116
116
|
return _setup_project(project, setup_kwargs)
|
|
117
117
|
|
|
118
118
|
|
|
@@ -148,7 +148,7 @@ def import_project(
|
|
|
148
148
|
build_client(local, config)
|
|
149
149
|
dict_obj: dict = read_yaml(file)
|
|
150
150
|
dict_obj["local"] = local
|
|
151
|
-
obj =
|
|
151
|
+
obj = build_entity_from_dict(dict_obj)
|
|
152
152
|
obj = _setup_project(obj, setup_kwargs)
|
|
153
153
|
|
|
154
154
|
# Import related entities
|
|
@@ -278,7 +278,7 @@ def update_project(entity: Project, local: bool = False, **kwargs) -> Project:
|
|
|
278
278
|
"""
|
|
279
279
|
client = get_client(local)
|
|
280
280
|
obj = update_entity_api_base(client, ENTITY_TYPE, entity.name, entity.to_dict(), **kwargs)
|
|
281
|
-
return
|
|
281
|
+
return build_entity_from_dict(obj)
|
|
282
282
|
|
|
283
283
|
|
|
284
284
|
def delete_project(
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import time
|
|
4
4
|
import typing
|
|
5
5
|
|
|
6
|
-
from digitalhub.entities._base.
|
|
6
|
+
from digitalhub.entities._base.api_utils import (
|
|
7
7
|
list_entity_api_base,
|
|
8
8
|
list_entity_api_ctx,
|
|
9
9
|
logs_api,
|
|
@@ -165,11 +165,6 @@ class Run(UnversionedEntity):
|
|
|
165
165
|
"""
|
|
166
166
|
if not self._context().local and not self.spec.local_execution:
|
|
167
167
|
return stop_api(self.project, self.ENTITY_TYPE, self.id)
|
|
168
|
-
try:
|
|
169
|
-
self.status.stop()
|
|
170
|
-
except AttributeError:
|
|
171
|
-
raise EntityError("Stop is not supported in local execution.")
|
|
172
|
-
return
|
|
173
168
|
|
|
174
169
|
def resume(self) -> None:
|
|
175
170
|
"""
|
|
@@ -181,14 +176,6 @@ class Run(UnversionedEntity):
|
|
|
181
176
|
"""
|
|
182
177
|
if not self._context().local and not self.spec.local_execution:
|
|
183
178
|
return resume_api(self.project, self.ENTITY_TYPE, self.id)
|
|
184
|
-
|
|
185
|
-
try:
|
|
186
|
-
self.status.resume()
|
|
187
|
-
except AttributeError:
|
|
188
|
-
raise EntityError("Resume is not supported in local execution.")
|
|
189
|
-
return
|
|
190
|
-
# re-run
|
|
191
|
-
# TODO verify the logic and order
|
|
192
179
|
self.run()
|
|
193
180
|
|
|
194
181
|
##############################
|
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import typing
|
|
4
|
-
|
|
5
3
|
from digitalhub.entities._base.entity.spec import Spec, SpecValidator
|
|
6
|
-
from digitalhub.entities.artifact.crud import get_artifact
|
|
7
|
-
from digitalhub.entities.dataitem.crud import get_dataitem
|
|
8
|
-
from digitalhub.entities.model.crud import get_model
|
|
9
4
|
from digitalhub.entities.task._base.models import K8s
|
|
10
|
-
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
11
|
-
from digitalhub.entities.utils.utils import parse_entity_key
|
|
12
|
-
|
|
13
|
-
if typing.TYPE_CHECKING:
|
|
14
|
-
from digitalhub.entities._base.entity.entity import Entity
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
ENTITY_FUNC = {
|
|
18
|
-
EntityTypes.ARTIFACT.value: get_artifact,
|
|
19
|
-
EntityTypes.DATAITEM.value: get_dataitem,
|
|
20
|
-
EntityTypes.MODEL.value: get_model,
|
|
21
|
-
}
|
|
22
5
|
|
|
23
6
|
|
|
24
7
|
class RunSpec(Spec):
|
|
@@ -51,92 +34,6 @@ class RunSpec(Spec):
|
|
|
51
34
|
self.secrets = secrets
|
|
52
35
|
self.profile = profile
|
|
53
36
|
|
|
54
|
-
def get_inputs(self, as_dict: bool = False) -> dict:
|
|
55
|
-
"""
|
|
56
|
-
Get inputs.
|
|
57
|
-
|
|
58
|
-
Returns
|
|
59
|
-
-------
|
|
60
|
-
dict
|
|
61
|
-
The inputs.
|
|
62
|
-
"""
|
|
63
|
-
inputs = {}
|
|
64
|
-
if not hasattr(self, "inputs") or self.inputs is None:
|
|
65
|
-
return inputs
|
|
66
|
-
|
|
67
|
-
for parameter, item in self.inputs.items():
|
|
68
|
-
parameter_type = self._parse_parameter(parameter)
|
|
69
|
-
|
|
70
|
-
# Get entity from key
|
|
71
|
-
if parameter_type == "key":
|
|
72
|
-
key = self._collect_key(item)
|
|
73
|
-
entity = self._collect_entity(key)
|
|
74
|
-
if as_dict:
|
|
75
|
-
entity = entity.to_dict()
|
|
76
|
-
inputs[parameter] = entity
|
|
77
|
-
|
|
78
|
-
# Create entity from parameter
|
|
79
|
-
elif parameter_type == "create":
|
|
80
|
-
raise NotImplementedError
|
|
81
|
-
|
|
82
|
-
return inputs
|
|
83
|
-
|
|
84
|
-
@staticmethod
|
|
85
|
-
def _parse_parameter(parameter: str) -> str:
|
|
86
|
-
"""
|
|
87
|
-
Parse parameter.
|
|
88
|
-
|
|
89
|
-
Parameters
|
|
90
|
-
----------
|
|
91
|
-
parameter : str
|
|
92
|
-
Parameter.
|
|
93
|
-
|
|
94
|
-
Returns
|
|
95
|
-
-------
|
|
96
|
-
str
|
|
97
|
-
The parsed parameter.
|
|
98
|
-
"""
|
|
99
|
-
if len(parameter.split(":")) == 1:
|
|
100
|
-
return "key"
|
|
101
|
-
return "create"
|
|
102
|
-
|
|
103
|
-
@staticmethod
|
|
104
|
-
def _collect_key(item: str | dict) -> str:
|
|
105
|
-
"""
|
|
106
|
-
Collect key from item.
|
|
107
|
-
|
|
108
|
-
Parameters
|
|
109
|
-
----------
|
|
110
|
-
item : str | dict
|
|
111
|
-
Key or dict representation of the entity.
|
|
112
|
-
|
|
113
|
-
Returns
|
|
114
|
-
-------
|
|
115
|
-
str
|
|
116
|
-
The key.
|
|
117
|
-
"""
|
|
118
|
-
if isinstance(item, str):
|
|
119
|
-
return item
|
|
120
|
-
return item.get("key")
|
|
121
|
-
|
|
122
|
-
@staticmethod
|
|
123
|
-
def _collect_entity(key: str) -> Entity:
|
|
124
|
-
"""
|
|
125
|
-
Collect entity from key.
|
|
126
|
-
|
|
127
|
-
Parameters
|
|
128
|
-
----------
|
|
129
|
-
key : str
|
|
130
|
-
Key of the entity.
|
|
131
|
-
|
|
132
|
-
Returns
|
|
133
|
-
-------
|
|
134
|
-
Entity
|
|
135
|
-
The entity.
|
|
136
|
-
"""
|
|
137
|
-
_, entity_type, _, _, _ = parse_entity_key(key)
|
|
138
|
-
return ENTITY_FUNC[entity_type](key)
|
|
139
|
-
|
|
140
37
|
|
|
141
38
|
class RunValidator(SpecValidator, K8s):
|
|
142
39
|
"""
|
|
@@ -1,114 +1,9 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from digitalhub.entities._base.entity.status import Status
|
|
4
|
-
from digitalhub.entities.artifact.crud import get_artifact
|
|
5
|
-
from digitalhub.entities.dataitem.crud import get_dataitem
|
|
6
|
-
from digitalhub.entities.model.crud import get_model
|
|
7
|
-
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
8
|
-
from digitalhub.entities.utils.utils import parse_entity_key
|
|
9
|
-
|
|
10
|
-
ENTITY_FUNC = {
|
|
11
|
-
EntityTypes.ARTIFACT.value: get_artifact,
|
|
12
|
-
EntityTypes.DATAITEM.value: get_dataitem,
|
|
13
|
-
EntityTypes.MODEL.value: get_model,
|
|
14
|
-
}
|
|
15
4
|
|
|
16
5
|
|
|
17
6
|
class RunStatus(Status):
|
|
18
7
|
"""
|
|
19
8
|
RunStatus status.
|
|
20
9
|
"""
|
|
21
|
-
|
|
22
|
-
def __init__(
|
|
23
|
-
self,
|
|
24
|
-
state: str,
|
|
25
|
-
message: str | None = None,
|
|
26
|
-
outputs: list | None = None,
|
|
27
|
-
results: dict | None = None,
|
|
28
|
-
**kwargs,
|
|
29
|
-
) -> None:
|
|
30
|
-
super().__init__(state, message)
|
|
31
|
-
self.outputs = outputs
|
|
32
|
-
self.results = results
|
|
33
|
-
|
|
34
|
-
self._any_setter(**kwargs)
|
|
35
|
-
|
|
36
|
-
def get_results(self) -> dict:
|
|
37
|
-
"""
|
|
38
|
-
Get results.
|
|
39
|
-
|
|
40
|
-
Returns
|
|
41
|
-
-------
|
|
42
|
-
dict
|
|
43
|
-
The results.
|
|
44
|
-
"""
|
|
45
|
-
if not hasattr(self, "results") or self.results is None:
|
|
46
|
-
return {}
|
|
47
|
-
return self.results
|
|
48
|
-
|
|
49
|
-
def get_outputs(self, as_key: bool = False, as_dict: bool = False) -> dict:
|
|
50
|
-
"""
|
|
51
|
-
Get outputs.
|
|
52
|
-
|
|
53
|
-
Parameters
|
|
54
|
-
----------
|
|
55
|
-
as_key : bool
|
|
56
|
-
If True, return outputs as keys.
|
|
57
|
-
as_dict : bool
|
|
58
|
-
If True, return outputs as dictionaries.
|
|
59
|
-
|
|
60
|
-
Returns
|
|
61
|
-
-------
|
|
62
|
-
dict
|
|
63
|
-
The outputs.
|
|
64
|
-
"""
|
|
65
|
-
outputs = {}
|
|
66
|
-
if not hasattr(self, "outputs") or self.outputs is None:
|
|
67
|
-
return outputs
|
|
68
|
-
|
|
69
|
-
for parameter, key in self.outputs.items():
|
|
70
|
-
entity_type = self._get_entity_type(key)
|
|
71
|
-
entity = ENTITY_FUNC[entity_type](key)
|
|
72
|
-
if as_key:
|
|
73
|
-
entity = entity.key
|
|
74
|
-
if as_dict:
|
|
75
|
-
entity = entity.to_dict()
|
|
76
|
-
outputs[parameter] = entity
|
|
77
|
-
|
|
78
|
-
return outputs
|
|
79
|
-
|
|
80
|
-
@staticmethod
|
|
81
|
-
def _get_entity_type(key: str) -> str:
|
|
82
|
-
"""
|
|
83
|
-
Get entity type.
|
|
84
|
-
|
|
85
|
-
Parameters
|
|
86
|
-
----------
|
|
87
|
-
key : str
|
|
88
|
-
The key of the entity.
|
|
89
|
-
|
|
90
|
-
Returns
|
|
91
|
-
-------
|
|
92
|
-
str
|
|
93
|
-
The entity type.
|
|
94
|
-
"""
|
|
95
|
-
_, entity_type, _, _, _ = parse_entity_key(key)
|
|
96
|
-
return entity_type
|
|
97
|
-
|
|
98
|
-
def get_values(self, values_list: list) -> dict:
|
|
99
|
-
"""
|
|
100
|
-
Get values.
|
|
101
|
-
|
|
102
|
-
Parameters
|
|
103
|
-
----------
|
|
104
|
-
values_list : list
|
|
105
|
-
The values list to search in.
|
|
106
|
-
|
|
107
|
-
Returns
|
|
108
|
-
-------
|
|
109
|
-
dict
|
|
110
|
-
The values.
|
|
111
|
-
"""
|
|
112
|
-
if not hasattr(self, "results") or self.results is None:
|
|
113
|
-
return {}
|
|
114
|
-
return {k: v for k, v in self.get_results().items() if k in values_list}
|
digitalhub/entities/run/crud.py
CHANGED
|
@@ -2,12 +2,15 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
|
-
from digitalhub.
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
from digitalhub.entities._base.crud import (
|
|
6
|
+
delete_entity,
|
|
7
|
+
get_unversioned_entity,
|
|
8
|
+
import_context_entity,
|
|
9
|
+
list_context_entities,
|
|
10
|
+
new_context_entity,
|
|
11
|
+
)
|
|
8
12
|
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
9
|
-
from digitalhub.utils.exceptions import
|
|
10
|
-
from digitalhub.utils.io_utils import read_yaml
|
|
13
|
+
from digitalhub.utils.exceptions import EntityError
|
|
11
14
|
|
|
12
15
|
if typing.TYPE_CHECKING:
|
|
13
16
|
from digitalhub.entities.run._base.entity import Run
|
|
@@ -52,13 +55,11 @@ def new_run(
|
|
|
52
55
|
|
|
53
56
|
Examples
|
|
54
57
|
--------
|
|
55
|
-
>>> obj =
|
|
56
|
-
>>>
|
|
57
|
-
>>>
|
|
58
|
-
>>> task="task-string"
|
|
58
|
+
>>> obj = new_run(project="my-project",
|
|
59
|
+
>>> kind="python+run",
|
|
60
|
+
>>> task="task-string")
|
|
59
61
|
"""
|
|
60
|
-
|
|
61
|
-
obj = run_from_parameters(
|
|
62
|
+
return new_context_entity(
|
|
62
63
|
project=project,
|
|
63
64
|
kind=kind,
|
|
64
65
|
uuid=uuid,
|
|
@@ -67,8 +68,6 @@ def new_run(
|
|
|
67
68
|
local_execution=local_execution,
|
|
68
69
|
**kwargs,
|
|
69
70
|
)
|
|
70
|
-
obj.save()
|
|
71
|
-
return obj
|
|
72
71
|
|
|
73
72
|
|
|
74
73
|
def get_run(
|
|
@@ -102,16 +101,12 @@ def get_run(
|
|
|
102
101
|
>>> obj = get_run("my-run-id"
|
|
103
102
|
>>> project="my-project")
|
|
104
103
|
"""
|
|
105
|
-
|
|
106
|
-
raise EntityError("Specify entity key or entity ID combined with project")
|
|
107
|
-
obj = read_entity_api_ctx(
|
|
104
|
+
return get_unversioned_entity(
|
|
108
105
|
identifier,
|
|
109
|
-
ENTITY_TYPE,
|
|
106
|
+
entity_type=ENTITY_TYPE,
|
|
110
107
|
project=project,
|
|
111
|
-
entity_id=identifier,
|
|
112
108
|
**kwargs,
|
|
113
109
|
)
|
|
114
|
-
return run_from_dict(obj)
|
|
115
110
|
|
|
116
111
|
|
|
117
112
|
def list_runs(project: str, **kwargs) -> list[Run]:
|
|
@@ -135,12 +130,11 @@ def list_runs(project: str, **kwargs) -> list[Run]:
|
|
|
135
130
|
>>> objs = list_runs(project="my-project")
|
|
136
131
|
"""
|
|
137
132
|
# TODO more examples: search by function, latest for task and function
|
|
138
|
-
|
|
133
|
+
return list_context_entities(
|
|
139
134
|
project=project,
|
|
140
135
|
entity_type=ENTITY_TYPE,
|
|
141
136
|
**kwargs,
|
|
142
137
|
)
|
|
143
|
-
return [run_from_dict(obj) for obj in objs]
|
|
144
138
|
|
|
145
139
|
|
|
146
140
|
def import_run(file: str) -> Run:
|
|
@@ -161,14 +155,7 @@ def import_run(file: str) -> Run:
|
|
|
161
155
|
-------
|
|
162
156
|
>>> obj = import_run("my-run.yaml")
|
|
163
157
|
"""
|
|
164
|
-
|
|
165
|
-
obj = run_from_dict(dict_obj)
|
|
166
|
-
try:
|
|
167
|
-
obj.save()
|
|
168
|
-
except EntityAlreadyExistsError:
|
|
169
|
-
pass
|
|
170
|
-
finally:
|
|
171
|
-
return obj
|
|
158
|
+
return import_context_entity(file)
|
|
172
159
|
|
|
173
160
|
|
|
174
161
|
def update_run(entity: Run) -> Run:
|
|
@@ -221,7 +208,7 @@ def delete_run(
|
|
|
221
208
|
"""
|
|
222
209
|
if not identifier.startswith("store://") and project is None:
|
|
223
210
|
raise EntityError("Specify entity key or entity ID combined with project")
|
|
224
|
-
return
|
|
211
|
+
return delete_entity(
|
|
225
212
|
identifier=identifier,
|
|
226
213
|
entity_type=ENTITY_TYPE,
|
|
227
214
|
project=project,
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
|
-
from digitalhub.entities._base.
|
|
5
|
+
from digitalhub.entities._base.api_utils import get_data_api, set_data_api
|
|
6
6
|
from digitalhub.entities._base.versioned.entity import VersionedEntity
|
|
7
7
|
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
8
8
|
|