digitalhub 0.8.0b0__py3-none-any.whl → 0.8.0b2__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 +62 -94
- digitalhub/client/__init__.py +0 -0
- digitalhub/client/builder.py +105 -0
- digitalhub/client/objects/__init__.py +0 -0
- digitalhub/client/objects/base.py +56 -0
- digitalhub/client/objects/dhcore.py +681 -0
- digitalhub/client/objects/local.py +533 -0
- digitalhub/context/__init__.py +0 -0
- digitalhub/context/builder.py +178 -0
- digitalhub/context/context.py +136 -0
- digitalhub/datastores/__init__.py +0 -0
- digitalhub/datastores/builder.py +134 -0
- digitalhub/datastores/objects/__init__.py +0 -0
- digitalhub/datastores/objects/base.py +85 -0
- digitalhub/datastores/objects/local.py +42 -0
- digitalhub/datastores/objects/remote.py +23 -0
- digitalhub/datastores/objects/s3.py +38 -0
- digitalhub/datastores/objects/sql.py +60 -0
- digitalhub/entities/__init__.py +0 -0
- digitalhub/entities/_base/__init__.py +0 -0
- digitalhub/entities/_base/api.py +346 -0
- digitalhub/entities/_base/base.py +82 -0
- digitalhub/entities/_base/crud.py +610 -0
- digitalhub/entities/_base/entity/__init__.py +0 -0
- digitalhub/entities/_base/entity/base.py +132 -0
- digitalhub/entities/_base/entity/context.py +118 -0
- digitalhub/entities/_base/entity/executable.py +380 -0
- digitalhub/entities/_base/entity/material.py +214 -0
- digitalhub/entities/_base/entity/unversioned.py +87 -0
- digitalhub/entities/_base/entity/versioned.py +94 -0
- digitalhub/entities/_base/metadata.py +59 -0
- digitalhub/entities/_base/spec/__init__.py +0 -0
- digitalhub/entities/_base/spec/base.py +58 -0
- digitalhub/entities/_base/spec/material.py +22 -0
- digitalhub/entities/_base/state.py +31 -0
- digitalhub/entities/_base/status/__init__.py +0 -0
- digitalhub/entities/_base/status/base.py +32 -0
- digitalhub/entities/_base/status/material.py +49 -0
- digitalhub/entities/_builders/__init__.py +0 -0
- digitalhub/entities/_builders/metadata.py +60 -0
- digitalhub/entities/_builders/name.py +31 -0
- digitalhub/entities/_builders/spec.py +43 -0
- digitalhub/entities/_builders/status.py +62 -0
- digitalhub/entities/_builders/uuid.py +33 -0
- digitalhub/entities/artifact/__init__.py +0 -0
- digitalhub/entities/artifact/builder.py +133 -0
- digitalhub/entities/artifact/crud.py +358 -0
- digitalhub/entities/artifact/entity/__init__.py +0 -0
- digitalhub/entities/artifact/entity/_base.py +39 -0
- digitalhub/entities/artifact/entity/artifact.py +9 -0
- digitalhub/entities/artifact/spec.py +39 -0
- digitalhub/entities/artifact/status.py +15 -0
- digitalhub/entities/dataitem/__init__.py +0 -0
- digitalhub/entities/dataitem/builder.py +144 -0
- digitalhub/entities/dataitem/crud.py +395 -0
- digitalhub/entities/dataitem/entity/__init__.py +0 -0
- digitalhub/entities/dataitem/entity/_base.py +75 -0
- digitalhub/entities/dataitem/entity/dataitem.py +9 -0
- digitalhub/entities/dataitem/entity/iceberg.py +7 -0
- digitalhub/entities/dataitem/entity/table.py +125 -0
- digitalhub/entities/dataitem/models.py +62 -0
- digitalhub/entities/dataitem/spec.py +61 -0
- digitalhub/entities/dataitem/status.py +38 -0
- digitalhub/entities/entity_types.py +19 -0
- digitalhub/entities/function/__init__.py +0 -0
- digitalhub/entities/function/builder.py +86 -0
- digitalhub/entities/function/crud.py +305 -0
- digitalhub/entities/function/entity.py +101 -0
- digitalhub/entities/function/models.py +118 -0
- digitalhub/entities/function/spec.py +81 -0
- digitalhub/entities/function/status.py +9 -0
- digitalhub/entities/model/__init__.py +0 -0
- digitalhub/entities/model/builder.py +152 -0
- digitalhub/entities/model/crud.py +358 -0
- digitalhub/entities/model/entity/__init__.py +0 -0
- digitalhub/entities/model/entity/_base.py +34 -0
- digitalhub/entities/model/entity/huggingface.py +9 -0
- digitalhub/entities/model/entity/mlflow.py +90 -0
- digitalhub/entities/model/entity/model.py +9 -0
- digitalhub/entities/model/entity/sklearn.py +9 -0
- digitalhub/entities/model/models.py +26 -0
- digitalhub/entities/model/spec.py +146 -0
- digitalhub/entities/model/status.py +33 -0
- digitalhub/entities/project/__init__.py +0 -0
- digitalhub/entities/project/builder.py +82 -0
- digitalhub/entities/project/crud.py +350 -0
- digitalhub/entities/project/entity.py +2060 -0
- digitalhub/entities/project/spec.py +50 -0
- digitalhub/entities/project/status.py +9 -0
- digitalhub/entities/registries.py +48 -0
- digitalhub/entities/run/__init__.py +0 -0
- digitalhub/entities/run/builder.py +77 -0
- digitalhub/entities/run/crud.py +232 -0
- digitalhub/entities/run/entity.py +461 -0
- digitalhub/entities/run/spec.py +153 -0
- digitalhub/entities/run/status.py +114 -0
- digitalhub/entities/secret/__init__.py +0 -0
- digitalhub/entities/secret/builder.py +93 -0
- digitalhub/entities/secret/crud.py +294 -0
- digitalhub/entities/secret/entity.py +73 -0
- digitalhub/entities/secret/spec.py +35 -0
- digitalhub/entities/secret/status.py +9 -0
- digitalhub/entities/task/__init__.py +0 -0
- digitalhub/entities/task/builder.py +74 -0
- digitalhub/entities/task/crud.py +241 -0
- digitalhub/entities/task/entity.py +135 -0
- digitalhub/entities/task/models.py +199 -0
- digitalhub/entities/task/spec.py +51 -0
- digitalhub/entities/task/status.py +9 -0
- digitalhub/entities/utils.py +184 -0
- digitalhub/entities/workflow/__init__.py +0 -0
- digitalhub/entities/workflow/builder.py +91 -0
- digitalhub/entities/workflow/crud.py +304 -0
- digitalhub/entities/workflow/entity.py +77 -0
- digitalhub/entities/workflow/spec.py +15 -0
- digitalhub/entities/workflow/status.py +9 -0
- digitalhub/readers/__init__.py +0 -0
- digitalhub/readers/builder.py +54 -0
- digitalhub/readers/objects/__init__.py +0 -0
- digitalhub/readers/objects/base.py +70 -0
- digitalhub/readers/objects/pandas.py +207 -0
- digitalhub/readers/registry.py +15 -0
- digitalhub/registry/__init__.py +0 -0
- digitalhub/registry/models.py +87 -0
- digitalhub/registry/registry.py +74 -0
- digitalhub/registry/utils.py +150 -0
- digitalhub/runtimes/__init__.py +0 -0
- digitalhub/runtimes/base.py +164 -0
- digitalhub/runtimes/builder.py +53 -0
- digitalhub/runtimes/kind_registry.py +170 -0
- digitalhub/stores/__init__.py +0 -0
- digitalhub/stores/builder.py +257 -0
- digitalhub/stores/objects/__init__.py +0 -0
- digitalhub/stores/objects/base.py +189 -0
- digitalhub/stores/objects/local.py +230 -0
- digitalhub/stores/objects/remote.py +143 -0
- digitalhub/stores/objects/s3.py +563 -0
- digitalhub/stores/objects/sql.py +328 -0
- digitalhub/utils/__init__.py +0 -0
- digitalhub/utils/data_utils.py +127 -0
- digitalhub/utils/env_utils.py +123 -0
- digitalhub/utils/exceptions.py +55 -0
- digitalhub/utils/file_utils.py +204 -0
- digitalhub/utils/generic_utils.py +207 -0
- digitalhub/utils/git_utils.py +148 -0
- digitalhub/utils/io_utils.py +79 -0
- digitalhub/utils/logger.py +17 -0
- digitalhub/utils/uri_utils.py +56 -0
- {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/METADATA +27 -12
- digitalhub-0.8.0b2.dist-info/RECORD +161 -0
- test/test_crud_artifacts.py +1 -1
- test/test_crud_dataitems.py +1 -1
- test/test_crud_functions.py +1 -1
- test/test_crud_runs.py +1 -1
- test/test_crud_tasks.py +1 -1
- digitalhub-0.8.0b0.dist-info/RECORD +0 -14
- {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/LICENSE.txt +0 -0
- {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/WHEEL +0 -0
- {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from digitalhub.entities._base.crud import files_info_get_api, files_info_put_api
|
|
7
|
+
from digitalhub.entities._base.entity.versioned import VersionedEntity
|
|
8
|
+
from digitalhub.stores.builder import get_store
|
|
9
|
+
|
|
10
|
+
if typing.TYPE_CHECKING:
|
|
11
|
+
from digitalhub.entities._base.metadata import Metadata
|
|
12
|
+
from digitalhub.entities._base.spec.material import MaterialSpec
|
|
13
|
+
from digitalhub.entities._base.status.material import MaterialStatus
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class MaterialEntity(VersionedEntity):
|
|
17
|
+
"""
|
|
18
|
+
A class representing an entity that can be materialized
|
|
19
|
+
as file(s).
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
project: str,
|
|
25
|
+
name: str,
|
|
26
|
+
uuid: str,
|
|
27
|
+
kind: str,
|
|
28
|
+
metadata: Metadata,
|
|
29
|
+
spec: MaterialSpec,
|
|
30
|
+
status: MaterialStatus,
|
|
31
|
+
user: str | None = None,
|
|
32
|
+
) -> None:
|
|
33
|
+
super().__init__(project, name, uuid, kind, metadata, spec, status, user)
|
|
34
|
+
self.spec: MaterialSpec
|
|
35
|
+
self.status: MaterialStatus
|
|
36
|
+
|
|
37
|
+
def save(self, update: bool = False) -> MaterialEntity:
|
|
38
|
+
"""
|
|
39
|
+
Save entity into backend.
|
|
40
|
+
|
|
41
|
+
Parameters
|
|
42
|
+
----------
|
|
43
|
+
update : bool
|
|
44
|
+
Flag to indicate update.
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
MaterialEntity
|
|
49
|
+
Entity saved.
|
|
50
|
+
"""
|
|
51
|
+
obj = self.to_dict()
|
|
52
|
+
|
|
53
|
+
files = None
|
|
54
|
+
if self.status.files is not None and len(self.status.files) > 5 and not self._context().local:
|
|
55
|
+
files = obj["status"].pop("files")
|
|
56
|
+
|
|
57
|
+
if not update:
|
|
58
|
+
new_obj: MaterialEntity = self._save(obj)
|
|
59
|
+
else:
|
|
60
|
+
new_obj: MaterialEntity = self._update(obj)
|
|
61
|
+
|
|
62
|
+
# Handle files info
|
|
63
|
+
if files is not None:
|
|
64
|
+
files_info_put_api(self.project, self.ENTITY_TYPE, self.id, files)
|
|
65
|
+
self.status.add_files_info(files)
|
|
66
|
+
|
|
67
|
+
return new_obj
|
|
68
|
+
|
|
69
|
+
##############################
|
|
70
|
+
# I/O Methods
|
|
71
|
+
##############################
|
|
72
|
+
|
|
73
|
+
def as_file(self) -> list[str]:
|
|
74
|
+
"""
|
|
75
|
+
Get object as file(s). It downloads the object from storage in
|
|
76
|
+
a temporary folder and returns the list of downloaded files paths.
|
|
77
|
+
|
|
78
|
+
Returns
|
|
79
|
+
-------
|
|
80
|
+
list[str]
|
|
81
|
+
List of file paths.
|
|
82
|
+
"""
|
|
83
|
+
store = get_store(self.spec.path)
|
|
84
|
+
paths = self.status.get_file_paths()
|
|
85
|
+
dst = store._build_temp()
|
|
86
|
+
return store.download(self.spec.path, dst=dst, src=paths)
|
|
87
|
+
|
|
88
|
+
def download(
|
|
89
|
+
self,
|
|
90
|
+
destination: str | None = None,
|
|
91
|
+
overwrite: bool = False,
|
|
92
|
+
) -> str:
|
|
93
|
+
"""
|
|
94
|
+
This function downloads one or more file from storage on local
|
|
95
|
+
machine.
|
|
96
|
+
It looks inside the object's status for the file(s) path under
|
|
97
|
+
files attribute. If it does not find it, it will try to download
|
|
98
|
+
what it can from spec.path.
|
|
99
|
+
The files are downloaded into a destination folder. If the destination
|
|
100
|
+
is not specified, it will set by default under the context path
|
|
101
|
+
as '<ctx-root>/<entity_type>', e.g. './dataitem'.
|
|
102
|
+
The overwrite flag allows to overwrite existing file(s) in the
|
|
103
|
+
destination folder.
|
|
104
|
+
|
|
105
|
+
Parameters
|
|
106
|
+
----------
|
|
107
|
+
destination : str
|
|
108
|
+
Destination path as filename or directory.
|
|
109
|
+
overwrite : bool
|
|
110
|
+
Specify if overwrite existing file(s). If file(s) already
|
|
111
|
+
exist and overwrite is False, it will raise an error.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
str
|
|
116
|
+
Downloaded path.
|
|
117
|
+
|
|
118
|
+
Examples
|
|
119
|
+
--------
|
|
120
|
+
Download a single file:
|
|
121
|
+
|
|
122
|
+
>>> entity.status.files[0]
|
|
123
|
+
{
|
|
124
|
+
"path ": "data.csv",
|
|
125
|
+
"name ": "data.csv",
|
|
126
|
+
"content_type ": "text/csv;charset=utf-8 "
|
|
127
|
+
}
|
|
128
|
+
>>> path = entity.download()
|
|
129
|
+
>>> print(path)
|
|
130
|
+
dataitem/data.csv
|
|
131
|
+
"""
|
|
132
|
+
store = get_store(self.spec.path)
|
|
133
|
+
paths = self.status.get_file_paths()
|
|
134
|
+
|
|
135
|
+
if destination is None:
|
|
136
|
+
dst = self._context().root / self.ENTITY_TYPE
|
|
137
|
+
else:
|
|
138
|
+
dst = Path(destination)
|
|
139
|
+
|
|
140
|
+
return store.download(self.spec.path, dst=dst, src=paths, overwrite=overwrite)
|
|
141
|
+
|
|
142
|
+
def upload(self, source: str | list[str]) -> None:
|
|
143
|
+
"""
|
|
144
|
+
Upload object from given local path to spec path destination.
|
|
145
|
+
Source must be a local path. If the path is a folder, destination
|
|
146
|
+
path (object's spec path) must be a folder or a partition ending
|
|
147
|
+
with '/' (s3).
|
|
148
|
+
|
|
149
|
+
Parameters
|
|
150
|
+
----------
|
|
151
|
+
source : str | list[str]
|
|
152
|
+
Local filepath, directory or list of filepaths.
|
|
153
|
+
|
|
154
|
+
Returns
|
|
155
|
+
-------
|
|
156
|
+
None
|
|
157
|
+
|
|
158
|
+
Examples
|
|
159
|
+
--------
|
|
160
|
+
Upload a single file:
|
|
161
|
+
|
|
162
|
+
>>> entity.spec.path = 's3://bucket/data.csv'
|
|
163
|
+
>>> entity.upload('./data.csv')
|
|
164
|
+
|
|
165
|
+
Upload a folder:
|
|
166
|
+
>>> entity.spec.path = 's3://bucket/data/'
|
|
167
|
+
>>> entity.upload('./data')
|
|
168
|
+
"""
|
|
169
|
+
# Get store and upload object
|
|
170
|
+
store = get_store(self.spec.path)
|
|
171
|
+
paths = store.upload(source, self.spec.path)
|
|
172
|
+
|
|
173
|
+
# Update files info
|
|
174
|
+
files_info = store.get_file_info(paths)
|
|
175
|
+
self._update_files_info(files_info)
|
|
176
|
+
|
|
177
|
+
##############################
|
|
178
|
+
# Private Helpers
|
|
179
|
+
##############################
|
|
180
|
+
|
|
181
|
+
def _update_files_info(self, files_info: list[dict] | None = None) -> None:
|
|
182
|
+
"""
|
|
183
|
+
Update files info.
|
|
184
|
+
|
|
185
|
+
Parameters
|
|
186
|
+
----------
|
|
187
|
+
files_info : list[dict] | None
|
|
188
|
+
Files info.
|
|
189
|
+
|
|
190
|
+
Returns
|
|
191
|
+
-------
|
|
192
|
+
None
|
|
193
|
+
"""
|
|
194
|
+
if files_info is None:
|
|
195
|
+
return
|
|
196
|
+
self.refresh()
|
|
197
|
+
self.status.add_files_info(files_info)
|
|
198
|
+
self.save(update=True)
|
|
199
|
+
|
|
200
|
+
def _get_files_info(self) -> None:
|
|
201
|
+
"""
|
|
202
|
+
Get files info from backend.
|
|
203
|
+
|
|
204
|
+
Returns
|
|
205
|
+
-------
|
|
206
|
+
None
|
|
207
|
+
"""
|
|
208
|
+
if not self._context().local and not self.status.files:
|
|
209
|
+
files = files_info_get_api(
|
|
210
|
+
project=self.project,
|
|
211
|
+
entity_type=self.ENTITY_TYPE,
|
|
212
|
+
entity_id=self.id,
|
|
213
|
+
)
|
|
214
|
+
self.status.add_files_info(files)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._base.entity.context import ContextEntity
|
|
6
|
+
from digitalhub.entities._builders.metadata import build_metadata
|
|
7
|
+
from digitalhub.entities._builders.spec import build_spec
|
|
8
|
+
from digitalhub.entities._builders.status import build_status
|
|
9
|
+
from digitalhub.entities._builders.uuid import build_uuid
|
|
10
|
+
from digitalhub.utils.io_utils import write_yaml
|
|
11
|
+
|
|
12
|
+
if typing.TYPE_CHECKING:
|
|
13
|
+
from digitalhub.entities._base.metadata import Metadata
|
|
14
|
+
from digitalhub.entities._base.spec.base import Spec
|
|
15
|
+
from digitalhub.entities._base.status.base import Status
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class UnversionedEntity(ContextEntity):
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
project: str,
|
|
22
|
+
uuid: str,
|
|
23
|
+
kind: str,
|
|
24
|
+
metadata: Metadata,
|
|
25
|
+
spec: Spec,
|
|
26
|
+
status: Status,
|
|
27
|
+
user: str | None = None,
|
|
28
|
+
) -> None:
|
|
29
|
+
super().__init__(project, kind, metadata, spec, status, user)
|
|
30
|
+
self.id = uuid
|
|
31
|
+
self.key = f"store://{project}/{self.ENTITY_TYPE}/{kind}/{uuid}"
|
|
32
|
+
self._obj_attr.extend(["id"])
|
|
33
|
+
|
|
34
|
+
def export(self, filename: str | None = None) -> str:
|
|
35
|
+
"""
|
|
36
|
+
Export object as a YAML file.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
filename : str
|
|
41
|
+
Name of the export YAML file. If not specified, the default value is used.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
str
|
|
46
|
+
Exported file.
|
|
47
|
+
"""
|
|
48
|
+
obj = self.to_dict()
|
|
49
|
+
if filename is None:
|
|
50
|
+
filename = f"{self.ENTITY_TYPE}-{self.id}.yml"
|
|
51
|
+
pth = self._context().root / filename
|
|
52
|
+
write_yaml(pth, obj)
|
|
53
|
+
return str(pth)
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def _parse_dict(obj: dict, validate: bool = True) -> dict:
|
|
57
|
+
"""
|
|
58
|
+
Get dictionary and parse it to a valid entity dictionary.
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
entity : str
|
|
63
|
+
Entity type.
|
|
64
|
+
obj : dict
|
|
65
|
+
Dictionary to parse.
|
|
66
|
+
|
|
67
|
+
Returns
|
|
68
|
+
-------
|
|
69
|
+
dict
|
|
70
|
+
A dictionary containing the attributes of the entity instance.
|
|
71
|
+
"""
|
|
72
|
+
project = obj.get("project")
|
|
73
|
+
kind = obj.get("kind")
|
|
74
|
+
uuid = build_uuid(obj.get("id"))
|
|
75
|
+
metadata = build_metadata(kind, **obj.get("metadata", {}))
|
|
76
|
+
spec = build_spec(kind, validate=validate, **obj.get("spec", {}))
|
|
77
|
+
status = build_status(kind, **obj.get("status", {}))
|
|
78
|
+
user = obj.get("user")
|
|
79
|
+
return {
|
|
80
|
+
"project": project,
|
|
81
|
+
"uuid": uuid,
|
|
82
|
+
"kind": kind,
|
|
83
|
+
"metadata": metadata,
|
|
84
|
+
"spec": spec,
|
|
85
|
+
"status": status,
|
|
86
|
+
"user": user,
|
|
87
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._base.entity.context import ContextEntity
|
|
6
|
+
from digitalhub.entities._builders.metadata import build_metadata
|
|
7
|
+
from digitalhub.entities._builders.name import build_name
|
|
8
|
+
from digitalhub.entities._builders.spec import build_spec
|
|
9
|
+
from digitalhub.entities._builders.status import build_status
|
|
10
|
+
from digitalhub.entities._builders.uuid import build_uuid
|
|
11
|
+
from digitalhub.utils.io_utils import write_yaml
|
|
12
|
+
|
|
13
|
+
if typing.TYPE_CHECKING:
|
|
14
|
+
from digitalhub.entities._base.metadata import Metadata
|
|
15
|
+
from digitalhub.entities._base.spec.base import Spec
|
|
16
|
+
from digitalhub.entities._base.status.base import Status
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class VersionedEntity(ContextEntity):
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
project: str,
|
|
23
|
+
name: str,
|
|
24
|
+
uuid: str,
|
|
25
|
+
kind: str,
|
|
26
|
+
metadata: Metadata,
|
|
27
|
+
spec: Spec,
|
|
28
|
+
status: Status,
|
|
29
|
+
user: str | None = None,
|
|
30
|
+
) -> None:
|
|
31
|
+
super().__init__(project, kind, metadata, spec, status, user)
|
|
32
|
+
self.name = name
|
|
33
|
+
self.id = uuid
|
|
34
|
+
self.key = f"store://{project}/{self.ENTITY_TYPE}/{kind}/{name}:{uuid}"
|
|
35
|
+
|
|
36
|
+
# Add attributes to be used in the to_dict method
|
|
37
|
+
self._obj_attr.extend(["name", "id"])
|
|
38
|
+
|
|
39
|
+
def export(self, filename: str | None = None) -> str:
|
|
40
|
+
"""
|
|
41
|
+
Export object as a YAML file.
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
filename : str
|
|
46
|
+
Name of the export YAML file. If not specified, the default value is used.
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
str
|
|
51
|
+
Exported file.
|
|
52
|
+
"""
|
|
53
|
+
obj = self.to_dict()
|
|
54
|
+
if filename is None:
|
|
55
|
+
filename = f"{self.ENTITY_TYPE}-{self.name}-{self.id}.yml"
|
|
56
|
+
pth = self._context().root / filename
|
|
57
|
+
write_yaml(pth, obj)
|
|
58
|
+
return str(pth)
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def _parse_dict(obj: dict, validate: bool = True) -> dict:
|
|
62
|
+
"""
|
|
63
|
+
Get dictionary and parse it to a valid entity dictionary.
|
|
64
|
+
|
|
65
|
+
Parameters
|
|
66
|
+
----------
|
|
67
|
+
entity : str
|
|
68
|
+
Entity type.
|
|
69
|
+
obj : dict
|
|
70
|
+
Dictionary to parse.
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
dict
|
|
75
|
+
A dictionary containing the attributes of the entity instance.
|
|
76
|
+
"""
|
|
77
|
+
project = obj.get("project")
|
|
78
|
+
kind = obj.get("kind")
|
|
79
|
+
name = build_name(obj.get("name"))
|
|
80
|
+
uuid = build_uuid(obj.get("id"))
|
|
81
|
+
metadata = build_metadata(kind, **obj.get("metadata", {}))
|
|
82
|
+
spec = build_spec(kind, validate=validate, **obj.get("spec", {}))
|
|
83
|
+
status = build_status(kind, **obj.get("status", {}))
|
|
84
|
+
user = obj.get("user")
|
|
85
|
+
return {
|
|
86
|
+
"project": project,
|
|
87
|
+
"name": name,
|
|
88
|
+
"uuid": uuid,
|
|
89
|
+
"kind": kind,
|
|
90
|
+
"metadata": metadata,
|
|
91
|
+
"spec": spec,
|
|
92
|
+
"status": status,
|
|
93
|
+
"user": user,
|
|
94
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities._base.base import ModelObj
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Metadata(ModelObj):
|
|
7
|
+
"""
|
|
8
|
+
A class representing the metadata of an entity.
|
|
9
|
+
Metadata is a collection of information about an entity thought
|
|
10
|
+
to be modifiable by the user. The information contained in the
|
|
11
|
+
metadata can be discordant with the actual state of the entity,
|
|
12
|
+
for example the name of the entity in the database.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
project: str | None = None,
|
|
18
|
+
name: str | None = None,
|
|
19
|
+
version: str | None = None,
|
|
20
|
+
description: str | None = None,
|
|
21
|
+
labels: list[str] | None = None,
|
|
22
|
+
created: str | None = None,
|
|
23
|
+
created_by: str | None = None,
|
|
24
|
+
updated: str | None = None,
|
|
25
|
+
updated_by: str | None = None,
|
|
26
|
+
embedded: bool | None = None,
|
|
27
|
+
ref: str | None = None,
|
|
28
|
+
**kwargs,
|
|
29
|
+
) -> None:
|
|
30
|
+
self.project = project
|
|
31
|
+
self.name = name
|
|
32
|
+
self.version = version
|
|
33
|
+
self.description = description
|
|
34
|
+
self.labels = labels
|
|
35
|
+
self.created = created
|
|
36
|
+
self.updated = updated
|
|
37
|
+
self.created_by = created_by
|
|
38
|
+
self.updated_by = updated_by
|
|
39
|
+
self.embedded = embedded
|
|
40
|
+
self.ref = ref
|
|
41
|
+
|
|
42
|
+
self._any_setter(**kwargs)
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def from_dict(cls, obj: dict) -> Metadata:
|
|
46
|
+
"""
|
|
47
|
+
Return entity metadata object from dictionary.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
obj : dict
|
|
52
|
+
A dictionary containing the attributes of the entity metadata.
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
Metadata
|
|
57
|
+
An entity metadata object.
|
|
58
|
+
"""
|
|
59
|
+
return cls(**obj)
|
|
File without changes
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._base.base import ModelObj
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Spec(ModelObj):
|
|
9
|
+
"""
|
|
10
|
+
A class representing the specification of an entity.
|
|
11
|
+
Specification is a collection of information about an entity
|
|
12
|
+
thought to be immutable by the user.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
@classmethod
|
|
16
|
+
def from_dict(cls, obj: dict) -> Spec:
|
|
17
|
+
"""
|
|
18
|
+
Return entity specification object from dictionary.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
obj : dict
|
|
23
|
+
A dictionary containing the attributes of the entity specification.
|
|
24
|
+
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
EntitySpec
|
|
28
|
+
An entity specification object.
|
|
29
|
+
"""
|
|
30
|
+
return cls(**obj)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class SpecParams(BaseModel, extra="ignore"):
|
|
34
|
+
"""
|
|
35
|
+
A class representing the parameters of an entity.
|
|
36
|
+
This base class is used to define the parameters of an entity
|
|
37
|
+
specification and is used to validate the parameters passed
|
|
38
|
+
to the constructor.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class MaterialSpec(Spec):
|
|
43
|
+
"""
|
|
44
|
+
Material specification class.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def __init__(self, path: str, **kwargs) -> None:
|
|
48
|
+
super().__init__(**kwargs)
|
|
49
|
+
self.path = path
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class MaterialParams(SpecParams):
|
|
53
|
+
"""
|
|
54
|
+
Material parameters class.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
path: str
|
|
58
|
+
"""Target path to file(s)"""
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities._base.spec.base import Spec, SpecParams
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MaterialSpec(Spec):
|
|
7
|
+
"""
|
|
8
|
+
Material specification class.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def __init__(self, path: str, **kwargs) -> None:
|
|
12
|
+
super().__init__(**kwargs)
|
|
13
|
+
self.path = path
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class MaterialParams(SpecParams):
|
|
17
|
+
"""
|
|
18
|
+
Material parameters class.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
path: str
|
|
22
|
+
"""Target path to file(s)"""
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class State(Enum):
|
|
7
|
+
"""
|
|
8
|
+
State enumeration.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
BUILT = "BUILT"
|
|
12
|
+
CANCELLED = "CANCELLED"
|
|
13
|
+
COMPLETED = "COMPLETED"
|
|
14
|
+
CREATED = "CREATED"
|
|
15
|
+
CREATING = "CREATING"
|
|
16
|
+
DELETED = "DELETED"
|
|
17
|
+
DELETING = "DELETING"
|
|
18
|
+
ERROR = "ERROR"
|
|
19
|
+
FSM_ERROR = "FSM_ERROR"
|
|
20
|
+
IDLE = "IDLE"
|
|
21
|
+
NONE = "NONE"
|
|
22
|
+
ONLINE = "ONLINE"
|
|
23
|
+
PENDING = "PENDING"
|
|
24
|
+
READY = "READY"
|
|
25
|
+
RESUME = "RESUME"
|
|
26
|
+
RUN_ERROR = "RUN_ERROR"
|
|
27
|
+
RUNNING = "RUNNING"
|
|
28
|
+
STOP = "STOP"
|
|
29
|
+
STOPPED = "STOPPED"
|
|
30
|
+
SUCCESS = "SUCCESS"
|
|
31
|
+
UNKNOWN = "UNKNOWN"
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities._base.base import ModelObj
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Status(ModelObj):
|
|
7
|
+
"""
|
|
8
|
+
Base Status class.
|
|
9
|
+
The status class contains information about the state of an entity,
|
|
10
|
+
for example, the state of a RUNNING run, and eventual error message.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, state: str, message: str | None = None) -> None:
|
|
14
|
+
self.state = state
|
|
15
|
+
self.message = message
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def from_dict(cls, obj: dict) -> Status:
|
|
19
|
+
"""
|
|
20
|
+
Return entity status object from dictionary.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
obj : dict
|
|
25
|
+
A dictionary containing the attributes of the entity status.
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
EntityStatus
|
|
30
|
+
An entity status object.
|
|
31
|
+
"""
|
|
32
|
+
return cls(**obj)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities._base.status.base import Status
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MaterialStatus(Status):
|
|
7
|
+
"""
|
|
8
|
+
Material Status class.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
state: str,
|
|
14
|
+
message: str | None = None,
|
|
15
|
+
files: list[dict] | None = None,
|
|
16
|
+
) -> None:
|
|
17
|
+
super().__init__(state, message)
|
|
18
|
+
if files is None:
|
|
19
|
+
files = []
|
|
20
|
+
self.files = files
|
|
21
|
+
|
|
22
|
+
def add_files_info(self, files: list[dict]) -> None:
|
|
23
|
+
"""
|
|
24
|
+
Add a file to the status.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
files : list[dict]
|
|
29
|
+
Files to add.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
None
|
|
34
|
+
"""
|
|
35
|
+
path_list = self.get_file_paths()
|
|
36
|
+
for f in files:
|
|
37
|
+
if f.get("path") not in path_list:
|
|
38
|
+
self.files.append(f)
|
|
39
|
+
|
|
40
|
+
def get_file_paths(self) -> list[str]:
|
|
41
|
+
"""
|
|
42
|
+
Get the paths of the files in the status.
|
|
43
|
+
|
|
44
|
+
Returns
|
|
45
|
+
-------
|
|
46
|
+
list[str]
|
|
47
|
+
Paths of the files in the status.
|
|
48
|
+
"""
|
|
49
|
+
return [f.get("path") for f in self.files]
|
|
File without changes
|