digitalhub 0.8.0__py3-none-any.whl → 0.8.0b1__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 (248) hide show
  1. digitalhub/__init__.py +4 -5
  2. digitalhub/client/builder.py +58 -3
  3. digitalhub/client/{dhcore/client.py → objects/dhcore.py} +60 -48
  4. digitalhub/client/{local/client.py → objects/local.py} +2 -2
  5. digitalhub/context/builder.py +85 -1
  6. digitalhub/context/context.py +1 -1
  7. digitalhub/datastores/builder.py +37 -13
  8. digitalhub/datastores/{_base/datastore.py → objects/base.py} +3 -3
  9. digitalhub/datastores/{local/datastore.py → objects/local.py} +2 -10
  10. digitalhub/datastores/{remote/datastore.py → objects/remote.py} +1 -9
  11. digitalhub/datastores/{s3/datastore.py → objects/s3.py} +2 -10
  12. digitalhub/datastores/{sql/datastore.py → objects/sql.py} +2 -10
  13. digitalhub/entities/_base/{_base/entity.py → base.py} +1 -1
  14. digitalhub/entities/_base/crud.py +389 -247
  15. digitalhub/entities/_base/entity/{entity.py → base.py} +34 -8
  16. digitalhub/entities/_base/{context/entity.py → entity/context.py} +6 -6
  17. digitalhub/entities/_base/{executable/entity.py → entity/executable.py} +36 -61
  18. digitalhub/entities/_base/{material/entity.py → entity/material.py} +6 -6
  19. digitalhub/entities/_base/entity/unversioned.py +87 -0
  20. digitalhub/entities/_base/entity/versioned.py +94 -0
  21. digitalhub/entities/_base/{entity/metadata.py → metadata.py} +2 -2
  22. digitalhub/entities/_base/{entity/spec.py → spec/base.py} +11 -11
  23. digitalhub/entities/_base/{material/spec.py → spec/material.py} +3 -3
  24. digitalhub/entities/_base/{entity/status.py → status/base.py} +3 -14
  25. digitalhub/entities/_base/{material/status.py → status/material.py} +1 -1
  26. digitalhub/entities/_builders/metadata.py +60 -0
  27. digitalhub/entities/_builders/spec.py +43 -0
  28. digitalhub/entities/_builders/status.py +62 -0
  29. digitalhub/entities/{_base/entity/_constructors → _builders}/uuid.py +11 -4
  30. digitalhub/entities/artifact/builder.py +133 -0
  31. digitalhub/entities/artifact/crud.py +48 -22
  32. digitalhub/entities/artifact/{_base/entity.py → entity/_base.py} +5 -5
  33. digitalhub/entities/artifact/entity/artifact.py +9 -0
  34. digitalhub/entities/artifact/{artifact/spec.py → spec.py} +16 -4
  35. digitalhub/entities/artifact/{artifact/status.py → status.py} +1 -1
  36. digitalhub/entities/dataitem/builder.py +144 -0
  37. digitalhub/entities/dataitem/crud.py +52 -29
  38. digitalhub/entities/dataitem/{_base/entity.py → entity/_base.py} +5 -5
  39. digitalhub/entities/dataitem/entity/dataitem.py +9 -0
  40. digitalhub/entities/dataitem/entity/iceberg.py +7 -0
  41. digitalhub/entities/dataitem/{table/entity.py → entity/table.py} +4 -25
  42. digitalhub/entities/dataitem/spec.py +61 -0
  43. digitalhub/entities/dataitem/status.py +38 -0
  44. digitalhub/entities/function/builder.py +86 -0
  45. digitalhub/entities/function/crud.py +43 -17
  46. digitalhub/entities/function/{_base/entity.py → entity.py} +12 -9
  47. digitalhub/entities/function/{_base/models.py → models.py} +1 -1
  48. digitalhub/entities/function/spec.py +81 -0
  49. digitalhub/entities/function/status.py +9 -0
  50. digitalhub/entities/model/builder.py +152 -0
  51. digitalhub/entities/model/crud.py +48 -21
  52. digitalhub/entities/model/{_base/entity.py → entity/_base.py} +5 -5
  53. digitalhub/entities/model/entity/huggingface.py +9 -0
  54. digitalhub/entities/model/{mlflow/utils.py → entity/mlflow.py} +10 -1
  55. digitalhub/entities/model/entity/model.py +9 -0
  56. digitalhub/entities/model/entity/sklearn.py +9 -0
  57. digitalhub/entities/model/spec.py +146 -0
  58. digitalhub/entities/model/status.py +33 -0
  59. digitalhub/entities/project/builder.py +82 -0
  60. digitalhub/entities/project/crud.py +12 -19
  61. digitalhub/entities/project/{_base/entity.py → entity.py} +102 -120
  62. digitalhub/entities/project/{_base/spec.py → spec.py} +4 -4
  63. digitalhub/entities/project/status.py +9 -0
  64. digitalhub/entities/registries.py +48 -0
  65. digitalhub/entities/run/builder.py +77 -0
  66. digitalhub/entities/run/crud.py +33 -20
  67. digitalhub/entities/run/{_base/entity.py → entity.py} +189 -35
  68. digitalhub/entities/run/spec.py +153 -0
  69. digitalhub/entities/run/status.py +114 -0
  70. digitalhub/entities/secret/builder.py +93 -0
  71. digitalhub/entities/secret/crud.py +31 -27
  72. digitalhub/entities/secret/{_base/entity.py → entity.py} +7 -8
  73. digitalhub/entities/secret/{_base/spec.py → spec.py} +4 -4
  74. digitalhub/entities/secret/status.py +9 -0
  75. digitalhub/entities/task/builder.py +74 -0
  76. digitalhub/entities/task/crud.py +33 -20
  77. digitalhub/entities/task/{_base/entity.py → entity.py} +8 -9
  78. digitalhub/entities/task/{_base/models.py → models.py} +0 -9
  79. digitalhub/entities/task/{_base/spec.py → spec.py} +7 -9
  80. digitalhub/entities/task/status.py +9 -0
  81. digitalhub/entities/{utils/utils.py → utils.py} +2 -20
  82. digitalhub/entities/workflow/builder.py +91 -0
  83. digitalhub/entities/workflow/crud.py +43 -17
  84. digitalhub/entities/workflow/{_base/entity.py → entity.py} +12 -9
  85. digitalhub/entities/workflow/spec.py +15 -0
  86. digitalhub/entities/workflow/status.py +9 -0
  87. digitalhub/readers/builder.py +54 -0
  88. digitalhub/readers/{pandas/reader.py → objects/pandas.py} +1 -1
  89. digitalhub/readers/registry.py +15 -0
  90. digitalhub/registry/models.py +87 -0
  91. digitalhub/registry/registry.py +74 -0
  92. digitalhub/registry/utils.py +150 -0
  93. digitalhub/runtimes/{_base.py → base.py} +65 -3
  94. digitalhub/runtimes/builder.py +40 -19
  95. digitalhub/runtimes/kind_registry.py +170 -0
  96. digitalhub/stores/builder.py +52 -6
  97. digitalhub/stores/{local/store.py → objects/local.py} +1 -1
  98. digitalhub/stores/{remote/store.py → objects/remote.py} +1 -1
  99. digitalhub/stores/{s3/store.py → objects/s3.py} +1 -1
  100. digitalhub/stores/{sql/store.py → objects/sql.py} +1 -1
  101. digitalhub/{client/dhcore/utils.py → utils/env_utils.py} +14 -2
  102. digitalhub/utils/exceptions.py +0 -12
  103. digitalhub/utils/generic_utils.py +42 -18
  104. digitalhub/utils/io_utils.py +2 -39
  105. {digitalhub-0.8.0.dist-info → digitalhub-0.8.0b1.dist-info}/METADATA +2 -3
  106. digitalhub-0.8.0b1.dist-info/RECORD +161 -0
  107. {digitalhub-0.8.0.dist-info → digitalhub-0.8.0b1.dist-info}/WHEEL +1 -1
  108. test/test_crud_artifacts.py +96 -0
  109. test/test_crud_dataitems.py +96 -0
  110. test/test_crud_functions.py +1 -1
  111. test/test_crud_runs.py +1 -1
  112. test/test_crud_tasks.py +1 -1
  113. digitalhub/client/api.py +0 -63
  114. digitalhub/client/dhcore/env.py +0 -21
  115. digitalhub/client/dhcore/models.py +0 -46
  116. digitalhub/context/api.py +0 -93
  117. digitalhub/datastores/api.py +0 -37
  118. digitalhub/entities/_base/api_utils.py +0 -620
  119. digitalhub/entities/_base/entity/_constructors/metadata.py +0 -44
  120. digitalhub/entities/_base/entity/_constructors/spec.py +0 -33
  121. digitalhub/entities/_base/entity/_constructors/status.py +0 -52
  122. digitalhub/entities/_base/entity/builder.py +0 -175
  123. digitalhub/entities/_base/executable/__init__.py +0 -0
  124. digitalhub/entities/_base/material/__init__.py +0 -0
  125. digitalhub/entities/_base/runtime_entity/__init__.py +0 -0
  126. digitalhub/entities/_base/runtime_entity/builder.py +0 -106
  127. digitalhub/entities/_base/unversioned/__init__.py +0 -0
  128. digitalhub/entities/_base/unversioned/builder.py +0 -66
  129. digitalhub/entities/_base/unversioned/entity.py +0 -49
  130. digitalhub/entities/_base/versioned/__init__.py +0 -0
  131. digitalhub/entities/_base/versioned/builder.py +0 -68
  132. digitalhub/entities/_base/versioned/entity.py +0 -53
  133. digitalhub/entities/artifact/_base/__init__.py +0 -0
  134. digitalhub/entities/artifact/_base/builder.py +0 -86
  135. digitalhub/entities/artifact/_base/spec.py +0 -15
  136. digitalhub/entities/artifact/_base/status.py +0 -9
  137. digitalhub/entities/artifact/artifact/__init__.py +0 -0
  138. digitalhub/entities/artifact/artifact/builder.py +0 -18
  139. digitalhub/entities/artifact/artifact/entity.py +0 -32
  140. digitalhub/entities/builders.py +0 -63
  141. digitalhub/entities/dataitem/_base/__init__.py +0 -0
  142. digitalhub/entities/dataitem/_base/builder.py +0 -86
  143. digitalhub/entities/dataitem/_base/spec.py +0 -15
  144. digitalhub/entities/dataitem/_base/status.py +0 -20
  145. digitalhub/entities/dataitem/dataitem/__init__.py +0 -0
  146. digitalhub/entities/dataitem/dataitem/builder.py +0 -18
  147. digitalhub/entities/dataitem/dataitem/entity.py +0 -32
  148. digitalhub/entities/dataitem/dataitem/spec.py +0 -15
  149. digitalhub/entities/dataitem/dataitem/status.py +0 -9
  150. digitalhub/entities/dataitem/iceberg/__init__.py +0 -0
  151. digitalhub/entities/dataitem/iceberg/builder.py +0 -18
  152. digitalhub/entities/dataitem/iceberg/entity.py +0 -32
  153. digitalhub/entities/dataitem/iceberg/spec.py +0 -15
  154. digitalhub/entities/dataitem/iceberg/status.py +0 -9
  155. digitalhub/entities/dataitem/table/__init__.py +0 -0
  156. digitalhub/entities/dataitem/table/builder.py +0 -18
  157. digitalhub/entities/dataitem/table/spec.py +0 -25
  158. digitalhub/entities/dataitem/table/status.py +0 -9
  159. digitalhub/entities/function/_base/__init__.py +0 -0
  160. digitalhub/entities/function/_base/builder.py +0 -79
  161. digitalhub/entities/function/_base/spec.py +0 -15
  162. digitalhub/entities/function/_base/status.py +0 -9
  163. digitalhub/entities/model/_base/__init__.py +0 -0
  164. digitalhub/entities/model/_base/builder.py +0 -86
  165. digitalhub/entities/model/_base/spec.py +0 -49
  166. digitalhub/entities/model/_base/status.py +0 -9
  167. digitalhub/entities/model/huggingface/__init__.py +0 -0
  168. digitalhub/entities/model/huggingface/builder.py +0 -18
  169. digitalhub/entities/model/huggingface/entity.py +0 -32
  170. digitalhub/entities/model/huggingface/spec.py +0 -36
  171. digitalhub/entities/model/huggingface/status.py +0 -9
  172. digitalhub/entities/model/mlflow/__init__.py +0 -0
  173. digitalhub/entities/model/mlflow/builder.py +0 -18
  174. digitalhub/entities/model/mlflow/entity.py +0 -32
  175. digitalhub/entities/model/mlflow/spec.py +0 -44
  176. digitalhub/entities/model/mlflow/status.py +0 -9
  177. digitalhub/entities/model/model/__init__.py +0 -0
  178. digitalhub/entities/model/model/builder.py +0 -18
  179. digitalhub/entities/model/model/entity.py +0 -32
  180. digitalhub/entities/model/model/spec.py +0 -15
  181. digitalhub/entities/model/model/status.py +0 -9
  182. digitalhub/entities/model/sklearn/__init__.py +0 -0
  183. digitalhub/entities/model/sklearn/builder.py +0 -18
  184. digitalhub/entities/model/sklearn/entity.py +0 -32
  185. digitalhub/entities/model/sklearn/spec.py +0 -15
  186. digitalhub/entities/model/sklearn/status.py +0 -9
  187. digitalhub/entities/project/_base/__init__.py +0 -0
  188. digitalhub/entities/project/_base/builder.py +0 -128
  189. digitalhub/entities/project/_base/status.py +0 -9
  190. digitalhub/entities/run/_base/__init__.py +0 -0
  191. digitalhub/entities/run/_base/builder.py +0 -94
  192. digitalhub/entities/run/_base/spec.py +0 -50
  193. digitalhub/entities/run/_base/status.py +0 -9
  194. digitalhub/entities/secret/_base/__init__.py +0 -0
  195. digitalhub/entities/secret/_base/builder.py +0 -81
  196. digitalhub/entities/secret/_base/status.py +0 -9
  197. digitalhub/entities/task/_base/__init__.py +0 -0
  198. digitalhub/entities/task/_base/builder.py +0 -91
  199. digitalhub/entities/task/_base/status.py +0 -9
  200. digitalhub/entities/utils/__init__.py +0 -0
  201. digitalhub/entities/workflow/_base/__init__.py +0 -0
  202. digitalhub/entities/workflow/_base/builder.py +0 -79
  203. digitalhub/entities/workflow/_base/spec.py +0 -15
  204. digitalhub/entities/workflow/_base/status.py +0 -9
  205. digitalhub/factory/__init__.py +0 -0
  206. digitalhub/factory/api.py +0 -277
  207. digitalhub/factory/factory.py +0 -268
  208. digitalhub/factory/utils.py +0 -90
  209. digitalhub/readers/_base/__init__.py +0 -0
  210. digitalhub/readers/_base/builder.py +0 -26
  211. digitalhub/readers/api.py +0 -80
  212. digitalhub/readers/factory.py +0 -133
  213. digitalhub/readers/pandas/__init__.py +0 -0
  214. digitalhub/readers/pandas/builder.py +0 -29
  215. digitalhub/stores/_base/__init__.py +0 -0
  216. digitalhub/stores/api.py +0 -54
  217. digitalhub/stores/local/__init__.py +0 -0
  218. digitalhub/stores/remote/__init__.py +0 -0
  219. digitalhub/stores/s3/__init__.py +0 -0
  220. digitalhub/stores/sql/__init__.py +0 -0
  221. digitalhub/utils/s3_utils.py +0 -58
  222. digitalhub-0.8.0.dist-info/RECORD +0 -231
  223. test/local/CRUD/test_artifacts.py +0 -96
  224. test/local/CRUD/test_dataitems.py +0 -96
  225. test/local/CRUD/test_models.py +0 -95
  226. /digitalhub/client/{_base → objects}/__init__.py +0 -0
  227. /digitalhub/client/{_base/client.py → objects/base.py} +0 -0
  228. /digitalhub/{client/dhcore → datastores/objects}/__init__.py +0 -0
  229. /digitalhub/entities/{utils → _base}/api.py +0 -0
  230. /digitalhub/{client/local → entities/_base/spec}/__init__.py +0 -0
  231. /digitalhub/entities/{utils → _base}/state.py +0 -0
  232. /digitalhub/{datastores/_base → entities/_base/status}/__init__.py +0 -0
  233. /digitalhub/{datastores/local → entities/_builders}/__init__.py +0 -0
  234. /digitalhub/entities/{_base/entity/_constructors → _builders}/name.py +0 -0
  235. /digitalhub/{datastores/remote → entities/artifact/entity}/__init__.py +0 -0
  236. /digitalhub/{datastores/s3 → entities/dataitem/entity}/__init__.py +0 -0
  237. /digitalhub/entities/dataitem/{table/models.py → models.py} +0 -0
  238. /digitalhub/entities/{utils/entity_types.py → entity_types.py} +0 -0
  239. /digitalhub/{datastores/sql → entities/model/entity}/__init__.py +0 -0
  240. /digitalhub/entities/model/{mlflow/models.py → models.py} +0 -0
  241. /digitalhub/{entities/_base/_base → readers/objects}/__init__.py +0 -0
  242. /digitalhub/readers/{_base/reader.py → objects/base.py} +0 -0
  243. /digitalhub/{entities/_base/context → registry}/__init__.py +0 -0
  244. /digitalhub/{entities/_base/entity/_constructors → stores/objects}/__init__.py +0 -0
  245. /digitalhub/stores/{_base/store.py → objects/base.py} +0 -0
  246. {digitalhub-0.8.0.dist-info → digitalhub-0.8.0b1.dist-info}/LICENSE.txt +0 -0
  247. {digitalhub-0.8.0.dist-info → digitalhub-0.8.0b1.dist-info}/top_level.txt +0 -0
  248. /test/{local/imports/test_imports.py → test_imports.py} +0 -0
@@ -0,0 +1,150 @@
1
+ from __future__ import annotations
2
+
3
+ import importlib
4
+ import importlib.metadata
5
+ import pkgutil
6
+ import re
7
+ from types import ModuleType
8
+
9
+
10
+ def import_module(package: str) -> ModuleType:
11
+ """
12
+ Import modules from package name.
13
+
14
+ Parameters
15
+ ----------
16
+ package : str
17
+ Package name.
18
+
19
+ Returns
20
+ -------
21
+ ModuleType
22
+ Module.
23
+ """
24
+ try:
25
+ return importlib.import_module(package)
26
+ except ModuleNotFoundError:
27
+ raise ModuleNotFoundError(f"Package {package} not found.")
28
+ except Exception as e:
29
+ raise e
30
+
31
+
32
+ def import_class(module_to_import: str, class_name: str) -> type:
33
+ """
34
+ Import class from implemented module.
35
+
36
+ Parameters
37
+ ----------
38
+ module_to_import : str
39
+ Module name.
40
+ class_name : str
41
+ Class name.
42
+
43
+ Returns
44
+ -------
45
+ type
46
+ Class.
47
+ """
48
+ module = import_module(module_to_import)
49
+ try:
50
+ return getattr(module, class_name)
51
+ except AttributeError:
52
+ raise ModuleNotFoundError(f"Module {module_to_import} has no '{class_name}' class.")
53
+
54
+
55
+ def list_runtimes() -> list[str]:
56
+ """
57
+ List installed runtimes for digitalhub.
58
+
59
+ Returns
60
+ -------
61
+ list
62
+ List of installed runtimes names.
63
+ """
64
+ pattern = r"digitalhub_runtime_.*"
65
+ runtimes = []
66
+ try:
67
+ for _, name, _ in pkgutil.iter_modules():
68
+ if re.match(pattern, name):
69
+ runtimes.append(name)
70
+ return runtimes
71
+ except Exception:
72
+ raise RuntimeError("Error listing installed runtimes.")
73
+
74
+
75
+ def register_runtimes_entities() -> None:
76
+ """
77
+ Register runtimes and related entities into registry.
78
+
79
+ Returns
80
+ -------
81
+ None
82
+ """
83
+ for package in list_runtimes():
84
+ import_module(package)
85
+
86
+
87
+ def register_entities() -> None:
88
+ """
89
+ Register layer and related entities into registry.
90
+
91
+ Returns
92
+ -------
93
+ None
94
+ """
95
+ # Try ot import registry from entities.registries module
96
+ try:
97
+ import_module(f"digitalhub.entities.registries")
98
+ except Exception:
99
+ pass
100
+
101
+
102
+ def create_info(
103
+ root: str,
104
+ entity_type: str,
105
+ prefix: str,
106
+ suffix: str | None = "",
107
+ runtime_info: dict | None = None,
108
+ ) -> dict:
109
+ """
110
+ Create entity info.
111
+
112
+ Parameters
113
+ ----------
114
+ root : str
115
+ Root module.
116
+ entity_type : str
117
+ Entity type.
118
+ prefix : str
119
+ Entity prefix.
120
+ suffix : str
121
+ Entity suffix.
122
+ runtime_info : dict
123
+ Runtime info.
124
+
125
+ Returns
126
+ -------
127
+ dict
128
+ Entity info.
129
+ """
130
+ dict_ = {
131
+ "entity_type": entity_type,
132
+ "spec": {
133
+ "module": f"{root}.{entity_type}.spec",
134
+ "class_name": f"{prefix}Spec{suffix}",
135
+ "parameters_validator": f"{prefix}Params{suffix}",
136
+ },
137
+ "status": {
138
+ "module": f"{root}.{entity_type}.status",
139
+ "class_name": f"{prefix}Status{suffix}",
140
+ },
141
+ "metadata": {
142
+ "module": "digitalhub.entities._base.metadata",
143
+ "class_name": "Metadata",
144
+ },
145
+ }
146
+ # Add runtime only if provided
147
+ # (in functions, tasks, runs and workflows)
148
+ if runtime_info is not None:
149
+ dict_["runtime"] = runtime_info
150
+ return dict_
@@ -1,12 +1,15 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import typing
3
4
  from abc import abstractmethod
4
5
  from typing import Any, Callable
5
6
 
6
- from digitalhub.factory.api import get_action_from_task_kind
7
7
  from digitalhub.utils.exceptions import EntityError
8
8
  from digitalhub.utils.logger import LOGGER
9
9
 
10
+ if typing.TYPE_CHECKING:
11
+ from digitalhub.runtimes.kind_registry import KindRegistry
12
+
10
13
 
11
14
  class Runtime:
12
15
  """
@@ -19,7 +22,8 @@ class Runtime:
19
22
  libraries, code, external tools etc.
20
23
  """
21
24
 
22
- def __init__(self, project: str) -> None:
25
+ def __init__(self, kind_registry: KindRegistry, project: str) -> None:
26
+ self.kind_registry = kind_registry
23
27
  self.project = project
24
28
 
25
29
  @abstractmethod
@@ -69,7 +73,7 @@ class Runtime:
69
73
  raise RuntimeError(msg)
70
74
 
71
75
  try:
72
- return get_action_from_task_kind(task_kind, task_kind)
76
+ return self.get_action_from_task_kind(task_kind)
73
77
  except EntityError:
74
78
  msg = f"Task {task_kind} not allowed."
75
79
  LOGGER.exception(msg)
@@ -100,3 +104,61 @@ class Runtime:
100
104
  msg = "Something got wrong during function execution."
101
105
  LOGGER.exception(msg)
102
106
  raise RuntimeError(msg)
107
+
108
+ ##############################
109
+ # Wrapper registry methods
110
+ ##############################
111
+
112
+ def get_executable_kind(self) -> str:
113
+ """
114
+ Get executable kind.
115
+
116
+ Returns
117
+ -------
118
+ str
119
+ Executable kind.
120
+ """
121
+ return self.kind_registry.get_executable_kind()
122
+
123
+ def get_task_kind_from_action(self, action: str) -> str:
124
+ """
125
+ Get task kind from action.
126
+
127
+ Parameters
128
+ ----------
129
+ action : str
130
+ Task action.
131
+
132
+ Returns
133
+ -------
134
+ str
135
+ Task kind.
136
+ """
137
+ return self.kind_registry.get_task_kind_from_action(action)
138
+
139
+ def get_action_from_task_kind(self, kind: str) -> str:
140
+ """
141
+ Get action from task.
142
+
143
+ Parameters
144
+ ----------
145
+ kind : str
146
+ Task kind.
147
+
148
+ Returns
149
+ -------
150
+ str
151
+ Action.
152
+ """
153
+ return self.kind_registry.get_action_from_task_kind(kind)
154
+
155
+ def get_run_kind(self) -> str:
156
+ """
157
+ Get run kind.
158
+
159
+ Returns
160
+ -------
161
+ str
162
+ Run kind.
163
+ """
164
+ return self.kind_registry.get_run_kind()
@@ -2,31 +2,52 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.utils.exceptions import BuilderError
5
+ from digitalhub.registry.registry import registry
6
+ from digitalhub.registry.utils import import_class
6
7
 
7
8
  if typing.TYPE_CHECKING:
8
- from digitalhub.runtimes._base import Runtime
9
+ from digitalhub.registry.models import RegistryEntry
10
+ from digitalhub.runtimes.base import Runtime
11
+ from digitalhub.runtimes.kind_registry import KindRegistry
9
12
 
10
13
 
11
- class RuntimeBuilder:
14
+ def build_runtime(kind: str, project: str) -> Runtime:
12
15
  """
13
- Builder class for building runtimes.
16
+ Build runtime object. The builder takes in input a kind.
17
+ This kind can derive from functions, tasks, or runs, and
18
+ is inserted in the global kind registry where the runtimes
19
+ pakages are registered.
20
+ The builder requires the module path where the Runtime
21
+ subclass is defined and the class name. It requires also
22
+ the kind registry module, kind registry class and the project
23
+ name.
24
+
25
+ Parameters
26
+ ----------
27
+ kind : str
28
+ The type of runtime to build.
29
+ project : str
30
+ The project name.
31
+
32
+ Returns
33
+ -------
34
+ Runtime
35
+ Runtime object.
14
36
  """
37
+ infos: RegistryEntry = getattr(registry, kind)
38
+ cls = import_class(infos.runtime.module, infos.runtime.class_name)
39
+ kind_registry = get_kind_registry(kind)
40
+ return cls(kind_registry, project)
15
41
 
16
- # Class variables
17
- RUNTIME_CLASS: Runtime = None
18
42
 
19
- def __init__(self) -> None:
20
- if self.RUNTIME_CLASS is None:
21
- raise BuilderError("RUNTIME_CLASS must be set")
22
-
23
- def build(self, project: str, *args, **kwargs) -> Runtime:
24
- """
25
- Build runtime object.
43
+ def get_kind_registry(kind: str) -> KindRegistry:
44
+ """
45
+ Get kind registry.
26
46
 
27
- Returns
28
- -------
29
- Runtime
30
- Runtime object.
31
- """
32
- return self.RUNTIME_CLASS(project, *args, **kwargs)
47
+ Returns
48
+ -------
49
+ KindRegistry
50
+ Kind registry.
51
+ """
52
+ infos: RegistryEntry = getattr(registry, kind)
53
+ return import_class(infos.runtime.kind_registry_module, infos.runtime.kind_registry_class_name)
@@ -0,0 +1,170 @@
1
+ from __future__ import annotations
2
+
3
+ from pydantic import BaseModel
4
+
5
+ from digitalhub.utils.exceptions import EntityError
6
+
7
+
8
+ class TaskModel(BaseModel):
9
+ """
10
+ Task model.
11
+ """
12
+
13
+ kind: str
14
+ action: str
15
+
16
+
17
+ class RunModel(BaseModel):
18
+ """
19
+ Run model.
20
+ """
21
+
22
+ kind: str
23
+
24
+
25
+ class ExecutableModel(BaseModel):
26
+ """
27
+ Executable model.
28
+ """
29
+
30
+ kind: str
31
+
32
+
33
+ class DataModel(BaseModel):
34
+ """
35
+ Data model.
36
+ """
37
+
38
+ executable: ExecutableModel
39
+ task: list[TaskModel]
40
+ run: RunModel
41
+
42
+
43
+ class KindRegistry:
44
+
45
+ """
46
+ Kind registry module for runtimes.
47
+ """
48
+
49
+ def __init__(self, data: dict[str, dict[str, str]]) -> None:
50
+ """
51
+ Constructor.
52
+
53
+ Parameters
54
+ ----------
55
+ data : dict[str, dict[str, str]]
56
+ Data to validate.
57
+
58
+ Examples
59
+ --------
60
+ >>> data = {
61
+ ... "executable": {
62
+ ... "kind": "executable-kind"
63
+ ... },
64
+ ... "run": {
65
+ ... "kind": "run-kind"
66
+ ... },
67
+ ... "task": [
68
+ ... {"kind": "task-kind-0", "action": "action-0"},
69
+ ... {"kind": "task-kind-1", "action": "action-1"},
70
+ ... {"kind": "task-kind-2", "action": "action-2"},
71
+ ... ]
72
+ ... }
73
+ """
74
+ validated_data = self._validate_data(data)
75
+ self.data = validated_data
76
+
77
+ def _validate_data(self, data: dict[str, dict[str, str]]) -> DataModel:
78
+ """
79
+ Validate data.
80
+
81
+ Parameters
82
+ ----------
83
+ data : dict[str, dict[str, str]]
84
+ Data to validate.
85
+
86
+ Raises
87
+ ------
88
+ EntityError
89
+ If data is not valid.
90
+ """
91
+ try:
92
+ return DataModel(**data)
93
+ except Exception as e:
94
+ raise EntityError("Invalid data.") from e
95
+
96
+ def get_task_kind_from_action(self, action: str) -> str:
97
+ """
98
+ Get task kind from action.
99
+
100
+ Parameters
101
+ ----------
102
+ action : str
103
+ Task action.
104
+
105
+ Returns
106
+ -------
107
+ str
108
+ Task kind.
109
+
110
+ Raises
111
+ ------
112
+ EntityError
113
+ If action is not allowed.
114
+ """
115
+ try:
116
+ for task in self.data.task:
117
+ if task.action == action:
118
+ return task.kind
119
+ except StopIteration:
120
+ msg = f"Action {action} not allowed."
121
+ raise EntityError(msg)
122
+
123
+ def get_action_from_task_kind(self, kind: str) -> str:
124
+ """
125
+ Get action from task.
126
+
127
+ Parameters
128
+ ----------
129
+ kind : str
130
+ Task kind.
131
+
132
+ Returns
133
+ -------
134
+ str
135
+ Action.
136
+
137
+ Raises
138
+ ------
139
+ EntityError
140
+ If task is not allowed.
141
+ """
142
+ try:
143
+ for task in self.data.task:
144
+ if task.kind == kind:
145
+ return task.action
146
+ except StopIteration:
147
+ msg = f"Task {kind} not allowed."
148
+ raise EntityError(msg)
149
+
150
+ def get_run_kind(self) -> str:
151
+ """
152
+ Get run kind.
153
+
154
+ Returns
155
+ -------
156
+ str
157
+ Run kind.
158
+ """
159
+ return self.data.run.kind
160
+
161
+ def get_executable_kind(self) -> str:
162
+ """
163
+ Get executable kind.
164
+
165
+ Returns
166
+ -------
167
+ str
168
+ Executable kind.
169
+ """
170
+ return self.data.executable.kind
@@ -5,16 +5,16 @@ import typing
5
5
 
6
6
  from pydantic import ValidationError
7
7
 
8
- from digitalhub.stores._base.store import StoreParameters
9
- from digitalhub.stores.local.store import LocalStore, LocalStoreConfig
10
- from digitalhub.stores.remote.store import RemoteStore, RemoteStoreConfig
11
- from digitalhub.stores.s3.store import S3Store, S3StoreConfig
12
- from digitalhub.stores.sql.store import SqlStore, SQLStoreConfig
8
+ from digitalhub.stores.objects.base import StoreParameters
9
+ from digitalhub.stores.objects.local import LocalStore, LocalStoreConfig
10
+ from digitalhub.stores.objects.remote import RemoteStore, RemoteStoreConfig
11
+ from digitalhub.stores.objects.s3 import S3Store, S3StoreConfig
12
+ from digitalhub.stores.objects.sql import SqlStore, SQLStoreConfig
13
13
  from digitalhub.utils.exceptions import StoreError
14
14
  from digitalhub.utils.uri_utils import map_uri_scheme
15
15
 
16
16
  if typing.TYPE_CHECKING:
17
- from digitalhub.stores._base.store import Store
17
+ from digitalhub.stores.objects.base import Store
18
18
 
19
19
 
20
20
  REGISTRY_STORES = {
@@ -208,4 +208,50 @@ def get_env_store_config(scheme: str) -> StoreParameters:
208
208
  raise ValueError(f"Unsupported scheme {scheme}")
209
209
 
210
210
 
211
+ def set_store(store_cfg: StoreParameters) -> None:
212
+ """
213
+ Set a new store instance with the given configuration.
214
+
215
+ Parameters
216
+ ----------
217
+ store_cfg : StoreParameters
218
+ Store configuration.
219
+
220
+ Returns
221
+ -------
222
+ None
223
+ """
224
+ store_builder.build(store_cfg)
225
+
226
+
227
+ def get_store(uri: str) -> Store:
228
+ """
229
+ Get store instance by uri.
230
+
231
+ Parameters
232
+ ---------
233
+ uri : str
234
+ URI to parse.
235
+
236
+ Returns
237
+ -------
238
+ Store
239
+ Store instance.
240
+ """
241
+ return store_builder.get(uri)
242
+
243
+
244
+ def get_default_store() -> Store:
245
+ """
246
+ Get the default store instance. The default store is the one that
247
+ can persist artifacts and dataitems.
248
+
249
+ Returns
250
+ -------
251
+ Store
252
+ Default store instance.
253
+ """
254
+ return store_builder.default()
255
+
256
+
211
257
  store_builder = StoreBuilder()
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  import shutil
4
4
  from pathlib import Path
5
5
 
6
- from digitalhub.stores._base.store import Store, StoreConfig
6
+ from digitalhub.stores.objects.base import Store, StoreConfig
7
7
  from digitalhub.utils.exceptions import StoreError
8
8
  from digitalhub.utils.file_utils import get_file_info_from_local
9
9
 
@@ -4,7 +4,7 @@ from pathlib import Path
4
4
 
5
5
  import requests
6
6
 
7
- from digitalhub.stores._base.store import Store, StoreConfig
7
+ from digitalhub.stores.objects.base import Store, StoreConfig
8
8
  from digitalhub.utils.exceptions import StoreError
9
9
 
10
10
 
@@ -9,7 +9,7 @@ import boto3
9
9
  import botocore.client # pylint: disable=unused-import
10
10
  from botocore.exceptions import ClientError
11
11
 
12
- from digitalhub.stores._base.store import Store, StoreConfig
12
+ from digitalhub.stores.objects.base import Store, StoreConfig
13
13
  from digitalhub.utils.exceptions import StoreError
14
14
  from digitalhub.utils.file_utils import get_file_info_from_s3, get_file_mime_type
15
15
 
@@ -9,7 +9,7 @@ from sqlalchemy.engine import Engine
9
9
  from sqlalchemy.engine.row import LegacyRow
10
10
  from sqlalchemy.exc import SQLAlchemyError
11
11
 
12
- from digitalhub.stores._base.store import Store, StoreConfig
12
+ from digitalhub.stores.objects.base import Store, StoreConfig
13
13
  from digitalhub.utils.exceptions import StoreError
14
14
 
15
15
 
@@ -3,10 +3,10 @@ from __future__ import annotations
3
3
  import os
4
4
  import typing
5
5
 
6
- from digitalhub.client.api import check_client_exists, get_client
6
+ from digitalhub.client.builder import check_client_exists, get_client
7
7
 
8
8
  if typing.TYPE_CHECKING:
9
- from digitalhub.client.dhcore.client import ClientDHCore
9
+ from digitalhub.client.objects.dhcore import ClientDHCore
10
10
 
11
11
 
12
12
  def set_dhcore_env(
@@ -109,3 +109,15 @@ def refresh_token() -> None:
109
109
  """
110
110
  client: ClientDHCore = get_client(local=False)
111
111
  client._get_new_access_token()
112
+
113
+
114
+ def get_s3_bucket() -> str | None:
115
+ """
116
+ Function to get S3 bucket name.
117
+
118
+ Returns
119
+ -------
120
+ str
121
+ The S3 bucket name.
122
+ """
123
+ return os.getenv("S3_BUCKET_NAME", "datalake")
@@ -1,12 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
3
 
4
- class BuilderError(Exception):
5
- """
6
- Raised when incontered errors on builders.
7
- """
8
-
9
-
10
4
  class StoreError(Exception):
11
5
  """
12
6
  Raised when incontered errors on stores.
@@ -59,9 +53,3 @@ class EntityError(Exception):
59
53
  """
60
54
  Raised when incontered errors on entities.
61
55
  """
62
-
63
-
64
- class ContextError(Exception):
65
- """
66
- Raised when context errors.
67
- """