digitalhub 0.11.0b7__py3-none-any.whl → 0.13.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 +4 -1
- digitalhub/context/api.py +9 -5
- digitalhub/context/builder.py +7 -5
- digitalhub/context/context.py +13 -1
- digitalhub/entities/__init__.py +3 -0
- digitalhub/entities/_base/__init__.py +3 -0
- digitalhub/entities/_base/_base/__init__.py +3 -0
- digitalhub/entities/_base/_base/entity.py +4 -0
- digitalhub/entities/_base/context/__init__.py +3 -0
- digitalhub/entities/_base/context/entity.py +4 -0
- digitalhub/entities/_base/entity/__init__.py +3 -0
- digitalhub/entities/_base/entity/_constructors/__init__.py +3 -0
- digitalhub/entities/_base/entity/_constructors/metadata.py +4 -0
- digitalhub/entities/_base/entity/_constructors/name.py +4 -0
- digitalhub/entities/_base/entity/_constructors/spec.py +4 -0
- digitalhub/entities/_base/entity/_constructors/status.py +4 -0
- digitalhub/entities/_base/entity/_constructors/uuid.py +4 -0
- digitalhub/entities/_base/entity/builder.py +4 -0
- digitalhub/entities/_base/entity/entity.py +4 -0
- digitalhub/entities/_base/entity/metadata.py +4 -0
- digitalhub/entities/_base/entity/spec.py +4 -0
- digitalhub/entities/_base/entity/status.py +4 -0
- digitalhub/entities/_base/executable/__init__.py +3 -0
- digitalhub/entities/_base/executable/entity.py +109 -57
- digitalhub/entities/_base/material/__init__.py +3 -0
- digitalhub/entities/_base/material/entity.py +15 -18
- digitalhub/entities/_base/material/spec.py +4 -0
- digitalhub/entities/_base/material/status.py +4 -0
- digitalhub/entities/_base/material/utils.py +5 -1
- digitalhub/entities/_base/runtime_entity/__init__.py +3 -0
- digitalhub/entities/_base/runtime_entity/builder.py +4 -0
- digitalhub/entities/_base/unversioned/__init__.py +3 -0
- digitalhub/entities/_base/unversioned/builder.py +4 -0
- digitalhub/entities/_base/unversioned/entity.py +4 -0
- digitalhub/entities/_base/versioned/__init__.py +3 -0
- digitalhub/entities/_base/versioned/builder.py +4 -0
- digitalhub/entities/_base/versioned/entity.py +4 -0
- digitalhub/entities/_commons/__init__.py +3 -0
- digitalhub/entities/_commons/enums.py +4 -0
- digitalhub/entities/_commons/metrics.py +68 -30
- digitalhub/entities/_commons/utils.py +40 -9
- digitalhub/entities/_processors/__init__.py +3 -0
- digitalhub/entities/_processors/base.py +154 -79
- digitalhub/entities/_processors/context.py +370 -215
- digitalhub/entities/_processors/utils.py +78 -30
- digitalhub/entities/artifact/__init__.py +3 -0
- digitalhub/entities/artifact/_base/__init__.py +3 -0
- digitalhub/entities/artifact/_base/builder.py +4 -0
- digitalhub/entities/artifact/_base/entity.py +4 -0
- digitalhub/entities/artifact/_base/spec.py +4 -0
- digitalhub/entities/artifact/_base/status.py +4 -0
- digitalhub/entities/artifact/artifact/__init__.py +3 -0
- digitalhub/entities/artifact/artifact/builder.py +4 -0
- digitalhub/entities/artifact/artifact/entity.py +4 -0
- digitalhub/entities/artifact/artifact/spec.py +4 -0
- digitalhub/entities/artifact/artifact/status.py +4 -0
- digitalhub/entities/artifact/crud.py +8 -0
- digitalhub/entities/artifact/utils.py +32 -13
- digitalhub/entities/builders.py +4 -0
- digitalhub/entities/dataitem/__init__.py +3 -0
- digitalhub/entities/dataitem/_base/__init__.py +3 -0
- digitalhub/entities/dataitem/_base/builder.py +4 -0
- digitalhub/entities/dataitem/_base/entity.py +4 -0
- digitalhub/entities/dataitem/_base/spec.py +4 -0
- digitalhub/entities/dataitem/_base/status.py +4 -0
- digitalhub/entities/dataitem/crud.py +18 -2
- digitalhub/entities/dataitem/dataitem/__init__.py +3 -0
- digitalhub/entities/dataitem/dataitem/builder.py +4 -0
- digitalhub/entities/dataitem/dataitem/entity.py +4 -0
- digitalhub/entities/dataitem/dataitem/spec.py +4 -0
- digitalhub/entities/dataitem/dataitem/status.py +4 -0
- digitalhub/entities/dataitem/iceberg/__init__.py +3 -0
- digitalhub/entities/dataitem/iceberg/builder.py +4 -0
- digitalhub/entities/dataitem/iceberg/entity.py +4 -0
- digitalhub/entities/dataitem/iceberg/spec.py +4 -0
- digitalhub/entities/dataitem/iceberg/status.py +4 -0
- digitalhub/entities/dataitem/table/__init__.py +3 -0
- digitalhub/entities/dataitem/table/builder.py +4 -0
- digitalhub/entities/dataitem/table/entity.py +7 -3
- digitalhub/entities/dataitem/table/models.py +4 -0
- digitalhub/entities/dataitem/table/spec.py +4 -0
- digitalhub/entities/dataitem/table/status.py +4 -0
- digitalhub/entities/dataitem/table/utils.py +4 -0
- digitalhub/entities/dataitem/utils.py +88 -35
- digitalhub/entities/function/__init__.py +3 -0
- digitalhub/entities/function/_base/__init__.py +3 -0
- digitalhub/entities/function/_base/builder.py +4 -0
- digitalhub/entities/function/_base/entity.py +4 -0
- digitalhub/entities/function/_base/spec.py +4 -0
- digitalhub/entities/function/_base/status.py +4 -0
- digitalhub/entities/function/crud.py +4 -0
- digitalhub/entities/model/__init__.py +3 -0
- digitalhub/entities/model/_base/__init__.py +3 -0
- digitalhub/entities/model/_base/builder.py +4 -0
- digitalhub/entities/model/_base/entity.py +4 -0
- digitalhub/entities/model/_base/spec.py +4 -0
- digitalhub/entities/model/_base/status.py +4 -0
- digitalhub/entities/model/crud.py +8 -0
- digitalhub/entities/model/huggingface/__init__.py +3 -0
- digitalhub/entities/model/huggingface/builder.py +4 -0
- digitalhub/entities/model/huggingface/entity.py +4 -0
- digitalhub/entities/model/huggingface/spec.py +4 -0
- digitalhub/entities/model/huggingface/status.py +4 -0
- digitalhub/entities/model/mlflow/__init__.py +3 -0
- digitalhub/entities/model/mlflow/builder.py +4 -0
- digitalhub/entities/model/mlflow/entity.py +4 -0
- digitalhub/entities/model/mlflow/models.py +4 -0
- digitalhub/entities/model/mlflow/spec.py +4 -0
- digitalhub/entities/model/mlflow/status.py +4 -0
- digitalhub/entities/model/mlflow/utils.py +4 -0
- digitalhub/entities/model/model/__init__.py +3 -0
- digitalhub/entities/model/model/builder.py +4 -0
- digitalhub/entities/model/model/entity.py +4 -0
- digitalhub/entities/model/model/spec.py +4 -0
- digitalhub/entities/model/model/status.py +4 -0
- digitalhub/entities/model/sklearn/__init__.py +3 -0
- digitalhub/entities/model/sklearn/builder.py +4 -0
- digitalhub/entities/model/sklearn/entity.py +4 -0
- digitalhub/entities/model/sklearn/spec.py +4 -0
- digitalhub/entities/model/sklearn/status.py +4 -0
- digitalhub/entities/model/utils.py +32 -13
- digitalhub/entities/project/__init__.py +3 -0
- digitalhub/entities/project/_base/__init__.py +3 -0
- digitalhub/entities/project/_base/builder.py +4 -0
- digitalhub/entities/project/_base/entity.py +4 -2
- digitalhub/entities/project/_base/models.py +4 -0
- digitalhub/entities/project/_base/spec.py +4 -0
- digitalhub/entities/project/_base/status.py +4 -0
- digitalhub/entities/project/crud.py +4 -0
- digitalhub/entities/project/utils.py +4 -0
- digitalhub/entities/run/__init__.py +3 -0
- digitalhub/entities/run/_base/__init__.py +3 -0
- digitalhub/entities/run/_base/builder.py +4 -0
- digitalhub/entities/run/_base/entity.py +6 -2
- digitalhub/entities/run/_base/spec.py +4 -0
- digitalhub/entities/run/_base/status.py +4 -0
- digitalhub/entities/run/crud.py +4 -0
- digitalhub/entities/secret/__init__.py +3 -0
- digitalhub/entities/secret/_base/__init__.py +3 -0
- digitalhub/entities/secret/_base/builder.py +4 -0
- digitalhub/entities/secret/_base/entity.py +4 -0
- digitalhub/entities/secret/_base/spec.py +4 -0
- digitalhub/entities/secret/_base/status.py +4 -0
- digitalhub/entities/secret/crud.py +4 -0
- digitalhub/entities/task/__init__.py +3 -0
- digitalhub/entities/task/_base/__init__.py +3 -0
- digitalhub/entities/task/_base/builder.py +4 -0
- digitalhub/entities/task/_base/entity.py +4 -0
- digitalhub/entities/task/_base/models.py +16 -3
- digitalhub/entities/task/_base/spec.py +4 -0
- digitalhub/entities/task/_base/status.py +4 -0
- digitalhub/entities/task/_base/utils.py +4 -0
- digitalhub/entities/task/crud.py +4 -0
- digitalhub/entities/trigger/__init__.py +3 -0
- digitalhub/entities/trigger/_base/__init__.py +3 -0
- digitalhub/entities/trigger/_base/builder.py +4 -0
- digitalhub/entities/trigger/_base/entity.py +15 -0
- digitalhub/entities/trigger/_base/spec.py +4 -0
- digitalhub/entities/trigger/_base/status.py +4 -0
- digitalhub/entities/trigger/crud.py +4 -0
- digitalhub/entities/trigger/lifecycle/__init__.py +3 -0
- digitalhub/entities/trigger/lifecycle/builder.py +4 -0
- digitalhub/entities/trigger/lifecycle/entity.py +4 -0
- digitalhub/entities/trigger/lifecycle/spec.py +4 -0
- digitalhub/entities/trigger/lifecycle/status.py +4 -0
- digitalhub/entities/trigger/scheduler/__init__.py +3 -0
- digitalhub/entities/trigger/scheduler/builder.py +4 -0
- digitalhub/entities/trigger/scheduler/entity.py +4 -0
- digitalhub/entities/trigger/scheduler/spec.py +4 -0
- digitalhub/entities/trigger/scheduler/status.py +4 -0
- digitalhub/entities/workflow/__init__.py +3 -0
- digitalhub/entities/workflow/_base/__init__.py +3 -0
- digitalhub/entities/workflow/_base/builder.py +4 -0
- digitalhub/entities/workflow/_base/entity.py +4 -0
- digitalhub/entities/workflow/_base/spec.py +4 -0
- digitalhub/entities/workflow/_base/status.py +4 -0
- digitalhub/entities/workflow/crud.py +4 -0
- digitalhub/factory/__init__.py +3 -0
- digitalhub/factory/factory.py +29 -3
- digitalhub/factory/utils.py +15 -3
- digitalhub/runtimes/__init__.py +3 -0
- digitalhub/runtimes/_base.py +5 -1
- digitalhub/runtimes/builder.py +22 -1
- digitalhub/runtimes/enums.py +4 -0
- digitalhub/stores/__init__.py +3 -0
- digitalhub/stores/client/__init__.py +15 -0
- digitalhub/stores/client/_base/__init__.py +3 -0
- digitalhub/stores/client/_base/api_builder.py +18 -0
- digitalhub/stores/client/_base/client.py +97 -0
- digitalhub/stores/client/_base/key_builder.py +32 -0
- digitalhub/stores/client/_base/params_builder.py +18 -0
- digitalhub/stores/client/api.py +14 -5
- digitalhub/stores/client/builder.py +7 -1
- digitalhub/stores/client/dhcore/__init__.py +3 -0
- digitalhub/stores/client/dhcore/api_builder.py +21 -0
- digitalhub/stores/client/dhcore/client.py +329 -70
- digitalhub/stores/client/dhcore/configurator.py +489 -193
- digitalhub/stores/client/dhcore/enums.py +7 -0
- digitalhub/stores/client/dhcore/error_parser.py +39 -1
- digitalhub/stores/client/dhcore/key_builder.py +4 -0
- digitalhub/stores/client/dhcore/models.py +4 -0
- digitalhub/stores/client/dhcore/params_builder.py +117 -17
- digitalhub/stores/client/dhcore/utils.py +44 -22
- digitalhub/stores/client/local/__init__.py +3 -0
- digitalhub/stores/client/local/api_builder.py +21 -0
- digitalhub/stores/client/local/client.py +10 -8
- digitalhub/stores/client/local/enums.py +4 -0
- digitalhub/stores/client/local/key_builder.py +4 -0
- digitalhub/stores/client/local/params_builder.py +4 -0
- digitalhub/stores/credentials/__init__.py +3 -0
- digitalhub/stores/credentials/api.py +35 -0
- digitalhub/stores/credentials/configurator.py +210 -0
- digitalhub/stores/credentials/enums.py +68 -0
- digitalhub/stores/credentials/handler.py +176 -0
- digitalhub/stores/credentials/ini_module.py +164 -0
- digitalhub/stores/credentials/store.py +81 -0
- digitalhub/stores/data/__init__.py +3 -0
- digitalhub/stores/data/_base/__init__.py +3 -0
- digitalhub/stores/data/_base/store.py +31 -9
- digitalhub/stores/data/api.py +53 -9
- digitalhub/stores/data/builder.py +94 -41
- digitalhub/stores/data/enums.py +4 -0
- digitalhub/stores/data/local/__init__.py +3 -0
- digitalhub/stores/data/local/store.py +8 -7
- digitalhub/stores/data/remote/__init__.py +3 -0
- digitalhub/stores/data/remote/store.py +8 -7
- digitalhub/stores/data/s3/__init__.py +3 -0
- digitalhub/stores/data/s3/configurator.py +69 -80
- digitalhub/stores/data/s3/store.py +73 -81
- digitalhub/stores/data/s3/utils.py +14 -10
- digitalhub/stores/data/sql/__init__.py +3 -0
- digitalhub/stores/data/sql/configurator.py +80 -73
- digitalhub/stores/data/sql/store.py +195 -102
- digitalhub/stores/readers/__init__.py +3 -0
- digitalhub/stores/readers/data/__init__.py +3 -0
- digitalhub/stores/readers/data/_base/__init__.py +3 -0
- digitalhub/stores/readers/data/_base/builder.py +4 -0
- digitalhub/stores/readers/data/_base/reader.py +4 -0
- digitalhub/stores/readers/data/api.py +4 -0
- digitalhub/stores/readers/data/factory.py +4 -0
- digitalhub/stores/readers/data/pandas/__init__.py +3 -0
- digitalhub/stores/readers/data/pandas/builder.py +4 -0
- digitalhub/stores/readers/data/pandas/reader.py +4 -0
- digitalhub/stores/readers/query/__init__.py +3 -0
- digitalhub/utils/__init__.py +3 -0
- digitalhub/utils/enums.py +4 -0
- digitalhub/utils/exceptions.py +10 -0
- digitalhub/utils/file_utils.py +57 -30
- digitalhub/utils/generic_utils.py +45 -33
- digitalhub/utils/git_utils.py +28 -14
- digitalhub/utils/io_utils.py +23 -18
- digitalhub/utils/logger.py +4 -0
- digitalhub/utils/types.py +4 -0
- digitalhub/utils/uri_utils.py +35 -31
- digitalhub-0.13.0.dist-info/METADATA +301 -0
- digitalhub-0.13.0.dist-info/RECORD +259 -0
- digitalhub-0.13.0.dist-info/licenses/AUTHORS +5 -0
- digitalhub-0.13.0.dist-info/licenses/LICENSE +201 -0
- digitalhub/entities/_commons/types.py +0 -5
- digitalhub/stores/configurator/__init__.py +0 -0
- digitalhub/stores/configurator/api.py +0 -31
- digitalhub/stores/configurator/configurator.py +0 -198
- digitalhub/stores/configurator/credentials_store.py +0 -65
- digitalhub/stores/configurator/enums.py +0 -21
- digitalhub/stores/configurator/ini_module.py +0 -128
- digitalhub/stores/data/s3/enums.py +0 -16
- digitalhub/stores/data/sql/enums.py +0 -16
- digitalhub/stores/data/utils.py +0 -34
- digitalhub-0.11.0b7.dist-info/METADATA +0 -259
- digitalhub-0.11.0b7.dist-info/RECORD +0 -261
- digitalhub-0.11.0b7.dist-info/licenses/LICENSE.txt +0 -216
- {digitalhub-0.11.0b7.dist-info → digitalhub-0.13.0.dist-info}/WHEEL +0 -0
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
1
5
|
from __future__ import annotations
|
|
2
6
|
|
|
3
7
|
from typing import Any, Union
|
|
@@ -9,7 +13,15 @@ MetricType = Union[float, int, list[Union[float, int]]]
|
|
|
9
13
|
|
|
10
14
|
class Metric(BaseModel):
|
|
11
15
|
"""
|
|
12
|
-
|
|
16
|
+
Pydantic model for validating metric values.
|
|
17
|
+
|
|
18
|
+
This model ensures that metric values are of the correct type,
|
|
19
|
+
accepting single numeric values or lists of numeric values.
|
|
20
|
+
|
|
21
|
+
Attributes
|
|
22
|
+
----------
|
|
23
|
+
value : MetricType
|
|
24
|
+
The metric value, which can be a float, int, or list of floats/ints.
|
|
13
25
|
"""
|
|
14
26
|
|
|
15
27
|
value: MetricType
|
|
@@ -17,17 +29,25 @@ class Metric(BaseModel):
|
|
|
17
29
|
|
|
18
30
|
def validate_metric_value(value: Any) -> MetricType:
|
|
19
31
|
"""
|
|
20
|
-
Validate metric
|
|
32
|
+
Validate and convert a value to a proper metric type.
|
|
33
|
+
|
|
34
|
+
Uses Pydantic validation to ensure the input value conforms to
|
|
35
|
+
the MetricType specification (float, int, or list of floats/ints).
|
|
21
36
|
|
|
22
37
|
Parameters
|
|
23
38
|
----------
|
|
24
39
|
value : Any
|
|
25
|
-
The value to validate.
|
|
40
|
+
The value to validate and convert.
|
|
26
41
|
|
|
27
42
|
Returns
|
|
28
43
|
-------
|
|
29
44
|
MetricType
|
|
30
|
-
The validated value.
|
|
45
|
+
The validated metric value.
|
|
46
|
+
|
|
47
|
+
Raises
|
|
48
|
+
------
|
|
49
|
+
ValueError
|
|
50
|
+
If the value cannot be converted to a valid metric type.
|
|
31
51
|
"""
|
|
32
52
|
try:
|
|
33
53
|
return Metric(value=value).value
|
|
@@ -43,23 +63,30 @@ def set_metrics(
|
|
|
43
63
|
single_value: bool,
|
|
44
64
|
) -> dict[str, MetricType]:
|
|
45
65
|
"""
|
|
46
|
-
Set metric value.
|
|
66
|
+
Set or update a metric value in the metrics dictionary.
|
|
67
|
+
|
|
68
|
+
This function routes to appropriate handling based on the value type
|
|
69
|
+
and the single_value flag. It can handle single values, lists, and
|
|
70
|
+
appending to existing metrics.
|
|
47
71
|
|
|
48
72
|
Parameters
|
|
49
73
|
----------
|
|
50
74
|
metrics : dict[str, MetricType]
|
|
51
|
-
The metrics dictionary.
|
|
75
|
+
The metrics dictionary to update.
|
|
52
76
|
key : str
|
|
53
|
-
The key
|
|
77
|
+
The metric key to set or update.
|
|
54
78
|
value : Any
|
|
55
|
-
The value to set.
|
|
79
|
+
The value to set for the metric.
|
|
56
80
|
overwrite : bool
|
|
57
|
-
Whether to overwrite
|
|
81
|
+
Whether to overwrite existing metrics.
|
|
82
|
+
single_value : bool
|
|
83
|
+
Whether to treat the value as a single metric rather than
|
|
84
|
+
appending to a list.
|
|
58
85
|
|
|
59
86
|
Returns
|
|
60
87
|
-------
|
|
61
88
|
dict[str, MetricType]
|
|
62
|
-
The metrics dictionary.
|
|
89
|
+
The updated metrics dictionary.
|
|
63
90
|
"""
|
|
64
91
|
if isinstance(value, list):
|
|
65
92
|
return handle_metric_list(metrics, key, value, overwrite)
|
|
@@ -75,23 +102,26 @@ def handle_metric_single(
|
|
|
75
102
|
overwrite: bool,
|
|
76
103
|
) -> dict:
|
|
77
104
|
"""
|
|
78
|
-
Handle
|
|
105
|
+
Handle setting a single metric value.
|
|
106
|
+
|
|
107
|
+
Sets or overwrites a metric with a single numeric value. If the key
|
|
108
|
+
already exists and overwrite is False, the existing value is preserved.
|
|
79
109
|
|
|
80
110
|
Parameters
|
|
81
111
|
----------
|
|
82
112
|
metrics : dict[str, MetricType]
|
|
83
|
-
|
|
113
|
+
The metrics dictionary to update.
|
|
84
114
|
key : str
|
|
85
|
-
|
|
86
|
-
value : float
|
|
87
|
-
|
|
115
|
+
The metric key to set.
|
|
116
|
+
value : float | int
|
|
117
|
+
The single numeric value to set.
|
|
88
118
|
overwrite : bool
|
|
89
|
-
|
|
119
|
+
Whether to overwrite an existing metric with the same key.
|
|
90
120
|
|
|
91
121
|
Returns
|
|
92
122
|
-------
|
|
93
123
|
dict
|
|
94
|
-
|
|
124
|
+
The updated metrics dictionary.
|
|
95
125
|
"""
|
|
96
126
|
if key not in metrics or overwrite:
|
|
97
127
|
metrics[key] = value
|
|
@@ -105,23 +135,27 @@ def handle_metric_list_append(
|
|
|
105
135
|
overwrite: bool,
|
|
106
136
|
) -> dict:
|
|
107
137
|
"""
|
|
108
|
-
Handle metric list
|
|
138
|
+
Handle appending a single value to a metric list.
|
|
139
|
+
|
|
140
|
+
If the metric doesn't exist or overwrite is True, creates a new list
|
|
141
|
+
with the single value. If the metric exists as a list, appends to it.
|
|
142
|
+
If the metric exists as a single value, converts it to a list and appends.
|
|
109
143
|
|
|
110
144
|
Parameters
|
|
111
145
|
----------
|
|
112
146
|
metrics : dict[str, MetricType]
|
|
113
|
-
|
|
147
|
+
The metrics dictionary to update.
|
|
114
148
|
key : str
|
|
115
|
-
|
|
116
|
-
value : float
|
|
117
|
-
|
|
149
|
+
The metric key to append to.
|
|
150
|
+
value : float | int
|
|
151
|
+
The numeric value to append.
|
|
118
152
|
overwrite : bool
|
|
119
|
-
|
|
153
|
+
Whether to overwrite an existing metric instead of appending.
|
|
120
154
|
|
|
121
155
|
Returns
|
|
122
156
|
-------
|
|
123
157
|
dict
|
|
124
|
-
|
|
158
|
+
The updated metrics dictionary.
|
|
125
159
|
"""
|
|
126
160
|
if key not in metrics or overwrite:
|
|
127
161
|
metrics[key] = [value]
|
|
@@ -139,23 +173,27 @@ def handle_metric_list(
|
|
|
139
173
|
overwrite: bool,
|
|
140
174
|
) -> dict:
|
|
141
175
|
"""
|
|
142
|
-
Handle metric list.
|
|
176
|
+
Handle setting or extending a metric with a list of values.
|
|
177
|
+
|
|
178
|
+
If the metric doesn't exist or overwrite is True, sets the metric to
|
|
179
|
+
the provided list. If the metric exists and overwrite is False, extends
|
|
180
|
+
the existing list with the new values.
|
|
143
181
|
|
|
144
182
|
Parameters
|
|
145
183
|
----------
|
|
146
184
|
metrics : dict[str, MetricType]
|
|
147
|
-
|
|
185
|
+
The metrics dictionary to update.
|
|
148
186
|
key : str
|
|
149
|
-
|
|
187
|
+
The metric key to set or extend.
|
|
150
188
|
value : list[int | float]
|
|
151
|
-
|
|
189
|
+
The list of numeric values to set or extend with.
|
|
152
190
|
overwrite : bool
|
|
153
|
-
|
|
191
|
+
Whether to overwrite an existing metric instead of extending it.
|
|
154
192
|
|
|
155
193
|
Returns
|
|
156
194
|
-------
|
|
157
195
|
dict
|
|
158
|
-
|
|
196
|
+
The updated metrics dictionary.
|
|
159
197
|
"""
|
|
160
198
|
if key not in metrics or overwrite:
|
|
161
199
|
metrics[key] = value
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
1
5
|
from __future__ import annotations
|
|
2
6
|
|
|
3
7
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
@@ -5,17 +9,28 @@ from digitalhub.entities._commons.enums import EntityTypes
|
|
|
5
9
|
|
|
6
10
|
def parse_entity_key(key: str) -> tuple[str, str, str, str | None, str]:
|
|
7
11
|
"""
|
|
8
|
-
Parse
|
|
12
|
+
Parse an entity key into its constituent components.
|
|
13
|
+
|
|
14
|
+
Extracts project name, entity type, kind, name, and UUID from a
|
|
15
|
+
standardized entity key format. Handles special cases for tasks
|
|
16
|
+
and runs which don't have name components.
|
|
9
17
|
|
|
10
18
|
Parameters
|
|
11
19
|
----------
|
|
12
20
|
key : str
|
|
13
|
-
The entity key
|
|
21
|
+
The entity key in format "store://project/type/kind/name:uuid"
|
|
22
|
+
or "store://project/type/kind/uuid" for tasks and runs.
|
|
14
23
|
|
|
15
24
|
Returns
|
|
16
25
|
-------
|
|
17
26
|
tuple[str, str, str, str | None, str]
|
|
18
|
-
|
|
27
|
+
A tuple containing (project, entity_type, kind, name, uuid).
|
|
28
|
+
The name component is None for tasks and runs.
|
|
29
|
+
|
|
30
|
+
Raises
|
|
31
|
+
------
|
|
32
|
+
ValueError
|
|
33
|
+
If the key format is invalid or cannot be parsed.
|
|
19
34
|
"""
|
|
20
35
|
try:
|
|
21
36
|
# Remove "store://" from the key
|
|
@@ -49,17 +64,25 @@ def parse_entity_key(key: str) -> tuple[str, str, str, str | None, str]:
|
|
|
49
64
|
|
|
50
65
|
def get_entity_type_from_key(key: str) -> str:
|
|
51
66
|
"""
|
|
52
|
-
|
|
67
|
+
Extract the entity type from an entity key.
|
|
68
|
+
|
|
69
|
+
Parses the entity key and returns only the entity type component,
|
|
70
|
+
which indicates the kind of entity (artifact, function, run, etc.).
|
|
53
71
|
|
|
54
72
|
Parameters
|
|
55
73
|
----------
|
|
56
74
|
key : str
|
|
57
|
-
The key
|
|
75
|
+
The entity key in standardized format.
|
|
58
76
|
|
|
59
77
|
Returns
|
|
60
78
|
-------
|
|
61
79
|
str
|
|
62
|
-
The entity type.
|
|
80
|
+
The entity type extracted from the key.
|
|
81
|
+
|
|
82
|
+
Raises
|
|
83
|
+
------
|
|
84
|
+
ValueError
|
|
85
|
+
If the key format is invalid or cannot be parsed.
|
|
63
86
|
"""
|
|
64
87
|
_, entity_type, _, _, _ = parse_entity_key(key)
|
|
65
88
|
return entity_type
|
|
@@ -67,17 +90,25 @@ def get_entity_type_from_key(key: str) -> str:
|
|
|
67
90
|
|
|
68
91
|
def get_project_from_key(key: str) -> str:
|
|
69
92
|
"""
|
|
70
|
-
|
|
93
|
+
Extract the project name from an entity key.
|
|
94
|
+
|
|
95
|
+
Parses the entity key and returns only the project component,
|
|
96
|
+
which identifies the project context the entity belongs to.
|
|
71
97
|
|
|
72
98
|
Parameters
|
|
73
99
|
----------
|
|
74
100
|
key : str
|
|
75
|
-
The key
|
|
101
|
+
The entity key in standardized format.
|
|
76
102
|
|
|
77
103
|
Returns
|
|
78
104
|
-------
|
|
79
105
|
str
|
|
80
|
-
The project.
|
|
106
|
+
The project name extracted from the key.
|
|
107
|
+
|
|
108
|
+
Raises
|
|
109
|
+
------
|
|
110
|
+
ValueError
|
|
111
|
+
If the key format is invalid or cannot be parsed.
|
|
81
112
|
"""
|
|
82
113
|
project, _, _, _, _ = parse_entity_key(key)
|
|
83
114
|
return project
|