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,106 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.utils.exceptions import EntityError
4
+
5
+
6
+ class RuntimeEntityBuilder:
7
+ """
8
+ RuntimeEntity builder.
9
+ """
10
+
11
+ EXECUTABLE_KIND: str = None
12
+ TASKS_KINDS: dict = None
13
+ RUN_KIND: str = None
14
+
15
+ def __init__(self) -> None:
16
+ if self.EXECUTABLE_KIND is None:
17
+ raise EntityError("EXECUTABLE_KIND must be set")
18
+ if self.TASKS_KINDS is None:
19
+ raise EntityError("TASKS_KINDS must be set")
20
+ if self.RUN_KIND is None:
21
+ raise EntityError("RUN_KIND must be set")
22
+
23
+ def get_action_from_task_kind(self, task_kind: str) -> str:
24
+ """
25
+ Get action from task kind.
26
+
27
+ Parameters
28
+ ----------
29
+ task_kind : str
30
+ Task kind.
31
+
32
+ Returns
33
+ -------
34
+ str
35
+ Action.
36
+ """
37
+ for task in self.TASKS_KINDS:
38
+ if task["kind"] == task_kind:
39
+ return task["action"]
40
+ msg = f"Task kind {task_kind} not allowed."
41
+ raise EntityError(msg)
42
+
43
+ def get_task_kind_from_action(self, action: str) -> list[str]:
44
+ """
45
+ Get task kinds from action.
46
+
47
+ Parameters
48
+ ----------
49
+ action : str
50
+ Action.
51
+
52
+ Returns
53
+ -------
54
+ list[str]
55
+ Task kinds.
56
+ """
57
+ for task in self.TASKS_KINDS:
58
+ if task["action"] == action:
59
+ return task["kind"]
60
+ msg = f"Action {action} not allowed."
61
+ raise EntityError(msg)
62
+
63
+ def get_run_kind(self) -> str:
64
+ """
65
+ Get run kind.
66
+
67
+ Returns
68
+ -------
69
+ str
70
+ Run kind.
71
+ """
72
+ return self.RUN_KIND
73
+
74
+ def get_executable_kind(self) -> str:
75
+ """
76
+ Get executable kind.
77
+
78
+ Returns
79
+ -------
80
+ str
81
+ Executable kind.
82
+ """
83
+ return self.EXECUTABLE_KIND
84
+
85
+ def get_all_kinds(self) -> list[str]:
86
+ """
87
+ Get all kinds.
88
+
89
+ Returns
90
+ -------
91
+ list[str]
92
+ All kinds.
93
+ """
94
+ task_kinds = [i["kind"] for i in self.TASKS_KINDS]
95
+ return [self.EXECUTABLE_KIND, self.RUN_KIND, *task_kinds]
96
+
97
+ def get_all_actions(self) -> list[str]:
98
+ """
99
+ Get all actions.
100
+
101
+ Returns
102
+ -------
103
+ list[str]
104
+ All actions.
105
+ """
106
+ return [i["action"] for i in self.TASKS_KINDS]
File without changes
@@ -0,0 +1,66 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.entity.builder import EntityBuilder
6
+
7
+ if typing.TYPE_CHECKING:
8
+ from digitalhub.entities._base.unversioned.entity import UnversionedEntity
9
+
10
+
11
+ class UnversionedBuilder(EntityBuilder):
12
+ """
13
+ Unversioned builder.
14
+ """
15
+
16
+ def from_dict(self, obj: dict, validate: bool = True) -> UnversionedEntity:
17
+ """
18
+ Create a new object from dictionary.
19
+
20
+ Parameters
21
+ ----------
22
+ obj : dict
23
+ Dictionary to create object from.
24
+ validate : bool
25
+ Flag to indicate if arguments must be validated.
26
+
27
+ Returns
28
+ -------
29
+ UnversionedEntity
30
+ Object instance.
31
+ """
32
+ parsed_dict = self._parse_dict(obj, validate=validate)
33
+ return self.build_entity(**parsed_dict)
34
+
35
+ def _parse_dict(self, obj: dict, validate: bool = True) -> dict:
36
+ """
37
+ Get dictionary and parse it to a valid entity dictionary.
38
+
39
+ Parameters
40
+ ----------
41
+ entity : str
42
+ Entity type.
43
+ obj : dict
44
+ Dictionary to parse.
45
+
46
+ Returns
47
+ -------
48
+ dict
49
+ A dictionary containing the attributes of the entity instance.
50
+ """
51
+ project = obj.get("project")
52
+ kind = obj.get("kind")
53
+ uuid = self.build_uuid(obj.get("id"))
54
+ metadata = self.build_metadata(**obj.get("metadata", {}))
55
+ spec = self.build_spec(validate=validate, **obj.get("spec", {}))
56
+ status = self.build_status(**obj.get("status", {}))
57
+ user = obj.get("user")
58
+ return {
59
+ "project": project,
60
+ "uuid": uuid,
61
+ "kind": kind,
62
+ "metadata": metadata,
63
+ "spec": spec,
64
+ "status": status,
65
+ "user": user,
66
+ }
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.context.entity import ContextEntity
6
+ from digitalhub.utils.io_utils import write_yaml
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from digitalhub.entities._base.entity.metadata import Metadata
10
+ from digitalhub.entities._base.entity.spec import Spec
11
+ from digitalhub.entities._base.entity.status import Status
12
+
13
+
14
+ class UnversionedEntity(ContextEntity):
15
+ def __init__(
16
+ self,
17
+ project: str,
18
+ uuid: str,
19
+ kind: str,
20
+ metadata: Metadata,
21
+ spec: Spec,
22
+ status: Status,
23
+ user: str | None = None,
24
+ ) -> None:
25
+ super().__init__(project, kind, metadata, spec, status, user)
26
+ self.id = uuid
27
+ self.key = f"store://{project}/{self.ENTITY_TYPE}/{kind}/{uuid}"
28
+ self._obj_attr.extend(["id"])
29
+
30
+ def export(self, filename: str | None = None) -> str:
31
+ """
32
+ Export object as a YAML file.
33
+
34
+ Parameters
35
+ ----------
36
+ filename : str
37
+ Name of the export YAML file. If not specified, the default value is used.
38
+
39
+ Returns
40
+ -------
41
+ str
42
+ Exported file.
43
+ """
44
+ obj = self.to_dict()
45
+ if filename is None:
46
+ filename = f"{self.ENTITY_TYPE}-{self.id}.yml"
47
+ pth = self._context().root / filename
48
+ write_yaml(pth, obj)
49
+ return str(pth)
File without changes
@@ -0,0 +1,68 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.entity.builder import EntityBuilder
6
+
7
+ if typing.TYPE_CHECKING:
8
+ from digitalhub.entities._base.versioned.entity import VersionedEntity
9
+
10
+
11
+ class VersionedBuilder(EntityBuilder):
12
+ """
13
+ Versioned builder.
14
+ """
15
+
16
+ def from_dict(self, obj: dict, validate: bool = True) -> VersionedEntity:
17
+ """
18
+ Create a new object from dictionary.
19
+
20
+ Parameters
21
+ ----------
22
+ obj : dict
23
+ Dictionary to create object from.
24
+ validate : bool
25
+ Flag to indicate if arguments must be validated.
26
+
27
+ Returns
28
+ -------
29
+ VersionedEntity
30
+ Object instance.
31
+ """
32
+ parsed_dict = self._parse_dict(obj, validate=validate)
33
+ return self.build_entity(**parsed_dict)
34
+
35
+ def _parse_dict(self, obj: dict, validate: bool = True) -> dict:
36
+ """
37
+ Get dictionary and parse it to a valid entity dictionary.
38
+
39
+ Parameters
40
+ ----------
41
+ entity : str
42
+ Entity type.
43
+ obj : dict
44
+ Dictionary to parse.
45
+
46
+ Returns
47
+ -------
48
+ dict
49
+ A dictionary containing the attributes of the entity instance.
50
+ """
51
+ project = obj.get("project")
52
+ kind = obj.get("kind")
53
+ name = self.build_name(obj.get("name"))
54
+ uuid = self.build_uuid(obj.get("id"))
55
+ metadata = self.build_metadata(**obj.get("metadata", {}))
56
+ spec = self.build_spec(validate=validate, **obj.get("spec", {}))
57
+ status = self.build_status(**obj.get("status", {}))
58
+ user = obj.get("user")
59
+ return {
60
+ "project": project,
61
+ "name": name,
62
+ "uuid": uuid,
63
+ "kind": kind,
64
+ "metadata": metadata,
65
+ "spec": spec,
66
+ "status": status,
67
+ "user": user,
68
+ }
@@ -0,0 +1,53 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.context.entity import ContextEntity
6
+ from digitalhub.utils.io_utils import write_yaml
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from digitalhub.entities._base.entity.metadata import Metadata
10
+ from digitalhub.entities._base.entity.spec import Spec
11
+ from digitalhub.entities._base.entity.status import Status
12
+
13
+
14
+ class VersionedEntity(ContextEntity):
15
+ def __init__(
16
+ self,
17
+ project: str,
18
+ name: str,
19
+ uuid: str,
20
+ kind: str,
21
+ metadata: Metadata,
22
+ spec: Spec,
23
+ status: Status,
24
+ user: str | None = None,
25
+ ) -> None:
26
+ super().__init__(project, kind, metadata, spec, status, user)
27
+ self.name = name
28
+ self.id = uuid
29
+ self.key = f"store://{project}/{self.ENTITY_TYPE}/{kind}/{name}:{uuid}"
30
+
31
+ # Add attributes to be used in the to_dict method
32
+ self._obj_attr.extend(["name", "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.name}-{self.id}.yml"
51
+ pth = self._context().root / filename
52
+ write_yaml(pth, obj)
53
+ return str(pth)
File without changes
File without changes
@@ -0,0 +1,86 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.versioned.builder import VersionedBuilder
6
+ from digitalhub.entities.utils.entity_types import EntityTypes
7
+ from digitalhub.utils.exceptions import EntityError
8
+
9
+ if typing.TYPE_CHECKING:
10
+ from digitalhub.entities.artifact._base.entity import Artifact
11
+
12
+
13
+ class ArtifactBuilder(VersionedBuilder):
14
+ """
15
+ Artifact builder.
16
+ """
17
+
18
+ ENTITY_TYPE = EntityTypes.ARTIFACT.value
19
+
20
+ def build(
21
+ self,
22
+ kind: str,
23
+ project: str,
24
+ name: str,
25
+ uuid: str | None = None,
26
+ description: str | None = None,
27
+ labels: list[str] | None = None,
28
+ embedded: bool = False,
29
+ path: str | None = None,
30
+ **kwargs,
31
+ ) -> Artifact:
32
+ """
33
+ Create a new object.
34
+
35
+ Parameters
36
+ ----------
37
+ project : str
38
+ Project name.
39
+ name : str
40
+ Object name.
41
+ kind : str
42
+ Kind the object.
43
+ uuid : str
44
+ ID of the object.
45
+ description : str
46
+ Description of the object (human readable).
47
+ labels : list[str]
48
+ List of labels.
49
+ embedded : bool
50
+ Flag to determine if object spec must be embedded in project spec.
51
+ path : str
52
+ Object path on local file system or remote storage. It is also the destination path of upload() method.
53
+ **kwargs : dict
54
+ Spec keyword arguments.
55
+
56
+ Returns
57
+ -------
58
+ Artifact
59
+ Object instance.
60
+ """
61
+ if path is None:
62
+ raise EntityError("Path must be provided.")
63
+
64
+ name = self.build_name(name)
65
+ uuid = self.build_uuid(uuid)
66
+ metadata = self.build_metadata(
67
+ project=project,
68
+ name=name,
69
+ description=description,
70
+ labels=labels,
71
+ embedded=embedded,
72
+ )
73
+ spec = self.build_spec(
74
+ path=path,
75
+ **kwargs,
76
+ )
77
+ status = self.build_status()
78
+ return self.build_entity(
79
+ project=project,
80
+ name=name,
81
+ uuid=uuid,
82
+ kind=kind,
83
+ metadata=metadata,
84
+ spec=spec,
85
+ status=status,
86
+ )
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.material.entity import MaterialEntity
6
+ from digitalhub.entities.utils.entity_types import EntityTypes
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from digitalhub.entities._base.entity.metadata import Metadata
10
+ from digitalhub.entities.artifact._base.spec import ArtifactSpec
11
+ from digitalhub.entities.artifact._base.status import ArtifactStatus
12
+
13
+
14
+ class Artifact(MaterialEntity):
15
+ """
16
+ A class representing a artifact.
17
+
18
+ Artifacts are (binary) objects stored in one of the artifact
19
+ stores of the platform, and available to every process, module
20
+ and component as files.
21
+ """
22
+
23
+ ENTITY_TYPE = EntityTypes.ARTIFACT.value
24
+
25
+ def __init__(
26
+ self,
27
+ project: str,
28
+ name: str,
29
+ uuid: str,
30
+ kind: str,
31
+ metadata: Metadata,
32
+ spec: ArtifactSpec,
33
+ status: ArtifactStatus,
34
+ user: str | None = None,
35
+ ) -> None:
36
+ super().__init__(project, name, uuid, kind, metadata, spec, status, user)
37
+
38
+ self.spec: ArtifactSpec
39
+ self.status: ArtifactStatus
@@ -0,0 +1,15 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.material.spec import MaterialSpec, MaterialValidator
4
+
5
+
6
+ class ArtifactSpec(MaterialSpec):
7
+ """
8
+ ArtifactSpec specifications.
9
+ """
10
+
11
+
12
+ class ArtifactValidator(MaterialValidator):
13
+ """
14
+ ArtifactValidator validator.
15
+ """
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.material.status import MaterialStatus
4
+
5
+
6
+ class ArtifactStatus(MaterialStatus):
7
+ """
8
+ ArtifactStatus status.
9
+ """
File without changes
@@ -0,0 +1,18 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities.artifact._base.builder import ArtifactBuilder
4
+ from digitalhub.entities.artifact.artifact.entity import ArtifactArtifact
5
+ from digitalhub.entities.artifact.artifact.spec import ArtifactSpecArtifact, ArtifactValidatorArtifact
6
+ from digitalhub.entities.artifact.artifact.status import ArtifactStatusArtifact
7
+
8
+
9
+ class ArtifactArtifactBuilder(ArtifactBuilder):
10
+ """
11
+ ArtifactArtifact builder.
12
+ """
13
+
14
+ ENTITY_CLASS = ArtifactArtifact
15
+ ENTITY_SPEC_CLASS = ArtifactSpecArtifact
16
+ ENTITY_SPEC_VALIDATOR = ArtifactValidatorArtifact
17
+ ENTITY_STATUS_CLASS = ArtifactStatusArtifact
18
+ ENTITY_KIND = "artifact"
@@ -0,0 +1,32 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities.artifact._base.entity import Artifact
6
+
7
+ if typing.TYPE_CHECKING:
8
+ from digitalhub.entities._base.entity.metadata import Metadata
9
+ from digitalhub.entities.artifact.artifact.spec import ArtifactSpecArtifact
10
+ from digitalhub.entities.artifact.artifact.status import ArtifactStatusArtifact
11
+
12
+
13
+ class ArtifactArtifact(Artifact):
14
+ """
15
+ ArtifactArtifact class.
16
+ """
17
+
18
+ def __init__(
19
+ self,
20
+ project: str,
21
+ name: str,
22
+ uuid: str,
23
+ kind: str,
24
+ metadata: Metadata,
25
+ spec: ArtifactSpecArtifact,
26
+ status: ArtifactStatusArtifact,
27
+ user: str | None = None,
28
+ ) -> None:
29
+ super().__init__(project, name, uuid, kind, metadata, spec, status, user)
30
+
31
+ self.spec: ArtifactSpecArtifact
32
+ self.status: ArtifactStatusArtifact
@@ -0,0 +1,27 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities.artifact._base.spec import ArtifactSpec, ArtifactValidator
4
+
5
+
6
+ class ArtifactSpecArtifact(ArtifactSpec):
7
+ """
8
+ ArtifactSpecArtifact specifications.
9
+ """
10
+
11
+ def __init__(
12
+ self,
13
+ path: str,
14
+ src_path: str | None = None,
15
+ **kwargs,
16
+ ) -> None:
17
+ super().__init__(path, **kwargs)
18
+ self.src_path = src_path
19
+
20
+
21
+ class ArtifactValidatorArtifact(ArtifactValidator):
22
+ """
23
+ ArtifactValidatorArtifact validator.
24
+ """
25
+
26
+ src_path: str = None
27
+ """Source path of the artifact."""
@@ -0,0 +1,15 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.material.status import MaterialStatus
4
+
5
+
6
+ class ArtifactStatus(MaterialStatus):
7
+ """
8
+ Status class for artifact entities.
9
+ """
10
+
11
+
12
+ class ArtifactStatusArtifact(ArtifactStatus):
13
+ """
14
+ Status class for artifact entities.
15
+ """