digitalhub 0.8.1__py3-none-any.whl → 0.9.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 +19 -2
- digitalhub/client/_base/api_builder.py +16 -0
- digitalhub/client/_base/client.py +31 -0
- digitalhub/client/api.py +2 -38
- digitalhub/client/dhcore/api_builder.py +100 -0
- digitalhub/client/dhcore/client.py +77 -24
- digitalhub/client/dhcore/enums.py +26 -0
- digitalhub/client/dhcore/env.py +2 -2
- digitalhub/client/dhcore/utils.py +17 -17
- digitalhub/client/local/api_builder.py +100 -0
- digitalhub/client/local/client.py +20 -0
- digitalhub/context/api.py +3 -38
- digitalhub/context/builder.py +10 -23
- digitalhub/context/context.py +20 -92
- digitalhub/entities/_base/context/entity.py +30 -22
- digitalhub/entities/_base/entity/_constructors/metadata.py +12 -1
- digitalhub/entities/_base/entity/_constructors/name.py +1 -1
- digitalhub/entities/_base/entity/_constructors/spec.py +1 -1
- digitalhub/entities/_base/entity/_constructors/status.py +3 -2
- digitalhub/entities/_base/entity/builder.py +6 -1
- digitalhub/entities/_base/entity/entity.py +30 -10
- digitalhub/entities/_base/entity/metadata.py +22 -0
- digitalhub/entities/_base/entity/spec.py +7 -2
- digitalhub/entities/_base/executable/entity.py +8 -8
- digitalhub/entities/_base/material/entity.py +48 -16
- digitalhub/entities/_base/material/status.py +0 -31
- digitalhub/entities/_base/material/utils.py +106 -0
- digitalhub/entities/_base/project/entity.py +341 -0
- digitalhub/entities/_base/unversioned/entity.py +1 -23
- digitalhub/entities/_base/versioned/entity.py +0 -25
- digitalhub/entities/_commons/enums.py +103 -0
- digitalhub/entities/_commons/utils.py +83 -0
- digitalhub/entities/_operations/processor.py +1747 -0
- digitalhub/entities/artifact/_base/builder.py +1 -1
- digitalhub/entities/artifact/_base/entity.py +1 -1
- digitalhub/entities/artifact/artifact/builder.py +2 -1
- digitalhub/entities/artifact/crud.py +46 -29
- digitalhub/entities/artifact/utils.py +62 -0
- digitalhub/entities/dataitem/_base/builder.py +1 -1
- digitalhub/entities/dataitem/_base/entity.py +6 -6
- digitalhub/entities/dataitem/crud.py +50 -66
- digitalhub/entities/dataitem/dataitem/builder.py +2 -1
- digitalhub/entities/dataitem/iceberg/builder.py +2 -1
- digitalhub/entities/dataitem/table/builder.py +2 -1
- digitalhub/entities/dataitem/table/entity.py +5 -10
- digitalhub/entities/dataitem/table/models.py +4 -5
- digitalhub/entities/dataitem/utils.py +137 -0
- digitalhub/entities/function/_base/builder.py +1 -1
- digitalhub/entities/function/_base/entity.py +5 -1
- digitalhub/entities/function/crud.py +36 -17
- digitalhub/entities/model/_base/builder.py +1 -1
- digitalhub/entities/model/_base/entity.py +1 -1
- digitalhub/entities/model/crud.py +46 -29
- digitalhub/entities/model/huggingface/builder.py +2 -1
- digitalhub/entities/model/huggingface/spec.py +4 -2
- digitalhub/entities/model/mlflow/builder.py +2 -1
- digitalhub/entities/model/mlflow/models.py +17 -9
- digitalhub/entities/model/mlflow/spec.py +6 -1
- digitalhub/entities/model/mlflow/utils.py +4 -2
- digitalhub/entities/model/model/builder.py +2 -1
- digitalhub/entities/model/sklearn/builder.py +2 -1
- digitalhub/entities/model/utils.py +62 -0
- digitalhub/entities/project/_base/builder.py +2 -2
- digitalhub/entities/project/_base/entity.py +82 -272
- digitalhub/entities/project/crud.py +110 -91
- digitalhub/entities/project/utils.py +35 -0
- digitalhub/entities/run/_base/builder.py +3 -1
- digitalhub/entities/run/_base/entity.py +52 -54
- digitalhub/entities/run/_base/spec.py +11 -7
- digitalhub/entities/run/crud.py +35 -17
- digitalhub/entities/secret/_base/builder.py +2 -2
- digitalhub/entities/secret/_base/entity.py +4 -10
- digitalhub/entities/secret/crud.py +36 -21
- digitalhub/entities/task/_base/builder.py +14 -14
- digitalhub/entities/task/_base/entity.py +6 -6
- digitalhub/entities/task/_base/models.py +29 -6
- digitalhub/entities/task/_base/spec.py +44 -13
- digitalhub/entities/task/_base/utils.py +18 -0
- digitalhub/entities/task/crud.py +35 -15
- digitalhub/entities/workflow/_base/builder.py +1 -1
- digitalhub/entities/workflow/_base/entity.py +14 -6
- digitalhub/entities/workflow/crud.py +36 -17
- digitalhub/factory/utils.py +1 -1
- digitalhub/readers/_base/reader.py +2 -2
- digitalhub/readers/_commons/enums.py +13 -0
- digitalhub/readers/api.py +3 -2
- digitalhub/readers/factory.py +12 -6
- digitalhub/readers/pandas/reader.py +20 -8
- digitalhub/runtimes/_base.py +0 -7
- digitalhub/stores/_base/store.py +53 -9
- digitalhub/stores/builder.py +5 -5
- digitalhub/stores/local/store.py +37 -2
- digitalhub/stores/remote/store.py +25 -3
- digitalhub/stores/s3/store.py +34 -7
- digitalhub/stores/sql/store.py +112 -45
- digitalhub/utils/exceptions.py +6 -0
- digitalhub/utils/file_utils.py +60 -2
- digitalhub/utils/generic_utils.py +45 -4
- digitalhub/utils/io_utils.py +18 -0
- digitalhub/utils/uri_utils.py +153 -15
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/METADATA +2 -2
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/RECORD +110 -113
- test/testkfp.py +4 -1
- digitalhub/datastores/_base/datastore.py +0 -85
- digitalhub/datastores/api.py +0 -37
- digitalhub/datastores/builder.py +0 -110
- digitalhub/datastores/local/datastore.py +0 -50
- digitalhub/datastores/remote/__init__.py +0 -0
- digitalhub/datastores/remote/datastore.py +0 -31
- digitalhub/datastores/s3/__init__.py +0 -0
- digitalhub/datastores/s3/datastore.py +0 -46
- digitalhub/datastores/sql/__init__.py +0 -0
- digitalhub/datastores/sql/datastore.py +0 -68
- digitalhub/entities/_base/api_utils.py +0 -620
- digitalhub/entities/_base/crud.py +0 -468
- digitalhub/entities/function/_base/models.py +0 -118
- digitalhub/entities/utils/__init__.py +0 -0
- digitalhub/entities/utils/api.py +0 -346
- digitalhub/entities/utils/entity_types.py +0 -19
- digitalhub/entities/utils/state.py +0 -31
- digitalhub/entities/utils/utils.py +0 -202
- /digitalhub/{context → entities/_base/project}/__init__.py +0 -0
- /digitalhub/{datastores → entities/_commons}/__init__.py +0 -0
- /digitalhub/{datastores/_base → entities/_operations}/__init__.py +0 -0
- /digitalhub/{datastores/local → readers/_commons}/__init__.py +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/LICENSE.txt +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/WHEEL +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/top_level.txt +0 -0
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.versioned.builder import VersionedBuilder
|
|
6
|
-
from digitalhub.entities.
|
|
6
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
7
|
from digitalhub.utils.exceptions import EntityError
|
|
8
8
|
|
|
9
9
|
if typing.TYPE_CHECKING:
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.material.entity import MaterialEntity
|
|
6
|
-
from digitalhub.entities.
|
|
6
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
7
|
|
|
8
8
|
if typing.TYPE_CHECKING:
|
|
9
9
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from digitalhub.entities._commons.enums import EntityKinds
|
|
3
4
|
from digitalhub.entities.artifact._base.builder import ArtifactBuilder
|
|
4
5
|
from digitalhub.entities.artifact.artifact.entity import ArtifactArtifact
|
|
5
6
|
from digitalhub.entities.artifact.artifact.spec import ArtifactSpecArtifact, ArtifactValidatorArtifact
|
|
@@ -15,4 +16,4 @@ class ArtifactArtifactBuilder(ArtifactBuilder):
|
|
|
15
16
|
ENTITY_SPEC_CLASS = ArtifactSpecArtifact
|
|
16
17
|
ENTITY_SPEC_VALIDATOR = ArtifactValidatorArtifact
|
|
17
18
|
ENTITY_STATUS_CLASS = ArtifactStatusArtifact
|
|
18
|
-
ENTITY_KIND =
|
|
19
|
+
ENTITY_KIND = EntityKinds.ARTIFACT_ARTIFACT.value
|
|
@@ -2,18 +2,10 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
|
-
from digitalhub.entities.
|
|
6
|
-
|
|
7
|
-
get_material_entity,
|
|
8
|
-
get_material_entity_versions,
|
|
9
|
-
import_context_entity,
|
|
10
|
-
list_material_entities,
|
|
11
|
-
new_context_entity,
|
|
12
|
-
)
|
|
13
|
-
from digitalhub.entities._base.entity._constructors.uuid import build_uuid
|
|
5
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
6
|
+
from digitalhub.entities._operations.processor import processor
|
|
14
7
|
from digitalhub.entities.artifact._base.entity import Artifact
|
|
15
|
-
from digitalhub.entities.utils
|
|
16
|
-
from digitalhub.entities.utils.utils import build_log_path_from_source, eval_local_source
|
|
8
|
+
from digitalhub.entities.artifact.utils import eval_source, process_kwargs
|
|
17
9
|
|
|
18
10
|
if typing.TYPE_CHECKING:
|
|
19
11
|
from digitalhub.entities.artifact._base.entity import Artifact
|
|
@@ -69,7 +61,7 @@ def new_artifact(
|
|
|
69
61
|
>>> kind="artifact",
|
|
70
62
|
>>> path="s3://my-bucket/my-key")
|
|
71
63
|
"""
|
|
72
|
-
return
|
|
64
|
+
return processor.create_context_entity(
|
|
73
65
|
project=project,
|
|
74
66
|
name=name,
|
|
75
67
|
kind=kind,
|
|
@@ -120,16 +112,15 @@ def log_artifact(
|
|
|
120
112
|
>>> kind="artifact",
|
|
121
113
|
>>> source="./local-path")
|
|
122
114
|
"""
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return obj
|
|
115
|
+
eval_source(source)
|
|
116
|
+
kwargs = process_kwargs(project, name, source=source, path=path, **kwargs)
|
|
117
|
+
return processor.log_material_entity(
|
|
118
|
+
source=source,
|
|
119
|
+
project=project,
|
|
120
|
+
name=name,
|
|
121
|
+
kind=kind,
|
|
122
|
+
**kwargs,
|
|
123
|
+
)
|
|
133
124
|
|
|
134
125
|
|
|
135
126
|
def get_artifact(
|
|
@@ -167,7 +158,7 @@ def get_artifact(
|
|
|
167
158
|
>>> project="my-project",
|
|
168
159
|
>>> entity_id="my-artifact-id")
|
|
169
160
|
"""
|
|
170
|
-
return
|
|
161
|
+
return processor.read_material_entity(
|
|
171
162
|
identifier=identifier,
|
|
172
163
|
entity_type=ENTITY_TYPE,
|
|
173
164
|
project=project,
|
|
@@ -207,7 +198,7 @@ def get_artifact_versions(
|
|
|
207
198
|
>>> obj = get_artifact_versions("my-artifact-name"
|
|
208
199
|
>>> project="my-project")
|
|
209
200
|
"""
|
|
210
|
-
return
|
|
201
|
+
return processor.read_material_entity_versions(
|
|
211
202
|
identifier=identifier,
|
|
212
203
|
entity_type=ENTITY_TYPE,
|
|
213
204
|
project=project,
|
|
@@ -235,7 +226,7 @@ def list_artifacts(project: str, **kwargs) -> list[Artifact]:
|
|
|
235
226
|
--------
|
|
236
227
|
>>> objs = list_artifacts(project="my-project")
|
|
237
228
|
"""
|
|
238
|
-
return list_material_entities(
|
|
229
|
+
return processor.list_material_entities(
|
|
239
230
|
project=project,
|
|
240
231
|
entity_type=ENTITY_TYPE,
|
|
241
232
|
**kwargs,
|
|
@@ -244,7 +235,7 @@ def list_artifacts(project: str, **kwargs) -> list[Artifact]:
|
|
|
244
235
|
|
|
245
236
|
def import_artifact(file: str) -> Artifact:
|
|
246
237
|
"""
|
|
247
|
-
Import object from a YAML file.
|
|
238
|
+
Import object from a YAML file and create a new object into the backend.
|
|
248
239
|
|
|
249
240
|
Parameters
|
|
250
241
|
----------
|
|
@@ -260,7 +251,28 @@ def import_artifact(file: str) -> Artifact:
|
|
|
260
251
|
--------
|
|
261
252
|
>>> obj = import_artifact("my-artifact.yaml")
|
|
262
253
|
"""
|
|
263
|
-
return import_context_entity(file)
|
|
254
|
+
return processor.import_context_entity(file)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def load_artifact(file: str) -> Artifact:
|
|
258
|
+
"""
|
|
259
|
+
Load object from a YAML file and update an existing object into the backend.
|
|
260
|
+
|
|
261
|
+
Parameters
|
|
262
|
+
----------
|
|
263
|
+
file : str
|
|
264
|
+
Path to YAML file.
|
|
265
|
+
|
|
266
|
+
Returns
|
|
267
|
+
-------
|
|
268
|
+
Artifact
|
|
269
|
+
Object instance.
|
|
270
|
+
|
|
271
|
+
Examples
|
|
272
|
+
--------
|
|
273
|
+
>>> obj = load_artifact("my-artifact.yaml")
|
|
274
|
+
"""
|
|
275
|
+
return processor.load_context_entity(file)
|
|
264
276
|
|
|
265
277
|
|
|
266
278
|
def update_artifact(entity: Artifact) -> Artifact:
|
|
@@ -281,7 +293,12 @@ def update_artifact(entity: Artifact) -> Artifact:
|
|
|
281
293
|
--------
|
|
282
294
|
>>> obj = update_artifact(obj)
|
|
283
295
|
"""
|
|
284
|
-
return
|
|
296
|
+
return processor.update_context_entity(
|
|
297
|
+
project=entity.project,
|
|
298
|
+
entity_type=entity.ENTITY_TYPE,
|
|
299
|
+
entity_id=entity.id,
|
|
300
|
+
entity_dict=entity.to_dict(),
|
|
301
|
+
)
|
|
285
302
|
|
|
286
303
|
|
|
287
304
|
def delete_artifact(
|
|
@@ -322,7 +339,7 @@ def delete_artifact(
|
|
|
322
339
|
>>> project="my-project",
|
|
323
340
|
>>> delete_all_versions=True)
|
|
324
341
|
"""
|
|
325
|
-
return
|
|
342
|
+
return processor.delete_context_entity(
|
|
326
343
|
identifier=identifier,
|
|
327
344
|
entity_type=ENTITY_TYPE,
|
|
328
345
|
project=project,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._base.entity._constructors.uuid import build_uuid
|
|
6
|
+
from digitalhub.entities._base.material.utils import build_log_path_from_source, eval_local_source
|
|
7
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def eval_source(
|
|
11
|
+
source: str | list[str] | None = None,
|
|
12
|
+
) -> Any:
|
|
13
|
+
"""
|
|
14
|
+
Evaluate if source is local.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
source : str | list[str]
|
|
19
|
+
Source(s).
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
None
|
|
24
|
+
"""
|
|
25
|
+
return eval_local_source(source)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def process_kwargs(
|
|
29
|
+
project: str,
|
|
30
|
+
name: str,
|
|
31
|
+
source: str | list[str],
|
|
32
|
+
path: str | None = None,
|
|
33
|
+
**kwargs,
|
|
34
|
+
) -> dict:
|
|
35
|
+
"""
|
|
36
|
+
Process spec kwargs.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
project : str
|
|
41
|
+
Project name.
|
|
42
|
+
name : str
|
|
43
|
+
Object name.
|
|
44
|
+
source : str
|
|
45
|
+
Source(s).
|
|
46
|
+
path : str
|
|
47
|
+
Destination path of the entity. If not provided, it's generated.
|
|
48
|
+
**kwargs : dict
|
|
49
|
+
Spec parameters.
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
dict
|
|
54
|
+
Kwargs updated.
|
|
55
|
+
"""
|
|
56
|
+
if path is None:
|
|
57
|
+
uuid = build_uuid()
|
|
58
|
+
kwargs["uuid"] = uuid
|
|
59
|
+
kwargs["path"] = build_log_path_from_source(project, EntityTypes.MODEL.value, name, uuid, source)
|
|
60
|
+
else:
|
|
61
|
+
kwargs["path"] = path
|
|
62
|
+
return kwargs
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.versioned.builder import VersionedBuilder
|
|
6
|
-
from digitalhub.entities.
|
|
6
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
7
|
from digitalhub.utils.exceptions import EntityError
|
|
8
8
|
|
|
9
9
|
if typing.TYPE_CHECKING:
|
|
@@ -4,9 +4,10 @@ import typing
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
|
|
6
6
|
from digitalhub.entities._base.material.entity import MaterialEntity
|
|
7
|
-
from digitalhub.entities.
|
|
7
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
8
|
+
from digitalhub.readers._commons.enums import Extensions
|
|
8
9
|
from digitalhub.utils.exceptions import EntityError
|
|
9
|
-
from digitalhub.utils.uri_utils import
|
|
10
|
+
from digitalhub.utils.uri_utils import has_sql_scheme
|
|
10
11
|
|
|
11
12
|
if typing.TYPE_CHECKING:
|
|
12
13
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -37,7 +38,7 @@ class Dataitem(MaterialEntity):
|
|
|
37
38
|
self.status: DataitemStatus
|
|
38
39
|
|
|
39
40
|
##############################
|
|
40
|
-
#
|
|
41
|
+
# Helper methods
|
|
41
42
|
##############################
|
|
42
43
|
|
|
43
44
|
@staticmethod
|
|
@@ -65,9 +66,8 @@ class Dataitem(MaterialEntity):
|
|
|
65
66
|
if file_format is not None:
|
|
66
67
|
return file_format
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return "parquet"
|
|
69
|
+
if has_sql_scheme(path):
|
|
70
|
+
return Extensions.PARQUET.value
|
|
71
71
|
|
|
72
72
|
ext = Path(path).suffix[1:]
|
|
73
73
|
if ext is not None:
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
|
-
from pathlib import Path
|
|
5
4
|
from typing import Any
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
from digitalhub.entities.
|
|
9
|
-
|
|
10
|
-
get_material_entity,
|
|
11
|
-
get_material_entity_versions,
|
|
12
|
-
import_context_entity,
|
|
13
|
-
list_material_entities,
|
|
14
|
-
new_context_entity,
|
|
15
|
-
)
|
|
16
|
-
from digitalhub.entities._base.entity._constructors.uuid import build_uuid
|
|
17
|
-
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
18
|
-
from digitalhub.entities.utils.utils import build_log_path_from_filename, build_log_path_from_source, eval_local_source
|
|
19
|
-
from digitalhub.factory.api import build_entity_from_params
|
|
20
|
-
from digitalhub.readers.api import get_reader_by_object
|
|
21
|
-
from digitalhub.stores.api import get_store
|
|
22
|
-
from digitalhub.utils.generic_utils import slugify_string
|
|
5
|
+
|
|
6
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
|
+
from digitalhub.entities._operations.processor import processor
|
|
8
|
+
from digitalhub.entities.dataitem.utils import clean_tmp_path, eval_source, post_process, process_kwargs
|
|
23
9
|
|
|
24
10
|
if typing.TYPE_CHECKING:
|
|
25
11
|
from digitalhub.entities.dataitem._base.entity import Dataitem
|
|
@@ -75,7 +61,7 @@ def new_dataitem(
|
|
|
75
61
|
>>> kind="dataitem",
|
|
76
62
|
>>> path="s3://my-bucket/my-key")
|
|
77
63
|
"""
|
|
78
|
-
return
|
|
64
|
+
return processor.create_context_entity(
|
|
79
65
|
project=project,
|
|
80
66
|
name=name,
|
|
81
67
|
kind=kind,
|
|
@@ -94,7 +80,6 @@ def log_dataitem(
|
|
|
94
80
|
kind: str,
|
|
95
81
|
source: list[str] | str | None = None,
|
|
96
82
|
data: Any | None = None,
|
|
97
|
-
extension: str | None = None,
|
|
98
83
|
path: str | None = None,
|
|
99
84
|
**kwargs,
|
|
100
85
|
) -> Dataitem:
|
|
@@ -113,8 +98,6 @@ def log_dataitem(
|
|
|
113
98
|
Dataitem location on local path.
|
|
114
99
|
data : Any
|
|
115
100
|
Dataframe to log. Alternative to source.
|
|
116
|
-
extension : str
|
|
117
|
-
Extension of the output dataframe.
|
|
118
101
|
path : str
|
|
119
102
|
Destination path of the dataitem. If not provided, it's generated.
|
|
120
103
|
**kwargs : dict
|
|
@@ -132,43 +115,18 @@ def log_dataitem(
|
|
|
132
115
|
>>> kind="table",
|
|
133
116
|
>>> data=df)
|
|
134
117
|
"""
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
obj = new_dataitem(project=project, name=name, kind=kind, path=path, **kwargs)
|
|
148
|
-
obj.upload(source)
|
|
149
|
-
|
|
150
|
-
# Case where data is provided
|
|
151
|
-
else:
|
|
152
|
-
extension = extension if extension is not None else "parquet"
|
|
153
|
-
if path is None:
|
|
154
|
-
uuid = build_uuid()
|
|
155
|
-
kwargs["uuid"] = uuid
|
|
156
|
-
slug = slugify_string(name) + f".{extension}"
|
|
157
|
-
path = build_log_path_from_filename(project, ENTITY_TYPE, name, uuid, slug)
|
|
158
|
-
|
|
159
|
-
obj = build_entity_from_params(project=project, name=name, kind=kind, path=path, **kwargs)
|
|
160
|
-
if kind == "table":
|
|
161
|
-
dst = obj.write_df(df=data, extension=extension)
|
|
162
|
-
reader = get_reader_by_object(data)
|
|
163
|
-
obj.spec.schema = reader.get_schema(data)
|
|
164
|
-
obj.status.preview = reader.get_preview(data)
|
|
165
|
-
store = get_store(obj.spec.path)
|
|
166
|
-
src = Path(urlparse(obj.spec.path).path).name
|
|
167
|
-
paths = [(dst, src)]
|
|
168
|
-
infos = store.get_file_info(paths)
|
|
169
|
-
obj.status.add_files_info(infos)
|
|
170
|
-
obj.save()
|
|
171
|
-
|
|
118
|
+
source = eval_source(source, data, kind, name, project)
|
|
119
|
+
kwargs = process_kwargs(project, name, kind, source=source, data=data, path=path, **kwargs)
|
|
120
|
+
obj = processor.log_material_entity(
|
|
121
|
+
source=source,
|
|
122
|
+
project=project,
|
|
123
|
+
name=name,
|
|
124
|
+
kind=kind,
|
|
125
|
+
**kwargs,
|
|
126
|
+
)
|
|
127
|
+
if data is not None:
|
|
128
|
+
obj = post_process(obj, data)
|
|
129
|
+
clean_tmp_path(source)
|
|
172
130
|
return obj
|
|
173
131
|
|
|
174
132
|
|
|
@@ -207,7 +165,7 @@ def get_dataitem(
|
|
|
207
165
|
>>> project="my-project",
|
|
208
166
|
>>> entity_id="my-dataitem-id")
|
|
209
167
|
"""
|
|
210
|
-
return
|
|
168
|
+
return processor.read_material_entity(
|
|
211
169
|
identifier=identifier,
|
|
212
170
|
entity_type=ENTITY_TYPE,
|
|
213
171
|
project=project,
|
|
@@ -247,7 +205,7 @@ def get_dataitem_versions(
|
|
|
247
205
|
>>> objs = get_dataitem_versions("my-dataitem-name",
|
|
248
206
|
>>> project="my-project")
|
|
249
207
|
"""
|
|
250
|
-
return
|
|
208
|
+
return processor.read_material_entity_versions(
|
|
251
209
|
identifier=identifier,
|
|
252
210
|
entity_type=ENTITY_TYPE,
|
|
253
211
|
project=project,
|
|
@@ -275,7 +233,7 @@ def list_dataitems(project: str, **kwargs) -> list[Dataitem]:
|
|
|
275
233
|
--------
|
|
276
234
|
>>> objs = list_dataitems(project="my-project")
|
|
277
235
|
"""
|
|
278
|
-
return list_material_entities(
|
|
236
|
+
return processor.list_material_entities(
|
|
279
237
|
project=project,
|
|
280
238
|
entity_type=ENTITY_TYPE,
|
|
281
239
|
**kwargs,
|
|
@@ -284,7 +242,7 @@ def list_dataitems(project: str, **kwargs) -> list[Dataitem]:
|
|
|
284
242
|
|
|
285
243
|
def import_dataitem(file: str) -> Dataitem:
|
|
286
244
|
"""
|
|
287
|
-
Import object from a YAML file.
|
|
245
|
+
Import object from a YAML file and create a new object into the backend.
|
|
288
246
|
|
|
289
247
|
Parameters
|
|
290
248
|
----------
|
|
@@ -300,7 +258,28 @@ def import_dataitem(file: str) -> Dataitem:
|
|
|
300
258
|
--------
|
|
301
259
|
>>> obj = import_dataitem("my-dataitem.yaml")
|
|
302
260
|
"""
|
|
303
|
-
return import_context_entity(file)
|
|
261
|
+
return processor.import_context_entity(file)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def load_dataitem(file: str) -> Dataitem:
|
|
265
|
+
"""
|
|
266
|
+
Load object from a YAML file and update an existing object into the backend.
|
|
267
|
+
|
|
268
|
+
Parameters
|
|
269
|
+
----------
|
|
270
|
+
file : str
|
|
271
|
+
Path to YAML file.
|
|
272
|
+
|
|
273
|
+
Returns
|
|
274
|
+
-------
|
|
275
|
+
Dataitem
|
|
276
|
+
Object instance.
|
|
277
|
+
|
|
278
|
+
Examples
|
|
279
|
+
--------
|
|
280
|
+
>>> obj = load_dataitem("my-dataitem.yaml")
|
|
281
|
+
"""
|
|
282
|
+
return processor.load_context_entity(file)
|
|
304
283
|
|
|
305
284
|
|
|
306
285
|
def update_dataitem(entity: Dataitem) -> Dataitem:
|
|
@@ -321,7 +300,12 @@ def update_dataitem(entity: Dataitem) -> Dataitem:
|
|
|
321
300
|
--------
|
|
322
301
|
>>> obj = update_dataitem(obj)
|
|
323
302
|
"""
|
|
324
|
-
return
|
|
303
|
+
return processor.update_context_entity(
|
|
304
|
+
project=entity.project,
|
|
305
|
+
entity_type=entity.ENTITY_TYPE,
|
|
306
|
+
entity_id=entity.id,
|
|
307
|
+
entity_dict=entity.to_dict(),
|
|
308
|
+
)
|
|
325
309
|
|
|
326
310
|
|
|
327
311
|
def delete_dataitem(
|
|
@@ -362,7 +346,7 @@ def delete_dataitem(
|
|
|
362
346
|
>>> project="my-project",
|
|
363
347
|
>>> delete_all_versions=True)
|
|
364
348
|
"""
|
|
365
|
-
return
|
|
349
|
+
return processor.delete_context_entity(
|
|
366
350
|
identifier=identifier,
|
|
367
351
|
entity_type=ENTITY_TYPE,
|
|
368
352
|
project=project,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from digitalhub.entities._commons.enums import EntityKinds
|
|
3
4
|
from digitalhub.entities.dataitem._base.builder import DataitemBuilder
|
|
4
5
|
from digitalhub.entities.dataitem.dataitem.entity import DataitemDataitem
|
|
5
6
|
from digitalhub.entities.dataitem.dataitem.spec import DataitemSpecDataitem, DataitemValidatorDataitem
|
|
@@ -15,4 +16,4 @@ class DataitemDataitemBuilder(DataitemBuilder):
|
|
|
15
16
|
ENTITY_SPEC_CLASS = DataitemSpecDataitem
|
|
16
17
|
ENTITY_SPEC_VALIDATOR = DataitemValidatorDataitem
|
|
17
18
|
ENTITY_STATUS_CLASS = DataitemStatusDataitem
|
|
18
|
-
ENTITY_KIND =
|
|
19
|
+
ENTITY_KIND = EntityKinds.DATAITEM_DATAITEM.value
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from digitalhub.entities._commons.enums import EntityKinds
|
|
3
4
|
from digitalhub.entities.dataitem._base.builder import DataitemBuilder
|
|
4
5
|
from digitalhub.entities.dataitem.iceberg.entity import DataitemIceberg
|
|
5
6
|
from digitalhub.entities.dataitem.iceberg.spec import DataitemSpecIceberg, DataitemValidatorIceberg
|
|
@@ -15,4 +16,4 @@ class DataitemIcebergBuilder(DataitemBuilder):
|
|
|
15
16
|
ENTITY_SPEC_CLASS = DataitemSpecIceberg
|
|
16
17
|
ENTITY_SPEC_VALIDATOR = DataitemValidatorIceberg
|
|
17
18
|
ENTITY_STATUS_CLASS = DataitemStatusIceberg
|
|
18
|
-
ENTITY_KIND =
|
|
19
|
+
ENTITY_KIND = EntityKinds.DATAITEM_ICEBERG.value
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from digitalhub.entities._commons.enums import EntityKinds
|
|
3
4
|
from digitalhub.entities.dataitem._base.builder import DataitemBuilder
|
|
4
5
|
from digitalhub.entities.dataitem.table.entity import DataitemTable
|
|
5
6
|
from digitalhub.entities.dataitem.table.spec import DataitemSpecTable, DataitemValidatorTable
|
|
@@ -15,4 +16,4 @@ class DataitemTableBuilder(DataitemBuilder):
|
|
|
15
16
|
ENTITY_SPEC_CLASS = DataitemSpecTable
|
|
16
17
|
ENTITY_SPEC_VALIDATOR = DataitemValidatorTable
|
|
17
18
|
ENTITY_STATUS_CLASS = DataitemStatusTable
|
|
18
|
-
ENTITY_KIND =
|
|
19
|
+
ENTITY_KIND = EntityKinds.DATAITEM_TABLE.value
|
|
@@ -5,9 +5,9 @@ import typing
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
8
|
-
from digitalhub.datastores.api import get_datastore
|
|
9
8
|
from digitalhub.entities.dataitem._base.entity import Dataitem
|
|
10
|
-
from digitalhub.
|
|
9
|
+
from digitalhub.stores.api import get_store
|
|
10
|
+
from digitalhub.utils.uri_utils import has_local_scheme
|
|
11
11
|
|
|
12
12
|
if typing.TYPE_CHECKING:
|
|
13
13
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -69,10 +69,8 @@ class DataitemTable(Dataitem):
|
|
|
69
69
|
Any
|
|
70
70
|
DataFrame.
|
|
71
71
|
"""
|
|
72
|
-
if engine is None:
|
|
73
|
-
engine = "pandas"
|
|
74
72
|
try:
|
|
75
|
-
if
|
|
73
|
+
if has_local_scheme(self.spec.path):
|
|
76
74
|
tmp_dir = None
|
|
77
75
|
data_path = self.spec.path
|
|
78
76
|
else:
|
|
@@ -87,9 +85,7 @@ class DataitemTable(Dataitem):
|
|
|
87
85
|
checker = data_path
|
|
88
86
|
|
|
89
87
|
extension = self._get_extension(checker, file_format)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return datastore.read_df(data_path, extension, engine, **kwargs)
|
|
88
|
+
return get_store("").read_df(data_path, extension, engine, **kwargs)
|
|
93
89
|
|
|
94
90
|
except Exception as e:
|
|
95
91
|
raise e
|
|
@@ -123,8 +119,7 @@ class DataitemTable(Dataitem):
|
|
|
123
119
|
str
|
|
124
120
|
Path to the written dataframe.
|
|
125
121
|
"""
|
|
126
|
-
|
|
127
|
-
return datastore.write_df(df, self.spec.path, extension=extension, **kwargs)
|
|
122
|
+
return get_store(self.spec.path).write_df(df, self.spec.path, extension=extension, **kwargs)
|
|
128
123
|
|
|
129
124
|
@staticmethod
|
|
130
125
|
def _clean_tmp_path(pth: Path | None, clean: bool) -> None:
|
|
@@ -2,10 +2,10 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from enum import Enum
|
|
4
4
|
|
|
5
|
-
from pydantic import BaseModel, Field
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
class FieldType(
|
|
8
|
+
class FieldType(Enum):
|
|
9
9
|
"""
|
|
10
10
|
Field type enum.
|
|
11
11
|
"""
|
|
@@ -32,6 +32,8 @@ class TableSchemaFieldEntry(BaseModel):
|
|
|
32
32
|
Table schema field entry model.
|
|
33
33
|
"""
|
|
34
34
|
|
|
35
|
+
model_config = ConfigDict(use_enum_values=True)
|
|
36
|
+
|
|
35
37
|
name: str
|
|
36
38
|
"""Field name."""
|
|
37
39
|
|
|
@@ -50,9 +52,6 @@ class TableSchemaFieldEntry(BaseModel):
|
|
|
50
52
|
description: str = None
|
|
51
53
|
"""Field description."""
|
|
52
54
|
|
|
53
|
-
class Config:
|
|
54
|
-
use_enum_values = True
|
|
55
|
-
|
|
56
55
|
|
|
57
56
|
class TableSchema(BaseModel):
|
|
58
57
|
"""
|