digitalhub 0.7.0b2__py3-none-any.whl → 0.8.0__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.

Files changed (232) hide show
  1. digitalhub/__init__.py +63 -93
  2. digitalhub/client/__init__.py +0 -0
  3. digitalhub/client/_base/__init__.py +0 -0
  4. digitalhub/client/_base/client.py +56 -0
  5. digitalhub/client/api.py +63 -0
  6. digitalhub/client/builder.py +50 -0
  7. digitalhub/client/dhcore/__init__.py +0 -0
  8. digitalhub/client/dhcore/client.py +669 -0
  9. digitalhub/client/dhcore/env.py +21 -0
  10. digitalhub/client/dhcore/models.py +46 -0
  11. digitalhub/client/dhcore/utils.py +111 -0
  12. digitalhub/client/local/__init__.py +0 -0
  13. digitalhub/client/local/client.py +533 -0
  14. digitalhub/context/__init__.py +0 -0
  15. digitalhub/context/api.py +93 -0
  16. digitalhub/context/builder.py +94 -0
  17. digitalhub/context/context.py +136 -0
  18. digitalhub/datastores/__init__.py +0 -0
  19. digitalhub/datastores/_base/__init__.py +0 -0
  20. digitalhub/datastores/_base/datastore.py +85 -0
  21. digitalhub/datastores/api.py +37 -0
  22. digitalhub/datastores/builder.py +110 -0
  23. digitalhub/datastores/local/__init__.py +0 -0
  24. digitalhub/datastores/local/datastore.py +50 -0
  25. digitalhub/datastores/remote/__init__.py +0 -0
  26. digitalhub/datastores/remote/datastore.py +31 -0
  27. digitalhub/datastores/s3/__init__.py +0 -0
  28. digitalhub/datastores/s3/datastore.py +46 -0
  29. digitalhub/datastores/sql/__init__.py +0 -0
  30. digitalhub/datastores/sql/datastore.py +68 -0
  31. digitalhub/entities/__init__.py +0 -0
  32. digitalhub/entities/_base/__init__.py +0 -0
  33. digitalhub/entities/_base/_base/__init__.py +0 -0
  34. digitalhub/entities/_base/_base/entity.py +82 -0
  35. digitalhub/entities/_base/api_utils.py +620 -0
  36. digitalhub/entities/_base/context/__init__.py +0 -0
  37. digitalhub/entities/_base/context/entity.py +118 -0
  38. digitalhub/entities/_base/crud.py +468 -0
  39. digitalhub/entities/_base/entity/__init__.py +0 -0
  40. digitalhub/entities/_base/entity/_constructors/__init__.py +0 -0
  41. digitalhub/entities/_base/entity/_constructors/metadata.py +44 -0
  42. digitalhub/entities/_base/entity/_constructors/name.py +31 -0
  43. digitalhub/entities/_base/entity/_constructors/spec.py +33 -0
  44. digitalhub/entities/_base/entity/_constructors/status.py +52 -0
  45. digitalhub/entities/_base/entity/_constructors/uuid.py +26 -0
  46. digitalhub/entities/_base/entity/builder.py +175 -0
  47. digitalhub/entities/_base/entity/entity.py +106 -0
  48. digitalhub/entities/_base/entity/metadata.py +59 -0
  49. digitalhub/entities/_base/entity/spec.py +58 -0
  50. digitalhub/entities/_base/entity/status.py +43 -0
  51. digitalhub/entities/_base/executable/__init__.py +0 -0
  52. digitalhub/entities/_base/executable/entity.py +405 -0
  53. digitalhub/entities/_base/material/__init__.py +0 -0
  54. digitalhub/entities/_base/material/entity.py +214 -0
  55. digitalhub/entities/_base/material/spec.py +22 -0
  56. digitalhub/entities/_base/material/status.py +49 -0
  57. digitalhub/entities/_base/runtime_entity/__init__.py +0 -0
  58. digitalhub/entities/_base/runtime_entity/builder.py +106 -0
  59. digitalhub/entities/_base/unversioned/__init__.py +0 -0
  60. digitalhub/entities/_base/unversioned/builder.py +66 -0
  61. digitalhub/entities/_base/unversioned/entity.py +49 -0
  62. digitalhub/entities/_base/versioned/__init__.py +0 -0
  63. digitalhub/entities/_base/versioned/builder.py +68 -0
  64. digitalhub/entities/_base/versioned/entity.py +53 -0
  65. digitalhub/entities/artifact/__init__.py +0 -0
  66. digitalhub/entities/artifact/_base/__init__.py +0 -0
  67. digitalhub/entities/artifact/_base/builder.py +86 -0
  68. digitalhub/entities/artifact/_base/entity.py +39 -0
  69. digitalhub/entities/artifact/_base/spec.py +15 -0
  70. digitalhub/entities/artifact/_base/status.py +9 -0
  71. digitalhub/entities/artifact/artifact/__init__.py +0 -0
  72. digitalhub/entities/artifact/artifact/builder.py +18 -0
  73. digitalhub/entities/artifact/artifact/entity.py +32 -0
  74. digitalhub/entities/artifact/artifact/spec.py +27 -0
  75. digitalhub/entities/artifact/artifact/status.py +15 -0
  76. digitalhub/entities/artifact/crud.py +332 -0
  77. digitalhub/entities/builders.py +63 -0
  78. digitalhub/entities/dataitem/__init__.py +0 -0
  79. digitalhub/entities/dataitem/_base/__init__.py +0 -0
  80. digitalhub/entities/dataitem/_base/builder.py +86 -0
  81. digitalhub/entities/dataitem/_base/entity.py +75 -0
  82. digitalhub/entities/dataitem/_base/spec.py +15 -0
  83. digitalhub/entities/dataitem/_base/status.py +20 -0
  84. digitalhub/entities/dataitem/crud.py +372 -0
  85. digitalhub/entities/dataitem/dataitem/__init__.py +0 -0
  86. digitalhub/entities/dataitem/dataitem/builder.py +18 -0
  87. digitalhub/entities/dataitem/dataitem/entity.py +32 -0
  88. digitalhub/entities/dataitem/dataitem/spec.py +15 -0
  89. digitalhub/entities/dataitem/dataitem/status.py +9 -0
  90. digitalhub/entities/dataitem/iceberg/__init__.py +0 -0
  91. digitalhub/entities/dataitem/iceberg/builder.py +18 -0
  92. digitalhub/entities/dataitem/iceberg/entity.py +32 -0
  93. digitalhub/entities/dataitem/iceberg/spec.py +15 -0
  94. digitalhub/entities/dataitem/iceberg/status.py +9 -0
  95. digitalhub/entities/dataitem/table/__init__.py +0 -0
  96. digitalhub/entities/dataitem/table/builder.py +18 -0
  97. digitalhub/entities/dataitem/table/entity.py +146 -0
  98. digitalhub/entities/dataitem/table/models.py +62 -0
  99. digitalhub/entities/dataitem/table/spec.py +25 -0
  100. digitalhub/entities/dataitem/table/status.py +9 -0
  101. digitalhub/entities/function/__init__.py +0 -0
  102. digitalhub/entities/function/_base/__init__.py +0 -0
  103. digitalhub/entities/function/_base/builder.py +79 -0
  104. digitalhub/entities/function/_base/entity.py +98 -0
  105. digitalhub/entities/function/_base/models.py +118 -0
  106. digitalhub/entities/function/_base/spec.py +15 -0
  107. digitalhub/entities/function/_base/status.py +9 -0
  108. digitalhub/entities/function/crud.py +279 -0
  109. digitalhub/entities/model/__init__.py +0 -0
  110. digitalhub/entities/model/_base/__init__.py +0 -0
  111. digitalhub/entities/model/_base/builder.py +86 -0
  112. digitalhub/entities/model/_base/entity.py +34 -0
  113. digitalhub/entities/model/_base/spec.py +49 -0
  114. digitalhub/entities/model/_base/status.py +9 -0
  115. digitalhub/entities/model/crud.py +331 -0
  116. digitalhub/entities/model/huggingface/__init__.py +0 -0
  117. digitalhub/entities/model/huggingface/builder.py +18 -0
  118. digitalhub/entities/model/huggingface/entity.py +32 -0
  119. digitalhub/entities/model/huggingface/spec.py +36 -0
  120. digitalhub/entities/model/huggingface/status.py +9 -0
  121. digitalhub/entities/model/mlflow/__init__.py +0 -0
  122. digitalhub/entities/model/mlflow/builder.py +18 -0
  123. digitalhub/entities/model/mlflow/entity.py +32 -0
  124. digitalhub/entities/model/mlflow/models.py +26 -0
  125. digitalhub/entities/model/mlflow/spec.py +44 -0
  126. digitalhub/entities/model/mlflow/status.py +9 -0
  127. digitalhub/entities/model/mlflow/utils.py +81 -0
  128. digitalhub/entities/model/model/__init__.py +0 -0
  129. digitalhub/entities/model/model/builder.py +18 -0
  130. digitalhub/entities/model/model/entity.py +32 -0
  131. digitalhub/entities/model/model/spec.py +15 -0
  132. digitalhub/entities/model/model/status.py +9 -0
  133. digitalhub/entities/model/sklearn/__init__.py +0 -0
  134. digitalhub/entities/model/sklearn/builder.py +18 -0
  135. digitalhub/entities/model/sklearn/entity.py +32 -0
  136. digitalhub/entities/model/sklearn/spec.py +15 -0
  137. digitalhub/entities/model/sklearn/status.py +9 -0
  138. digitalhub/entities/project/__init__.py +0 -0
  139. digitalhub/entities/project/_base/__init__.py +0 -0
  140. digitalhub/entities/project/_base/builder.py +128 -0
  141. digitalhub/entities/project/_base/entity.py +2078 -0
  142. digitalhub/entities/project/_base/spec.py +50 -0
  143. digitalhub/entities/project/_base/status.py +9 -0
  144. digitalhub/entities/project/crud.py +357 -0
  145. digitalhub/entities/run/__init__.py +0 -0
  146. digitalhub/entities/run/_base/__init__.py +0 -0
  147. digitalhub/entities/run/_base/builder.py +94 -0
  148. digitalhub/entities/run/_base/entity.py +307 -0
  149. digitalhub/entities/run/_base/spec.py +50 -0
  150. digitalhub/entities/run/_base/status.py +9 -0
  151. digitalhub/entities/run/crud.py +219 -0
  152. digitalhub/entities/secret/__init__.py +0 -0
  153. digitalhub/entities/secret/_base/__init__.py +0 -0
  154. digitalhub/entities/secret/_base/builder.py +81 -0
  155. digitalhub/entities/secret/_base/entity.py +74 -0
  156. digitalhub/entities/secret/_base/spec.py +35 -0
  157. digitalhub/entities/secret/_base/status.py +9 -0
  158. digitalhub/entities/secret/crud.py +290 -0
  159. digitalhub/entities/task/__init__.py +0 -0
  160. digitalhub/entities/task/_base/__init__.py +0 -0
  161. digitalhub/entities/task/_base/builder.py +91 -0
  162. digitalhub/entities/task/_base/entity.py +136 -0
  163. digitalhub/entities/task/_base/models.py +208 -0
  164. digitalhub/entities/task/_base/spec.py +53 -0
  165. digitalhub/entities/task/_base/status.py +9 -0
  166. digitalhub/entities/task/crud.py +228 -0
  167. digitalhub/entities/utils/__init__.py +0 -0
  168. digitalhub/entities/utils/api.py +346 -0
  169. digitalhub/entities/utils/entity_types.py +19 -0
  170. digitalhub/entities/utils/state.py +31 -0
  171. digitalhub/entities/utils/utils.py +202 -0
  172. digitalhub/entities/workflow/__init__.py +0 -0
  173. digitalhub/entities/workflow/_base/__init__.py +0 -0
  174. digitalhub/entities/workflow/_base/builder.py +79 -0
  175. digitalhub/entities/workflow/_base/entity.py +74 -0
  176. digitalhub/entities/workflow/_base/spec.py +15 -0
  177. digitalhub/entities/workflow/_base/status.py +9 -0
  178. digitalhub/entities/workflow/crud.py +278 -0
  179. digitalhub/factory/__init__.py +0 -0
  180. digitalhub/factory/api.py +277 -0
  181. digitalhub/factory/factory.py +268 -0
  182. digitalhub/factory/utils.py +90 -0
  183. digitalhub/readers/__init__.py +0 -0
  184. digitalhub/readers/_base/__init__.py +0 -0
  185. digitalhub/readers/_base/builder.py +26 -0
  186. digitalhub/readers/_base/reader.py +70 -0
  187. digitalhub/readers/api.py +80 -0
  188. digitalhub/readers/factory.py +133 -0
  189. digitalhub/readers/pandas/__init__.py +0 -0
  190. digitalhub/readers/pandas/builder.py +29 -0
  191. digitalhub/readers/pandas/reader.py +207 -0
  192. digitalhub/runtimes/__init__.py +0 -0
  193. digitalhub/runtimes/_base.py +102 -0
  194. digitalhub/runtimes/builder.py +32 -0
  195. digitalhub/stores/__init__.py +0 -0
  196. digitalhub/stores/_base/__init__.py +0 -0
  197. digitalhub/stores/_base/store.py +189 -0
  198. digitalhub/stores/api.py +54 -0
  199. digitalhub/stores/builder.py +211 -0
  200. digitalhub/stores/local/__init__.py +0 -0
  201. digitalhub/stores/local/store.py +230 -0
  202. digitalhub/stores/remote/__init__.py +0 -0
  203. digitalhub/stores/remote/store.py +143 -0
  204. digitalhub/stores/s3/__init__.py +0 -0
  205. digitalhub/stores/s3/store.py +563 -0
  206. digitalhub/stores/sql/__init__.py +0 -0
  207. digitalhub/stores/sql/store.py +328 -0
  208. digitalhub/utils/__init__.py +0 -0
  209. digitalhub/utils/data_utils.py +127 -0
  210. digitalhub/utils/exceptions.py +67 -0
  211. digitalhub/utils/file_utils.py +204 -0
  212. digitalhub/utils/generic_utils.py +183 -0
  213. digitalhub/utils/git_utils.py +148 -0
  214. digitalhub/utils/io_utils.py +116 -0
  215. digitalhub/utils/logger.py +17 -0
  216. digitalhub/utils/s3_utils.py +58 -0
  217. digitalhub/utils/uri_utils.py +56 -0
  218. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/METADATA +30 -13
  219. digitalhub-0.8.0.dist-info/RECORD +231 -0
  220. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/WHEEL +1 -1
  221. test/local/CRUD/test_artifacts.py +96 -0
  222. test/local/CRUD/test_dataitems.py +96 -0
  223. test/local/CRUD/test_models.py +95 -0
  224. test/test_crud_functions.py +1 -1
  225. test/test_crud_runs.py +1 -1
  226. test/test_crud_tasks.py +1 -1
  227. digitalhub-0.7.0b2.dist-info/RECORD +0 -14
  228. test/test_crud_artifacts.py +0 -96
  229. test/test_crud_dataitems.py +0 -96
  230. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/LICENSE.txt +0 -0
  231. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/top_level.txt +0 -0
  232. /test/{test_imports.py → local/imports/test_imports.py} +0 -0
@@ -0,0 +1,52 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities.utils.state import State
6
+
7
+ if typing.TYPE_CHECKING:
8
+ from digitalhub.entities._base.entity.status import Status
9
+
10
+
11
+ def build_status(status_cls: Status, **kwargs) -> Status:
12
+ """
13
+ Build entity status object. This method is used to build entity
14
+ status.
15
+
16
+ Parameters
17
+ ----------
18
+ status_cls : Status
19
+ Entity status class.
20
+ **kwargs : dict
21
+ Keyword arguments.
22
+
23
+ Returns
24
+ -------
25
+ Status
26
+ Entity status object.
27
+ """
28
+ kwargs = parse_arguments(**kwargs)
29
+ return status_cls(**kwargs)
30
+
31
+
32
+ def parse_arguments(**kwargs) -> dict:
33
+ """
34
+ Parse keyword arguments and add default values if necessary.
35
+
36
+ Parameters
37
+ ----------
38
+ **kwargs : dict
39
+ Keyword arguments.
40
+
41
+ Returns
42
+ -------
43
+ dict
44
+ Keyword arguments with default values.
45
+ """
46
+ state = kwargs.get("state")
47
+ if state is None:
48
+ kwargs["state"] = State.CREATED.value
49
+ else:
50
+ if kwargs["state"] not in State.__members__:
51
+ raise ValueError(f"Invalid state: {state}")
52
+ return kwargs
@@ -0,0 +1,26 @@
1
+ from __future__ import annotations
2
+
3
+ from uuid import uuid4
4
+
5
+ from digitalhub.utils.generic_utils import slugify_string
6
+
7
+
8
+ def build_uuid(uuid: str | None = None) -> str:
9
+ """
10
+ Create a uuid if not given. If given, validate it.
11
+
12
+ Parameters
13
+ ----------
14
+ uuid : str
15
+ ID of the object.
16
+
17
+ Returns
18
+ -------
19
+ str
20
+ Validated UUID4.
21
+ """
22
+ if uuid is not None:
23
+ if slugify_string(uuid) != uuid:
24
+ raise ValueError(f"Invalid ID: {uuid}. Must pass slugified ID.")
25
+ return uuid
26
+ return str(uuid4())
@@ -0,0 +1,175 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+ from abc import abstractmethod
5
+
6
+ from digitalhub.entities._base.entity._constructors.metadata import build_metadata
7
+ from digitalhub.entities._base.entity._constructors.name import build_name
8
+ from digitalhub.entities._base.entity._constructors.spec import build_spec
9
+ from digitalhub.entities._base.entity._constructors.status import build_status
10
+ from digitalhub.entities._base.entity._constructors.uuid import build_uuid
11
+ from digitalhub.utils.exceptions import BuilderError
12
+
13
+ if typing.TYPE_CHECKING:
14
+ from digitalhub.entities._base.entity.entity import Entity
15
+ from digitalhub.entities._base.entity.metadata import Metadata
16
+ from digitalhub.entities._base.entity.spec import Spec, SpecValidator
17
+ from digitalhub.entities._base.entity.status import Status
18
+
19
+
20
+ class EntityBuilder:
21
+ """
22
+ Builder class for building entities.
23
+ """
24
+
25
+ # Class variables
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
31
+ ENTITY_KIND: str = None
32
+
33
+ def __init__(self) -> None:
34
+ if self.ENTITY_TYPE is None:
35
+ raise BuilderError("ENTITY_TYPE must be set")
36
+ if self.ENTITY_CLASS is None:
37
+ raise BuilderError("ENTITY_CLASS must be set")
38
+ if self.ENTITY_SPEC_CLASS is None:
39
+ raise BuilderError("ENTITY_SPEC_CLASS must be set")
40
+ if self.ENTITY_SPEC_VALIDATOR is None:
41
+ raise BuilderError("ENTITY_SPEC_VALIDATOR must be set")
42
+ if self.ENTITY_STATUS_CLASS is None:
43
+ raise BuilderError("ENTITY_STATUS_CLASS must be set")
44
+ if self.ENTITY_KIND is None:
45
+ raise BuilderError("ENTITY_KIND must be set")
46
+
47
+ def build_name(self, name: str) -> str:
48
+ """
49
+ Build entity name.
50
+
51
+ Parameters
52
+ ----------
53
+ name : str
54
+ Entity name.
55
+
56
+ Returns
57
+ -------
58
+ str
59
+ Entity name.
60
+ """
61
+ return build_name(name)
62
+
63
+ def build_uuid(self, uuid: str) -> str:
64
+ """
65
+ Build entity uuid.
66
+
67
+ Parameters
68
+ ----------
69
+ uuid : str
70
+ Entity uuid.
71
+
72
+ Returns
73
+ -------
74
+ str
75
+ Entity uuid.
76
+ """
77
+ return build_uuid(uuid)
78
+
79
+ def build_metadata(self, **kwargs) -> Metadata:
80
+ """
81
+ Build entity metadata object.
82
+
83
+ Parameters
84
+ ----------
85
+ **kwargs : dict
86
+ Keyword arguments for the constructor.
87
+
88
+ Returns
89
+ -------
90
+ Metadata
91
+ Metadata object.
92
+ """
93
+ return build_metadata(**kwargs)
94
+
95
+ def build_spec(self, validate: bool = True, **kwargs) -> Spec:
96
+ """
97
+ Build entity spec object.
98
+
99
+ Parameters
100
+ ----------
101
+ **kwargs : dict
102
+ Keyword arguments for the constructor.
103
+
104
+ Returns
105
+ -------
106
+ Spec
107
+ Spec object.
108
+ """
109
+ return build_spec(self.ENTITY_SPEC_CLASS, self.ENTITY_SPEC_VALIDATOR, validate=validate, **kwargs)
110
+
111
+ def build_status(self, **kwargs) -> Status:
112
+ """
113
+ Build entity status object.
114
+
115
+ Parameters
116
+ ----------
117
+ **kwargs : dict
118
+ Keyword arguments for the constructor.
119
+
120
+ Returns
121
+ -------
122
+ Status
123
+ Status object.
124
+ """
125
+ return build_status(self.ENTITY_STATUS_CLASS, **kwargs)
126
+
127
+ def build_entity(self, **kwargs) -> Entity:
128
+ """
129
+ Build entity object.
130
+
131
+ Parameters
132
+ ----------
133
+ **kwargs : dict
134
+ Keyword arguments for the constructor.
135
+
136
+ Returns
137
+ -------
138
+ Entity
139
+ Entity object.
140
+ """
141
+ return self.ENTITY_CLASS(**kwargs)
142
+
143
+ @abstractmethod
144
+ def build(self, *args, **kwargs) -> Entity:
145
+ """
146
+ Build entity object.
147
+ """
148
+
149
+ @abstractmethod
150
+ def from_dict(self, obj: dict, validate: bool = True) -> Entity:
151
+ """
152
+ Build entity object from dictionary.
153
+ """
154
+
155
+ def get_entity_type(self) -> str:
156
+ """
157
+ Get entity type.
158
+
159
+ Returns
160
+ -------
161
+ str
162
+ Entity type.
163
+ """
164
+ return self.ENTITY_TYPE
165
+
166
+ def get_kind(self) -> str:
167
+ """
168
+ Get entity kind.
169
+
170
+ Returns
171
+ -------
172
+ str
173
+ Entity kind.
174
+ """
175
+ return self.ENTITY_KIND
@@ -0,0 +1,106 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+ from abc import ABCMeta, abstractmethod
5
+
6
+ from digitalhub.entities._base._base.entity import Base
7
+ from digitalhub.factory.api import build_entity_from_dict
8
+
9
+ if typing.TYPE_CHECKING:
10
+ from digitalhub.entities._base.entity.metadata import Metadata
11
+ from digitalhub.entities._base.entity.spec import Spec
12
+ from digitalhub.entities._base.entity.status import Status
13
+
14
+
15
+ class Entity(Base, metaclass=ABCMeta):
16
+ """
17
+ Abstract class for entities.
18
+
19
+ An entity is a collection of metadata, specifications.and status
20
+ representing a variety of objects handled by Digitalhub.
21
+ """
22
+
23
+ # Entity type
24
+ # Need to be set in subclasses
25
+ ENTITY_TYPE: str
26
+
27
+ # Attributes to render as dict. Need to be expanded in subclasses.
28
+ _obj_attr = ["kind", "metadata", "spec", "status", "user", "key"]
29
+
30
+ def __init__(
31
+ self,
32
+ kind: str,
33
+ metadata: Metadata,
34
+ spec: Spec,
35
+ status: Status,
36
+ user: str | None = None,
37
+ ) -> None:
38
+ self.kind = kind
39
+ self.metadata = metadata
40
+ self.spec = spec
41
+ self.status = status
42
+ self.user = user
43
+
44
+ # Need to be set in subclasses
45
+ self.key: str
46
+
47
+ @abstractmethod
48
+ def save(self, update: bool = False) -> Entity:
49
+ """
50
+ Abstract save method.
51
+ """
52
+
53
+ @abstractmethod
54
+ def refresh(self) -> Entity:
55
+ """
56
+ Abstract refresh method.
57
+ """
58
+
59
+ def _update_attributes(self, obj: dict) -> None:
60
+ """
61
+ Update attributes.
62
+
63
+ Parameters
64
+ ----------
65
+ obj : dict
66
+ Mapping representation of object.
67
+
68
+ Returns
69
+ -------
70
+ None
71
+ """
72
+ new_obj = build_entity_from_dict(obj)
73
+ self.metadata = new_obj.metadata
74
+ self.spec = new_obj.spec
75
+ self.status = new_obj.status
76
+ self.user = new_obj.user
77
+
78
+ @abstractmethod
79
+ def export(self, filename: str | None = None) -> str:
80
+ """
81
+ Abstract export method.
82
+ """
83
+
84
+ def to_dict(self) -> dict:
85
+ """
86
+ Override default to_dict method to add the possibility to exclude
87
+ some attributes. This requires to set a list of _obj_attr
88
+ attributes in the subclass.
89
+
90
+ Returns
91
+ -------
92
+ dict
93
+ A dictionary containing the attributes of the entity instance.
94
+ """
95
+ return {k: v for k, v in super().to_dict().items() if k in self._obj_attr}
96
+
97
+ def __repr__(self) -> str:
98
+ """
99
+ Return string representation of the entity object.
100
+
101
+ Returns
102
+ -------
103
+ str
104
+ A string representing the entity instance.
105
+ """
106
+ return str(self.to_dict())
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base._base.entity import Base
4
+
5
+
6
+ class Metadata(Base):
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)
@@ -0,0 +1,58 @@
1
+ from __future__ import annotations
2
+
3
+ from pydantic import BaseModel
4
+
5
+ from digitalhub.entities._base._base.entity import Base
6
+
7
+
8
+ class Spec(Base):
9
+ """
10
+ A class representing the specifications.of an entity.
11
+ specifications.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 specifications.object from dictionary.
19
+
20
+ Parameters
21
+ ----------
22
+ obj : dict
23
+ A dictionary containing the attributes of the entity specifications.
24
+
25
+ Returns
26
+ -------
27
+ EntitySpec
28
+ An entity specifications.object.
29
+ """
30
+ return cls(**obj)
31
+
32
+
33
+ class SpecValidator(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
+ specifications.and is used to validate the parameters passed
38
+ to the constructor.
39
+ """
40
+
41
+
42
+ class MaterialSpec(Spec):
43
+ """
44
+ Material specifications.class.
45
+ """
46
+
47
+ def __init__(self, path: str, **kwargs) -> None:
48
+ super().__init__(**kwargs)
49
+ self.path = path
50
+
51
+
52
+ class MaterialValidator(SpecValidator):
53
+ """
54
+ Material parameters class.
55
+ """
56
+
57
+ path: str
58
+ """Target path to file(s)"""
@@ -0,0 +1,43 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base._base.entity import Base
4
+
5
+
6
+ class Status(Base):
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__(
14
+ self,
15
+ state: str,
16
+ message: str | None = None,
17
+ transitions: list[dict] | None = None,
18
+ k8s: dict | None = None,
19
+ **kwargs,
20
+ ) -> None:
21
+ self.state = state
22
+ self.message = message
23
+ self.transitions = transitions
24
+ self.k8s = k8s
25
+
26
+ self._any_setter(**kwargs)
27
+
28
+ @classmethod
29
+ def from_dict(cls, obj: dict) -> Status:
30
+ """
31
+ Return entity status object from dictionary.
32
+
33
+ Parameters
34
+ ----------
35
+ obj : dict
36
+ A dictionary containing the attributes of the entity status.
37
+
38
+ Returns
39
+ -------
40
+ EntityStatus
41
+ An entity status object.
42
+ """
43
+ return cls(**obj)
File without changes