digitalhub 0.13.0b3__py3-none-any.whl → 0.13.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/entities/_commons/metrics.py +64 -30
- digitalhub/entities/_commons/utils.py +36 -9
- digitalhub/entities/_processors/base.py +150 -79
- digitalhub/entities/_processors/context.py +363 -212
- digitalhub/entities/_processors/utils.py +74 -30
- digitalhub/entities/artifact/utils.py +28 -13
- digitalhub/entities/dataitem/utils.py +83 -33
- digitalhub/entities/model/utils.py +28 -13
- digitalhub/stores/credentials/enums.py +1 -0
- digitalhub/stores/data/api.py +1 -1
- digitalhub/stores/data/builder.py +66 -4
- digitalhub/stores/data/sql/configurator.py +57 -7
- digitalhub/stores/data/sql/store.py +169 -78
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.13.0b4.dist-info}/METADATA +1 -1
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.13.0b4.dist-info}/RECORD +18 -19
- digitalhub/entities/_commons/types.py +0 -9
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.13.0b4.dist-info}/WHEEL +0 -0
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.13.0b4.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.13.0b4.dist-info}/licenses/LICENSE +0 -0
|
@@ -13,7 +13,15 @@ MetricType = Union[float, int, list[Union[float, int]]]
|
|
|
13
13
|
|
|
14
14
|
class Metric(BaseModel):
|
|
15
15
|
"""
|
|
16
|
-
|
|
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.
|
|
17
25
|
"""
|
|
18
26
|
|
|
19
27
|
value: MetricType
|
|
@@ -21,17 +29,25 @@ class Metric(BaseModel):
|
|
|
21
29
|
|
|
22
30
|
def validate_metric_value(value: Any) -> MetricType:
|
|
23
31
|
"""
|
|
24
|
-
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).
|
|
25
36
|
|
|
26
37
|
Parameters
|
|
27
38
|
----------
|
|
28
39
|
value : Any
|
|
29
|
-
The value to validate.
|
|
40
|
+
The value to validate and convert.
|
|
30
41
|
|
|
31
42
|
Returns
|
|
32
43
|
-------
|
|
33
44
|
MetricType
|
|
34
|
-
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.
|
|
35
51
|
"""
|
|
36
52
|
try:
|
|
37
53
|
return Metric(value=value).value
|
|
@@ -47,23 +63,30 @@ def set_metrics(
|
|
|
47
63
|
single_value: bool,
|
|
48
64
|
) -> dict[str, MetricType]:
|
|
49
65
|
"""
|
|
50
|
-
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.
|
|
51
71
|
|
|
52
72
|
Parameters
|
|
53
73
|
----------
|
|
54
74
|
metrics : dict[str, MetricType]
|
|
55
|
-
The metrics dictionary.
|
|
75
|
+
The metrics dictionary to update.
|
|
56
76
|
key : str
|
|
57
|
-
The key
|
|
77
|
+
The metric key to set or update.
|
|
58
78
|
value : Any
|
|
59
|
-
The value to set.
|
|
79
|
+
The value to set for the metric.
|
|
60
80
|
overwrite : bool
|
|
61
|
-
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.
|
|
62
85
|
|
|
63
86
|
Returns
|
|
64
87
|
-------
|
|
65
88
|
dict[str, MetricType]
|
|
66
|
-
The metrics dictionary.
|
|
89
|
+
The updated metrics dictionary.
|
|
67
90
|
"""
|
|
68
91
|
if isinstance(value, list):
|
|
69
92
|
return handle_metric_list(metrics, key, value, overwrite)
|
|
@@ -79,23 +102,26 @@ def handle_metric_single(
|
|
|
79
102
|
overwrite: bool,
|
|
80
103
|
) -> dict:
|
|
81
104
|
"""
|
|
82
|
-
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.
|
|
83
109
|
|
|
84
110
|
Parameters
|
|
85
111
|
----------
|
|
86
112
|
metrics : dict[str, MetricType]
|
|
87
|
-
|
|
113
|
+
The metrics dictionary to update.
|
|
88
114
|
key : str
|
|
89
|
-
|
|
90
|
-
value : float
|
|
91
|
-
|
|
115
|
+
The metric key to set.
|
|
116
|
+
value : float | int
|
|
117
|
+
The single numeric value to set.
|
|
92
118
|
overwrite : bool
|
|
93
|
-
|
|
119
|
+
Whether to overwrite an existing metric with the same key.
|
|
94
120
|
|
|
95
121
|
Returns
|
|
96
122
|
-------
|
|
97
123
|
dict
|
|
98
|
-
|
|
124
|
+
The updated metrics dictionary.
|
|
99
125
|
"""
|
|
100
126
|
if key not in metrics or overwrite:
|
|
101
127
|
metrics[key] = value
|
|
@@ -109,23 +135,27 @@ def handle_metric_list_append(
|
|
|
109
135
|
overwrite: bool,
|
|
110
136
|
) -> dict:
|
|
111
137
|
"""
|
|
112
|
-
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.
|
|
113
143
|
|
|
114
144
|
Parameters
|
|
115
145
|
----------
|
|
116
146
|
metrics : dict[str, MetricType]
|
|
117
|
-
|
|
147
|
+
The metrics dictionary to update.
|
|
118
148
|
key : str
|
|
119
|
-
|
|
120
|
-
value : float
|
|
121
|
-
|
|
149
|
+
The metric key to append to.
|
|
150
|
+
value : float | int
|
|
151
|
+
The numeric value to append.
|
|
122
152
|
overwrite : bool
|
|
123
|
-
|
|
153
|
+
Whether to overwrite an existing metric instead of appending.
|
|
124
154
|
|
|
125
155
|
Returns
|
|
126
156
|
-------
|
|
127
157
|
dict
|
|
128
|
-
|
|
158
|
+
The updated metrics dictionary.
|
|
129
159
|
"""
|
|
130
160
|
if key not in metrics or overwrite:
|
|
131
161
|
metrics[key] = [value]
|
|
@@ -143,23 +173,27 @@ def handle_metric_list(
|
|
|
143
173
|
overwrite: bool,
|
|
144
174
|
) -> dict:
|
|
145
175
|
"""
|
|
146
|
-
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.
|
|
147
181
|
|
|
148
182
|
Parameters
|
|
149
183
|
----------
|
|
150
184
|
metrics : dict[str, MetricType]
|
|
151
|
-
|
|
185
|
+
The metrics dictionary to update.
|
|
152
186
|
key : str
|
|
153
|
-
|
|
187
|
+
The metric key to set or extend.
|
|
154
188
|
value : list[int | float]
|
|
155
|
-
|
|
189
|
+
The list of numeric values to set or extend with.
|
|
156
190
|
overwrite : bool
|
|
157
|
-
|
|
191
|
+
Whether to overwrite an existing metric instead of extending it.
|
|
158
192
|
|
|
159
193
|
Returns
|
|
160
194
|
-------
|
|
161
195
|
dict
|
|
162
|
-
|
|
196
|
+
The updated metrics dictionary.
|
|
163
197
|
"""
|
|
164
198
|
if key not in metrics or overwrite:
|
|
165
199
|
metrics[key] = value
|
|
@@ -9,17 +9,28 @@ from digitalhub.entities._commons.enums import EntityTypes
|
|
|
9
9
|
|
|
10
10
|
def parse_entity_key(key: str) -> tuple[str, str, str, str | None, str]:
|
|
11
11
|
"""
|
|
12
|
-
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.
|
|
13
17
|
|
|
14
18
|
Parameters
|
|
15
19
|
----------
|
|
16
20
|
key : str
|
|
17
|
-
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.
|
|
18
23
|
|
|
19
24
|
Returns
|
|
20
25
|
-------
|
|
21
26
|
tuple[str, str, str, str | None, str]
|
|
22
|
-
|
|
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.
|
|
23
34
|
"""
|
|
24
35
|
try:
|
|
25
36
|
# Remove "store://" from the key
|
|
@@ -53,17 +64,25 @@ def parse_entity_key(key: str) -> tuple[str, str, str, str | None, str]:
|
|
|
53
64
|
|
|
54
65
|
def get_entity_type_from_key(key: str) -> str:
|
|
55
66
|
"""
|
|
56
|
-
|
|
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.).
|
|
57
71
|
|
|
58
72
|
Parameters
|
|
59
73
|
----------
|
|
60
74
|
key : str
|
|
61
|
-
The key
|
|
75
|
+
The entity key in standardized format.
|
|
62
76
|
|
|
63
77
|
Returns
|
|
64
78
|
-------
|
|
65
79
|
str
|
|
66
|
-
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.
|
|
67
86
|
"""
|
|
68
87
|
_, entity_type, _, _, _ = parse_entity_key(key)
|
|
69
88
|
return entity_type
|
|
@@ -71,17 +90,25 @@ def get_entity_type_from_key(key: str) -> str:
|
|
|
71
90
|
|
|
72
91
|
def get_project_from_key(key: str) -> str:
|
|
73
92
|
"""
|
|
74
|
-
|
|
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.
|
|
75
97
|
|
|
76
98
|
Parameters
|
|
77
99
|
----------
|
|
78
100
|
key : str
|
|
79
|
-
The key
|
|
101
|
+
The entity key in standardized format.
|
|
80
102
|
|
|
81
103
|
Returns
|
|
82
104
|
-------
|
|
83
105
|
str
|
|
84
|
-
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.
|
|
85
112
|
"""
|
|
86
113
|
project, _, _, _, _ = parse_entity_key(key)
|
|
87
114
|
return project
|