digitalhub 0.13.0b3__py3-none-any.whl → 0.14.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. digitalhub/__init__.py +3 -8
  2. digitalhub/context/api.py +43 -6
  3. digitalhub/context/builder.py +1 -5
  4. digitalhub/context/context.py +28 -13
  5. digitalhub/entities/_base/_base/entity.py +0 -15
  6. digitalhub/entities/_base/context/entity.py +1 -4
  7. digitalhub/entities/_base/entity/builder.py +5 -5
  8. digitalhub/entities/_base/entity/entity.py +0 -8
  9. digitalhub/entities/_base/executable/entity.py +195 -87
  10. digitalhub/entities/_base/material/entity.py +11 -23
  11. digitalhub/entities/_base/material/utils.py +28 -4
  12. digitalhub/entities/_base/runtime_entity/builder.py +53 -18
  13. digitalhub/entities/_base/unversioned/entity.py +1 -1
  14. digitalhub/entities/_base/versioned/entity.py +1 -1
  15. digitalhub/entities/_commons/enums.py +1 -31
  16. digitalhub/entities/_commons/metrics.py +64 -30
  17. digitalhub/entities/_commons/utils.py +119 -30
  18. digitalhub/entities/_constructors/_resources.py +151 -0
  19. digitalhub/entities/{_base/entity/_constructors → _constructors}/name.py +18 -0
  20. digitalhub/entities/_processors/base/crud.py +381 -0
  21. digitalhub/entities/_processors/base/import_export.py +118 -0
  22. digitalhub/entities/_processors/base/processor.py +299 -0
  23. digitalhub/entities/_processors/base/special_ops.py +104 -0
  24. digitalhub/entities/_processors/context/crud.py +652 -0
  25. digitalhub/entities/_processors/context/import_export.py +242 -0
  26. digitalhub/entities/_processors/context/material.py +123 -0
  27. digitalhub/entities/_processors/context/processor.py +400 -0
  28. digitalhub/entities/_processors/context/special_ops.py +476 -0
  29. digitalhub/entities/_processors/processors.py +12 -0
  30. digitalhub/entities/_processors/utils.py +38 -102
  31. digitalhub/entities/artifact/crud.py +58 -22
  32. digitalhub/entities/artifact/utils.py +28 -13
  33. digitalhub/entities/builders.py +2 -0
  34. digitalhub/entities/dataitem/crud.py +63 -20
  35. digitalhub/entities/dataitem/table/entity.py +27 -22
  36. digitalhub/entities/dataitem/utils.py +82 -32
  37. digitalhub/entities/function/_base/entity.py +3 -6
  38. digitalhub/entities/function/crud.py +55 -24
  39. digitalhub/entities/model/_base/entity.py +62 -20
  40. digitalhub/entities/model/crud.py +59 -23
  41. digitalhub/entities/model/mlflow/utils.py +29 -20
  42. digitalhub/entities/model/utils.py +28 -13
  43. digitalhub/entities/project/_base/builder.py +0 -6
  44. digitalhub/entities/project/_base/entity.py +337 -164
  45. digitalhub/entities/project/_base/spec.py +4 -4
  46. digitalhub/entities/project/crud.py +28 -71
  47. digitalhub/entities/project/utils.py +7 -3
  48. digitalhub/entities/run/_base/builder.py +0 -4
  49. digitalhub/entities/run/_base/entity.py +70 -63
  50. digitalhub/entities/run/crud.py +79 -26
  51. digitalhub/entities/secret/_base/entity.py +1 -5
  52. digitalhub/entities/secret/crud.py +31 -28
  53. digitalhub/entities/task/_base/builder.py +0 -4
  54. digitalhub/entities/task/_base/entity.py +5 -5
  55. digitalhub/entities/task/_base/models.py +13 -16
  56. digitalhub/entities/task/crud.py +61 -29
  57. digitalhub/entities/trigger/_base/entity.py +1 -5
  58. digitalhub/entities/trigger/crud.py +89 -30
  59. digitalhub/entities/workflow/_base/entity.py +3 -8
  60. digitalhub/entities/workflow/crud.py +55 -24
  61. digitalhub/factory/entity.py +283 -0
  62. digitalhub/factory/enums.py +18 -0
  63. digitalhub/factory/registry.py +197 -0
  64. digitalhub/factory/runtime.py +44 -0
  65. digitalhub/factory/utils.py +3 -54
  66. digitalhub/runtimes/_base.py +2 -2
  67. digitalhub/stores/client/{dhcore/api_builder.py → api_builder.py} +3 -3
  68. digitalhub/stores/client/builder.py +19 -31
  69. digitalhub/stores/client/client.py +322 -0
  70. digitalhub/stores/client/configurator.py +408 -0
  71. digitalhub/stores/client/enums.py +50 -0
  72. digitalhub/stores/client/{dhcore/error_parser.py → error_parser.py} +0 -4
  73. digitalhub/stores/client/header_manager.py +61 -0
  74. digitalhub/stores/client/http_handler.py +152 -0
  75. digitalhub/stores/client/{_base/key_builder.py → key_builder.py} +14 -14
  76. digitalhub/stores/client/params_builder.py +330 -0
  77. digitalhub/stores/client/response_processor.py +102 -0
  78. digitalhub/stores/client/utils.py +35 -0
  79. digitalhub/stores/{credentials → configurator}/api.py +5 -9
  80. digitalhub/stores/configurator/configurator.py +123 -0
  81. digitalhub/stores/{credentials → configurator}/enums.py +27 -10
  82. digitalhub/stores/configurator/handler.py +213 -0
  83. digitalhub/stores/{credentials → configurator}/ini_module.py +31 -22
  84. digitalhub/stores/data/_base/store.py +0 -20
  85. digitalhub/stores/data/api.py +5 -7
  86. digitalhub/stores/data/builder.py +53 -27
  87. digitalhub/stores/data/local/store.py +0 -103
  88. digitalhub/stores/data/remote/store.py +0 -4
  89. digitalhub/stores/data/s3/configurator.py +39 -77
  90. digitalhub/stores/data/s3/store.py +57 -37
  91. digitalhub/stores/data/sql/configurator.py +66 -46
  92. digitalhub/stores/data/sql/store.py +171 -104
  93. digitalhub/stores/readers/data/factory.py +0 -8
  94. digitalhub/stores/readers/data/pandas/reader.py +9 -19
  95. digitalhub/utils/file_utils.py +0 -17
  96. digitalhub/utils/generic_utils.py +1 -14
  97. digitalhub/utils/git_utils.py +0 -8
  98. digitalhub/utils/io_utils.py +0 -12
  99. digitalhub/utils/store_utils.py +44 -0
  100. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/METADATA +5 -4
  101. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/RECORD +112 -113
  102. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/WHEEL +1 -1
  103. digitalhub/entities/_commons/types.py +0 -9
  104. digitalhub/entities/_processors/base.py +0 -531
  105. digitalhub/entities/_processors/context.py +0 -1299
  106. digitalhub/entities/task/_base/utils.py +0 -22
  107. digitalhub/factory/factory.py +0 -381
  108. digitalhub/stores/client/_base/api_builder.py +0 -34
  109. digitalhub/stores/client/_base/client.py +0 -243
  110. digitalhub/stores/client/_base/params_builder.py +0 -34
  111. digitalhub/stores/client/api.py +0 -36
  112. digitalhub/stores/client/dhcore/client.py +0 -613
  113. digitalhub/stores/client/dhcore/configurator.py +0 -675
  114. digitalhub/stores/client/dhcore/enums.py +0 -34
  115. digitalhub/stores/client/dhcore/key_builder.py +0 -62
  116. digitalhub/stores/client/dhcore/models.py +0 -40
  117. digitalhub/stores/client/dhcore/params_builder.py +0 -278
  118. digitalhub/stores/client/dhcore/utils.py +0 -94
  119. digitalhub/stores/client/local/api_builder.py +0 -116
  120. digitalhub/stores/client/local/client.py +0 -573
  121. digitalhub/stores/client/local/enums.py +0 -15
  122. digitalhub/stores/client/local/key_builder.py +0 -62
  123. digitalhub/stores/client/local/params_builder.py +0 -120
  124. digitalhub/stores/credentials/__init__.py +0 -3
  125. digitalhub/stores/credentials/configurator.py +0 -210
  126. digitalhub/stores/credentials/handler.py +0 -176
  127. digitalhub/stores/credentials/store.py +0 -81
  128. digitalhub/stores/data/enums.py +0 -15
  129. digitalhub/stores/data/s3/utils.py +0 -78
  130. /digitalhub/entities/{_base/entity/_constructors → _constructors}/__init__.py +0 -0
  131. /digitalhub/entities/{_base/entity/_constructors → _constructors}/metadata.py +0 -0
  132. /digitalhub/entities/{_base/entity/_constructors → _constructors}/spec.py +0 -0
  133. /digitalhub/entities/{_base/entity/_constructors → _constructors}/status.py +0 -0
  134. /digitalhub/entities/{_base/entity/_constructors → _constructors}/uuid.py +0 -0
  135. /digitalhub/{stores/client/_base → entities/_processors/base}/__init__.py +0 -0
  136. /digitalhub/{stores/client/dhcore → entities/_processors/context}/__init__.py +0 -0
  137. /digitalhub/stores/{client/local → configurator}/__init__.py +0 -0
  138. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/licenses/AUTHORS +0 -0
  139. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,299 @@
1
+ # SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from __future__ import annotations
6
+
7
+ import typing
8
+
9
+ from digitalhub.entities._processors.base.crud import BaseEntityCRUDProcessor
10
+ from digitalhub.entities._processors.base.import_export import BaseEntityImportExportProcessor
11
+ from digitalhub.entities._processors.base.special_ops import BaseEntitySpecialOpsProcessor
12
+
13
+ if typing.TYPE_CHECKING:
14
+ from digitalhub.entities.project._base.entity import Project
15
+
16
+
17
+ class BaseEntityOperationsProcessor:
18
+ """
19
+ Processor for base entity operations.
20
+
21
+ This class handles CRUD operations and other entity management tasks
22
+ for base-level entities (primarily projects). It interacts with the
23
+ client layer to perform backend operations and manages entity lifecycle
24
+ including creation, reading, updating, deletion, and sharing.
25
+
26
+ Uses composition with specialized processors for different operation types.
27
+ """
28
+
29
+ def __init__(self):
30
+ self.crud_processor = BaseEntityCRUDProcessor()
31
+ self.import_export_processor = BaseEntityImportExportProcessor()
32
+ self.special_ops_processor = BaseEntitySpecialOpsProcessor()
33
+
34
+ ##############################
35
+ # CRUD base entity
36
+ ##############################
37
+
38
+ def create_project_entity(
39
+ self,
40
+ _entity: Project | None = None,
41
+ **kwargs,
42
+ ) -> Project:
43
+ """
44
+ Create a project entity in the backend.
45
+
46
+ Creates a new project either from an existing entity object or
47
+ by building one from the provided parameters. Handles both
48
+ local and remote backend creation.
49
+
50
+ Parameters
51
+ ----------
52
+ _entity : Project
53
+ An existing project entity object to create. If None,
54
+ a new entity will be built from kwargs.
55
+ **kwargs : dict
56
+ Parameters for entity creation, including 'local' flag
57
+ and entity-specific parameters.
58
+
59
+ Returns
60
+ -------
61
+ Project
62
+ The created project entity with backend data populated.
63
+ """
64
+ return self.crud_processor.create_project_entity(_entity, **kwargs)
65
+
66
+ def read_project_entity(
67
+ self,
68
+ entity_type: str,
69
+ entity_name: str,
70
+ **kwargs,
71
+ ) -> Project:
72
+ """
73
+ Read a project entity from the backend.
74
+
75
+ Retrieves project data from the backend and constructs a
76
+ Project entity object with the retrieved data.
77
+
78
+ Parameters
79
+ ----------
80
+ entity_type : str
81
+ The type of entity to read (typically 'project').
82
+ entity_name : str
83
+ The name identifier of the project to read.
84
+ **kwargs : dict
85
+ Additional parameters including 'local' flag and
86
+ API call parameters.
87
+
88
+ Returns
89
+ -------
90
+ Project
91
+ The project entity object populated with backend data.
92
+ """
93
+ return self.crud_processor.read_project_entity(entity_type, entity_name, **kwargs)
94
+
95
+ def update_project_entity(
96
+ self,
97
+ entity_type: str,
98
+ entity_name: str,
99
+ entity_dict: dict,
100
+ **kwargs,
101
+ ) -> Project:
102
+ """
103
+ Update a project entity in the backend.
104
+
105
+ Updates an existing project with new data and returns the
106
+ updated Project entity object.
107
+
108
+ Parameters
109
+ ----------
110
+ entity_type : str
111
+ The type of entity to update (typically 'project').
112
+ entity_name : str
113
+ The name identifier of the project to update.
114
+ entity_dict : dict
115
+ The updated project data dictionary.
116
+ **kwargs : dict
117
+ Additional parameters including 'local' flag and
118
+ API call parameters.
119
+
120
+ Returns
121
+ -------
122
+ Project
123
+ The updated project entity object.
124
+ """
125
+ return self.crud_processor.update_project_entity(entity_type, entity_name, entity_dict, **kwargs)
126
+
127
+ def delete_project_entity(
128
+ self,
129
+ entity_type: str,
130
+ entity_name: str,
131
+ **kwargs,
132
+ ) -> dict:
133
+ """
134
+ Delete a project entity from the backend.
135
+
136
+ Deletes a project from the backend and optionally cleans up
137
+ the associated context. Handles both local and remote backends.
138
+
139
+ Parameters
140
+ ----------
141
+ entity_type : str
142
+ The type of entity to delete (typically 'project').
143
+ entity_name : str
144
+ The name identifier of the project to delete.
145
+ **kwargs : dict
146
+ Additional parameters including 'local' flag, 'clean_context'
147
+ flag (default True), and API call parameters.
148
+
149
+ Returns
150
+ -------
151
+ dict
152
+ Response data from the backend delete operation.
153
+ """
154
+ return self.crud_processor.delete_project_entity(entity_type, entity_name, **kwargs)
155
+
156
+ def list_project_entities(
157
+ self,
158
+ entity_type: str,
159
+ **kwargs,
160
+ ) -> list[Project]:
161
+ """
162
+ List project entities from the backend.
163
+
164
+ Retrieves a list of projects from the backend and converts
165
+ them to Project entity objects.
166
+
167
+ Parameters
168
+ ----------
169
+ entity_type : str
170
+ The type of entities to list (typically 'project').
171
+ **kwargs : dict
172
+ Additional parameters including 'local' flag and
173
+ API call parameters for filtering or pagination.
174
+
175
+ Returns
176
+ -------
177
+ list[Project]
178
+ List of project entity objects.
179
+ """
180
+ return self.crud_processor.list_project_entities(entity_type, **kwargs)
181
+
182
+ ##############################
183
+ # Import/Export operations
184
+ ##############################
185
+
186
+ def import_project_entity(
187
+ self,
188
+ file: str,
189
+ **kwargs,
190
+ ) -> Project:
191
+ """
192
+ Import a project entity from a YAML file and create it in the backend.
193
+
194
+ Reads project configuration from a YAML file, creates a new project
195
+ entity in the backend, and imports any related entities defined
196
+ in the file. Raises an error if the project already exists.
197
+
198
+ Parameters
199
+ ----------
200
+ file : str
201
+ Path to the YAML file containing project configuration.
202
+ **kwargs : dict
203
+ Additional parameters including 'local' and 'reset_id' flags.
204
+
205
+ Returns
206
+ -------
207
+ Project
208
+ The imported and created project entity.
209
+
210
+ Raises
211
+ ------
212
+ EntityError
213
+ If the project already exists in the backend.
214
+ """
215
+ return self.import_export_processor.import_project_entity(self.crud_processor, file, **kwargs)
216
+
217
+ def load_project_entity(
218
+ self,
219
+ file: str,
220
+ **kwargs,
221
+ ) -> Project:
222
+ """
223
+ Load a project entity from a YAML file and update it in the backend.
224
+
225
+ Reads project configuration from a YAML file and updates an existing
226
+ project in the backend. If the project doesn't exist, it creates a
227
+ new one. Also loads any related entities defined in the file.
228
+
229
+ Parameters
230
+ ----------
231
+ file : str
232
+ Path to the YAML file containing project configuration.
233
+ **kwargs : dict
234
+ Additional parameters including 'local' flag.
235
+
236
+ Returns
237
+ -------
238
+ Project
239
+ The loaded and updated project entity.
240
+ """
241
+ return self.import_export_processor.load_project_entity(self.crud_processor, file, **kwargs)
242
+
243
+ ##############################
244
+ # Base entity operations
245
+ ##############################
246
+
247
+ def build_project_key(
248
+ self,
249
+ entity_id: str,
250
+ ) -> str:
251
+ """
252
+ Build a storage key for a project entity.
253
+
254
+ Creates a standardized key string for project identification
255
+ and storage, handling both local and remote client contexts.
256
+
257
+ Parameters
258
+ ----------
259
+ entity_id : str
260
+ The unique identifier of the project entity.
261
+
262
+ Returns
263
+ -------
264
+ str
265
+ The constructed project entity key string.
266
+ """
267
+ return self.special_ops_processor.build_project_key(entity_id)
268
+
269
+ def share_project_entity(
270
+ self,
271
+ entity_type: str,
272
+ entity_name: str,
273
+ **kwargs,
274
+ ) -> None:
275
+ """
276
+ Share or unshare a project entity with a user.
277
+
278
+ Manages project access permissions by sharing the project with
279
+ a specified user or removing user access. Handles both sharing
280
+ and unsharing operations based on the 'unshare' parameter.
281
+
282
+ Parameters
283
+ ----------
284
+ entity_type : str
285
+ The type of entity to share (typically 'project').
286
+ entity_name : str
287
+ The name identifier of the project to share.
288
+ **kwargs : dict
289
+ Additional parameters including:
290
+ - 'user': username to share with/unshare from
291
+ - 'unshare': boolean flag for unsharing (default False)
292
+ - 'local': boolean flag for local backend
293
+
294
+ Raises
295
+ ------
296
+ ValueError
297
+ If trying to unshare from a user who doesn't have access.
298
+ """
299
+ return self.special_ops_processor.share_project_entity(entity_type, entity_name, **kwargs)
@@ -0,0 +1,104 @@
1
+ # SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from __future__ import annotations
6
+
7
+ import typing
8
+
9
+ from digitalhub.stores.client.builder import get_client
10
+ from digitalhub.stores.client.enums import ApiCategories, BackendOperations
11
+
12
+ if typing.TYPE_CHECKING:
13
+ pass
14
+
15
+
16
+ class BaseEntitySpecialOpsProcessor:
17
+ """
18
+ Processor for specialized base entity operations.
19
+
20
+ Handles backend operations like sharing, key building, and other
21
+ specialized functionality for base-level entities.
22
+ """
23
+
24
+ def build_project_key(
25
+ self,
26
+ entity_id: str,
27
+ ) -> str:
28
+ """
29
+ Build a storage key for a project entity.
30
+
31
+ Creates a standardized key string for project identification
32
+ and storage, handling both local and remote client contexts.
33
+
34
+ Parameters
35
+ ----------
36
+ entity_id : str
37
+ The unique identifier of the project entity.
38
+
39
+ Returns
40
+ -------
41
+ str
42
+ The constructed project entity key string.
43
+ """
44
+ return get_client().build_key(ApiCategories.BASE.value, entity_id)
45
+
46
+ def share_project_entity(
47
+ self,
48
+ entity_type: str,
49
+ entity_name: str,
50
+ **kwargs,
51
+ ) -> None:
52
+ """
53
+ Share or unshare a project entity with a user.
54
+
55
+ Manages project access permissions by sharing the project with
56
+ a specified user or removing user access. Handles both sharing
57
+ and unsharing operations based on the 'unshare' parameter.
58
+
59
+ Parameters
60
+ ----------
61
+ entity_type : str
62
+ The type of entity to share (typically 'project').
63
+ entity_name : str
64
+ The name identifier of the project to share.
65
+ **kwargs : dict
66
+ Additional parameters including:
67
+ - 'user': username to share with/unshare from
68
+ - 'unshare': boolean flag for unsharing (default False)
69
+ - 'local': boolean flag for local backend
70
+
71
+ Raises
72
+ ------
73
+ ValueError
74
+ If trying to unshare from a user who doesn't have access.
75
+ """
76
+ client = get_client()
77
+ api = client.build_api(
78
+ ApiCategories.BASE.value,
79
+ BackendOperations.SHARE.value,
80
+ entity_type=entity_type,
81
+ entity_name=entity_name,
82
+ )
83
+
84
+ user = kwargs.pop("user", None)
85
+ if unshare := kwargs.pop("unshare", False):
86
+ users = client.read_object(api, **kwargs)
87
+ for u in users:
88
+ if u["user"] == user:
89
+ kwargs["id"] = u["id"]
90
+ break
91
+ else:
92
+ raise ValueError(f"User '{user}' does not have access to project.")
93
+
94
+ kwargs = client.build_parameters(
95
+ ApiCategories.BASE.value,
96
+ BackendOperations.SHARE.value,
97
+ unshare=unshare,
98
+ user=user,
99
+ **kwargs,
100
+ )
101
+ if unshare:
102
+ client.delete_object(api, **kwargs)
103
+ return
104
+ client.create_object(api, obj={}, **kwargs)