digitalhub 0.13.0b3__py3-none-any.whl → 0.14.9__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.
- digitalhub/__init__.py +3 -8
- digitalhub/context/api.py +43 -6
- digitalhub/context/builder.py +1 -5
- digitalhub/context/context.py +28 -13
- digitalhub/entities/_base/_base/entity.py +0 -15
- digitalhub/entities/_base/context/entity.py +1 -4
- digitalhub/entities/_base/entity/builder.py +5 -5
- digitalhub/entities/_base/entity/entity.py +0 -8
- digitalhub/entities/_base/executable/entity.py +195 -87
- digitalhub/entities/_base/material/entity.py +11 -23
- digitalhub/entities/_base/material/utils.py +28 -4
- digitalhub/entities/_base/runtime_entity/builder.py +53 -18
- digitalhub/entities/_base/unversioned/entity.py +1 -1
- digitalhub/entities/_base/versioned/entity.py +1 -1
- digitalhub/entities/_commons/enums.py +1 -31
- digitalhub/entities/_commons/metrics.py +64 -30
- digitalhub/entities/_commons/utils.py +119 -30
- digitalhub/entities/_constructors/_resources.py +151 -0
- digitalhub/entities/{_base/entity/_constructors → _constructors}/name.py +18 -0
- digitalhub/entities/_processors/base/crud.py +381 -0
- digitalhub/entities/_processors/base/import_export.py +118 -0
- digitalhub/entities/_processors/base/processor.py +299 -0
- digitalhub/entities/_processors/base/special_ops.py +104 -0
- digitalhub/entities/_processors/context/crud.py +652 -0
- digitalhub/entities/_processors/context/import_export.py +242 -0
- digitalhub/entities/_processors/context/material.py +123 -0
- digitalhub/entities/_processors/context/processor.py +400 -0
- digitalhub/entities/_processors/context/special_ops.py +476 -0
- digitalhub/entities/_processors/processors.py +12 -0
- digitalhub/entities/_processors/utils.py +38 -102
- digitalhub/entities/artifact/crud.py +58 -22
- digitalhub/entities/artifact/utils.py +28 -13
- digitalhub/entities/builders.py +2 -0
- digitalhub/entities/dataitem/crud.py +63 -20
- digitalhub/entities/dataitem/table/entity.py +27 -22
- digitalhub/entities/dataitem/utils.py +82 -32
- digitalhub/entities/function/_base/entity.py +3 -6
- digitalhub/entities/function/crud.py +55 -24
- digitalhub/entities/model/_base/entity.py +62 -20
- digitalhub/entities/model/crud.py +59 -23
- digitalhub/entities/model/mlflow/utils.py +29 -20
- digitalhub/entities/model/utils.py +28 -13
- digitalhub/entities/project/_base/builder.py +0 -6
- digitalhub/entities/project/_base/entity.py +337 -164
- digitalhub/entities/project/_base/spec.py +4 -4
- digitalhub/entities/project/crud.py +28 -71
- digitalhub/entities/project/utils.py +7 -3
- digitalhub/entities/run/_base/builder.py +0 -4
- digitalhub/entities/run/_base/entity.py +70 -63
- digitalhub/entities/run/crud.py +79 -26
- digitalhub/entities/secret/_base/entity.py +1 -5
- digitalhub/entities/secret/crud.py +31 -28
- digitalhub/entities/task/_base/builder.py +0 -4
- digitalhub/entities/task/_base/entity.py +5 -5
- digitalhub/entities/task/_base/models.py +13 -16
- digitalhub/entities/task/crud.py +61 -29
- digitalhub/entities/trigger/_base/entity.py +1 -5
- digitalhub/entities/trigger/crud.py +89 -30
- digitalhub/entities/workflow/_base/entity.py +3 -8
- digitalhub/entities/workflow/crud.py +55 -24
- digitalhub/factory/entity.py +283 -0
- digitalhub/factory/enums.py +18 -0
- digitalhub/factory/registry.py +197 -0
- digitalhub/factory/runtime.py +44 -0
- digitalhub/factory/utils.py +3 -54
- digitalhub/runtimes/_base.py +2 -2
- digitalhub/stores/client/{dhcore/api_builder.py → api_builder.py} +3 -3
- digitalhub/stores/client/builder.py +19 -31
- digitalhub/stores/client/client.py +322 -0
- digitalhub/stores/client/configurator.py +408 -0
- digitalhub/stores/client/enums.py +50 -0
- digitalhub/stores/client/{dhcore/error_parser.py → error_parser.py} +0 -4
- digitalhub/stores/client/header_manager.py +61 -0
- digitalhub/stores/client/http_handler.py +152 -0
- digitalhub/stores/client/{_base/key_builder.py → key_builder.py} +14 -14
- digitalhub/stores/client/params_builder.py +330 -0
- digitalhub/stores/client/response_processor.py +102 -0
- digitalhub/stores/client/utils.py +35 -0
- digitalhub/stores/{credentials → configurator}/api.py +5 -9
- digitalhub/stores/configurator/configurator.py +123 -0
- digitalhub/stores/{credentials → configurator}/enums.py +27 -10
- digitalhub/stores/configurator/handler.py +213 -0
- digitalhub/stores/{credentials → configurator}/ini_module.py +31 -22
- digitalhub/stores/data/_base/store.py +0 -20
- digitalhub/stores/data/api.py +5 -7
- digitalhub/stores/data/builder.py +53 -27
- digitalhub/stores/data/local/store.py +0 -103
- digitalhub/stores/data/remote/store.py +0 -4
- digitalhub/stores/data/s3/configurator.py +39 -77
- digitalhub/stores/data/s3/store.py +57 -37
- digitalhub/stores/data/sql/configurator.py +66 -46
- digitalhub/stores/data/sql/store.py +171 -104
- digitalhub/stores/readers/data/factory.py +0 -8
- digitalhub/stores/readers/data/pandas/reader.py +9 -19
- digitalhub/utils/file_utils.py +0 -17
- digitalhub/utils/generic_utils.py +1 -14
- digitalhub/utils/git_utils.py +0 -8
- digitalhub/utils/io_utils.py +0 -12
- digitalhub/utils/store_utils.py +44 -0
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/METADATA +5 -4
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/RECORD +112 -113
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/WHEEL +1 -1
- digitalhub/entities/_commons/types.py +0 -9
- digitalhub/entities/_processors/base.py +0 -531
- digitalhub/entities/_processors/context.py +0 -1299
- digitalhub/entities/task/_base/utils.py +0 -22
- digitalhub/factory/factory.py +0 -381
- digitalhub/stores/client/_base/api_builder.py +0 -34
- digitalhub/stores/client/_base/client.py +0 -243
- digitalhub/stores/client/_base/params_builder.py +0 -34
- digitalhub/stores/client/api.py +0 -36
- digitalhub/stores/client/dhcore/client.py +0 -613
- digitalhub/stores/client/dhcore/configurator.py +0 -675
- digitalhub/stores/client/dhcore/enums.py +0 -34
- digitalhub/stores/client/dhcore/key_builder.py +0 -62
- digitalhub/stores/client/dhcore/models.py +0 -40
- digitalhub/stores/client/dhcore/params_builder.py +0 -278
- digitalhub/stores/client/dhcore/utils.py +0 -94
- digitalhub/stores/client/local/api_builder.py +0 -116
- digitalhub/stores/client/local/client.py +0 -573
- digitalhub/stores/client/local/enums.py +0 -15
- digitalhub/stores/client/local/key_builder.py +0 -62
- digitalhub/stores/client/local/params_builder.py +0 -120
- digitalhub/stores/credentials/__init__.py +0 -3
- digitalhub/stores/credentials/configurator.py +0 -210
- digitalhub/stores/credentials/handler.py +0 -176
- digitalhub/stores/credentials/store.py +0 -81
- digitalhub/stores/data/enums.py +0 -15
- 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}/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/{stores/client/_base → entities/_processors/base}/__init__.py +0 -0
- /digitalhub/{stores/client/dhcore → entities/_processors/context}/__init__.py +0 -0
- /digitalhub/stores/{client/local → configurator}/__init__.py +0 -0
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/licenses/LICENSE +0 -0
|
@@ -7,7 +7,7 @@ from __future__ import annotations
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
9
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
10
|
-
from digitalhub.entities._processors.
|
|
10
|
+
from digitalhub.entities._processors.processors import context_processor
|
|
11
11
|
from digitalhub.entities.artifact._base.entity import Artifact
|
|
12
12
|
from digitalhub.entities.artifact.utils import eval_source, process_kwargs
|
|
13
13
|
from digitalhub.utils.types import SourcesOrListOfSources
|
|
@@ -132,7 +132,6 @@ def get_artifact(
|
|
|
132
132
|
identifier: str,
|
|
133
133
|
project: str | None = None,
|
|
134
134
|
entity_id: str | None = None,
|
|
135
|
-
**kwargs,
|
|
136
135
|
) -> Artifact:
|
|
137
136
|
"""
|
|
138
137
|
Get object from backend.
|
|
@@ -145,8 +144,6 @@ def get_artifact(
|
|
|
145
144
|
Project name.
|
|
146
145
|
entity_id : str
|
|
147
146
|
Entity ID.
|
|
148
|
-
**kwargs : dict
|
|
149
|
-
Parameters to pass to the API call.
|
|
150
147
|
|
|
151
148
|
Returns
|
|
152
149
|
-------
|
|
@@ -168,14 +165,12 @@ def get_artifact(
|
|
|
168
165
|
entity_type=ENTITY_TYPE,
|
|
169
166
|
project=project,
|
|
170
167
|
entity_id=entity_id,
|
|
171
|
-
**kwargs,
|
|
172
168
|
)
|
|
173
169
|
|
|
174
170
|
|
|
175
171
|
def get_artifact_versions(
|
|
176
172
|
identifier: str,
|
|
177
173
|
project: str | None = None,
|
|
178
|
-
**kwargs,
|
|
179
174
|
) -> list[Artifact]:
|
|
180
175
|
"""
|
|
181
176
|
Get object versions from backend.
|
|
@@ -186,8 +181,6 @@ def get_artifact_versions(
|
|
|
186
181
|
Entity key (store://...) or entity name.
|
|
187
182
|
project : str
|
|
188
183
|
Project name.
|
|
189
|
-
**kwargs : dict
|
|
190
|
-
Parameters to pass to the API call.
|
|
191
184
|
|
|
192
185
|
Returns
|
|
193
186
|
-------
|
|
@@ -207,11 +200,20 @@ def get_artifact_versions(
|
|
|
207
200
|
identifier=identifier,
|
|
208
201
|
entity_type=ENTITY_TYPE,
|
|
209
202
|
project=project,
|
|
210
|
-
**kwargs,
|
|
211
203
|
)
|
|
212
204
|
|
|
213
205
|
|
|
214
|
-
def list_artifacts(
|
|
206
|
+
def list_artifacts(
|
|
207
|
+
project: str,
|
|
208
|
+
q: str | None = None,
|
|
209
|
+
name: str | None = None,
|
|
210
|
+
kind: str | None = None,
|
|
211
|
+
user: str | None = None,
|
|
212
|
+
state: str | None = None,
|
|
213
|
+
created: str | None = None,
|
|
214
|
+
updated: str | None = None,
|
|
215
|
+
versions: str | None = None,
|
|
216
|
+
) -> list[Artifact]:
|
|
215
217
|
"""
|
|
216
218
|
List all latest version objects from backend.
|
|
217
219
|
|
|
@@ -219,8 +221,22 @@ def list_artifacts(project: str, **kwargs) -> list[Artifact]:
|
|
|
219
221
|
----------
|
|
220
222
|
project : str
|
|
221
223
|
Project name.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
+
q : str
|
|
225
|
+
Query string to filter objects.
|
|
226
|
+
name : str
|
|
227
|
+
Object name.
|
|
228
|
+
kind : str
|
|
229
|
+
Kind of the object.
|
|
230
|
+
user : str
|
|
231
|
+
User that created the object.
|
|
232
|
+
state : str
|
|
233
|
+
Object state.
|
|
234
|
+
created : str
|
|
235
|
+
Creation date filter.
|
|
236
|
+
updated : str
|
|
237
|
+
Update date filter.
|
|
238
|
+
versions : str
|
|
239
|
+
Object version, default is latest.
|
|
224
240
|
|
|
225
241
|
Returns
|
|
226
242
|
-------
|
|
@@ -234,18 +250,36 @@ def list_artifacts(project: str, **kwargs) -> list[Artifact]:
|
|
|
234
250
|
return context_processor.list_context_entities(
|
|
235
251
|
project=project,
|
|
236
252
|
entity_type=ENTITY_TYPE,
|
|
237
|
-
|
|
253
|
+
q=q,
|
|
254
|
+
name=name,
|
|
255
|
+
kind=kind,
|
|
256
|
+
user=user,
|
|
257
|
+
state=state,
|
|
258
|
+
created=created,
|
|
259
|
+
updated=updated,
|
|
260
|
+
versions=versions,
|
|
238
261
|
)
|
|
239
262
|
|
|
240
263
|
|
|
241
|
-
def import_artifact(
|
|
264
|
+
def import_artifact(
|
|
265
|
+
file: str | None = None,
|
|
266
|
+
key: str | None = None,
|
|
267
|
+
reset_id: bool = False,
|
|
268
|
+
context: str | None = None,
|
|
269
|
+
) -> Artifact:
|
|
242
270
|
"""
|
|
243
|
-
Import object from a YAML file
|
|
271
|
+
Import an object from a YAML file or from a storage key.
|
|
244
272
|
|
|
245
273
|
Parameters
|
|
246
274
|
----------
|
|
247
275
|
file : str
|
|
248
|
-
Path to YAML file.
|
|
276
|
+
Path to the YAML file.
|
|
277
|
+
key : str
|
|
278
|
+
Entity key (store://...).
|
|
279
|
+
reset_id : bool
|
|
280
|
+
Flag to determine if the ID of executable entities should be reset.
|
|
281
|
+
context : str
|
|
282
|
+
Project name to use for context resolution.
|
|
249
283
|
|
|
250
284
|
Returns
|
|
251
285
|
-------
|
|
@@ -256,7 +290,12 @@ def import_artifact(file: str) -> Artifact:
|
|
|
256
290
|
--------
|
|
257
291
|
>>> obj = import_artifact("my-artifact.yaml")
|
|
258
292
|
"""
|
|
259
|
-
return context_processor.import_context_entity(
|
|
293
|
+
return context_processor.import_context_entity(
|
|
294
|
+
file,
|
|
295
|
+
key,
|
|
296
|
+
reset_id,
|
|
297
|
+
context,
|
|
298
|
+
)
|
|
260
299
|
|
|
261
300
|
|
|
262
301
|
def load_artifact(file: str) -> Artifact:
|
|
@@ -312,7 +351,6 @@ def delete_artifact(
|
|
|
312
351
|
entity_id: str | None = None,
|
|
313
352
|
delete_all_versions: bool = False,
|
|
314
353
|
cascade: bool = True,
|
|
315
|
-
**kwargs,
|
|
316
354
|
) -> dict:
|
|
317
355
|
"""
|
|
318
356
|
Delete object from backend.
|
|
@@ -326,11 +364,10 @@ def delete_artifact(
|
|
|
326
364
|
entity_id : str
|
|
327
365
|
Entity ID.
|
|
328
366
|
delete_all_versions : bool
|
|
329
|
-
Delete all versions of the named entity.
|
|
367
|
+
Delete all versions of the named entity.
|
|
368
|
+
If True, use entity name instead of entity key as identifier.
|
|
330
369
|
cascade : bool
|
|
331
370
|
Cascade delete.
|
|
332
|
-
**kwargs : dict
|
|
333
|
-
Parameters to pass to the API call.
|
|
334
371
|
|
|
335
372
|
Returns
|
|
336
373
|
-------
|
|
@@ -354,5 +391,4 @@ def delete_artifact(
|
|
|
354
391
|
entity_id=entity_id,
|
|
355
392
|
delete_all_versions=delete_all_versions,
|
|
356
393
|
cascade=cascade,
|
|
357
|
-
**kwargs,
|
|
358
394
|
)
|
|
@@ -6,25 +6,32 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
9
|
-
from digitalhub.entities._base.entity._constructors.uuid import build_uuid
|
|
10
9
|
from digitalhub.entities._base.material.utils import build_log_path_from_source, eval_local_source
|
|
11
10
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
11
|
+
from digitalhub.entities._constructors.uuid import build_uuid
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def eval_source(
|
|
15
15
|
source: str | list[str] | None = None,
|
|
16
16
|
) -> Any:
|
|
17
17
|
"""
|
|
18
|
-
Evaluate
|
|
18
|
+
Evaluate whether the source is local or remote.
|
|
19
|
+
|
|
20
|
+
Determines if the provided source(s) reference local files or
|
|
21
|
+
remote resources. This evaluation affects how the artifact
|
|
22
|
+
will be processed and stored.
|
|
19
23
|
|
|
20
24
|
Parameters
|
|
21
25
|
----------
|
|
22
|
-
source : str
|
|
23
|
-
|
|
26
|
+
source : str, list[str], or None
|
|
27
|
+
The source specification(s) to evaluate. Can be a single
|
|
28
|
+
source string, a list of source strings, or None.
|
|
24
29
|
|
|
25
30
|
Returns
|
|
26
31
|
-------
|
|
27
|
-
|
|
32
|
+
Any
|
|
33
|
+
The result of the local source evaluation, indicating
|
|
34
|
+
whether the source is local or remote.
|
|
28
35
|
"""
|
|
29
36
|
return eval_local_source(source)
|
|
30
37
|
|
|
@@ -37,25 +44,33 @@ def process_kwargs(
|
|
|
37
44
|
**kwargs,
|
|
38
45
|
) -> dict:
|
|
39
46
|
"""
|
|
40
|
-
Process
|
|
47
|
+
Process and enhance specification parameters for artifact creation.
|
|
48
|
+
|
|
49
|
+
Processes the keyword arguments for artifact specification, handling
|
|
50
|
+
path generation and UUID assignment. If no path is provided, generates
|
|
51
|
+
a unique path based on project, entity type, name, and source.
|
|
41
52
|
|
|
42
53
|
Parameters
|
|
43
54
|
----------
|
|
44
55
|
project : str
|
|
45
|
-
|
|
56
|
+
The name of the project.
|
|
46
57
|
name : str
|
|
47
|
-
|
|
48
|
-
source : str
|
|
49
|
-
|
|
58
|
+
The name of the artifact entity.
|
|
59
|
+
source : str or list[str]
|
|
60
|
+
The source specification(s) for the artifact content.
|
|
61
|
+
Can be a single source or multiple sources.
|
|
50
62
|
path : str
|
|
51
|
-
|
|
63
|
+
The destination path for the artifact entity.
|
|
64
|
+
If None, a path will be automatically generated.
|
|
52
65
|
**kwargs : dict
|
|
53
|
-
|
|
66
|
+
Additional specification parameters to be processed
|
|
67
|
+
and passed to the artifact creation.
|
|
54
68
|
|
|
55
69
|
Returns
|
|
56
70
|
-------
|
|
57
71
|
dict
|
|
58
|
-
|
|
72
|
+
The updated kwargs dictionary with processed path
|
|
73
|
+
and UUID information included.
|
|
59
74
|
"""
|
|
60
75
|
if path is None:
|
|
61
76
|
uuid = build_uuid()
|
digitalhub/entities/builders.py
CHANGED
|
@@ -10,6 +10,7 @@ from digitalhub.entities.dataitem.table.builder import DataitemTableBuilder
|
|
|
10
10
|
from digitalhub.entities.model.mlflow.builder import ModelModelBuilder
|
|
11
11
|
from digitalhub.entities.project._base.builder import ProjectProjectBuilder
|
|
12
12
|
from digitalhub.entities.secret._base.builder import SecretSecretBuilder
|
|
13
|
+
from digitalhub.entities.trigger.lifecycle.builder import TriggerLifecycleBuilder
|
|
13
14
|
from digitalhub.entities.trigger.scheduler.builder import TriggerSchedulerBuilder
|
|
14
15
|
|
|
15
16
|
entity_builders: tuple = (
|
|
@@ -20,6 +21,7 @@ entity_builders: tuple = (
|
|
|
20
21
|
(DataitemTableBuilder.ENTITY_KIND, DataitemTableBuilder),
|
|
21
22
|
(ModelModelBuilder.ENTITY_KIND, ModelModelBuilder),
|
|
22
23
|
(TriggerSchedulerBuilder.ENTITY_KIND, TriggerSchedulerBuilder),
|
|
24
|
+
(TriggerLifecycleBuilder.ENTITY_KIND, TriggerLifecycleBuilder),
|
|
23
25
|
)
|
|
24
26
|
|
|
25
27
|
##############################
|
|
@@ -8,7 +8,7 @@ import typing
|
|
|
8
8
|
from typing import Any
|
|
9
9
|
|
|
10
10
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
11
|
-
from digitalhub.entities._processors.
|
|
11
|
+
from digitalhub.entities._processors.processors import context_processor
|
|
12
12
|
from digitalhub.entities.dataitem.utils import clean_tmp_path, eval_data, eval_source, post_process, process_kwargs
|
|
13
13
|
from digitalhub.utils.types import SourcesOrListOfSources
|
|
14
14
|
|
|
@@ -87,6 +87,7 @@ def log_dataitem(
|
|
|
87
87
|
data: Any | None = None,
|
|
88
88
|
path: str | None = None,
|
|
89
89
|
file_format: str | None = None,
|
|
90
|
+
read_df_params: dict | None = None,
|
|
90
91
|
engine: str | None = "pandas",
|
|
91
92
|
**kwargs,
|
|
92
93
|
) -> Dataitem:
|
|
@@ -108,7 +109,9 @@ def log_dataitem(
|
|
|
108
109
|
path : str
|
|
109
110
|
Destination path of the dataitem. If not provided, it's generated.
|
|
110
111
|
file_format : str
|
|
111
|
-
Extension of the file.
|
|
112
|
+
Extension of the file source (parquet, csv, json, xlsx, txt).
|
|
113
|
+
read_df_params : dict
|
|
114
|
+
Parameters to pass to the dataframe reader.
|
|
112
115
|
engine : str
|
|
113
116
|
Dataframe engine (pandas, polars, etc.).
|
|
114
117
|
**kwargs : dict
|
|
@@ -131,7 +134,7 @@ def log_dataitem(
|
|
|
131
134
|
cleanup = True
|
|
132
135
|
|
|
133
136
|
source = eval_source(source, data, kind, name, project)
|
|
134
|
-
data = eval_data(kind, source, data, file_format, engine)
|
|
137
|
+
data = eval_data(kind, source, data, file_format, read_df_params, engine)
|
|
135
138
|
kwargs = process_kwargs(
|
|
136
139
|
project,
|
|
137
140
|
name,
|
|
@@ -158,7 +161,6 @@ def get_dataitem(
|
|
|
158
161
|
identifier: str,
|
|
159
162
|
project: str | None = None,
|
|
160
163
|
entity_id: str | None = None,
|
|
161
|
-
**kwargs,
|
|
162
164
|
) -> Dataitem:
|
|
163
165
|
"""
|
|
164
166
|
Get object from backend.
|
|
@@ -171,8 +173,6 @@ def get_dataitem(
|
|
|
171
173
|
Project name.
|
|
172
174
|
entity_id : str
|
|
173
175
|
Entity ID.
|
|
174
|
-
**kwargs : dict
|
|
175
|
-
Parameters to pass to the API call.
|
|
176
176
|
|
|
177
177
|
Returns
|
|
178
178
|
-------
|
|
@@ -194,14 +194,12 @@ def get_dataitem(
|
|
|
194
194
|
entity_type=ENTITY_TYPE,
|
|
195
195
|
project=project,
|
|
196
196
|
entity_id=entity_id,
|
|
197
|
-
**kwargs,
|
|
198
197
|
)
|
|
199
198
|
|
|
200
199
|
|
|
201
200
|
def get_dataitem_versions(
|
|
202
201
|
identifier: str,
|
|
203
202
|
project: str | None = None,
|
|
204
|
-
**kwargs,
|
|
205
203
|
) -> list[Dataitem]:
|
|
206
204
|
"""
|
|
207
205
|
Get object versions from backend.
|
|
@@ -212,8 +210,6 @@ def get_dataitem_versions(
|
|
|
212
210
|
Entity key (store://...) or entity name.
|
|
213
211
|
project : str
|
|
214
212
|
Project name.
|
|
215
|
-
**kwargs : dict
|
|
216
|
-
Parameters to pass to the API call.
|
|
217
213
|
|
|
218
214
|
Returns
|
|
219
215
|
-------
|
|
@@ -233,11 +229,20 @@ def get_dataitem_versions(
|
|
|
233
229
|
identifier=identifier,
|
|
234
230
|
entity_type=ENTITY_TYPE,
|
|
235
231
|
project=project,
|
|
236
|
-
**kwargs,
|
|
237
232
|
)
|
|
238
233
|
|
|
239
234
|
|
|
240
|
-
def list_dataitems(
|
|
235
|
+
def list_dataitems(
|
|
236
|
+
project: str,
|
|
237
|
+
q: str | None = None,
|
|
238
|
+
name: str | None = None,
|
|
239
|
+
kind: str | None = None,
|
|
240
|
+
user: str | None = None,
|
|
241
|
+
state: str | None = None,
|
|
242
|
+
created: str | None = None,
|
|
243
|
+
updated: str | None = None,
|
|
244
|
+
versions: str | None = None,
|
|
245
|
+
) -> list[Dataitem]:
|
|
241
246
|
"""
|
|
242
247
|
List all latest version objects from backend.
|
|
243
248
|
|
|
@@ -245,8 +250,22 @@ def list_dataitems(project: str, **kwargs) -> list[Dataitem]:
|
|
|
245
250
|
----------
|
|
246
251
|
project : str
|
|
247
252
|
Project name.
|
|
248
|
-
|
|
249
|
-
|
|
253
|
+
q : str
|
|
254
|
+
Query string to filter objects.
|
|
255
|
+
name : str
|
|
256
|
+
Object name.
|
|
257
|
+
kind : str
|
|
258
|
+
Kind of the object.
|
|
259
|
+
user : str
|
|
260
|
+
User that created the object.
|
|
261
|
+
state : str
|
|
262
|
+
Object state.
|
|
263
|
+
created : str
|
|
264
|
+
Creation date filter.
|
|
265
|
+
updated : str
|
|
266
|
+
Update date filter.
|
|
267
|
+
versions : str
|
|
268
|
+
Object version, default is latest.
|
|
250
269
|
|
|
251
270
|
Returns
|
|
252
271
|
-------
|
|
@@ -260,18 +279,36 @@ def list_dataitems(project: str, **kwargs) -> list[Dataitem]:
|
|
|
260
279
|
return context_processor.list_context_entities(
|
|
261
280
|
project=project,
|
|
262
281
|
entity_type=ENTITY_TYPE,
|
|
263
|
-
|
|
282
|
+
q=q,
|
|
283
|
+
name=name,
|
|
284
|
+
kind=kind,
|
|
285
|
+
user=user,
|
|
286
|
+
state=state,
|
|
287
|
+
created=created,
|
|
288
|
+
updated=updated,
|
|
289
|
+
versions=versions,
|
|
264
290
|
)
|
|
265
291
|
|
|
266
292
|
|
|
267
|
-
def import_dataitem(
|
|
293
|
+
def import_dataitem(
|
|
294
|
+
file: str | None = None,
|
|
295
|
+
key: str | None = None,
|
|
296
|
+
reset_id: bool = False,
|
|
297
|
+
context: str | None = None,
|
|
298
|
+
) -> Dataitem:
|
|
268
299
|
"""
|
|
269
|
-
Import object from a YAML file
|
|
300
|
+
Import an object from a YAML file or from a storage key.
|
|
270
301
|
|
|
271
302
|
Parameters
|
|
272
303
|
----------
|
|
273
304
|
file : str
|
|
274
|
-
Path to YAML file.
|
|
305
|
+
Path to the YAML file.
|
|
306
|
+
key : str
|
|
307
|
+
Entity key (store://...).
|
|
308
|
+
reset_id : bool
|
|
309
|
+
Flag to determine if the ID of executable entities should be reset.
|
|
310
|
+
context : str
|
|
311
|
+
Project name to use for context resolution.
|
|
275
312
|
|
|
276
313
|
Returns
|
|
277
314
|
-------
|
|
@@ -282,7 +319,12 @@ def import_dataitem(file: str) -> Dataitem:
|
|
|
282
319
|
--------
|
|
283
320
|
>>> obj = import_dataitem("my-dataitem.yaml")
|
|
284
321
|
"""
|
|
285
|
-
return context_processor.import_context_entity(
|
|
322
|
+
return context_processor.import_context_entity(
|
|
323
|
+
file,
|
|
324
|
+
key,
|
|
325
|
+
reset_id,
|
|
326
|
+
context,
|
|
327
|
+
)
|
|
286
328
|
|
|
287
329
|
|
|
288
330
|
def load_dataitem(file: str) -> Dataitem:
|
|
@@ -352,7 +394,8 @@ def delete_dataitem(
|
|
|
352
394
|
entity_id : str
|
|
353
395
|
Entity ID.
|
|
354
396
|
delete_all_versions : bool
|
|
355
|
-
Delete all versions of the named entity.
|
|
397
|
+
Delete all versions of the named entity.
|
|
398
|
+
If True, use entity name instead of entity key as identifier.
|
|
356
399
|
cascade : bool
|
|
357
400
|
Cascade delete.
|
|
358
401
|
**kwargs : dict
|
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
-
import shutil
|
|
8
7
|
import typing
|
|
9
|
-
from pathlib import Path
|
|
10
8
|
from typing import Any
|
|
11
9
|
|
|
10
|
+
from digitalhub.entities._base.material.utils import refresh_decorator
|
|
12
11
|
from digitalhub.entities.dataitem._base.entity import Dataitem
|
|
13
12
|
from digitalhub.stores.data.api import get_store
|
|
14
13
|
from digitalhub.utils.uri_utils import has_sql_scheme
|
|
@@ -65,6 +64,7 @@ class DataitemTable(Dataitem):
|
|
|
65
64
|
self._query = query
|
|
66
65
|
return self
|
|
67
66
|
|
|
67
|
+
@refresh_decorator
|
|
68
68
|
def as_df(
|
|
69
69
|
self,
|
|
70
70
|
file_format: str | None = None,
|
|
@@ -107,6 +107,7 @@ class DataitemTable(Dataitem):
|
|
|
107
107
|
**kwargs,
|
|
108
108
|
)
|
|
109
109
|
|
|
110
|
+
@refresh_decorator
|
|
110
111
|
def write_df(
|
|
111
112
|
self,
|
|
112
113
|
df: Any,
|
|
@@ -117,13 +118,17 @@ class DataitemTable(Dataitem):
|
|
|
117
118
|
Write DataFrame as parquet/csv/table into dataitem spec.path.
|
|
118
119
|
keyword arguments will be passed to the DataFrame reader function such as
|
|
119
120
|
pandas's to_csv or to_parquet.
|
|
121
|
+
Note that by default the index is dropped when writing the dataframe. To
|
|
122
|
+
keep the index, you can pass index=True as a keyword argument.
|
|
123
|
+
If the dataitem path is a SQL scheme, the dataframe will be written to the
|
|
124
|
+
table specified in the path (sql://<database_name>(/<schema_name>)/<table_name>).
|
|
120
125
|
|
|
121
126
|
Parameters
|
|
122
127
|
----------
|
|
123
128
|
df : Any
|
|
124
129
|
DataFrame to write.
|
|
125
130
|
extension : str
|
|
126
|
-
Extension of the file.
|
|
131
|
+
Extension of the file (supported parquet and csv).
|
|
127
132
|
**kwargs : dict
|
|
128
133
|
Keyword arguments passed to the write_df function.
|
|
129
134
|
|
|
@@ -131,6 +136,25 @@ class DataitemTable(Dataitem):
|
|
|
131
136
|
-------
|
|
132
137
|
str
|
|
133
138
|
Path to the written dataframe.
|
|
139
|
+
|
|
140
|
+
Examples
|
|
141
|
+
--------
|
|
142
|
+
>>> import digitalhub as dh
|
|
143
|
+
>>> import pandas as pd
|
|
144
|
+
>>>
|
|
145
|
+
>>> p = dh.get_project("my_project")
|
|
146
|
+
>>> df = pd.read_df("data/my_data.csv")
|
|
147
|
+
>>> di = p.new_dataitem(
|
|
148
|
+
... name="my_dataitem",
|
|
149
|
+
... kind="table",
|
|
150
|
+
... path="s3://my-bucket/my-data.parquet",
|
|
151
|
+
... )
|
|
152
|
+
>>> di.write_df(
|
|
153
|
+
... df,
|
|
154
|
+
... extension="parquet",
|
|
155
|
+
... index=True,
|
|
156
|
+
... )
|
|
157
|
+
's3://my-bucket/my-data.parquet'
|
|
134
158
|
"""
|
|
135
159
|
return get_store(self.spec.path).write_df(
|
|
136
160
|
df,
|
|
@@ -138,22 +162,3 @@ class DataitemTable(Dataitem):
|
|
|
138
162
|
extension=extension,
|
|
139
163
|
**kwargs,
|
|
140
164
|
)
|
|
141
|
-
|
|
142
|
-
@staticmethod
|
|
143
|
-
def _clean_tmp_path(pth: Path | None, clean: bool) -> None:
|
|
144
|
-
"""
|
|
145
|
-
Clean temporary path.
|
|
146
|
-
|
|
147
|
-
Parameters
|
|
148
|
-
----------
|
|
149
|
-
pth : Path | None
|
|
150
|
-
Path to clean.
|
|
151
|
-
clean : bool
|
|
152
|
-
If True, the path will be cleaned.
|
|
153
|
-
|
|
154
|
-
Returns
|
|
155
|
-
-------
|
|
156
|
-
None
|
|
157
|
-
"""
|
|
158
|
-
if pth is not None and clean:
|
|
159
|
-
shutil.rmtree(pth)
|