digitalhub 0.10.0b3__py3-none-any.whl → 0.10.0b5__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/dhcore/configurator.py +4 -4
- digitalhub/configurator/configurator.py +10 -9
- digitalhub/entities/_base/entity/builder.py +5 -5
- digitalhub/entities/_base/material/entity.py +4 -17
- digitalhub/entities/_base/material/status.py +1 -1
- digitalhub/entities/_commons/models.py +7 -3
- digitalhub/entities/_commons/types.py +5 -0
- digitalhub/entities/_commons/utils.py +5 -4
- digitalhub/entities/_operations/processor.py +49 -16
- digitalhub/entities/artifact/artifact/spec.py +3 -1
- digitalhub/entities/artifact/crud.py +3 -2
- digitalhub/entities/builders.py +6 -18
- digitalhub/entities/dataitem/crud.py +3 -2
- digitalhub/entities/dataitem/table/models.py +4 -3
- digitalhub/entities/dataitem/table/utils.py +7 -7
- digitalhub/entities/dataitem/utils.py +14 -8
- digitalhub/entities/model/_base/spec.py +6 -7
- digitalhub/entities/model/crud.py +3 -2
- digitalhub/entities/model/huggingface/spec.py +4 -2
- digitalhub/entities/model/mlflow/spec.py +6 -4
- digitalhub/entities/project/_base/spec.py +8 -6
- digitalhub/entities/project/crud.py +2 -2
- digitalhub/entities/run/_base/spec.py +4 -2
- digitalhub/entities/secret/_base/spec.py +4 -2
- digitalhub/entities/secret/crud.py +2 -0
- digitalhub/entities/task/_base/models.py +41 -40
- digitalhub/entities/task/_base/utils.py +2 -2
- digitalhub/factory/utils.py +9 -9
- digitalhub/readers/data/pandas/reader.py +9 -9
- digitalhub/stores/_base/store.py +4 -3
- digitalhub/stores/local/store.py +4 -3
- digitalhub/stores/remote/store.py +4 -3
- digitalhub/stores/s3/configurator.py +1 -1
- digitalhub/stores/s3/enums.py +7 -7
- digitalhub/stores/s3/store.py +5 -4
- digitalhub/stores/sql/configurator.py +5 -5
- digitalhub/stores/sql/enums.py +6 -6
- digitalhub/stores/sql/store.py +7 -3
- digitalhub/{readers/data/pandas → utils}/enums.py +1 -1
- digitalhub/utils/file_utils.py +8 -7
- digitalhub/utils/generic_utils.py +20 -8
- digitalhub/utils/types.py +5 -0
- digitalhub/utils/uri_utils.py +1 -1
- {digitalhub-0.10.0b3.dist-info → digitalhub-0.10.0b5.dist-info}/METADATA +1 -1
- {digitalhub-0.10.0b3.dist-info → digitalhub-0.10.0b5.dist-info}/RECORD +47 -45
- {digitalhub-0.10.0b3.dist-info → digitalhub-0.10.0b5.dist-info}/WHEEL +0 -0
- {digitalhub-0.10.0b3.dist-info → digitalhub-0.10.0b5.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -118,7 +118,7 @@ class ClientDHCoreConfigurator:
|
|
|
118
118
|
The url.
|
|
119
119
|
"""
|
|
120
120
|
api = api.removeprefix("/")
|
|
121
|
-
return f"{configurator.
|
|
121
|
+
return f"{configurator.get_credential(DhcoreEnvVar.ENDPOINT.value)}/{api}"
|
|
122
122
|
|
|
123
123
|
##############################
|
|
124
124
|
# Private methods
|
|
@@ -193,7 +193,7 @@ class ClientDHCoreConfigurator:
|
|
|
193
193
|
-------
|
|
194
194
|
bool
|
|
195
195
|
"""
|
|
196
|
-
auth_type = configurator.
|
|
196
|
+
auth_type = configurator.get_credential(AUTH_KEY)
|
|
197
197
|
return auth_type == AuthType.BASIC.value
|
|
198
198
|
|
|
199
199
|
def oauth2_auth(self) -> bool:
|
|
@@ -204,7 +204,7 @@ class ClientDHCoreConfigurator:
|
|
|
204
204
|
-------
|
|
205
205
|
bool
|
|
206
206
|
"""
|
|
207
|
-
auth_type = configurator.
|
|
207
|
+
auth_type = configurator.get_credential(AUTH_KEY)
|
|
208
208
|
return auth_type == AuthType.OAUTH2.value
|
|
209
209
|
|
|
210
210
|
def set_request_auth(self, kwargs: dict) -> dict:
|
|
@@ -221,7 +221,7 @@ class ClientDHCoreConfigurator:
|
|
|
221
221
|
dict
|
|
222
222
|
Authentication header.
|
|
223
223
|
"""
|
|
224
|
-
creds = configurator.
|
|
224
|
+
creds = configurator.get_all_credentials()
|
|
225
225
|
if AUTH_KEY not in creds:
|
|
226
226
|
return kwargs
|
|
227
227
|
if self.basic_auth():
|
|
@@ -66,7 +66,7 @@ class EnvConfigurator:
|
|
|
66
66
|
str | None
|
|
67
67
|
Environment variable value.
|
|
68
68
|
"""
|
|
69
|
-
var = self.
|
|
69
|
+
var = self.get_credential(var_name)
|
|
70
70
|
if var is None:
|
|
71
71
|
var = self.load_from_env(var_name)
|
|
72
72
|
if var is None:
|
|
@@ -123,7 +123,7 @@ class EnvConfigurator:
|
|
|
123
123
|
"""
|
|
124
124
|
if key_to_include is None:
|
|
125
125
|
key_to_include = []
|
|
126
|
-
creds = self.
|
|
126
|
+
creds = self.get_credential_list(key_to_include)
|
|
127
127
|
write_config(creds, self._environment)
|
|
128
128
|
|
|
129
129
|
##############################
|
|
@@ -147,9 +147,9 @@ class EnvConfigurator:
|
|
|
147
147
|
"""
|
|
148
148
|
self._creds_store.set(self._environment, key, value)
|
|
149
149
|
|
|
150
|
-
def
|
|
150
|
+
def get_credential(self, key: str) -> dict:
|
|
151
151
|
"""
|
|
152
|
-
Get
|
|
152
|
+
Get single credential value from key.
|
|
153
153
|
|
|
154
154
|
Parameters
|
|
155
155
|
----------
|
|
@@ -159,13 +159,13 @@ class EnvConfigurator:
|
|
|
159
159
|
Returns
|
|
160
160
|
-------
|
|
161
161
|
dict
|
|
162
|
-
The
|
|
162
|
+
The credential.
|
|
163
163
|
"""
|
|
164
164
|
return self._creds_store.get(self._environment, key)
|
|
165
165
|
|
|
166
|
-
def
|
|
166
|
+
def get_all_credentials(self) -> dict:
|
|
167
167
|
"""
|
|
168
|
-
Get all the credentials.
|
|
168
|
+
Get all the credentials from the current credentials set.
|
|
169
169
|
|
|
170
170
|
Returns
|
|
171
171
|
-------
|
|
@@ -174,7 +174,7 @@ class EnvConfigurator:
|
|
|
174
174
|
"""
|
|
175
175
|
return self._creds_store.get_all(self._environment)
|
|
176
176
|
|
|
177
|
-
def
|
|
177
|
+
def get_credential_list(self, keys: list[str]) -> list[str]:
|
|
178
178
|
"""
|
|
179
179
|
Get the list of credentials.
|
|
180
180
|
|
|
@@ -188,7 +188,8 @@ class EnvConfigurator:
|
|
|
188
188
|
list[str]
|
|
189
189
|
The list of credentials.
|
|
190
190
|
"""
|
|
191
|
-
return {k: v for k, v in self.
|
|
191
|
+
return {k: v for k, v in self.get_all_credentials().items() if k in keys}
|
|
192
192
|
|
|
193
193
|
|
|
194
|
+
# Define global configurator
|
|
194
195
|
configurator = EnvConfigurator()
|
|
@@ -24,10 +24,10 @@ class EntityBuilder:
|
|
|
24
24
|
|
|
25
25
|
# Class variables
|
|
26
26
|
ENTITY_TYPE: str = None
|
|
27
|
-
ENTITY_CLASS: Entity = None
|
|
28
|
-
ENTITY_SPEC_CLASS: Spec = None
|
|
29
|
-
ENTITY_SPEC_VALIDATOR: SpecValidator = None
|
|
30
|
-
ENTITY_STATUS_CLASS: Status = None
|
|
27
|
+
ENTITY_CLASS: type[Entity] = None
|
|
28
|
+
ENTITY_SPEC_CLASS: type[Spec] = None
|
|
29
|
+
ENTITY_SPEC_VALIDATOR: type[SpecValidator] = None
|
|
30
|
+
ENTITY_STATUS_CLASS: type[Status] = None
|
|
31
31
|
ENTITY_KIND: str = None
|
|
32
32
|
|
|
33
33
|
def __init__(self) -> None:
|
|
@@ -60,7 +60,7 @@ class EntityBuilder:
|
|
|
60
60
|
"""
|
|
61
61
|
return build_name(name)
|
|
62
62
|
|
|
63
|
-
def build_uuid(self, uuid: str) -> str:
|
|
63
|
+
def build_uuid(self, uuid: str | None = None) -> str:
|
|
64
64
|
"""
|
|
65
65
|
Build entity uuid.
|
|
66
66
|
|
|
@@ -6,6 +6,7 @@ from pathlib import Path
|
|
|
6
6
|
from digitalhub.entities._base.versioned.entity import VersionedEntity
|
|
7
7
|
from digitalhub.entities._operations.processor import processor
|
|
8
8
|
from digitalhub.stores.api import get_store
|
|
9
|
+
from digitalhub.utils.types import SourcesOrListOfSources
|
|
9
10
|
|
|
10
11
|
if typing.TYPE_CHECKING:
|
|
11
12
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -34,9 +35,6 @@ class MaterialEntity(VersionedEntity):
|
|
|
34
35
|
self.spec: MaterialSpec
|
|
35
36
|
self.status: MaterialStatus
|
|
36
37
|
|
|
37
|
-
# Init files info
|
|
38
|
-
self._init_files_info()
|
|
39
|
-
|
|
40
38
|
def save(self, update: bool = False) -> MaterialEntity:
|
|
41
39
|
"""
|
|
42
40
|
Save entity into backend.
|
|
@@ -139,7 +137,7 @@ class MaterialEntity(VersionedEntity):
|
|
|
139
137
|
|
|
140
138
|
return store.download(self.spec.path, dst=dst, src=paths, overwrite=overwrite)
|
|
141
139
|
|
|
142
|
-
def upload(self, source:
|
|
140
|
+
def upload(self, source: SourcesOrListOfSources) -> None:
|
|
143
141
|
"""
|
|
144
142
|
Upload object from given local path to spec path destination.
|
|
145
143
|
Source must be a local path. If the path is a folder, destination
|
|
@@ -178,17 +176,6 @@ class MaterialEntity(VersionedEntity):
|
|
|
178
176
|
# Public Helpers
|
|
179
177
|
##############################
|
|
180
178
|
|
|
181
|
-
def _init_files_info(self) -> None:
|
|
182
|
-
"""
|
|
183
|
-
Initialize files info.
|
|
184
|
-
|
|
185
|
-
Returns
|
|
186
|
-
-------
|
|
187
|
-
None
|
|
188
|
-
"""
|
|
189
|
-
if self.status.files is None:
|
|
190
|
-
self.status.files = []
|
|
191
|
-
|
|
192
179
|
def add_files_info(self, files: list[dict]) -> None:
|
|
193
180
|
"""
|
|
194
181
|
Add a file to the status.
|
|
@@ -207,13 +194,13 @@ class MaterialEntity(VersionedEntity):
|
|
|
207
194
|
if f.get("path") not in path_list:
|
|
208
195
|
self.status.files.append(f)
|
|
209
196
|
|
|
210
|
-
def get_file_paths(self) -> list
|
|
197
|
+
def get_file_paths(self) -> list:
|
|
211
198
|
"""
|
|
212
199
|
Get the paths of the files in the status.
|
|
213
200
|
|
|
214
201
|
Returns
|
|
215
202
|
-------
|
|
216
|
-
list
|
|
203
|
+
list
|
|
217
204
|
Paths of the files in the status.
|
|
218
205
|
"""
|
|
219
206
|
return [f.get("path") for f in self.status.files]
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Union
|
|
4
|
-
|
|
5
3
|
from pydantic import BaseModel
|
|
6
4
|
|
|
5
|
+
from digitalhub.entities._commons.types import MetricType
|
|
6
|
+
|
|
7
7
|
|
|
8
8
|
class Metric(BaseModel):
|
|
9
|
-
|
|
9
|
+
"""
|
|
10
|
+
Metric.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
value: MetricType
|
|
@@ -6,9 +6,10 @@ from pydantic import ValidationError
|
|
|
6
6
|
|
|
7
7
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
8
8
|
from digitalhub.entities._commons.models import Metric
|
|
9
|
+
from digitalhub.entities._commons.types import MetricType
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
def parse_entity_key(key: str) -> tuple[str]:
|
|
12
|
+
def parse_entity_key(key: str) -> tuple[str, str, str, str | None, str]:
|
|
12
13
|
"""
|
|
13
14
|
Parse the entity key. Returns project, entity type, kind, name and uuid.
|
|
14
15
|
|
|
@@ -19,7 +20,7 @@ def parse_entity_key(key: str) -> tuple[str]:
|
|
|
19
20
|
|
|
20
21
|
Returns
|
|
21
22
|
-------
|
|
22
|
-
tuple[str]
|
|
23
|
+
tuple[str, str, str, str | None, str]
|
|
23
24
|
Project, entity type, kind, name and uuid.
|
|
24
25
|
"""
|
|
25
26
|
try:
|
|
@@ -88,7 +89,7 @@ def get_project_from_key(key: str) -> str:
|
|
|
88
89
|
return project
|
|
89
90
|
|
|
90
91
|
|
|
91
|
-
def validate_metric_value(value: Any) ->
|
|
92
|
+
def validate_metric_value(value: Any) -> MetricType:
|
|
92
93
|
"""
|
|
93
94
|
Validate metric value.
|
|
94
95
|
|
|
@@ -99,7 +100,7 @@ def validate_metric_value(value: Any) -> float | int | list[float | int]:
|
|
|
99
100
|
|
|
100
101
|
Returns
|
|
101
102
|
-------
|
|
102
|
-
|
|
103
|
+
MetricType
|
|
103
104
|
The validated value.
|
|
104
105
|
"""
|
|
105
106
|
try:
|
|
@@ -10,6 +10,7 @@ from digitalhub.entities._commons.utils import get_project_from_key, parse_entit
|
|
|
10
10
|
from digitalhub.factory.api import build_entity_from_dict, build_entity_from_params
|
|
11
11
|
from digitalhub.utils.exceptions import ContextError, EntityAlreadyExistsError, EntityError, EntityNotExistsError
|
|
12
12
|
from digitalhub.utils.io_utils import read_yaml
|
|
13
|
+
from digitalhub.utils.types import SourcesOrListOfSources
|
|
13
14
|
|
|
14
15
|
if typing.TYPE_CHECKING:
|
|
15
16
|
from digitalhub.client._base.client import Client
|
|
@@ -605,7 +606,7 @@ class OperationsProcessor:
|
|
|
605
606
|
MaterialEntity
|
|
606
607
|
Object instance.
|
|
607
608
|
"""
|
|
608
|
-
source = kwargs.pop("source")
|
|
609
|
+
source: SourcesOrListOfSources = kwargs.pop("source")
|
|
609
610
|
context = self._get_context(kwargs["project"])
|
|
610
611
|
obj = build_entity_from_params(**kwargs)
|
|
611
612
|
if context.is_running:
|
|
@@ -648,12 +649,12 @@ class OperationsProcessor:
|
|
|
648
649
|
dict
|
|
649
650
|
Object instance.
|
|
650
651
|
"""
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
652
|
+
project, entity_type, _, entity_name, entity_id = self._parse_identifier(
|
|
653
|
+
identifier,
|
|
654
|
+
project=project,
|
|
655
|
+
entity_type=entity_type,
|
|
656
|
+
entity_id=entity_id,
|
|
657
|
+
)
|
|
657
658
|
|
|
658
659
|
kwargs = self._set_params(**kwargs)
|
|
659
660
|
|
|
@@ -917,12 +918,11 @@ class OperationsProcessor:
|
|
|
917
918
|
list[dict]
|
|
918
919
|
Object instances.
|
|
919
920
|
"""
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
project, entity_type, _, entity_name, _ = parse_entity_key(identifier)
|
|
921
|
+
project, entity_type, _, entity_name, _ = self._parse_identifier(
|
|
922
|
+
identifier,
|
|
923
|
+
project=project,
|
|
924
|
+
entity_type=entity_type,
|
|
925
|
+
)
|
|
926
926
|
|
|
927
927
|
kwargs = self._set_params(**kwargs)
|
|
928
928
|
kwargs["params"]["name"] = entity_name
|
|
@@ -1382,7 +1382,7 @@ class OperationsProcessor:
|
|
|
1382
1382
|
project=context.name,
|
|
1383
1383
|
entity_type=entity_type,
|
|
1384
1384
|
)
|
|
1385
|
-
|
|
1385
|
+
context.client.update_object(api, data, **kwargs)
|
|
1386
1386
|
|
|
1387
1387
|
def read_run_logs(
|
|
1388
1388
|
self,
|
|
@@ -1453,7 +1453,7 @@ class OperationsProcessor:
|
|
|
1453
1453
|
entity_type=entity_type,
|
|
1454
1454
|
entity_id=entity_id,
|
|
1455
1455
|
)
|
|
1456
|
-
|
|
1456
|
+
context.client.create_object(api, **kwargs)
|
|
1457
1457
|
|
|
1458
1458
|
def resume_run(
|
|
1459
1459
|
self,
|
|
@@ -1488,7 +1488,7 @@ class OperationsProcessor:
|
|
|
1488
1488
|
entity_type=entity_type,
|
|
1489
1489
|
entity_id=entity_id,
|
|
1490
1490
|
)
|
|
1491
|
-
|
|
1491
|
+
context.client.create_object(api, **kwargs)
|
|
1492
1492
|
|
|
1493
1493
|
def read_files_info(
|
|
1494
1494
|
self,
|
|
@@ -1767,6 +1767,39 @@ class OperationsProcessor:
|
|
|
1767
1767
|
# Helpers
|
|
1768
1768
|
##############################
|
|
1769
1769
|
|
|
1770
|
+
@staticmethod
|
|
1771
|
+
def _parse_identifier(
|
|
1772
|
+
identifier: str,
|
|
1773
|
+
project: str | None = None,
|
|
1774
|
+
entity_type: str | None = None,
|
|
1775
|
+
entity_kind: str | None = None,
|
|
1776
|
+
entity_id: str | None = None,
|
|
1777
|
+
) -> tuple[str, str, str, str | None, str]:
|
|
1778
|
+
"""
|
|
1779
|
+
Parse entity identifier.
|
|
1780
|
+
|
|
1781
|
+
Parameters
|
|
1782
|
+
----------
|
|
1783
|
+
identifier : str
|
|
1784
|
+
Entity key (store://...) or entity name.
|
|
1785
|
+
project : str
|
|
1786
|
+
Project name.
|
|
1787
|
+
entity_type : str
|
|
1788
|
+
Entity type.
|
|
1789
|
+
entity_id : str
|
|
1790
|
+
Entity ID.
|
|
1791
|
+
|
|
1792
|
+
Returns
|
|
1793
|
+
-------
|
|
1794
|
+
tuple[str, str, str, str | None, str]
|
|
1795
|
+
Project name, entity type, entity kind, entity name, entity ID.
|
|
1796
|
+
"""
|
|
1797
|
+
if not identifier.startswith("store://"):
|
|
1798
|
+
if project is None or entity_type is None:
|
|
1799
|
+
raise ValueError("Project and entity type must be specified.")
|
|
1800
|
+
return project, entity_type, entity_kind, identifier, entity_id
|
|
1801
|
+
return parse_entity_key(identifier)
|
|
1802
|
+
|
|
1770
1803
|
@staticmethod
|
|
1771
1804
|
def _set_params(**kwargs) -> dict:
|
|
1772
1805
|
"""
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
3
5
|
from digitalhub.entities.artifact._base.spec import ArtifactSpec, ArtifactValidator
|
|
4
6
|
|
|
5
7
|
|
|
@@ -23,5 +25,5 @@ class ArtifactValidatorArtifact(ArtifactValidator):
|
|
|
23
25
|
ArtifactValidatorArtifact validator.
|
|
24
26
|
"""
|
|
25
27
|
|
|
26
|
-
src_path: str = None
|
|
28
|
+
src_path: Optional[str] = None
|
|
27
29
|
"""Source path of the artifact."""
|
|
@@ -6,6 +6,7 @@ from digitalhub.entities._commons.enums import EntityTypes
|
|
|
6
6
|
from digitalhub.entities._operations.processor import processor
|
|
7
7
|
from digitalhub.entities.artifact._base.entity import Artifact
|
|
8
8
|
from digitalhub.entities.artifact.utils import eval_source, process_kwargs
|
|
9
|
+
from digitalhub.utils.types import SourcesOrListOfSources
|
|
9
10
|
|
|
10
11
|
if typing.TYPE_CHECKING:
|
|
11
12
|
from digitalhub.entities.artifact._base.entity import Artifact
|
|
@@ -78,7 +79,7 @@ def log_artifact(
|
|
|
78
79
|
project: str,
|
|
79
80
|
name: str,
|
|
80
81
|
kind: str,
|
|
81
|
-
source:
|
|
82
|
+
source: SourcesOrListOfSources,
|
|
82
83
|
path: str | None = None,
|
|
83
84
|
**kwargs,
|
|
84
85
|
) -> Artifact:
|
|
@@ -93,7 +94,7 @@ def log_artifact(
|
|
|
93
94
|
Object name.
|
|
94
95
|
kind : str
|
|
95
96
|
Kind the object.
|
|
96
|
-
source :
|
|
97
|
+
source : SourcesOrListOfSources
|
|
97
98
|
Artifact location on local path.
|
|
98
99
|
path : str
|
|
99
100
|
Destination path of the artifact. If not provided, it's generated.
|
digitalhub/entities/builders.py
CHANGED
|
@@ -7,7 +7,7 @@ from digitalhub.entities.model.mlflow.builder import ModelModelBuilder
|
|
|
7
7
|
from digitalhub.entities.project._base.builder import ProjectProjectBuilder
|
|
8
8
|
from digitalhub.entities.secret._base.builder import SecretSecretBuilder
|
|
9
9
|
|
|
10
|
-
entity_builders = (
|
|
10
|
+
entity_builders: tuple = (
|
|
11
11
|
(ProjectProjectBuilder.ENTITY_KIND, ProjectProjectBuilder),
|
|
12
12
|
(SecretSecretBuilder.ENTITY_KIND, SecretSecretBuilder),
|
|
13
13
|
(ArtifactArtifactBuilder.ENTITY_KIND, ArtifactArtifactBuilder),
|
|
@@ -17,17 +17,14 @@ entity_builders = (
|
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
##############################
|
|
20
|
-
#
|
|
20
|
+
# Add custom entities here
|
|
21
21
|
##############################
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
try:
|
|
25
25
|
from digitalhub.entities.dataitem.iceberg.builder import DataitemIcebergBuilder
|
|
26
26
|
|
|
27
|
-
entity_builders
|
|
28
|
-
*entity_builders,
|
|
29
|
-
(DataitemIcebergBuilder.ENTITY_KIND, DataitemIcebergBuilder),
|
|
30
|
-
)
|
|
27
|
+
entity_builders += ((DataitemIcebergBuilder.ENTITY_KIND, DataitemIcebergBuilder),)
|
|
31
28
|
except ImportError:
|
|
32
29
|
...
|
|
33
30
|
|
|
@@ -35,29 +32,20 @@ except ImportError:
|
|
|
35
32
|
try:
|
|
36
33
|
from digitalhub.entities.model.model.builder import ModelMlflowBuilder
|
|
37
34
|
|
|
38
|
-
entity_builders
|
|
39
|
-
*entity_builders,
|
|
40
|
-
(ModelMlflowBuilder.ENTITY_KIND, ModelMlflowBuilder),
|
|
41
|
-
)
|
|
35
|
+
entity_builders += ((ModelMlflowBuilder.ENTITY_KIND, ModelMlflowBuilder),)
|
|
42
36
|
except ImportError:
|
|
43
37
|
...
|
|
44
38
|
|
|
45
39
|
try:
|
|
46
40
|
from digitalhub.entities.model.sklearn.builder import ModelSklearnBuilder
|
|
47
41
|
|
|
48
|
-
entity_builders
|
|
49
|
-
*entity_builders,
|
|
50
|
-
(ModelSklearnBuilder.ENTITY_KIND, ModelSklearnBuilder),
|
|
51
|
-
)
|
|
42
|
+
entity_builders += ((ModelSklearnBuilder.ENTITY_KIND, ModelSklearnBuilder),)
|
|
52
43
|
except ImportError:
|
|
53
44
|
...
|
|
54
45
|
|
|
55
46
|
try:
|
|
56
47
|
from digitalhub.entities.model.huggingface.builder import ModelHuggingfaceBuilder
|
|
57
48
|
|
|
58
|
-
entity_builders
|
|
59
|
-
*entity_builders,
|
|
60
|
-
(ModelHuggingfaceBuilder.ENTITY_KIND, ModelHuggingfaceBuilder),
|
|
61
|
-
)
|
|
49
|
+
entity_builders += ((ModelHuggingfaceBuilder.ENTITY_KIND, ModelHuggingfaceBuilder),)
|
|
62
50
|
except ImportError:
|
|
63
51
|
...
|
|
@@ -6,6 +6,7 @@ from typing import Any
|
|
|
6
6
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
7
|
from digitalhub.entities._operations.processor import processor
|
|
8
8
|
from digitalhub.entities.dataitem.utils import clean_tmp_path, eval_data, eval_source, post_process, process_kwargs
|
|
9
|
+
from digitalhub.utils.types import SourcesOrListOfSources
|
|
9
10
|
|
|
10
11
|
if typing.TYPE_CHECKING:
|
|
11
12
|
from digitalhub.entities.dataitem._base.entity import Dataitem
|
|
@@ -78,7 +79,7 @@ def log_dataitem(
|
|
|
78
79
|
project: str,
|
|
79
80
|
name: str,
|
|
80
81
|
kind: str,
|
|
81
|
-
source:
|
|
82
|
+
source: SourcesOrListOfSources | None = None,
|
|
82
83
|
data: Any | None = None,
|
|
83
84
|
path: str | None = None,
|
|
84
85
|
file_format: str | None = None,
|
|
@@ -96,7 +97,7 @@ def log_dataitem(
|
|
|
96
97
|
Object name.
|
|
97
98
|
kind : str
|
|
98
99
|
Kind the object.
|
|
99
|
-
source :
|
|
100
|
+
source : SourcesOrListOfSources
|
|
100
101
|
Dataitem location on local path.
|
|
101
102
|
data : Any
|
|
102
103
|
Dataframe to log. Alternative to source.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from enum import Enum
|
|
4
|
+
from typing import Optional
|
|
4
5
|
|
|
5
6
|
from pydantic import BaseModel, ConfigDict, Field
|
|
6
7
|
|
|
@@ -40,16 +41,16 @@ class TableSchemaFieldEntry(BaseModel):
|
|
|
40
41
|
type_: FieldType = Field(alias="type")
|
|
41
42
|
"""Field type."""
|
|
42
43
|
|
|
43
|
-
title: str = None
|
|
44
|
+
title: Optional[str] = None
|
|
44
45
|
"""Field title."""
|
|
45
46
|
|
|
46
47
|
format_: str = Field(default=None, alias="format")
|
|
47
48
|
"""Field format."""
|
|
48
49
|
|
|
49
|
-
example: str = None
|
|
50
|
+
example: Optional[str] = None
|
|
50
51
|
"""Field example."""
|
|
51
52
|
|
|
52
|
-
description: str = None
|
|
53
|
+
description: Optional[str] = None
|
|
53
54
|
"""Field description."""
|
|
54
55
|
|
|
55
56
|
|
|
@@ -76,9 +76,9 @@ def filter_memoryview(data: list[dict]) -> list[dict]:
|
|
|
76
76
|
return data
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
def check_preview_size(preview: dict) ->
|
|
79
|
+
def check_preview_size(preview: dict) -> dict:
|
|
80
80
|
"""
|
|
81
|
-
Check preview size. If it's too big, return empty
|
|
81
|
+
Check preview size. If it's too big, return empty dict.
|
|
82
82
|
|
|
83
83
|
Parameters
|
|
84
84
|
----------
|
|
@@ -87,11 +87,11 @@ def check_preview_size(preview: dict) -> list:
|
|
|
87
87
|
|
|
88
88
|
Returns
|
|
89
89
|
-------
|
|
90
|
-
|
|
90
|
+
dict
|
|
91
91
|
Preview.
|
|
92
92
|
"""
|
|
93
93
|
if len(dump_json(preview)) >= 64000:
|
|
94
|
-
return
|
|
94
|
+
return {}
|
|
95
95
|
return preview
|
|
96
96
|
|
|
97
97
|
|
|
@@ -101,9 +101,9 @@ def finalize_preview(preview: list[dict] | None = None, rows_count: int | None =
|
|
|
101
101
|
|
|
102
102
|
Parameters
|
|
103
103
|
----------
|
|
104
|
-
preview : list[dict]
|
|
104
|
+
preview : list[dict]
|
|
105
105
|
Preview.
|
|
106
|
-
rows_count : int
|
|
106
|
+
rows_count : int
|
|
107
107
|
Row count.
|
|
108
108
|
|
|
109
109
|
Returns
|
|
@@ -111,7 +111,7 @@ def finalize_preview(preview: list[dict] | None = None, rows_count: int | None =
|
|
|
111
111
|
dict
|
|
112
112
|
Data preview.
|
|
113
113
|
"""
|
|
114
|
-
data = {}
|
|
114
|
+
data: dict[str, list[dict] | int] = {}
|
|
115
115
|
if preview is not None:
|
|
116
116
|
data["cols"] = preview
|
|
117
117
|
if rows_count is not None:
|
|
@@ -10,17 +10,19 @@ 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
|
|
15
|
+
from digitalhub.utils.types import SourcesOrListOfSources
|
|
14
16
|
|
|
15
17
|
if typing.TYPE_CHECKING:
|
|
16
18
|
from digitalhub.entities.dataitem._base.entity import Dataitem
|
|
17
19
|
|
|
18
20
|
|
|
19
|
-
DEFAULT_EXTENSION =
|
|
21
|
+
DEFAULT_EXTENSION = FileExtensions.PARQUET.value
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
def eval_source(
|
|
23
|
-
source:
|
|
25
|
+
source: SourcesOrListOfSources | None = None,
|
|
24
26
|
data: Any | None = None,
|
|
25
27
|
kind: str | None = None,
|
|
26
28
|
name: str | None = None,
|
|
@@ -31,7 +33,7 @@ def eval_source(
|
|
|
31
33
|
|
|
32
34
|
Parameters
|
|
33
35
|
----------
|
|
34
|
-
source :
|
|
36
|
+
source : SourcesOrListOfSources
|
|
35
37
|
Source(s).
|
|
36
38
|
|
|
37
39
|
Returns
|
|
@@ -58,7 +60,7 @@ def eval_source(
|
|
|
58
60
|
def eval_data(
|
|
59
61
|
project: str,
|
|
60
62
|
kind: str,
|
|
61
|
-
source:
|
|
63
|
+
source: SourcesOrListOfSources,
|
|
62
64
|
data: Any | None = None,
|
|
63
65
|
file_format: str | None = None,
|
|
64
66
|
engine: str | None = None,
|
|
@@ -97,7 +99,7 @@ def process_kwargs(
|
|
|
97
99
|
project: str,
|
|
98
100
|
name: str,
|
|
99
101
|
kind: str,
|
|
100
|
-
source:
|
|
102
|
+
source: SourcesOrListOfSources,
|
|
101
103
|
data: Any | None = None,
|
|
102
104
|
path: str | None = None,
|
|
103
105
|
**kwargs,
|
|
@@ -113,7 +115,7 @@ def process_kwargs(
|
|
|
113
115
|
Object name.
|
|
114
116
|
kind : str
|
|
115
117
|
Kind the object.
|
|
116
|
-
source :
|
|
118
|
+
source : SourcesOrListOfSources
|
|
117
119
|
Source(s).
|
|
118
120
|
data : Any
|
|
119
121
|
Dataframe to log. Alternative to source.
|
|
@@ -140,19 +142,23 @@ def process_kwargs(
|
|
|
140
142
|
return kwargs
|
|
141
143
|
|
|
142
144
|
|
|
143
|
-
def clean_tmp_path(pth:
|
|
145
|
+
def clean_tmp_path(pth: SourcesOrListOfSources) -> None:
|
|
144
146
|
"""
|
|
145
147
|
Clean temporary path.
|
|
146
148
|
|
|
147
149
|
Parameters
|
|
148
150
|
----------
|
|
149
|
-
pth :
|
|
151
|
+
pth : SourcesOrListOfSources
|
|
150
152
|
Path to clean.
|
|
151
153
|
|
|
152
154
|
Returns
|
|
153
155
|
-------
|
|
154
156
|
None
|
|
155
157
|
"""
|
|
158
|
+
if isinstance(pth, list):
|
|
159
|
+
for p in pth:
|
|
160
|
+
shutil.rmtree(p, ignore_errors=True)
|
|
161
|
+
return
|
|
156
162
|
shutil.rmtree(pth, ignore_errors=True)
|
|
157
163
|
|
|
158
164
|
|