digitalhub 0.13.0b4__py3-none-any.whl → 0.14.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.
- digitalhub/__init__.py +3 -8
- digitalhub/entities/_base/_base/entity.py +0 -11
- digitalhub/entities/_base/entity/builder.py +5 -5
- digitalhub/entities/_base/executable/entity.py +1 -1
- digitalhub/entities/_base/runtime_entity/builder.py +53 -18
- digitalhub/entities/_commons/utils.py +64 -21
- digitalhub/entities/_processors/base.py +11 -3
- digitalhub/entities/_processors/context.py +71 -22
- digitalhub/entities/_processors/utils.py +3 -3
- digitalhub/entities/artifact/crud.py +20 -4
- digitalhub/entities/artifact/utils.py +1 -1
- digitalhub/entities/dataitem/crud.py +20 -4
- digitalhub/entities/dataitem/table/entity.py +0 -21
- digitalhub/entities/dataitem/utils.py +1 -1
- digitalhub/entities/function/_base/entity.py +1 -1
- digitalhub/entities/function/crud.py +15 -4
- digitalhub/entities/model/_base/entity.py +21 -1
- digitalhub/entities/model/crud.py +21 -5
- digitalhub/entities/model/utils.py +1 -1
- digitalhub/entities/project/_base/entity.py +65 -33
- digitalhub/entities/project/crud.py +8 -1
- digitalhub/entities/run/_base/entity.py +21 -1
- digitalhub/entities/run/crud.py +22 -5
- digitalhub/entities/secret/crud.py +22 -5
- digitalhub/entities/task/crud.py +22 -5
- digitalhub/entities/trigger/crud.py +20 -4
- digitalhub/entities/workflow/_base/entity.py +1 -1
- digitalhub/entities/workflow/crud.py +15 -4
- digitalhub/factory/enums.py +18 -0
- digitalhub/factory/factory.py +136 -57
- digitalhub/factory/utils.py +3 -54
- digitalhub/stores/client/api.py +6 -10
- digitalhub/stores/client/builder.py +3 -3
- digitalhub/stores/client/dhcore/client.py +105 -163
- digitalhub/stores/client/dhcore/configurator.py +92 -289
- digitalhub/stores/client/dhcore/enums.py +0 -16
- digitalhub/stores/client/dhcore/params_builder.py +41 -83
- digitalhub/stores/client/dhcore/utils.py +14 -22
- digitalhub/stores/client/local/client.py +77 -45
- digitalhub/stores/credentials/ini_module.py +0 -16
- digitalhub/stores/data/local/store.py +0 -103
- digitalhub/stores/data/s3/configurator.py +60 -6
- digitalhub/stores/data/s3/store.py +44 -2
- digitalhub/stores/data/sql/store.py +15 -0
- digitalhub/utils/file_utils.py +0 -17
- digitalhub/utils/generic_utils.py +1 -2
- digitalhub/utils/store_utils.py +44 -0
- {digitalhub-0.13.0b4.dist-info → digitalhub-0.14.0b1.dist-info}/METADATA +3 -2
- {digitalhub-0.13.0b4.dist-info → digitalhub-0.14.0b1.dist-info}/RECORD +58 -59
- digitalhub/entities/task/_base/utils.py +0 -22
- digitalhub/stores/client/dhcore/models.py +0 -40
- digitalhub/stores/data/s3/utils.py +0 -78
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/__init__.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/metadata.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/name.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/spec.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/status.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/uuid.py +0 -0
- {digitalhub-0.13.0b4.dist-info → digitalhub-0.14.0b1.dist-info}/WHEEL +0 -0
- {digitalhub-0.13.0b4.dist-info → digitalhub-0.14.0b1.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub-0.13.0b4.dist-info → digitalhub-0.14.0b1.dist-info}/licenses/LICENSE +0 -0
|
@@ -73,7 +73,7 @@ class Workflow(ExecutableEntity):
|
|
|
73
73
|
"""
|
|
74
74
|
# Get task and run kind
|
|
75
75
|
task_kind = factory.get_task_kind_from_action(self.kind, action)
|
|
76
|
-
run_kind = factory.
|
|
76
|
+
run_kind = factory.get_run_kind_from_action(self.kind, action)
|
|
77
77
|
|
|
78
78
|
# Create or update new task
|
|
79
79
|
task = self._get_or_create_task(task_kind)
|
|
@@ -181,14 +181,25 @@ def list_workflows(project: str, **kwargs) -> list[Workflow]:
|
|
|
181
181
|
)
|
|
182
182
|
|
|
183
183
|
|
|
184
|
-
def import_workflow(
|
|
184
|
+
def import_workflow(
|
|
185
|
+
file: str | None = None,
|
|
186
|
+
key: str | None = None,
|
|
187
|
+
reset_id: bool = False,
|
|
188
|
+
context: str | None = None,
|
|
189
|
+
) -> Workflow:
|
|
185
190
|
"""
|
|
186
|
-
Import object from a YAML file
|
|
191
|
+
Import an object from a YAML file or from a storage key.
|
|
187
192
|
|
|
188
193
|
Parameters
|
|
189
194
|
----------
|
|
190
195
|
file : str
|
|
191
|
-
Path to YAML file.
|
|
196
|
+
Path to the YAML file.
|
|
197
|
+
key : str
|
|
198
|
+
Entity key (store://...).
|
|
199
|
+
reset_id : bool
|
|
200
|
+
Flag to determine if the ID of executable entities should be reset.
|
|
201
|
+
context : str
|
|
202
|
+
Project name to use for context resolution.
|
|
192
203
|
|
|
193
204
|
Returns
|
|
194
205
|
-------
|
|
@@ -199,7 +210,7 @@ def import_workflow(file: str) -> Workflow:
|
|
|
199
210
|
--------
|
|
200
211
|
>>> obj = import_workflow("my-workflow.yaml")
|
|
201
212
|
"""
|
|
202
|
-
return context_processor.import_executable_entity(file)
|
|
213
|
+
return context_processor.import_executable_entity(file, key, reset_id, context)
|
|
203
214
|
|
|
204
215
|
|
|
205
216
|
def load_workflow(file: str) -> Workflow:
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from enum import Enum
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FactoryEnum(Enum):
|
|
11
|
+
"""
|
|
12
|
+
Enumeration for factory.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
RGX_RUNTIMES = r"digitalhub_runtime_.*"
|
|
16
|
+
REG_ENTITIES = "digitalhub.entities.builders"
|
|
17
|
+
REG_ENTITIES_VAR = "entity_builders"
|
|
18
|
+
REG_RUNTIME_VAR = "runtime_builders"
|
digitalhub/factory/factory.py
CHANGED
|
@@ -6,6 +6,8 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
|
+
from digitalhub.factory.enums import FactoryEnum
|
|
10
|
+
from digitalhub.factory.utils import import_module, list_runtimes
|
|
9
11
|
from digitalhub.utils.exceptions import BuilderError
|
|
10
12
|
|
|
11
13
|
if typing.TYPE_CHECKING:
|
|
@@ -33,9 +35,9 @@ class Factory:
|
|
|
33
35
|
Attributes
|
|
34
36
|
----------
|
|
35
37
|
_entity_builders : dict[str, EntityBuilder | RuntimeEntityBuilder]
|
|
36
|
-
Registry of entity builders indexed by kind.
|
|
38
|
+
Registry of instantiated entity builders indexed by kind.
|
|
37
39
|
_runtime_builders : dict[str, RuntimeBuilder]
|
|
38
|
-
Registry of runtime builders indexed by kind.
|
|
40
|
+
Registry of instantiated runtime builders indexed by kind.
|
|
39
41
|
|
|
40
42
|
Notes
|
|
41
43
|
-----
|
|
@@ -46,8 +48,10 @@ class Factory:
|
|
|
46
48
|
def __init__(self):
|
|
47
49
|
self._entity_builders: dict[str, EntityBuilder | RuntimeEntityBuilder] = {}
|
|
48
50
|
self._runtime_builders: dict[str, RuntimeBuilder] = {}
|
|
51
|
+
self._entities_registered = False
|
|
52
|
+
self._runtimes_registered = False
|
|
49
53
|
|
|
50
|
-
def add_entity_builder(self, name: str, builder: EntityBuilder | RuntimeEntityBuilder) -> None:
|
|
54
|
+
def add_entity_builder(self, name: str, builder: type[EntityBuilder | RuntimeEntityBuilder]) -> None:
|
|
51
55
|
"""
|
|
52
56
|
Register an entity builder.
|
|
53
57
|
|
|
@@ -55,8 +59,8 @@ class Factory:
|
|
|
55
59
|
----------
|
|
56
60
|
name : str
|
|
57
61
|
The unique identifier for the builder.
|
|
58
|
-
builder : EntityBuilder
|
|
59
|
-
The builder
|
|
62
|
+
builder : type[EntityBuilder] | type[RuntimeEntityBuilder]
|
|
63
|
+
The builder class to register. It will be instantiated immediately.
|
|
60
64
|
|
|
61
65
|
Returns
|
|
62
66
|
-------
|
|
@@ -71,7 +75,7 @@ class Factory:
|
|
|
71
75
|
raise BuilderError(f"Builder {name} already exists.")
|
|
72
76
|
self._entity_builders[name] = builder()
|
|
73
77
|
|
|
74
|
-
def add_runtime_builder(self, name: str, builder: RuntimeBuilder) -> None:
|
|
78
|
+
def add_runtime_builder(self, name: str, builder: type[RuntimeBuilder]) -> None:
|
|
75
79
|
"""
|
|
76
80
|
Register a runtime builder.
|
|
77
81
|
|
|
@@ -79,8 +83,8 @@ class Factory:
|
|
|
79
83
|
----------
|
|
80
84
|
name : str
|
|
81
85
|
The unique identifier for the builder.
|
|
82
|
-
builder : RuntimeBuilder
|
|
83
|
-
The builder
|
|
86
|
+
builder : type[RuntimeBuilder]
|
|
87
|
+
The builder class to register. It will be instantiated immediately.
|
|
84
88
|
|
|
85
89
|
Returns
|
|
86
90
|
-------
|
|
@@ -113,8 +117,8 @@ class Factory:
|
|
|
113
117
|
kind = kwargs["kind"]
|
|
114
118
|
except KeyError:
|
|
115
119
|
raise BuilderError("Missing 'kind' parameter.")
|
|
116
|
-
self.
|
|
117
|
-
return
|
|
120
|
+
builder = self._get_entity_builder(kind)
|
|
121
|
+
return builder.build(**kwargs)
|
|
118
122
|
|
|
119
123
|
def build_entity_from_dict(self, obj: dict) -> Entity:
|
|
120
124
|
"""
|
|
@@ -134,8 +138,8 @@ class Factory:
|
|
|
134
138
|
kind = obj["kind"]
|
|
135
139
|
except KeyError:
|
|
136
140
|
raise BuilderError("Missing 'kind' parameter.")
|
|
137
|
-
self.
|
|
138
|
-
return
|
|
141
|
+
builder = self._get_entity_builder(kind)
|
|
142
|
+
return builder.from_dict(obj)
|
|
139
143
|
|
|
140
144
|
def build_spec(self, kind_to_build_from: str, **kwargs) -> Spec:
|
|
141
145
|
"""
|
|
@@ -153,8 +157,8 @@ class Factory:
|
|
|
153
157
|
Spec
|
|
154
158
|
Spec object.
|
|
155
159
|
"""
|
|
156
|
-
self.
|
|
157
|
-
return
|
|
160
|
+
builder = self._get_entity_builder(kind_to_build_from)
|
|
161
|
+
return builder.build_spec(**kwargs)
|
|
158
162
|
|
|
159
163
|
def build_metadata(self, kind_to_build_from: str, **kwargs) -> Metadata:
|
|
160
164
|
"""
|
|
@@ -172,8 +176,8 @@ class Factory:
|
|
|
172
176
|
Metadata
|
|
173
177
|
Metadata object.
|
|
174
178
|
"""
|
|
175
|
-
self.
|
|
176
|
-
return
|
|
179
|
+
builder = self._get_entity_builder(kind_to_build_from)
|
|
180
|
+
return builder.build_metadata(**kwargs)
|
|
177
181
|
|
|
178
182
|
def build_status(self, kind_to_build_from: str, **kwargs) -> Status:
|
|
179
183
|
"""
|
|
@@ -191,8 +195,8 @@ class Factory:
|
|
|
191
195
|
Status
|
|
192
196
|
Status object.
|
|
193
197
|
"""
|
|
194
|
-
self.
|
|
195
|
-
return
|
|
198
|
+
builder = self._get_entity_builder(kind_to_build_from)
|
|
199
|
+
return builder.build_status(**kwargs)
|
|
196
200
|
|
|
197
201
|
def build_runtime(self, kind_to_build_from: str, project: str) -> Runtime:
|
|
198
202
|
"""
|
|
@@ -210,8 +214,8 @@ class Factory:
|
|
|
210
214
|
Runtime
|
|
211
215
|
Runtime object.
|
|
212
216
|
"""
|
|
213
|
-
self.
|
|
214
|
-
return
|
|
217
|
+
builder = self._get_runtime_builder(kind_to_build_from)
|
|
218
|
+
return builder.build(project=project)
|
|
215
219
|
|
|
216
220
|
def get_entity_type_from_kind(self, kind: str) -> str:
|
|
217
221
|
"""
|
|
@@ -227,8 +231,8 @@ class Factory:
|
|
|
227
231
|
str
|
|
228
232
|
Entity type.
|
|
229
233
|
"""
|
|
230
|
-
self.
|
|
231
|
-
return
|
|
234
|
+
builder = self._get_entity_builder(kind)
|
|
235
|
+
return builder.get_entity_type()
|
|
232
236
|
|
|
233
237
|
def get_executable_kind(self, kind: str) -> str:
|
|
234
238
|
"""
|
|
@@ -244,8 +248,8 @@ class Factory:
|
|
|
244
248
|
str
|
|
245
249
|
Executable kind.
|
|
246
250
|
"""
|
|
247
|
-
self.
|
|
248
|
-
return
|
|
251
|
+
builder = self._get_entity_builder(kind)
|
|
252
|
+
return builder.get_executable_kind()
|
|
249
253
|
|
|
250
254
|
def get_action_from_task_kind(self, kind: str, task_kind: str) -> str:
|
|
251
255
|
"""
|
|
@@ -263,8 +267,8 @@ class Factory:
|
|
|
263
267
|
str
|
|
264
268
|
Action.
|
|
265
269
|
"""
|
|
266
|
-
self.
|
|
267
|
-
return
|
|
270
|
+
builder = self._get_entity_builder(kind)
|
|
271
|
+
return builder.get_action_from_task_kind(task_kind)
|
|
268
272
|
|
|
269
273
|
def get_task_kind_from_action(self, kind: str, action: str) -> list[str]:
|
|
270
274
|
"""
|
|
@@ -282,10 +286,10 @@ class Factory:
|
|
|
282
286
|
list of str
|
|
283
287
|
Task kinds.
|
|
284
288
|
"""
|
|
285
|
-
self.
|
|
286
|
-
return
|
|
289
|
+
builder = self._get_entity_builder(kind)
|
|
290
|
+
return builder.get_task_kind_from_action(action)
|
|
287
291
|
|
|
288
|
-
def
|
|
292
|
+
def get_run_kind_from_action(self, kind: str, action: str) -> str:
|
|
289
293
|
"""
|
|
290
294
|
Get run kind.
|
|
291
295
|
|
|
@@ -299,8 +303,8 @@ class Factory:
|
|
|
299
303
|
str
|
|
300
304
|
Run kind.
|
|
301
305
|
"""
|
|
302
|
-
self.
|
|
303
|
-
return
|
|
306
|
+
builder = self._get_entity_builder(kind)
|
|
307
|
+
return builder.get_run_kind_from_action(action)
|
|
304
308
|
|
|
305
309
|
def get_all_kinds(self, kind: str) -> list[str]:
|
|
306
310
|
"""
|
|
@@ -316,7 +320,8 @@ class Factory:
|
|
|
316
320
|
list of str
|
|
317
321
|
All kinds.
|
|
318
322
|
"""
|
|
319
|
-
|
|
323
|
+
builder = self._get_entity_builder(kind)
|
|
324
|
+
return builder.get_all_kinds()
|
|
320
325
|
|
|
321
326
|
def get_spec_validator(self, kind: str) -> SpecValidator:
|
|
322
327
|
"""
|
|
@@ -332,50 +337,124 @@ class Factory:
|
|
|
332
337
|
SpecValidator
|
|
333
338
|
Spec validator.
|
|
334
339
|
"""
|
|
335
|
-
self.
|
|
336
|
-
return
|
|
340
|
+
builder = self._get_entity_builder(kind)
|
|
341
|
+
return builder.get_spec_validator()
|
|
337
342
|
|
|
338
|
-
def
|
|
343
|
+
def _get_entity_builder(self, kind: str) -> EntityBuilder | RuntimeEntityBuilder:
|
|
339
344
|
"""
|
|
340
|
-
|
|
345
|
+
Return the entity builder for the given kind, ensuring lazy runtime registration.
|
|
341
346
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
347
|
+
Raises
|
|
348
|
+
------
|
|
349
|
+
BuilderError
|
|
350
|
+
If no builder exists for the specified kind.
|
|
351
|
+
"""
|
|
352
|
+
if not self._entities_registered:
|
|
353
|
+
self._ensure_entities_registered()
|
|
354
|
+
if kind not in self._entity_builders:
|
|
355
|
+
if not self._runtimes_registered:
|
|
356
|
+
self._ensure_runtimes_registered()
|
|
357
|
+
if kind not in self._entity_builders:
|
|
358
|
+
raise BuilderError(f"Entity builder for kind '{kind}' not found.")
|
|
359
|
+
return self._entity_builders[kind]
|
|
346
360
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
361
|
+
def _get_runtime_builder(self, kind: str) -> RuntimeBuilder:
|
|
362
|
+
"""
|
|
363
|
+
Return the runtime builder for the given kind, ensuring lazy runtime registration.
|
|
350
364
|
|
|
351
365
|
Raises
|
|
352
366
|
------
|
|
353
367
|
BuilderError
|
|
354
368
|
If no builder exists for the specified kind.
|
|
355
369
|
"""
|
|
356
|
-
if kind not in self.
|
|
357
|
-
|
|
370
|
+
if kind not in self._runtime_builders:
|
|
371
|
+
if not self._runtimes_registered:
|
|
372
|
+
self._ensure_runtimes_registered()
|
|
373
|
+
if kind not in self._runtime_builders:
|
|
374
|
+
raise BuilderError(f"Runtime builder for kind '{kind}' not found.")
|
|
375
|
+
return self._runtime_builders[kind]
|
|
358
376
|
|
|
359
|
-
def
|
|
377
|
+
def _ensure_entities_registered(self) -> None:
|
|
360
378
|
"""
|
|
361
|
-
|
|
379
|
+
Ensure core entities are registered on-demand.
|
|
362
380
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
381
|
+
Returns
|
|
382
|
+
-------
|
|
383
|
+
None
|
|
384
|
+
"""
|
|
385
|
+
if self._entities_registered:
|
|
386
|
+
return
|
|
387
|
+
try:
|
|
388
|
+
self._register_entities()
|
|
389
|
+
self._entities_registered = True
|
|
390
|
+
except Exception as e:
|
|
391
|
+
# Avoid repeated attempts; surface as BuilderError for consistency
|
|
392
|
+
self._entities_registered = True
|
|
393
|
+
raise BuilderError(f"Failed to register core entities: {e}")
|
|
394
|
+
|
|
395
|
+
def _register_entities(self) -> None:
|
|
396
|
+
"""
|
|
397
|
+
Register core entity builders into the factory.
|
|
398
|
+
|
|
399
|
+
Imports the core entities module and registers all entity
|
|
400
|
+
builders with the global factory instance.
|
|
367
401
|
|
|
368
402
|
Returns
|
|
369
403
|
-------
|
|
370
404
|
None
|
|
405
|
+
"""
|
|
406
|
+
try:
|
|
407
|
+
module = import_module(FactoryEnum.REG_ENTITIES.value)
|
|
371
408
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
409
|
+
# Register core entities
|
|
410
|
+
for k, b in getattr(module, FactoryEnum.REG_ENTITIES_VAR.value, []):
|
|
411
|
+
self.add_entity_builder(k, b)
|
|
412
|
+
|
|
413
|
+
except Exception as e:
|
|
414
|
+
raise RuntimeError("Error registering core entities.") from e
|
|
415
|
+
|
|
416
|
+
def _ensure_runtimes_registered(self) -> None:
|
|
376
417
|
"""
|
|
377
|
-
|
|
378
|
-
|
|
418
|
+
Ensure runtime entities are registered on-demand.
|
|
419
|
+
|
|
420
|
+
Returns
|
|
421
|
+
-------
|
|
422
|
+
None
|
|
423
|
+
"""
|
|
424
|
+
if self._runtimes_registered:
|
|
425
|
+
return
|
|
426
|
+
try:
|
|
427
|
+
self._register_runtimes_entities()
|
|
428
|
+
self._runtimes_registered = True
|
|
429
|
+
except Exception as e:
|
|
430
|
+
# If registration fails, mark as attempted to avoid infinite loops
|
|
431
|
+
self._runtimes_registered = True
|
|
432
|
+
raise BuilderError(f"Failed to register runtime entities: {e}")
|
|
433
|
+
|
|
434
|
+
def _register_runtimes_entities(self) -> None:
|
|
435
|
+
"""
|
|
436
|
+
Register all runtime builders and their entities into the factory.
|
|
437
|
+
|
|
438
|
+
Imports each runtime package and registers its entity and runtime
|
|
439
|
+
builders with the global factory instance.
|
|
440
|
+
|
|
441
|
+
Returns
|
|
442
|
+
-------
|
|
443
|
+
None
|
|
444
|
+
"""
|
|
445
|
+
try:
|
|
446
|
+
for package in list_runtimes():
|
|
447
|
+
module = import_module(package)
|
|
448
|
+
|
|
449
|
+
# Register workflows, functions, tasks and runs entities builders
|
|
450
|
+
for k, b in getattr(module, FactoryEnum.REG_ENTITIES_VAR.value, []):
|
|
451
|
+
self.add_entity_builder(k, b)
|
|
452
|
+
|
|
453
|
+
# Register runtime builders
|
|
454
|
+
for k, b in getattr(module, FactoryEnum.REG_RUNTIME_VAR.value, []):
|
|
455
|
+
self.add_runtime_builder(k, b)
|
|
456
|
+
except Exception as e:
|
|
457
|
+
raise RuntimeError("Error registering runtime entities.") from e
|
|
379
458
|
|
|
380
459
|
|
|
381
460
|
factory = Factory()
|
digitalhub/factory/utils.py
CHANGED
|
@@ -9,7 +9,7 @@ import pkgutil
|
|
|
9
9
|
import re
|
|
10
10
|
from types import ModuleType
|
|
11
11
|
|
|
12
|
-
from digitalhub.factory.
|
|
12
|
+
from digitalhub.factory.enums import FactoryEnum
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def import_module(package: str) -> ModuleType:
|
|
@@ -58,62 +58,11 @@ def list_runtimes() -> list[str]:
|
|
|
58
58
|
RuntimeError
|
|
59
59
|
If an error occurs while scanning for runtime packages.
|
|
60
60
|
"""
|
|
61
|
-
pattern = r"digitalhub_runtime_.*"
|
|
62
|
-
runtimes: list[str] = []
|
|
63
61
|
try:
|
|
62
|
+
runtimes: list[str] = []
|
|
64
63
|
for _, name, _ in pkgutil.iter_modules():
|
|
65
|
-
if re.match(
|
|
64
|
+
if re.match(FactoryEnum.RGX_RUNTIMES.value, name):
|
|
66
65
|
runtimes.append(name)
|
|
67
66
|
return runtimes
|
|
68
67
|
except Exception as e:
|
|
69
68
|
raise RuntimeError("Error listing installed runtimes.") from e
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def register_runtimes_entities() -> None:
|
|
73
|
-
"""
|
|
74
|
-
Register all runtime builders and their entities into the factory.
|
|
75
|
-
|
|
76
|
-
Imports each runtime package and registers its entity and runtime
|
|
77
|
-
builders with the global factory instance.
|
|
78
|
-
|
|
79
|
-
Returns
|
|
80
|
-
-------
|
|
81
|
-
None
|
|
82
|
-
"""
|
|
83
|
-
for package in list_runtimes():
|
|
84
|
-
module = import_module(package)
|
|
85
|
-
entity_builders = getattr(module, "entity_builders")
|
|
86
|
-
for entity_builder_tuple in entity_builders:
|
|
87
|
-
kind, builder = entity_builder_tuple
|
|
88
|
-
factory.add_entity_builder(kind, builder)
|
|
89
|
-
|
|
90
|
-
runtime_builders = getattr(module, "runtime_builders")
|
|
91
|
-
for runtime_builder_tuple in runtime_builders:
|
|
92
|
-
kind, builder = runtime_builder_tuple
|
|
93
|
-
factory.add_runtime_builder(kind, builder)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def register_entities() -> None:
|
|
97
|
-
"""
|
|
98
|
-
Register core entity builders into the factory.
|
|
99
|
-
|
|
100
|
-
Imports the core entities module and registers all entity
|
|
101
|
-
builders with the global factory instance.
|
|
102
|
-
|
|
103
|
-
Returns
|
|
104
|
-
-------
|
|
105
|
-
None
|
|
106
|
-
|
|
107
|
-
Raises
|
|
108
|
-
------
|
|
109
|
-
RuntimeError
|
|
110
|
-
If registration of core entities fails.
|
|
111
|
-
"""
|
|
112
|
-
try:
|
|
113
|
-
module = import_module("digitalhub.entities.builders")
|
|
114
|
-
entities_builders_list = getattr(module, "entity_builders")
|
|
115
|
-
for entity_builder_tuple in entities_builders_list:
|
|
116
|
-
kind, builder = entity_builder_tuple
|
|
117
|
-
factory.add_entity_builder(kind, builder)
|
|
118
|
-
except Exception as e:
|
|
119
|
-
raise RuntimeError("Error registering entities.") from e
|
digitalhub/stores/client/api.py
CHANGED
|
@@ -9,10 +9,11 @@ import typing
|
|
|
9
9
|
from digitalhub.stores.client.builder import client_builder
|
|
10
10
|
|
|
11
11
|
if typing.TYPE_CHECKING:
|
|
12
|
-
from digitalhub.stores.client.
|
|
12
|
+
from digitalhub.stores.client.dhcore.client import ClientDHCore
|
|
13
|
+
from digitalhub.stores.client.local.client import ClientLocal
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
def get_client(local: bool = False
|
|
16
|
+
def get_client(local: bool = False) -> ClientLocal | ClientDHCore:
|
|
16
17
|
"""
|
|
17
18
|
Wrapper around ClientBuilder.build.
|
|
18
19
|
|
|
@@ -22,15 +23,10 @@ def get_client(local: bool = False, config: dict | None = None) -> Client:
|
|
|
22
23
|
Whether to create a local client or not. If True, creates a
|
|
23
24
|
ClientLocal instance that operates in-memory. If False, creates
|
|
24
25
|
a ClientDHCore instance that communicates with a remote backend.
|
|
25
|
-
config : dict, optional
|
|
26
|
-
DHCore environment configuration. Only used when local=False.
|
|
27
|
-
If None, configuration will be loaded from environment variables
|
|
28
|
-
and configuration files.
|
|
29
26
|
|
|
30
27
|
Returns
|
|
31
28
|
-------
|
|
32
|
-
|
|
33
|
-
The client instance.
|
|
34
|
-
on the local parameter.
|
|
29
|
+
ClientLocal | ClientDHCore
|
|
30
|
+
The client instance.
|
|
35
31
|
"""
|
|
36
|
-
return client_builder.build(local
|
|
32
|
+
return client_builder.build(local)
|
|
@@ -10,7 +10,7 @@ from digitalhub.stores.client.dhcore.client import ClientDHCore
|
|
|
10
10
|
from digitalhub.stores.client.local.client import ClientLocal
|
|
11
11
|
|
|
12
12
|
if typing.TYPE_CHECKING:
|
|
13
|
-
|
|
13
|
+
pass
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class ClientBuilder:
|
|
@@ -27,7 +27,7 @@ class ClientBuilder:
|
|
|
27
27
|
self._local = None
|
|
28
28
|
self._dhcore = None
|
|
29
29
|
|
|
30
|
-
def build(self, local: bool = False, config: dict | None = None) ->
|
|
30
|
+
def build(self, local: bool = False, config: dict | None = None) -> ClientLocal | ClientDHCore:
|
|
31
31
|
"""
|
|
32
32
|
Method to create a client instance.
|
|
33
33
|
|
|
@@ -40,7 +40,7 @@ class ClientBuilder:
|
|
|
40
40
|
|
|
41
41
|
Returns
|
|
42
42
|
-------
|
|
43
|
-
|
|
43
|
+
ClientLocal | ClientDHCore
|
|
44
44
|
Returns the client instance.
|
|
45
45
|
"""
|
|
46
46
|
if local:
|