digitalhub 0.8.0b3__py3-none-any.whl → 0.8.0b5__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 -2
- digitalhub/client/dhcore/client.py +6 -1
- digitalhub/context/builder.py +1 -1
- digitalhub/context/context.py +1 -1
- digitalhub/entities/_base/entity/entity.py +2 -28
- digitalhub/entities/_base/unversioned/builder.py +66 -0
- digitalhub/entities/_base/unversioned/entity.py +0 -38
- digitalhub/entities/_base/versioned/builder.py +68 -0
- digitalhub/entities/_base/versioned/entity.py +0 -41
- digitalhub/entities/_builders/entity.py +37 -32
- digitalhub/entities/_builders/metadata.py +3 -10
- digitalhub/entities/_builders/spec.py +11 -21
- digitalhub/entities/_builders/status.py +8 -18
- digitalhub/entities/_builders/uuid.py +4 -11
- digitalhub/entities/artifact/_base/builder.py +86 -0
- digitalhub/entities/artifact/artifact/builder.py +18 -0
- digitalhub/entities/artifact/builder.py +15 -97
- digitalhub/entities/artifact/crud.py +1 -1
- digitalhub/entities/builders.py +63 -0
- digitalhub/entities/dataitem/_base/builder.py +86 -0
- digitalhub/entities/dataitem/builder.py +15 -108
- digitalhub/entities/dataitem/crud.py +3 -3
- digitalhub/entities/dataitem/dataitem/builder.py +18 -0
- digitalhub/entities/dataitem/iceberg/builder.py +18 -0
- digitalhub/entities/dataitem/table/builder.py +18 -0
- digitalhub/entities/function/_base/builder.py +78 -0
- digitalhub/entities/function/_base/entity.py +2 -2
- digitalhub/entities/function/builder.py +22 -57
- digitalhub/entities/function/crud.py +1 -1
- digitalhub/entities/model/_base/builder.py +86 -0
- digitalhub/entities/model/builder.py +15 -116
- digitalhub/entities/model/crud.py +1 -1
- digitalhub/entities/model/huggingface/builder.py +18 -0
- digitalhub/entities/model/mlflow/builder.py +18 -0
- digitalhub/entities/model/model/builder.py +18 -0
- digitalhub/entities/model/sklearn/builder.py +18 -0
- digitalhub/entities/project/_base/builder.py +128 -0
- digitalhub/entities/project/{project → _base}/entity.py +9 -51
- digitalhub/entities/project/builder.py +20 -51
- digitalhub/entities/project/crud.py +1 -1
- digitalhub/entities/run/_base/builder.py +73 -0
- digitalhub/entities/run/_base/entity.py +17 -152
- digitalhub/entities/run/builder.py +21 -47
- digitalhub/entities/run/crud.py +1 -1
- digitalhub/entities/secret/_base/builder.py +81 -0
- digitalhub/entities/secret/{secret → _base}/entity.py +2 -2
- digitalhub/entities/secret/builder.py +20 -62
- digitalhub/entities/secret/crud.py +2 -2
- digitalhub/entities/task/_base/builder.py +76 -0
- digitalhub/entities/task/builder.py +21 -44
- digitalhub/entities/task/crud.py +1 -1
- digitalhub/entities/workflow/_base/builder.py +78 -0
- digitalhub/entities/workflow/_base/entity.py +2 -2
- digitalhub/entities/workflow/builder.py +20 -60
- digitalhub/entities/workflow/crud.py +1 -1
- digitalhub/factory/factory.py +204 -0
- digitalhub/factory/utils.py +90 -0
- digitalhub/runtimes/builder.py +24 -41
- digitalhub/runtimes/kind_registry.py +14 -0
- digitalhub/runtimes/utils.py +28 -0
- digitalhub/utils/exceptions.py +6 -0
- digitalhub/utils/generic_utils.py +1 -1
- {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b5.dist-info}/METADATA +1 -1
- {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b5.dist-info}/RECORD +75 -57
- digitalhub/entities/_builders/factory.py +0 -44
- digitalhub/entities/registries.py +0 -48
- digitalhub/registry/models.py +0 -87
- digitalhub/registry/registry.py +0 -74
- digitalhub/registry/utils.py +0 -151
- /digitalhub/entities/project/{project → _base}/__init__.py +0 -0
- /digitalhub/entities/project/{project → _base}/spec.py +0 -0
- /digitalhub/entities/project/{project → _base}/status.py +0 -0
- /digitalhub/entities/secret/{secret → _base}/__init__.py +0 -0
- /digitalhub/entities/secret/{secret → _base}/spec.py +0 -0
- /digitalhub/entities/secret/{secret → _base}/status.py +0 -0
- /digitalhub/{registry → factory}/__init__.py +0 -0
- /digitalhub/runtimes/{base.py → _base.py} +0 -0
- {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b5.dist-info}/LICENSE.txt +0 -0
- {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b5.dist-info}/WHEEL +0 -0
- {digitalhub-0.8.0b3.dist-info → digitalhub-0.8.0b5.dist-info}/top_level.txt +0 -0
digitalhub/__init__.py
CHANGED
|
@@ -73,9 +73,10 @@ except ImportError:
|
|
|
73
73
|
...
|
|
74
74
|
|
|
75
75
|
from digitalhub.client.dhcore.utils import refresh_token, set_dhcore_env
|
|
76
|
-
from digitalhub.registry.utils import register_entities, register_runtimes_entities
|
|
77
|
-
from digitalhub.stores.builder import set_store
|
|
78
76
|
|
|
79
77
|
# Register entities into registry
|
|
78
|
+
from digitalhub.factory.utils import register_entities, register_runtimes_entities
|
|
79
|
+
from digitalhub.stores.builder import set_store
|
|
80
|
+
|
|
80
81
|
register_entities()
|
|
81
82
|
register_runtimes_entities()
|
|
@@ -579,11 +579,16 @@ class ClientDHCore(Client):
|
|
|
579
579
|
dict
|
|
580
580
|
Response object.
|
|
581
581
|
"""
|
|
582
|
+
# Get refersh token from .core file to avoid concurrency
|
|
583
|
+
# in a shared workspace
|
|
584
|
+
self._load_env()
|
|
585
|
+
refresh_token = os.getenv("DHCORE_REFRESH_TOKEN")
|
|
586
|
+
|
|
582
587
|
# Send request to get new access token
|
|
583
588
|
payload = {
|
|
584
589
|
"grant_type": "refresh_token",
|
|
585
590
|
"client_id": self._client_id,
|
|
586
|
-
"refresh_token":
|
|
591
|
+
"refresh_token": refresh_token,
|
|
587
592
|
}
|
|
588
593
|
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
|
589
594
|
r = request("POST", url, data=payload, headers=headers, timeout=60)
|
digitalhub/context/builder.py
CHANGED
digitalhub/context/context.py
CHANGED
|
@@ -4,6 +4,7 @@ import typing
|
|
|
4
4
|
from abc import ABCMeta, abstractmethod
|
|
5
5
|
|
|
6
6
|
from digitalhub.entities._base._base.entity import Base
|
|
7
|
+
from digitalhub.factory.factory import factory
|
|
7
8
|
|
|
8
9
|
if typing.TYPE_CHECKING:
|
|
9
10
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -68,7 +69,7 @@ class Entity(Base, metaclass=ABCMeta):
|
|
|
68
69
|
-------
|
|
69
70
|
None
|
|
70
71
|
"""
|
|
71
|
-
new_obj = self.
|
|
72
|
+
new_obj = factory.build_entity_from_dict(self.kind, obj)
|
|
72
73
|
self.metadata = new_obj.metadata
|
|
73
74
|
self.spec = new_obj.spec
|
|
74
75
|
self.status = new_obj.status
|
|
@@ -93,33 +94,6 @@ class Entity(Base, metaclass=ABCMeta):
|
|
|
93
94
|
"""
|
|
94
95
|
return {k: v for k, v in super().to_dict().items() if k in self._obj_attr}
|
|
95
96
|
|
|
96
|
-
@classmethod
|
|
97
|
-
def from_dict(cls, obj: dict, validate: bool = True) -> Entity:
|
|
98
|
-
"""
|
|
99
|
-
Create a new object from dictionary.
|
|
100
|
-
|
|
101
|
-
Parameters
|
|
102
|
-
----------
|
|
103
|
-
obj : dict
|
|
104
|
-
Dictionary to create object from.
|
|
105
|
-
validate : bool
|
|
106
|
-
Flag to indicate if arguments validation against a pydantic schema must be ignored.
|
|
107
|
-
|
|
108
|
-
Returns
|
|
109
|
-
-------
|
|
110
|
-
Self
|
|
111
|
-
Self instance.
|
|
112
|
-
"""
|
|
113
|
-
parsed_dict = cls._parse_dict(obj, validate=validate)
|
|
114
|
-
return cls(**parsed_dict)
|
|
115
|
-
|
|
116
|
-
@staticmethod
|
|
117
|
-
@abstractmethod
|
|
118
|
-
def _parse_dict(obj: dict, validate: bool = True) -> dict:
|
|
119
|
-
"""
|
|
120
|
-
Abstract method to parse dictionary.
|
|
121
|
-
"""
|
|
122
|
-
|
|
123
97
|
def __repr__(self) -> str:
|
|
124
98
|
"""
|
|
125
99
|
Return string representation of the entity object.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._builders.entity 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
|
+
}
|
|
@@ -3,10 +3,6 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.context.entity import ContextEntity
|
|
6
|
-
from digitalhub.entities._builders.metadata import build_metadata
|
|
7
|
-
from digitalhub.entities._builders.spec import build_spec
|
|
8
|
-
from digitalhub.entities._builders.status import build_status
|
|
9
|
-
from digitalhub.entities._builders.uuid import build_uuid
|
|
10
6
|
from digitalhub.utils.io_utils import write_yaml
|
|
11
7
|
|
|
12
8
|
if typing.TYPE_CHECKING:
|
|
@@ -51,37 +47,3 @@ class UnversionedEntity(ContextEntity):
|
|
|
51
47
|
pth = self._context().root / filename
|
|
52
48
|
write_yaml(pth, obj)
|
|
53
49
|
return str(pth)
|
|
54
|
-
|
|
55
|
-
@staticmethod
|
|
56
|
-
def _parse_dict(obj: dict, validate: bool = True) -> dict:
|
|
57
|
-
"""
|
|
58
|
-
Get dictionary and parse it to a valid entity dictionary.
|
|
59
|
-
|
|
60
|
-
Parameters
|
|
61
|
-
----------
|
|
62
|
-
entity : str
|
|
63
|
-
Entity type.
|
|
64
|
-
obj : dict
|
|
65
|
-
Dictionary to parse.
|
|
66
|
-
|
|
67
|
-
Returns
|
|
68
|
-
-------
|
|
69
|
-
dict
|
|
70
|
-
A dictionary containing the attributes of the entity instance.
|
|
71
|
-
"""
|
|
72
|
-
project = obj.get("project")
|
|
73
|
-
kind = obj.get("kind")
|
|
74
|
-
uuid = build_uuid(obj.get("id"))
|
|
75
|
-
metadata = build_metadata(kind, **obj.get("metadata", {}))
|
|
76
|
-
spec = build_spec(kind, validate=validate, **obj.get("spec", {}))
|
|
77
|
-
status = build_status(kind, **obj.get("status", {}))
|
|
78
|
-
user = obj.get("user")
|
|
79
|
-
return {
|
|
80
|
-
"project": project,
|
|
81
|
-
"uuid": uuid,
|
|
82
|
-
"kind": kind,
|
|
83
|
-
"metadata": metadata,
|
|
84
|
-
"spec": spec,
|
|
85
|
-
"status": status,
|
|
86
|
-
"user": user,
|
|
87
|
-
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._builders.entity 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
|
+
}
|
|
@@ -3,11 +3,6 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.context.entity import ContextEntity
|
|
6
|
-
from digitalhub.entities._builders.metadata import build_metadata
|
|
7
|
-
from digitalhub.entities._builders.name import build_name
|
|
8
|
-
from digitalhub.entities._builders.spec import build_spec
|
|
9
|
-
from digitalhub.entities._builders.status import build_status
|
|
10
|
-
from digitalhub.entities._builders.uuid import build_uuid
|
|
11
6
|
from digitalhub.utils.io_utils import write_yaml
|
|
12
7
|
|
|
13
8
|
if typing.TYPE_CHECKING:
|
|
@@ -56,39 +51,3 @@ class VersionedEntity(ContextEntity):
|
|
|
56
51
|
pth = self._context().root / filename
|
|
57
52
|
write_yaml(pth, obj)
|
|
58
53
|
return str(pth)
|
|
59
|
-
|
|
60
|
-
@staticmethod
|
|
61
|
-
def _parse_dict(obj: dict, validate: bool = True) -> dict:
|
|
62
|
-
"""
|
|
63
|
-
Get dictionary and parse it to a valid entity dictionary.
|
|
64
|
-
|
|
65
|
-
Parameters
|
|
66
|
-
----------
|
|
67
|
-
entity : str
|
|
68
|
-
Entity type.
|
|
69
|
-
obj : dict
|
|
70
|
-
Dictionary to parse.
|
|
71
|
-
|
|
72
|
-
Returns
|
|
73
|
-
-------
|
|
74
|
-
dict
|
|
75
|
-
A dictionary containing the attributes of the entity instance.
|
|
76
|
-
"""
|
|
77
|
-
project = obj.get("project")
|
|
78
|
-
kind = obj.get("kind")
|
|
79
|
-
name = build_name(obj.get("name"))
|
|
80
|
-
uuid = build_uuid(obj.get("id"))
|
|
81
|
-
metadata = build_metadata(kind, **obj.get("metadata", {}))
|
|
82
|
-
spec = build_spec(kind, validate=validate, **obj.get("spec", {}))
|
|
83
|
-
status = build_status(kind, **obj.get("status", {}))
|
|
84
|
-
user = obj.get("user")
|
|
85
|
-
return {
|
|
86
|
-
"project": project,
|
|
87
|
-
"name": name,
|
|
88
|
-
"uuid": uuid,
|
|
89
|
-
"kind": kind,
|
|
90
|
-
"metadata": metadata,
|
|
91
|
-
"spec": spec,
|
|
92
|
-
"status": status,
|
|
93
|
-
"user": user,
|
|
94
|
-
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
|
-
from abc import
|
|
4
|
+
from abc import abstractmethod
|
|
5
5
|
|
|
6
6
|
from digitalhub.entities._builders.metadata import build_metadata
|
|
7
7
|
from digitalhub.entities._builders.name import build_name
|
|
8
8
|
from digitalhub.entities._builders.spec import build_spec
|
|
9
9
|
from digitalhub.entities._builders.status import build_status
|
|
10
10
|
from digitalhub.entities._builders.uuid import build_uuid
|
|
11
|
+
from digitalhub.utils.exceptions import BuilderError
|
|
11
12
|
|
|
12
13
|
if typing.TYPE_CHECKING:
|
|
13
14
|
from digitalhub.entities._base.entity.entity import Entity
|
|
@@ -16,26 +17,32 @@ if typing.TYPE_CHECKING:
|
|
|
16
17
|
from digitalhub.entities._base.entity.status import Status
|
|
17
18
|
|
|
18
19
|
|
|
19
|
-
class EntityBuilder
|
|
20
|
+
class EntityBuilder:
|
|
20
21
|
"""
|
|
21
22
|
Builder class for building entities.
|
|
22
23
|
"""
|
|
23
24
|
|
|
24
25
|
# Class variables
|
|
26
|
+
ENTITY_TYPE: str = None
|
|
25
27
|
ENTITY_CLASS: Entity = None
|
|
26
28
|
ENTITY_SPEC_CLASS: Spec = None
|
|
27
29
|
ENTITY_SPEC_VALIDATOR: SpecValidator = None
|
|
28
30
|
ENTITY_STATUS_CLASS: Status = None
|
|
31
|
+
ENTITY_KIND: str = None
|
|
29
32
|
|
|
30
33
|
def __init__(self) -> None:
|
|
34
|
+
if self.ENTITY_TYPE is None:
|
|
35
|
+
raise BuilderError("ENTITY_TYPE must be set")
|
|
31
36
|
if self.ENTITY_CLASS is None:
|
|
32
|
-
raise
|
|
37
|
+
raise BuilderError("ENTITY_CLASS must be set")
|
|
33
38
|
if self.ENTITY_SPEC_CLASS is None:
|
|
34
|
-
raise
|
|
39
|
+
raise BuilderError("ENTITY_SPEC_CLASS must be set")
|
|
35
40
|
if self.ENTITY_SPEC_VALIDATOR is None:
|
|
36
|
-
raise
|
|
41
|
+
raise BuilderError("ENTITY_SPEC_VALIDATOR must be set")
|
|
37
42
|
if self.ENTITY_STATUS_CLASS is None:
|
|
38
|
-
raise
|
|
43
|
+
raise BuilderError("ENTITY_STATUS_CLASS must be set")
|
|
44
|
+
if self.ENTITY_KIND is None:
|
|
45
|
+
raise BuilderError("ENTITY_KIND must be set")
|
|
39
46
|
|
|
40
47
|
def build_name(self, name: str) -> str:
|
|
41
48
|
"""
|
|
@@ -69,14 +76,12 @@ class EntityBuilder(metaclass=ABCMeta):
|
|
|
69
76
|
"""
|
|
70
77
|
return build_uuid(uuid)
|
|
71
78
|
|
|
72
|
-
def build_metadata(self,
|
|
79
|
+
def build_metadata(self, **kwargs) -> Metadata:
|
|
73
80
|
"""
|
|
74
81
|
Build entity metadata object.
|
|
75
82
|
|
|
76
83
|
Parameters
|
|
77
84
|
----------
|
|
78
|
-
kind : str
|
|
79
|
-
Registry entry kind.
|
|
80
85
|
**kwargs : dict
|
|
81
86
|
Keyword arguments for the constructor.
|
|
82
87
|
|
|
@@ -85,16 +90,14 @@ class EntityBuilder(metaclass=ABCMeta):
|
|
|
85
90
|
Metadata
|
|
86
91
|
Metadata object.
|
|
87
92
|
"""
|
|
88
|
-
return build_metadata(
|
|
93
|
+
return build_metadata(**kwargs)
|
|
89
94
|
|
|
90
|
-
def build_spec(self,
|
|
95
|
+
def build_spec(self, validate: bool = True, **kwargs) -> Spec:
|
|
91
96
|
"""
|
|
92
97
|
Build entity spec object.
|
|
93
98
|
|
|
94
99
|
Parameters
|
|
95
100
|
----------
|
|
96
|
-
kind : str
|
|
97
|
-
Registry entry kind.
|
|
98
101
|
**kwargs : dict
|
|
99
102
|
Keyword arguments for the constructor.
|
|
100
103
|
|
|
@@ -103,16 +106,14 @@ class EntityBuilder(metaclass=ABCMeta):
|
|
|
103
106
|
Spec
|
|
104
107
|
Spec object.
|
|
105
108
|
"""
|
|
106
|
-
return build_spec(
|
|
109
|
+
return build_spec(self.ENTITY_SPEC_CLASS, self.ENTITY_SPEC_VALIDATOR, validate=validate, **kwargs)
|
|
107
110
|
|
|
108
|
-
def build_status(self,
|
|
111
|
+
def build_status(self, **kwargs) -> Status:
|
|
109
112
|
"""
|
|
110
113
|
Build entity status object.
|
|
111
114
|
|
|
112
115
|
Parameters
|
|
113
116
|
----------
|
|
114
|
-
kind : str
|
|
115
|
-
Registry entry kind.
|
|
116
117
|
**kwargs : dict
|
|
117
118
|
Keyword arguments for the constructor.
|
|
118
119
|
|
|
@@ -121,28 +122,32 @@ class EntityBuilder(metaclass=ABCMeta):
|
|
|
121
122
|
Status
|
|
122
123
|
Status object.
|
|
123
124
|
"""
|
|
124
|
-
return build_status(
|
|
125
|
+
return build_status(self.ENTITY_STATUS_CLASS, **kwargs)
|
|
125
126
|
|
|
126
|
-
|
|
127
|
-
def build(self, _validate: bool = True, **kwargs) -> Entity:
|
|
127
|
+
def build_entity(self, **kwargs) -> Entity:
|
|
128
128
|
"""
|
|
129
129
|
Build entity object.
|
|
130
|
-
"""
|
|
131
|
-
|
|
132
|
-
def from_dict(self, obj: dict, validate: bool = True) -> Entity:
|
|
133
|
-
"""
|
|
134
|
-
Build entity from dictionary.
|
|
135
130
|
|
|
136
131
|
Parameters
|
|
137
132
|
----------
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
validate : bool
|
|
141
|
-
Whether to validate the entity.
|
|
133
|
+
**kwargs : dict
|
|
134
|
+
Keyword arguments for the constructor.
|
|
142
135
|
|
|
143
136
|
Returns
|
|
144
137
|
-------
|
|
145
|
-
|
|
146
|
-
Entity
|
|
138
|
+
Entity
|
|
139
|
+
Entity object.
|
|
140
|
+
"""
|
|
141
|
+
return self.ENTITY_CLASS(**kwargs)
|
|
142
|
+
|
|
143
|
+
@abstractmethod
|
|
144
|
+
def build(self, *args, **kwargs) -> Entity:
|
|
145
|
+
"""
|
|
146
|
+
Build entity object.
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
@abstractmethod
|
|
150
|
+
def from_dict(self, obj: dict, validate: bool = True) -> Entity:
|
|
151
|
+
"""
|
|
152
|
+
Build entity object from dictionary.
|
|
147
153
|
"""
|
|
148
|
-
return self.build(**obj, _validate=validate)
|
|
@@ -4,20 +4,13 @@ from digitalhub.entities._base.entity.metadata import Metadata
|
|
|
4
4
|
from digitalhub.utils.generic_utils import get_timestamp
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
def build_metadata(
|
|
7
|
+
def build_metadata(**kwargs) -> Metadata:
|
|
8
8
|
"""
|
|
9
|
-
Build entity metadata object.
|
|
10
|
-
|
|
11
|
-
arguments to pass to the metadata's constructor.
|
|
12
|
-
The specific Metadata class is searched in the global
|
|
13
|
-
registry, where lies info about where to find the class.
|
|
14
|
-
The arguments are parsed, eventually adding default values,
|
|
15
|
-
and then passed to the constructor.
|
|
9
|
+
Build entity metadata object. This method is used to build entity
|
|
10
|
+
metadata.
|
|
16
11
|
|
|
17
12
|
Parameters
|
|
18
13
|
----------
|
|
19
|
-
kind : str
|
|
20
|
-
Registry entry kind.
|
|
21
14
|
**kwargs : dict
|
|
22
15
|
Keyword arguments for the constructor.
|
|
23
16
|
|
|
@@ -2,29 +2,22 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
|
-
from digitalhub.registry.registry import registry
|
|
6
|
-
from digitalhub.registry.utils import import_class
|
|
7
|
-
|
|
8
5
|
if typing.TYPE_CHECKING:
|
|
9
|
-
from digitalhub.entities._base.entity.spec import Spec
|
|
10
|
-
from digitalhub.registry.models import RegistryEntry
|
|
6
|
+
from digitalhub.entities._base.entity.spec import Spec, SpecValidator
|
|
11
7
|
|
|
12
8
|
|
|
13
|
-
def build_spec(
|
|
9
|
+
def build_spec(spec_cls: Spec, spec_validator: SpecValidator, validate: bool = True, **kwargs) -> Spec:
|
|
14
10
|
"""
|
|
15
|
-
Build entity spec object.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
The specific Spec class is searched in the global registry,
|
|
19
|
-
where lies info about where to find the class.
|
|
20
|
-
If the validation flag is set to True, the arguments are
|
|
21
|
-
validated against a pydantic schema and then passed to the
|
|
22
|
-
constructor.
|
|
11
|
+
Build entity spec object. This method is used to build entity
|
|
12
|
+
specifications and is used to validate the parameters passed
|
|
13
|
+
to the constructor.
|
|
23
14
|
|
|
24
15
|
Parameters
|
|
25
16
|
----------
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
spec_cls : Spec
|
|
18
|
+
Spec class.
|
|
19
|
+
spec_validator : SpecValidator
|
|
20
|
+
Spec validator class.
|
|
28
21
|
validate : bool
|
|
29
22
|
Flag to determine if validate kwargs.
|
|
30
23
|
**kwargs : dict
|
|
@@ -35,9 +28,6 @@ def build_spec(kind: str, validate: bool = True, **kwargs) -> Spec:
|
|
|
35
28
|
Spec
|
|
36
29
|
Spec object.
|
|
37
30
|
"""
|
|
38
|
-
infos: RegistryEntry = getattr(registry, kind)
|
|
39
|
-
spec = import_class(infos.spec.module, infos.spec.class_name)
|
|
40
31
|
if validate:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return spec(**kwargs)
|
|
32
|
+
kwargs = spec_validator(**kwargs).dict(by_alias=True, exclude_none=True)
|
|
33
|
+
return spec_cls(**kwargs)
|
|
@@ -3,40 +3,30 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities.utils.state import State
|
|
6
|
-
from digitalhub.registry.registry import registry
|
|
7
|
-
from digitalhub.registry.utils import import_class
|
|
8
6
|
|
|
9
7
|
if typing.TYPE_CHECKING:
|
|
10
8
|
from digitalhub.entities._base.entity.status import Status
|
|
11
|
-
from digitalhub.registry.models import RegistryEntry
|
|
12
9
|
|
|
13
10
|
|
|
14
|
-
def build_status(
|
|
11
|
+
def build_status(status_cls: Status, **kwargs) -> Status:
|
|
15
12
|
"""
|
|
16
|
-
Build entity status object.
|
|
17
|
-
|
|
18
|
-
arguments to pass to the status's constructor.
|
|
19
|
-
The specific Status class is searched in the global
|
|
20
|
-
registry, where lies info about where to find the class.
|
|
21
|
-
The arguments are parsed, eventually adding default values,
|
|
22
|
-
and then passed to the constructor.
|
|
13
|
+
Build entity status object. This method is used to build entity
|
|
14
|
+
status.
|
|
23
15
|
|
|
24
16
|
Parameters
|
|
25
17
|
----------
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
status_cls : Status
|
|
19
|
+
Entity status class.
|
|
28
20
|
**kwargs : dict
|
|
29
|
-
Keyword arguments
|
|
21
|
+
Keyword arguments.
|
|
30
22
|
|
|
31
23
|
Returns
|
|
32
24
|
-------
|
|
33
25
|
Status
|
|
34
|
-
|
|
26
|
+
Entity status object.
|
|
35
27
|
"""
|
|
36
|
-
infos: RegistryEntry = getattr(registry, kind)
|
|
37
|
-
status = import_class(infos.status.module, infos.status.class_name)
|
|
38
28
|
kwargs = parse_arguments(**kwargs)
|
|
39
|
-
return
|
|
29
|
+
return status_cls(**kwargs)
|
|
40
30
|
|
|
41
31
|
|
|
42
32
|
def parse_arguments(**kwargs) -> dict:
|
|
@@ -2,15 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from uuid import uuid4
|
|
4
4
|
|
|
5
|
-
from
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class UUIDValidator(BaseModel):
|
|
9
|
-
"""
|
|
10
|
-
Validate UUID format.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
uuid: UUID4
|
|
5
|
+
from digitalhub.utils.generic_utils import slugify_string
|
|
14
6
|
|
|
15
7
|
|
|
16
8
|
def build_uuid(uuid: str | None = None) -> str:
|
|
@@ -20,7 +12,7 @@ def build_uuid(uuid: str | None = None) -> str:
|
|
|
20
12
|
Parameters
|
|
21
13
|
----------
|
|
22
14
|
uuid : str
|
|
23
|
-
ID of the object
|
|
15
|
+
ID of the object.
|
|
24
16
|
|
|
25
17
|
Returns
|
|
26
18
|
-------
|
|
@@ -28,6 +20,7 @@ def build_uuid(uuid: str | None = None) -> str:
|
|
|
28
20
|
Validated UUID4.
|
|
29
21
|
"""
|
|
30
22
|
if uuid is not None:
|
|
31
|
-
|
|
23
|
+
if slugify_string(uuid) != uuid:
|
|
24
|
+
raise ValueError(f"Invalid ID: {uuid}. Must pass slugified ID.")
|
|
32
25
|
return uuid
|
|
33
26
|
return str(uuid4())
|