digitalhub 0.13.0b3__py3-none-any.whl → 0.14.0b0__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 -8
- digitalhub/entities/_base/_base/entity.py +0 -11
- digitalhub/entities/_base/entity/builder.py +5 -5
- digitalhub/entities/_base/executable/entity.py +1 -1
- digitalhub/entities/_base/runtime_entity/builder.py +53 -18
- digitalhub/entities/_commons/metrics.py +64 -30
- digitalhub/entities/_commons/utils.py +100 -30
- digitalhub/entities/_processors/base.py +160 -81
- digitalhub/entities/_processors/context.py +424 -224
- digitalhub/entities/_processors/utils.py +77 -33
- digitalhub/entities/artifact/crud.py +20 -4
- digitalhub/entities/artifact/utils.py +29 -14
- digitalhub/entities/dataitem/crud.py +20 -4
- digitalhub/entities/dataitem/table/entity.py +0 -21
- digitalhub/entities/dataitem/utils.py +84 -34
- digitalhub/entities/function/_base/entity.py +1 -1
- digitalhub/entities/function/crud.py +15 -4
- digitalhub/entities/model/_base/entity.py +21 -1
- digitalhub/entities/model/crud.py +21 -5
- digitalhub/entities/model/utils.py +29 -14
- digitalhub/entities/project/_base/entity.py +65 -33
- digitalhub/entities/project/crud.py +8 -1
- digitalhub/entities/run/_base/entity.py +21 -1
- digitalhub/entities/run/crud.py +22 -5
- digitalhub/entities/secret/crud.py +22 -5
- digitalhub/entities/task/crud.py +22 -5
- digitalhub/entities/trigger/crud.py +20 -4
- digitalhub/entities/workflow/_base/entity.py +1 -1
- digitalhub/entities/workflow/crud.py +15 -4
- digitalhub/factory/enums.py +18 -0
- digitalhub/factory/factory.py +136 -57
- digitalhub/factory/utils.py +3 -54
- digitalhub/stores/client/api.py +6 -10
- digitalhub/stores/client/builder.py +3 -3
- digitalhub/stores/client/dhcore/client.py +104 -162
- digitalhub/stores/client/dhcore/configurator.py +92 -289
- digitalhub/stores/client/dhcore/enums.py +0 -16
- digitalhub/stores/client/dhcore/params_builder.py +41 -83
- digitalhub/stores/client/dhcore/utils.py +14 -22
- digitalhub/stores/client/local/client.py +77 -45
- digitalhub/stores/credentials/enums.py +1 -0
- digitalhub/stores/credentials/ini_module.py +0 -16
- digitalhub/stores/data/api.py +1 -1
- digitalhub/stores/data/builder.py +66 -4
- digitalhub/stores/data/local/store.py +0 -103
- digitalhub/stores/data/s3/configurator.py +60 -6
- digitalhub/stores/data/s3/store.py +44 -2
- digitalhub/stores/data/sql/configurator.py +57 -7
- digitalhub/stores/data/sql/store.py +184 -78
- digitalhub/utils/file_utils.py +0 -17
- digitalhub/utils/generic_utils.py +1 -2
- digitalhub/utils/store_utils.py +44 -0
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.0b0.dist-info}/METADATA +3 -2
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.0b0.dist-info}/RECORD +63 -65
- digitalhub/entities/_commons/types.py +0 -9
- digitalhub/entities/task/_base/utils.py +0 -22
- digitalhub/stores/client/dhcore/models.py +0 -40
- digitalhub/stores/data/s3/utils.py +0 -78
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/__init__.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/metadata.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/name.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/spec.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/status.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/uuid.py +0 -0
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.0b0.dist-info}/WHEEL +0 -0
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.0b0.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.0b0.dist-info}/licenses/LICENSE +0 -0
digitalhub/__init__.py
CHANGED
|
@@ -95,16 +95,11 @@ from digitalhub.entities.workflow.crud import (
|
|
|
95
95
|
new_workflow,
|
|
96
96
|
update_workflow,
|
|
97
97
|
)
|
|
98
|
+
from digitalhub.stores.client.dhcore.utils import refresh_token, set_dhcore_env
|
|
99
|
+
from digitalhub.stores.credentials.api import get_current_profile, set_current_profile
|
|
100
|
+
from digitalhub.utils.store_utils import get_s3_client, get_sql_engine
|
|
98
101
|
|
|
99
102
|
try:
|
|
100
103
|
from digitalhub.entities.model.mlflow.utils import from_mlflow_run, get_mlflow_model_metrics
|
|
101
104
|
except ImportError:
|
|
102
105
|
...
|
|
103
|
-
|
|
104
|
-
# Register entities into registry
|
|
105
|
-
from digitalhub.factory.utils import register_entities, register_runtimes_entities
|
|
106
|
-
from digitalhub.stores.client.dhcore.utils import refresh_token, set_dhcore_env
|
|
107
|
-
from digitalhub.stores.credentials.api import get_current_profile, set_current_profile
|
|
108
|
-
|
|
109
|
-
register_entities()
|
|
110
|
-
register_runtimes_entities()
|
|
@@ -63,17 +63,6 @@ class Base:
|
|
|
63
63
|
if k not in self.__dict__:
|
|
64
64
|
setattr(self, k, v)
|
|
65
65
|
|
|
66
|
-
def _get_private_attrs(self) -> dict:
|
|
67
|
-
"""
|
|
68
|
-
Return all private attributes of the object.
|
|
69
|
-
|
|
70
|
-
Returns
|
|
71
|
-
-------
|
|
72
|
-
dict
|
|
73
|
-
A dictionary containing the private attributes of the entity instance.
|
|
74
|
-
"""
|
|
75
|
-
return {k: v for k, v in self.__dict__.items() if k.startswith("_")}
|
|
76
|
-
|
|
77
66
|
def __repr__(self) -> str:
|
|
78
67
|
"""
|
|
79
68
|
Return string representation of the entity object.
|
|
@@ -7,11 +7,11 @@ from __future__ import annotations
|
|
|
7
7
|
import typing
|
|
8
8
|
from abc import abstractmethod
|
|
9
9
|
|
|
10
|
-
from digitalhub.entities.
|
|
11
|
-
from digitalhub.entities.
|
|
12
|
-
from digitalhub.entities.
|
|
13
|
-
from digitalhub.entities.
|
|
14
|
-
from digitalhub.entities.
|
|
10
|
+
from digitalhub.entities._constructors.metadata import build_metadata
|
|
11
|
+
from digitalhub.entities._constructors.name import build_name
|
|
12
|
+
from digitalhub.entities._constructors.spec import build_spec
|
|
13
|
+
from digitalhub.entities._constructors.status import build_status
|
|
14
|
+
from digitalhub.entities._constructors.uuid import build_uuid
|
|
15
15
|
from digitalhub.utils.exceptions import BuilderError
|
|
16
16
|
|
|
17
17
|
if typing.TYPE_CHECKING:
|
|
@@ -430,7 +430,7 @@ class ExecutableEntity(VersionedEntity):
|
|
|
430
430
|
task_string = task._get_task_string()
|
|
431
431
|
|
|
432
432
|
# Get run validator for building trigger template
|
|
433
|
-
run_kind = factory.
|
|
433
|
+
run_kind = factory.get_run_kind_from_action(self.kind, action)
|
|
434
434
|
run_validator: SpecValidator = factory.get_spec_validator(run_kind)
|
|
435
435
|
# Override kwargs
|
|
436
436
|
kwargs["project"] = self.project
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
+
from digitalhub.entities._commons.utils import KindAction
|
|
7
8
|
from digitalhub.utils.exceptions import EntityError
|
|
8
9
|
|
|
9
10
|
|
|
@@ -13,16 +14,40 @@ class RuntimeEntityBuilder:
|
|
|
13
14
|
"""
|
|
14
15
|
|
|
15
16
|
EXECUTABLE_KIND: str = None
|
|
16
|
-
TASKS_KINDS:
|
|
17
|
-
|
|
17
|
+
TASKS_KINDS: list[KindAction] = None
|
|
18
|
+
RUN_KINDS: list[KindAction] = None
|
|
18
19
|
|
|
19
20
|
def __init__(self) -> None:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
self._validate()
|
|
22
|
+
|
|
23
|
+
def _validate(self) -> None:
|
|
24
|
+
"""
|
|
25
|
+
Validate the entity.
|
|
26
|
+
"""
|
|
27
|
+
for attr_name in ["EXECUTABLE_KIND", "TASKS_KINDS", "RUN_KINDS"]:
|
|
28
|
+
value = getattr(self, attr_name)
|
|
29
|
+
if value is None:
|
|
30
|
+
raise EntityError(f"{attr_name} must be set")
|
|
31
|
+
|
|
32
|
+
for attr_name in ["TASKS_KINDS", "RUN_KINDS"]:
|
|
33
|
+
self._instance_validation(getattr(self, attr_name))
|
|
34
|
+
|
|
35
|
+
def _instance_validation(self, attribute: list[KindAction]) -> None:
|
|
36
|
+
"""
|
|
37
|
+
Validate if the attribute is a list of KindAction.
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
attribute : list[KindAction]
|
|
42
|
+
Attribute to validate.
|
|
43
|
+
"""
|
|
44
|
+
if not isinstance(attribute, list):
|
|
45
|
+
raise EntityError(f"{attribute} must be a list")
|
|
46
|
+
for i in attribute:
|
|
47
|
+
if not isinstance(i, KindAction):
|
|
48
|
+
raise EntityError(f"{attribute} must be a list of KindAction")
|
|
49
|
+
if i.kind is None:
|
|
50
|
+
raise EntityError(f"{attribute} must be a list of KindAction with kind set")
|
|
26
51
|
|
|
27
52
|
def get_action_from_task_kind(self, task_kind: str) -> str:
|
|
28
53
|
"""
|
|
@@ -39,8 +64,8 @@ class RuntimeEntityBuilder:
|
|
|
39
64
|
Action.
|
|
40
65
|
"""
|
|
41
66
|
for task in self.TASKS_KINDS:
|
|
42
|
-
if task
|
|
43
|
-
return task
|
|
67
|
+
if task.kind == task_kind:
|
|
68
|
+
return task.action
|
|
44
69
|
msg = f"Task kind {task_kind} not allowed."
|
|
45
70
|
raise EntityError(msg)
|
|
46
71
|
|
|
@@ -59,21 +84,30 @@ class RuntimeEntityBuilder:
|
|
|
59
84
|
Task kinds.
|
|
60
85
|
"""
|
|
61
86
|
for task in self.TASKS_KINDS:
|
|
62
|
-
if task
|
|
63
|
-
return task
|
|
87
|
+
if task.action == action:
|
|
88
|
+
return task.kind
|
|
64
89
|
msg = f"Action {action} not allowed."
|
|
65
90
|
raise EntityError(msg)
|
|
66
91
|
|
|
67
|
-
def
|
|
92
|
+
def get_run_kind_from_action(self, action: str) -> str:
|
|
68
93
|
"""
|
|
69
|
-
Get run kind.
|
|
94
|
+
Get run kind from action.
|
|
95
|
+
|
|
96
|
+
Parameters
|
|
97
|
+
----------
|
|
98
|
+
action : str
|
|
99
|
+
Action.
|
|
70
100
|
|
|
71
101
|
Returns
|
|
72
102
|
-------
|
|
73
103
|
str
|
|
74
104
|
Run kind.
|
|
75
105
|
"""
|
|
76
|
-
|
|
106
|
+
for run in self.RUN_KINDS:
|
|
107
|
+
if run.action == action:
|
|
108
|
+
return run.kind
|
|
109
|
+
msg = f"Action {action} not allowed."
|
|
110
|
+
raise EntityError(msg)
|
|
77
111
|
|
|
78
112
|
def get_executable_kind(self) -> str:
|
|
79
113
|
"""
|
|
@@ -95,8 +129,9 @@ class RuntimeEntityBuilder:
|
|
|
95
129
|
list[str]
|
|
96
130
|
All kinds.
|
|
97
131
|
"""
|
|
98
|
-
task_kinds = [i
|
|
99
|
-
|
|
132
|
+
task_kinds = [i.kind for i in self.TASKS_KINDS]
|
|
133
|
+
run_kinds = [i.kind for i in self.RUN_KINDS]
|
|
134
|
+
return [self.EXECUTABLE_KIND, *run_kinds, *task_kinds]
|
|
100
135
|
|
|
101
136
|
def get_all_actions(self) -> list[str]:
|
|
102
137
|
"""
|
|
@@ -107,4 +142,4 @@ class RuntimeEntityBuilder:
|
|
|
107
142
|
list[str]
|
|
108
143
|
All actions.
|
|
109
144
|
"""
|
|
110
|
-
return [i
|
|
145
|
+
return [i.action for i in self.TASKS_KINDS]
|
|
@@ -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
|
|
@@ -4,66 +4,111 @@
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
+
import re
|
|
8
|
+
from collections import namedtuple
|
|
9
|
+
|
|
7
10
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
8
11
|
|
|
12
|
+
KindAction = namedtuple("KindAction", ["kind", "action"])
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
KEY_PATTERN_WITH_ID = "store://([^/]+)/([^/]+)/([^/]+)/([^:]+):(.+)"
|
|
16
|
+
KEY_PATTERN_NO_ID = "store://([^/]+)/([^/]+)/([^/]+)/([^:]+)"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def is_valid_key(key: str) -> bool:
|
|
20
|
+
"""
|
|
21
|
+
Check if an entity key is valid.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
key : str
|
|
26
|
+
The entity key to validate.
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
-------
|
|
30
|
+
bool
|
|
31
|
+
True if the key is valid, False otherwise.
|
|
32
|
+
"""
|
|
33
|
+
return bool(re.fullmatch(KEY_PATTERN_WITH_ID, key) or re.fullmatch(KEY_PATTERN_NO_ID, key))
|
|
34
|
+
|
|
9
35
|
|
|
10
36
|
def parse_entity_key(key: str) -> tuple[str, str, str, str | None, str]:
|
|
11
37
|
"""
|
|
12
|
-
Parse
|
|
38
|
+
Parse an entity key into its constituent components.
|
|
39
|
+
|
|
40
|
+
Extracts project name, entity type, kind, name, and UUID from a
|
|
41
|
+
standardized entity key format. Handles special cases for tasks
|
|
42
|
+
and runs which don't have name components.
|
|
13
43
|
|
|
14
44
|
Parameters
|
|
15
45
|
----------
|
|
16
46
|
key : str
|
|
17
|
-
The entity key
|
|
47
|
+
The entity key in format "store://project/type/kind/name:uuid"
|
|
48
|
+
or "store://project/type/kind/uuid" for tasks and runs.
|
|
18
49
|
|
|
19
50
|
Returns
|
|
20
51
|
-------
|
|
21
52
|
tuple[str, str, str, str | None, str]
|
|
22
|
-
|
|
53
|
+
A tuple containing (project, entity_type, kind, name, uuid).
|
|
54
|
+
The name component is None for tasks and runs.
|
|
55
|
+
|
|
56
|
+
Raises
|
|
57
|
+
------
|
|
58
|
+
ValueError
|
|
59
|
+
If the key format is invalid or cannot be parsed.
|
|
23
60
|
"""
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
61
|
+
if not is_valid_key(key):
|
|
62
|
+
raise ValueError("Invalid entity key format.")
|
|
63
|
+
|
|
64
|
+
# Remove "store://" from the key
|
|
65
|
+
key = key.replace("store://", "")
|
|
27
66
|
|
|
28
|
-
|
|
29
|
-
|
|
67
|
+
# Split the key into parts
|
|
68
|
+
parts = key.split("/")
|
|
30
69
|
|
|
31
|
-
|
|
32
|
-
|
|
70
|
+
# The project is the first part
|
|
71
|
+
project = parts[0]
|
|
33
72
|
|
|
34
|
-
|
|
35
|
-
|
|
73
|
+
# The entity type is the second part
|
|
74
|
+
entity_type = parts[1]
|
|
36
75
|
|
|
37
|
-
|
|
38
|
-
|
|
76
|
+
# The kind is the third part
|
|
77
|
+
kind = parts[2]
|
|
39
78
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
79
|
+
# Tasks and runs have no name and uuid
|
|
80
|
+
if entity_type in (EntityTypes.TASK.value, EntityTypes.RUN.value):
|
|
81
|
+
name = None
|
|
82
|
+
uuid = parts[3]
|
|
44
83
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
84
|
+
# The name and uuid are separated by a colon in the last part
|
|
85
|
+
else:
|
|
86
|
+
name, uuid = parts[3].split(":")
|
|
48
87
|
|
|
49
|
-
|
|
50
|
-
except Exception as e:
|
|
51
|
-
raise ValueError("Invalid key format.") from e
|
|
88
|
+
return project, entity_type, kind, name, uuid
|
|
52
89
|
|
|
53
90
|
|
|
54
91
|
def get_entity_type_from_key(key: str) -> str:
|
|
55
92
|
"""
|
|
56
|
-
|
|
93
|
+
Extract the entity type from an entity key.
|
|
94
|
+
|
|
95
|
+
Parses the entity key and returns only the entity type component,
|
|
96
|
+
which indicates the kind of entity (artifact, function, run, etc.).
|
|
57
97
|
|
|
58
98
|
Parameters
|
|
59
99
|
----------
|
|
60
100
|
key : str
|
|
61
|
-
The key
|
|
101
|
+
The entity key in standardized format.
|
|
62
102
|
|
|
63
103
|
Returns
|
|
64
104
|
-------
|
|
65
105
|
str
|
|
66
|
-
The entity type.
|
|
106
|
+
The entity type extracted from the key.
|
|
107
|
+
|
|
108
|
+
Raises
|
|
109
|
+
------
|
|
110
|
+
ValueError
|
|
111
|
+
If the key format is invalid or cannot be parsed.
|
|
67
112
|
"""
|
|
68
113
|
_, entity_type, _, _, _ = parse_entity_key(key)
|
|
69
114
|
return entity_type
|
|
@@ -71,17 +116,42 @@ def get_entity_type_from_key(key: str) -> str:
|
|
|
71
116
|
|
|
72
117
|
def get_project_from_key(key: str) -> str:
|
|
73
118
|
"""
|
|
74
|
-
|
|
119
|
+
Extract the project name from an entity key.
|
|
120
|
+
|
|
121
|
+
Parses the entity key and returns only the project component,
|
|
122
|
+
which identifies the project context the entity belongs to.
|
|
75
123
|
|
|
76
124
|
Parameters
|
|
77
125
|
----------
|
|
78
126
|
key : str
|
|
79
|
-
The key
|
|
127
|
+
The entity key in standardized format.
|
|
80
128
|
|
|
81
129
|
Returns
|
|
82
130
|
-------
|
|
83
131
|
str
|
|
84
|
-
The project.
|
|
132
|
+
The project name extracted from the key.
|
|
133
|
+
|
|
134
|
+
Raises
|
|
135
|
+
------
|
|
136
|
+
ValueError
|
|
137
|
+
If the key format is invalid or cannot be parsed.
|
|
85
138
|
"""
|
|
86
139
|
project, _, _, _, _ = parse_entity_key(key)
|
|
87
140
|
return project
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def map_actions(kind_action_list: list[tuple[str, str]]) -> list[KindAction]:
|
|
144
|
+
"""
|
|
145
|
+
Build task actions as KindAction namedtuples.
|
|
146
|
+
|
|
147
|
+
Parameters
|
|
148
|
+
----------
|
|
149
|
+
kind_action_list : list[tuple[str, str]]
|
|
150
|
+
List of kind-action couples.
|
|
151
|
+
|
|
152
|
+
Returns
|
|
153
|
+
-------
|
|
154
|
+
list[KindAction]
|
|
155
|
+
Returns the task actions as KindAction namedtuples.
|
|
156
|
+
"""
|
|
157
|
+
return [KindAction(kind, action) for (kind, action) in kind_action_list]
|