digitalhub 0.10.0b4__py3-none-any.whl → 0.10.0b6__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/client/_base/api_builder.py +1 -1
- digitalhub/client/_base/client.py +22 -0
- digitalhub/client/_base/params_builder.py +16 -0
- digitalhub/client/dhcore/api_builder.py +4 -3
- digitalhub/client/dhcore/client.py +4 -0
- digitalhub/client/dhcore/configurator.py +26 -4
- digitalhub/client/dhcore/params_builder.py +174 -0
- digitalhub/client/local/api_builder.py +4 -1
- digitalhub/client/local/client.py +6 -0
- digitalhub/client/local/params_builder.py +116 -0
- digitalhub/configurator/configurator.py +10 -9
- digitalhub/entities/_base/context/entity.py +4 -4
- digitalhub/entities/_base/executable/entity.py +2 -2
- digitalhub/entities/_base/material/entity.py +3 -3
- digitalhub/entities/_base/unversioned/entity.py +2 -2
- digitalhub/entities/_base/versioned/entity.py +2 -2
- digitalhub/entities/_commons/enums.py +1 -0
- digitalhub/entities/_commons/metrics.py +164 -0
- digitalhub/entities/_commons/types.py +5 -0
- digitalhub/entities/_commons/utils.py +0 -26
- digitalhub/entities/_processors/base.py +527 -0
- digitalhub/entities/{_operations/processor.py → _processors/context.py} +94 -716
- digitalhub/entities/_processors/utils.py +158 -0
- digitalhub/entities/artifact/crud.py +10 -10
- digitalhub/entities/dataitem/crud.py +10 -10
- digitalhub/entities/dataitem/utils.py +2 -1
- digitalhub/entities/function/crud.py +9 -9
- digitalhub/entities/model/_base/entity.py +26 -78
- digitalhub/entities/model/_base/status.py +1 -1
- digitalhub/entities/model/crud.py +10 -10
- digitalhub/entities/project/_base/entity.py +317 -9
- digitalhub/entities/project/crud.py +10 -9
- digitalhub/entities/run/_base/entity.py +32 -84
- digitalhub/entities/run/_base/status.py +1 -1
- digitalhub/entities/run/crud.py +8 -8
- digitalhub/entities/secret/_base/entity.py +3 -3
- digitalhub/entities/secret/crud.py +9 -9
- digitalhub/entities/task/_base/entity.py +4 -4
- digitalhub/entities/task/_base/models.py +10 -0
- digitalhub/entities/task/crud.py +8 -8
- digitalhub/entities/workflow/crud.py +9 -9
- digitalhub/factory/utils.py +9 -9
- digitalhub/readers/data/pandas/reader.py +9 -9
- digitalhub/stores/s3/configurator.py +1 -1
- digitalhub/stores/sql/configurator.py +1 -1
- digitalhub/{readers/data/pandas → utils}/enums.py +1 -1
- digitalhub/utils/git_utils.py +16 -9
- digitalhub/utils/types.py +0 -1
- {digitalhub-0.10.0b4.dist-info → digitalhub-0.10.0b6.dist-info}/METADATA +1 -4
- {digitalhub-0.10.0b4.dist-info → digitalhub-0.10.0b6.dist-info}/RECORD +53 -49
- digitalhub/entities/_base/project/entity.py +0 -341
- digitalhub/entities/_commons/models.py +0 -13
- digitalhub/entities/_operations/__init__.py +0 -0
- /digitalhub/entities/{_base/project → _processors}/__init__.py +0 -0
- {digitalhub-0.10.0b4.dist-info → digitalhub-0.10.0b6.dist-info}/WHEEL +0 -0
- {digitalhub-0.10.0b4.dist-info → digitalhub-0.10.0b6.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.client.api import get_client
|
|
6
|
+
from digitalhub.context.api import get_context
|
|
7
|
+
from digitalhub.entities._commons.enums import ApiCategories, BackendOperations, EntityTypes
|
|
8
|
+
from digitalhub.entities._commons.utils import get_project_from_key, parse_entity_key
|
|
9
|
+
from digitalhub.factory.api import build_entity_from_dict
|
|
10
|
+
from digitalhub.utils.exceptions import ContextError, EntityError, EntityNotExistsError
|
|
11
|
+
|
|
12
|
+
if typing.TYPE_CHECKING:
|
|
13
|
+
from digitalhub.client._base.client import Client
|
|
14
|
+
from digitalhub.context.context import Context
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def parse_identifier(
|
|
18
|
+
identifier: str,
|
|
19
|
+
project: str | None = None,
|
|
20
|
+
entity_type: str | None = None,
|
|
21
|
+
entity_kind: str | None = None,
|
|
22
|
+
entity_id: str | None = None,
|
|
23
|
+
) -> tuple[str, str, str | None, str | None, str | None]:
|
|
24
|
+
"""
|
|
25
|
+
Parse entity identifier.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
identifier : str
|
|
30
|
+
Entity key (store://...) or entity name.
|
|
31
|
+
project : str
|
|
32
|
+
Project name.
|
|
33
|
+
entity_type : str
|
|
34
|
+
Entity type.
|
|
35
|
+
entity_id : str
|
|
36
|
+
Entity ID.
|
|
37
|
+
|
|
38
|
+
Returns
|
|
39
|
+
-------
|
|
40
|
+
tuple[str, str, str | None, str | None, str | None]
|
|
41
|
+
Project name, entity type, entity kind, entity name, entity ID.
|
|
42
|
+
"""
|
|
43
|
+
if not identifier.startswith("store://"):
|
|
44
|
+
if project is None or entity_type is None:
|
|
45
|
+
raise ValueError("Project and entity type must be specified.")
|
|
46
|
+
return project, entity_type, entity_kind, identifier, entity_id
|
|
47
|
+
return parse_entity_key(identifier)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def get_context_from_identifier(
|
|
51
|
+
identifier: str,
|
|
52
|
+
project: str | None = None,
|
|
53
|
+
) -> Context:
|
|
54
|
+
"""
|
|
55
|
+
Get context from project.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
identifier : str
|
|
60
|
+
Entity key (store://...) or entity name.
|
|
61
|
+
project : str
|
|
62
|
+
Project name.
|
|
63
|
+
|
|
64
|
+
Returns
|
|
65
|
+
-------
|
|
66
|
+
Context
|
|
67
|
+
Context.
|
|
68
|
+
"""
|
|
69
|
+
if not identifier.startswith("store://"):
|
|
70
|
+
if project is None:
|
|
71
|
+
raise EntityError("Specify project if you do not specify entity key.")
|
|
72
|
+
else:
|
|
73
|
+
project = get_project_from_key(identifier)
|
|
74
|
+
|
|
75
|
+
return get_context_from_project(project)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def get_context_from_project(
|
|
79
|
+
project: str,
|
|
80
|
+
) -> Context:
|
|
81
|
+
"""
|
|
82
|
+
Check if the given project is in the context.
|
|
83
|
+
Otherwise try to get the project from remote.
|
|
84
|
+
Finally return the client.
|
|
85
|
+
|
|
86
|
+
Parameters
|
|
87
|
+
----------
|
|
88
|
+
project : str
|
|
89
|
+
Project name.
|
|
90
|
+
|
|
91
|
+
Returns
|
|
92
|
+
-------
|
|
93
|
+
Context
|
|
94
|
+
Context.
|
|
95
|
+
"""
|
|
96
|
+
try:
|
|
97
|
+
return get_context(project)
|
|
98
|
+
except ContextError:
|
|
99
|
+
return get_context_from_remote(project)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def get_context_from_remote(
|
|
103
|
+
project: str,
|
|
104
|
+
) -> Client:
|
|
105
|
+
"""
|
|
106
|
+
Get context from remote.
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
project : str
|
|
111
|
+
Project name.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
Client
|
|
116
|
+
Client.
|
|
117
|
+
"""
|
|
118
|
+
try:
|
|
119
|
+
client = get_client()
|
|
120
|
+
obj = _read_base_entity(client, EntityTypes.PROJECT.value, project)
|
|
121
|
+
build_entity_from_dict(obj)
|
|
122
|
+
return get_context(project)
|
|
123
|
+
except EntityNotExistsError:
|
|
124
|
+
raise ContextError(f"Project '{project}' not found.")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _read_base_entity(
|
|
128
|
+
client: Client,
|
|
129
|
+
entity_type: str,
|
|
130
|
+
entity_name: str,
|
|
131
|
+
**kwargs,
|
|
132
|
+
) -> dict:
|
|
133
|
+
"""
|
|
134
|
+
Read object from backend.
|
|
135
|
+
|
|
136
|
+
Parameters
|
|
137
|
+
----------
|
|
138
|
+
client : Client
|
|
139
|
+
Client instance.
|
|
140
|
+
entity_type : str
|
|
141
|
+
Entity type.
|
|
142
|
+
entity_name : str
|
|
143
|
+
Entity name.
|
|
144
|
+
**kwargs : dict
|
|
145
|
+
Parameters to pass to the API call.
|
|
146
|
+
|
|
147
|
+
Returns
|
|
148
|
+
-------
|
|
149
|
+
dict
|
|
150
|
+
Object instance.
|
|
151
|
+
"""
|
|
152
|
+
api = client.build_api(
|
|
153
|
+
ApiCategories.BASE.value,
|
|
154
|
+
BackendOperations.READ.value,
|
|
155
|
+
entity_type=entity_type,
|
|
156
|
+
entity_name=entity_name,
|
|
157
|
+
)
|
|
158
|
+
return client.read_object(api, **kwargs)
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
6
|
-
from digitalhub.entities.
|
|
6
|
+
from digitalhub.entities._processors.context import context_processor
|
|
7
7
|
from digitalhub.entities.artifact._base.entity import Artifact
|
|
8
8
|
from digitalhub.entities.artifact.utils import eval_source, process_kwargs
|
|
9
9
|
from digitalhub.utils.types import SourcesOrListOfSources
|
|
@@ -62,7 +62,7 @@ def new_artifact(
|
|
|
62
62
|
>>> kind="artifact",
|
|
63
63
|
>>> path="s3://my-bucket/my-key")
|
|
64
64
|
"""
|
|
65
|
-
return
|
|
65
|
+
return context_processor.create_context_entity(
|
|
66
66
|
project=project,
|
|
67
67
|
name=name,
|
|
68
68
|
kind=kind,
|
|
@@ -115,7 +115,7 @@ def log_artifact(
|
|
|
115
115
|
"""
|
|
116
116
|
eval_source(source)
|
|
117
117
|
kwargs = process_kwargs(project, name, source=source, path=path, **kwargs)
|
|
118
|
-
return
|
|
118
|
+
return context_processor.log_material_entity(
|
|
119
119
|
source=source,
|
|
120
120
|
project=project,
|
|
121
121
|
name=name,
|
|
@@ -159,7 +159,7 @@ def get_artifact(
|
|
|
159
159
|
>>> project="my-project",
|
|
160
160
|
>>> entity_id="my-artifact-id")
|
|
161
161
|
"""
|
|
162
|
-
return
|
|
162
|
+
return context_processor.read_context_entity(
|
|
163
163
|
identifier=identifier,
|
|
164
164
|
entity_type=ENTITY_TYPE,
|
|
165
165
|
project=project,
|
|
@@ -199,7 +199,7 @@ def get_artifact_versions(
|
|
|
199
199
|
>>> obj = get_artifact_versions("my-artifact-name"
|
|
200
200
|
>>> project="my-project")
|
|
201
201
|
"""
|
|
202
|
-
return
|
|
202
|
+
return context_processor.read_context_entity_versions(
|
|
203
203
|
identifier=identifier,
|
|
204
204
|
entity_type=ENTITY_TYPE,
|
|
205
205
|
project=project,
|
|
@@ -227,7 +227,7 @@ def list_artifacts(project: str, **kwargs) -> list[Artifact]:
|
|
|
227
227
|
--------
|
|
228
228
|
>>> objs = list_artifacts(project="my-project")
|
|
229
229
|
"""
|
|
230
|
-
return
|
|
230
|
+
return context_processor.list_context_entities(
|
|
231
231
|
project=project,
|
|
232
232
|
entity_type=ENTITY_TYPE,
|
|
233
233
|
**kwargs,
|
|
@@ -252,7 +252,7 @@ def import_artifact(file: str) -> Artifact:
|
|
|
252
252
|
--------
|
|
253
253
|
>>> obj = import_artifact("my-artifact.yaml")
|
|
254
254
|
"""
|
|
255
|
-
return
|
|
255
|
+
return context_processor.import_context_entity(file)
|
|
256
256
|
|
|
257
257
|
|
|
258
258
|
def load_artifact(file: str) -> Artifact:
|
|
@@ -273,7 +273,7 @@ def load_artifact(file: str) -> Artifact:
|
|
|
273
273
|
--------
|
|
274
274
|
>>> obj = load_artifact("my-artifact.yaml")
|
|
275
275
|
"""
|
|
276
|
-
return
|
|
276
|
+
return context_processor.load_context_entity(file)
|
|
277
277
|
|
|
278
278
|
|
|
279
279
|
def update_artifact(entity: Artifact) -> Artifact:
|
|
@@ -294,7 +294,7 @@ def update_artifact(entity: Artifact) -> Artifact:
|
|
|
294
294
|
--------
|
|
295
295
|
>>> obj = update_artifact(obj)
|
|
296
296
|
"""
|
|
297
|
-
return
|
|
297
|
+
return context_processor.update_context_entity(
|
|
298
298
|
project=entity.project,
|
|
299
299
|
entity_type=entity.ENTITY_TYPE,
|
|
300
300
|
entity_id=entity.id,
|
|
@@ -340,7 +340,7 @@ def delete_artifact(
|
|
|
340
340
|
>>> project="my-project",
|
|
341
341
|
>>> delete_all_versions=True)
|
|
342
342
|
"""
|
|
343
|
-
return
|
|
343
|
+
return context_processor.delete_context_entity(
|
|
344
344
|
identifier=identifier,
|
|
345
345
|
entity_type=ENTITY_TYPE,
|
|
346
346
|
project=project,
|
|
@@ -4,7 +4,7 @@ import typing
|
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
6
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
|
-
from digitalhub.entities.
|
|
7
|
+
from digitalhub.entities._processors.context import context_processor
|
|
8
8
|
from digitalhub.entities.dataitem.utils import clean_tmp_path, eval_data, eval_source, post_process, process_kwargs
|
|
9
9
|
from digitalhub.utils.types import SourcesOrListOfSources
|
|
10
10
|
|
|
@@ -62,7 +62,7 @@ def new_dataitem(
|
|
|
62
62
|
>>> kind="dataitem",
|
|
63
63
|
>>> path="s3://my-bucket/my-key")
|
|
64
64
|
"""
|
|
65
|
-
return
|
|
65
|
+
return context_processor.create_context_entity(
|
|
66
66
|
project=project,
|
|
67
67
|
name=name,
|
|
68
68
|
kind=kind,
|
|
@@ -129,7 +129,7 @@ def log_dataitem(
|
|
|
129
129
|
source = eval_source(source, data, kind, name, project)
|
|
130
130
|
data = eval_data(project, kind, source, data, file_format, engine)
|
|
131
131
|
kwargs = process_kwargs(project, name, kind, source=source, data=data, path=path, **kwargs)
|
|
132
|
-
obj =
|
|
132
|
+
obj = context_processor.log_material_entity(
|
|
133
133
|
source=source,
|
|
134
134
|
project=project,
|
|
135
135
|
name=name,
|
|
@@ -177,7 +177,7 @@ def get_dataitem(
|
|
|
177
177
|
>>> project="my-project",
|
|
178
178
|
>>> entity_id="my-dataitem-id")
|
|
179
179
|
"""
|
|
180
|
-
return
|
|
180
|
+
return context_processor.read_context_entity(
|
|
181
181
|
identifier=identifier,
|
|
182
182
|
entity_type=ENTITY_TYPE,
|
|
183
183
|
project=project,
|
|
@@ -217,7 +217,7 @@ def get_dataitem_versions(
|
|
|
217
217
|
>>> objs = get_dataitem_versions("my-dataitem-name",
|
|
218
218
|
>>> project="my-project")
|
|
219
219
|
"""
|
|
220
|
-
return
|
|
220
|
+
return context_processor.read_context_entity_versions(
|
|
221
221
|
identifier=identifier,
|
|
222
222
|
entity_type=ENTITY_TYPE,
|
|
223
223
|
project=project,
|
|
@@ -245,7 +245,7 @@ def list_dataitems(project: str, **kwargs) -> list[Dataitem]:
|
|
|
245
245
|
--------
|
|
246
246
|
>>> objs = list_dataitems(project="my-project")
|
|
247
247
|
"""
|
|
248
|
-
return
|
|
248
|
+
return context_processor.list_context_entities(
|
|
249
249
|
project=project,
|
|
250
250
|
entity_type=ENTITY_TYPE,
|
|
251
251
|
**kwargs,
|
|
@@ -270,7 +270,7 @@ def import_dataitem(file: str) -> Dataitem:
|
|
|
270
270
|
--------
|
|
271
271
|
>>> obj = import_dataitem("my-dataitem.yaml")
|
|
272
272
|
"""
|
|
273
|
-
return
|
|
273
|
+
return context_processor.import_context_entity(file)
|
|
274
274
|
|
|
275
275
|
|
|
276
276
|
def load_dataitem(file: str) -> Dataitem:
|
|
@@ -291,7 +291,7 @@ def load_dataitem(file: str) -> Dataitem:
|
|
|
291
291
|
--------
|
|
292
292
|
>>> obj = load_dataitem("my-dataitem.yaml")
|
|
293
293
|
"""
|
|
294
|
-
return
|
|
294
|
+
return context_processor.load_context_entity(file)
|
|
295
295
|
|
|
296
296
|
|
|
297
297
|
def update_dataitem(entity: Dataitem) -> Dataitem:
|
|
@@ -312,7 +312,7 @@ def update_dataitem(entity: Dataitem) -> Dataitem:
|
|
|
312
312
|
--------
|
|
313
313
|
>>> obj = update_dataitem(obj)
|
|
314
314
|
"""
|
|
315
|
-
return
|
|
315
|
+
return context_processor.update_context_entity(
|
|
316
316
|
project=entity.project,
|
|
317
317
|
entity_type=entity.ENTITY_TYPE,
|
|
318
318
|
entity_id=entity.id,
|
|
@@ -358,7 +358,7 @@ def delete_dataitem(
|
|
|
358
358
|
>>> project="my-project",
|
|
359
359
|
>>> delete_all_versions=True)
|
|
360
360
|
"""
|
|
361
|
-
return
|
|
361
|
+
return context_processor.delete_context_entity(
|
|
362
362
|
identifier=identifier,
|
|
363
363
|
entity_type=ENTITY_TYPE,
|
|
364
364
|
project=project,
|
|
@@ -10,6 +10,7 @@ from digitalhub.entities._base.material.utils import build_log_path_from_source,
|
|
|
10
10
|
from digitalhub.entities._commons.enums import EntityKinds, EntityTypes
|
|
11
11
|
from digitalhub.readers.data.api import get_reader_by_object
|
|
12
12
|
from digitalhub.stores.api import get_store
|
|
13
|
+
from digitalhub.utils.enums import FileExtensions
|
|
13
14
|
from digitalhub.utils.generic_utils import slugify_string
|
|
14
15
|
from digitalhub.utils.types import SourcesOrListOfSources
|
|
15
16
|
|
|
@@ -17,7 +18,7 @@ if typing.TYPE_CHECKING:
|
|
|
17
18
|
from digitalhub.entities.dataitem._base.entity import Dataitem
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
DEFAULT_EXTENSION =
|
|
21
|
+
DEFAULT_EXTENSION = FileExtensions.PARQUET.value
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
def eval_source(
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
6
|
-
from digitalhub.entities.
|
|
6
|
+
from digitalhub.entities._processors.context import context_processor
|
|
7
7
|
|
|
8
8
|
if typing.TYPE_CHECKING:
|
|
9
9
|
from digitalhub.entities.function._base.entity import Function
|
|
@@ -56,7 +56,7 @@ def new_function(
|
|
|
56
56
|
>>> code_src="function.py",
|
|
57
57
|
>>> handler="function-handler")
|
|
58
58
|
"""
|
|
59
|
-
return
|
|
59
|
+
return context_processor.create_context_entity(
|
|
60
60
|
project=project,
|
|
61
61
|
name=name,
|
|
62
62
|
kind=kind,
|
|
@@ -103,7 +103,7 @@ def get_function(
|
|
|
103
103
|
>>> project="my-project",
|
|
104
104
|
>>> entity_id="my-function-id")
|
|
105
105
|
"""
|
|
106
|
-
return
|
|
106
|
+
return context_processor.read_context_entity(
|
|
107
107
|
identifier,
|
|
108
108
|
entity_type=ENTITY_TYPE,
|
|
109
109
|
project=project,
|
|
@@ -143,7 +143,7 @@ def get_function_versions(
|
|
|
143
143
|
>>> obj = get_function_versions("my-function-name"
|
|
144
144
|
>>> project="my-project")
|
|
145
145
|
"""
|
|
146
|
-
return
|
|
146
|
+
return context_processor.read_context_entity_versions(
|
|
147
147
|
identifier,
|
|
148
148
|
entity_type=ENTITY_TYPE,
|
|
149
149
|
project=project,
|
|
@@ -171,7 +171,7 @@ def list_functions(project: str, **kwargs) -> list[Function]:
|
|
|
171
171
|
--------
|
|
172
172
|
>>> objs = list_functions(project="my-project")
|
|
173
173
|
"""
|
|
174
|
-
return
|
|
174
|
+
return context_processor.list_context_entities(
|
|
175
175
|
project=project,
|
|
176
176
|
entity_type=ENTITY_TYPE,
|
|
177
177
|
**kwargs,
|
|
@@ -196,7 +196,7 @@ def import_function(file: str) -> Function:
|
|
|
196
196
|
--------
|
|
197
197
|
>>> obj = import_function("my-function.yaml")
|
|
198
198
|
"""
|
|
199
|
-
return
|
|
199
|
+
return context_processor.import_executable_entity(file)
|
|
200
200
|
|
|
201
201
|
|
|
202
202
|
def load_function(file: str) -> Function:
|
|
@@ -217,7 +217,7 @@ def load_function(file: str) -> Function:
|
|
|
217
217
|
--------
|
|
218
218
|
>>> obj = load_function("my-function.yaml")
|
|
219
219
|
"""
|
|
220
|
-
return
|
|
220
|
+
return context_processor.load_executable_entity(file)
|
|
221
221
|
|
|
222
222
|
|
|
223
223
|
def update_function(entity: Function) -> Function:
|
|
@@ -238,7 +238,7 @@ def update_function(entity: Function) -> Function:
|
|
|
238
238
|
--------
|
|
239
239
|
>>> obj = update_function(obj)
|
|
240
240
|
"""
|
|
241
|
-
return
|
|
241
|
+
return context_processor.update_context_entity(
|
|
242
242
|
project=entity.project,
|
|
243
243
|
entity_type=entity.ENTITY_TYPE,
|
|
244
244
|
entity_id=entity.id,
|
|
@@ -287,7 +287,7 @@ def delete_function(
|
|
|
287
287
|
>>> project="my-project",
|
|
288
288
|
>>> delete_all_versions=True)
|
|
289
289
|
"""
|
|
290
|
-
return
|
|
290
|
+
return context_processor.delete_context_entity(
|
|
291
291
|
identifier=identifier,
|
|
292
292
|
entity_type=ENTITY_TYPE,
|
|
293
293
|
project=project,
|
|
@@ -4,8 +4,8 @@ import typing
|
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.material.entity import MaterialEntity
|
|
6
6
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
|
-
from digitalhub.entities._commons.
|
|
8
|
-
from digitalhub.entities.
|
|
7
|
+
from digitalhub.entities._commons.metrics import MetricType, set_metrics, validate_metric_value
|
|
8
|
+
from digitalhub.entities._processors.context import context_processor
|
|
9
9
|
|
|
10
10
|
if typing.TYPE_CHECKING:
|
|
11
11
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -35,9 +35,6 @@ class Model(MaterialEntity):
|
|
|
35
35
|
self.spec: ModelSpec
|
|
36
36
|
self.status: ModelStatus
|
|
37
37
|
|
|
38
|
-
# Initialize metrics
|
|
39
|
-
self._init_metrics()
|
|
40
|
-
|
|
41
38
|
def save(self, update: bool = False) -> Model:
|
|
42
39
|
"""
|
|
43
40
|
Save entity into backend.
|
|
@@ -59,7 +56,7 @@ class Model(MaterialEntity):
|
|
|
59
56
|
def log_metric(
|
|
60
57
|
self,
|
|
61
58
|
key: str,
|
|
62
|
-
value:
|
|
59
|
+
value: MetricType,
|
|
63
60
|
overwrite: bool = False,
|
|
64
61
|
single_value: bool = False,
|
|
65
62
|
) -> None:
|
|
@@ -73,7 +70,7 @@ class Model(MaterialEntity):
|
|
|
73
70
|
----------
|
|
74
71
|
key : str
|
|
75
72
|
Key of the metric.
|
|
76
|
-
value :
|
|
73
|
+
value : MetricType
|
|
77
74
|
Value of the metric.
|
|
78
75
|
overwrite : bool
|
|
79
76
|
If True, overwrite existing metric.
|
|
@@ -101,32 +98,13 @@ class Model(MaterialEntity):
|
|
|
101
98
|
Log a list of values and overwrite existing metric:
|
|
102
99
|
>>> entity.log_metric("accuracy", [0.8, 0.9], overwrite=True)
|
|
103
100
|
"""
|
|
104
|
-
value
|
|
105
|
-
|
|
106
|
-
if isinstance(value, list):
|
|
107
|
-
self._handle_metric_list(key, value, overwrite)
|
|
108
|
-
elif single_value:
|
|
109
|
-
self._handle_metric_single(key, value, overwrite)
|
|
110
|
-
else:
|
|
111
|
-
self._handle_metric_list_append(key, value, overwrite)
|
|
112
|
-
|
|
113
|
-
processor.update_metric(self.project, self.ENTITY_TYPE, self.id, key, self.status.metrics[key])
|
|
101
|
+
self._set_metrics(key, value, overwrite, single_value)
|
|
102
|
+
context_processor.update_metric(self.project, self.ENTITY_TYPE, self.id, key, self.status.metrics[key])
|
|
114
103
|
|
|
115
104
|
##############################
|
|
116
105
|
# Helper methods
|
|
117
106
|
##############################
|
|
118
107
|
|
|
119
|
-
def _init_metrics(self) -> None:
|
|
120
|
-
"""
|
|
121
|
-
Initialize metrics.
|
|
122
|
-
|
|
123
|
-
Returns
|
|
124
|
-
-------
|
|
125
|
-
None
|
|
126
|
-
"""
|
|
127
|
-
if self.status.metrics is None:
|
|
128
|
-
self.status.metrics = {}
|
|
129
|
-
|
|
130
108
|
def _get_metrics(self) -> None:
|
|
131
109
|
"""
|
|
132
110
|
Get model metrics from backend.
|
|
@@ -135,72 +113,42 @@ class Model(MaterialEntity):
|
|
|
135
113
|
-------
|
|
136
114
|
None
|
|
137
115
|
"""
|
|
138
|
-
self.status.metrics =
|
|
116
|
+
self.status.metrics = context_processor.read_metrics(
|
|
139
117
|
project=self.project,
|
|
140
118
|
entity_type=self.ENTITY_TYPE,
|
|
141
119
|
entity_id=self.id,
|
|
142
120
|
)
|
|
143
121
|
|
|
144
|
-
def
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
Key of the metric.
|
|
152
|
-
value : float
|
|
153
|
-
Value of the metric.
|
|
154
|
-
overwrite : bool
|
|
155
|
-
If True, overwrite existing metric.
|
|
156
|
-
|
|
157
|
-
Returns
|
|
158
|
-
-------
|
|
159
|
-
None
|
|
160
|
-
"""
|
|
161
|
-
if key not in self.status.metrics or overwrite:
|
|
162
|
-
self.status.metrics[key] = value
|
|
163
|
-
|
|
164
|
-
def _handle_metric_list_append(self, key: str, value: float | int, overwrite: bool = False) -> None:
|
|
165
|
-
"""
|
|
166
|
-
Handle metric list append.
|
|
167
|
-
|
|
168
|
-
Parameters
|
|
169
|
-
----------
|
|
170
|
-
key : str
|
|
171
|
-
Key of the metric.
|
|
172
|
-
value : float
|
|
173
|
-
Value of the metric.
|
|
174
|
-
overwrite : bool
|
|
175
|
-
If True, overwrite existing metric.
|
|
176
|
-
|
|
177
|
-
Returns
|
|
178
|
-
-------
|
|
179
|
-
None
|
|
180
|
-
"""
|
|
181
|
-
if key not in self.status.metrics or overwrite:
|
|
182
|
-
self.status.metrics[key] = [value]
|
|
183
|
-
else:
|
|
184
|
-
self.status.metrics[key].append(value)
|
|
185
|
-
|
|
186
|
-
def _handle_metric_list(self, key: str, value: list[int | float], overwrite: bool = False) -> None:
|
|
122
|
+
def _set_metrics(
|
|
123
|
+
self,
|
|
124
|
+
key: str,
|
|
125
|
+
value: MetricType,
|
|
126
|
+
overwrite: bool,
|
|
127
|
+
single_value: bool,
|
|
128
|
+
) -> None:
|
|
187
129
|
"""
|
|
188
|
-
|
|
130
|
+
Set model metrics.
|
|
189
131
|
|
|
190
132
|
Parameters
|
|
191
133
|
----------
|
|
192
134
|
key : str
|
|
193
135
|
Key of the metric.
|
|
194
|
-
value :
|
|
136
|
+
value : MetricType
|
|
195
137
|
Value of the metric.
|
|
196
138
|
overwrite : bool
|
|
197
139
|
If True, overwrite existing metric.
|
|
140
|
+
single_value : bool
|
|
141
|
+
If True, value is a single value.
|
|
198
142
|
|
|
199
143
|
Returns
|
|
200
144
|
-------
|
|
201
145
|
None
|
|
202
146
|
"""
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
147
|
+
value = validate_metric_value(value)
|
|
148
|
+
self.status.metrics = set_metrics(
|
|
149
|
+
self.status.metrics,
|
|
150
|
+
key,
|
|
151
|
+
value,
|
|
152
|
+
overwrite,
|
|
153
|
+
single_value,
|
|
154
|
+
)
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
6
|
-
from digitalhub.entities.
|
|
6
|
+
from digitalhub.entities._processors.context import context_processor
|
|
7
7
|
from digitalhub.entities.artifact.utils import eval_source, process_kwargs
|
|
8
8
|
from digitalhub.utils.types import SourcesOrListOfSources
|
|
9
9
|
|
|
@@ -61,7 +61,7 @@ def new_model(
|
|
|
61
61
|
>>> kind="model",
|
|
62
62
|
>>> path="s3://my-bucket/my-key")
|
|
63
63
|
"""
|
|
64
|
-
return
|
|
64
|
+
return context_processor.create_context_entity(
|
|
65
65
|
project=project,
|
|
66
66
|
name=name,
|
|
67
67
|
kind=kind,
|
|
@@ -114,7 +114,7 @@ def log_model(
|
|
|
114
114
|
"""
|
|
115
115
|
eval_source(source)
|
|
116
116
|
kwargs = process_kwargs(project, name, source=source, path=path, **kwargs)
|
|
117
|
-
return
|
|
117
|
+
return context_processor.log_material_entity(
|
|
118
118
|
source=source,
|
|
119
119
|
project=project,
|
|
120
120
|
name=name,
|
|
@@ -158,7 +158,7 @@ def get_model(
|
|
|
158
158
|
>>> project="my-project",
|
|
159
159
|
>>> entity_id="my-model-id")
|
|
160
160
|
"""
|
|
161
|
-
return
|
|
161
|
+
return context_processor.read_context_entity(
|
|
162
162
|
identifier=identifier,
|
|
163
163
|
entity_type=ENTITY_TYPE,
|
|
164
164
|
project=project,
|
|
@@ -198,7 +198,7 @@ def get_model_versions(
|
|
|
198
198
|
>>> objs = get_model_versions("my-model-name",
|
|
199
199
|
>>> project="my-project")
|
|
200
200
|
"""
|
|
201
|
-
return
|
|
201
|
+
return context_processor.read_context_entity_versions(
|
|
202
202
|
identifier=identifier,
|
|
203
203
|
entity_type=ENTITY_TYPE,
|
|
204
204
|
project=project,
|
|
@@ -226,7 +226,7 @@ def list_models(project: str, **kwargs) -> list[Model]:
|
|
|
226
226
|
--------
|
|
227
227
|
>>> objs = list_models(project="my-project")
|
|
228
228
|
"""
|
|
229
|
-
return
|
|
229
|
+
return context_processor.list_context_entities(
|
|
230
230
|
project=project,
|
|
231
231
|
entity_type=ENTITY_TYPE,
|
|
232
232
|
**kwargs,
|
|
@@ -251,7 +251,7 @@ def import_model(file: str) -> Model:
|
|
|
251
251
|
--------
|
|
252
252
|
>>> obj = import_model("my-model.yaml")
|
|
253
253
|
"""
|
|
254
|
-
return
|
|
254
|
+
return context_processor.import_context_entity(file)
|
|
255
255
|
|
|
256
256
|
|
|
257
257
|
def load_model(file: str) -> Model:
|
|
@@ -272,7 +272,7 @@ def load_model(file: str) -> Model:
|
|
|
272
272
|
--------
|
|
273
273
|
>>> obj = load_model("my-model.yaml")
|
|
274
274
|
"""
|
|
275
|
-
return
|
|
275
|
+
return context_processor.load_context_entity(file)
|
|
276
276
|
|
|
277
277
|
|
|
278
278
|
def update_model(entity: Model) -> Model:
|
|
@@ -293,7 +293,7 @@ def update_model(entity: Model) -> Model:
|
|
|
293
293
|
--------
|
|
294
294
|
>>> obj = get_model("store://my-model-key")
|
|
295
295
|
"""
|
|
296
|
-
return
|
|
296
|
+
return context_processor.update_context_entity(
|
|
297
297
|
project=entity.project,
|
|
298
298
|
entity_type=entity.ENTITY_TYPE,
|
|
299
299
|
entity_id=entity.id,
|
|
@@ -339,7 +339,7 @@ def delete_model(
|
|
|
339
339
|
>>> project="my-project",
|
|
340
340
|
>>> delete_all_versions=True)
|
|
341
341
|
"""
|
|
342
|
-
return
|
|
342
|
+
return context_processor.delete_context_entity(
|
|
343
343
|
identifier=identifier,
|
|
344
344
|
entity_type=ENTITY_TYPE,
|
|
345
345
|
project=project,
|