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,43 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.registry.registry import registry
6
+ from digitalhub.registry.utils import import_class
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from digitalhub.entities._base.spec.base import Spec
10
+ from digitalhub.registry.models import RegistryEntry
11
+
12
+
13
+ def build_spec(kind: str, validate: bool = True, **kwargs) -> Spec:
14
+ """
15
+ Build entity spec object. The builder takes as input
16
+ the kind of spec's object to build, a validation flag
17
+ and the keyword arguments to pass to the spec's constructor.
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.
23
+
24
+ Parameters
25
+ ----------
26
+ kind : str
27
+ Registry entry kind.
28
+ validate : bool
29
+ Flag to determine if validate kwargs.
30
+ **kwargs : dict
31
+ Keyword arguments for the constructor.
32
+
33
+ Returns
34
+ -------
35
+ Spec
36
+ Spec object.
37
+ """
38
+ infos: RegistryEntry = getattr(registry, kind)
39
+ spec = import_class(infos.spec.module, infos.spec.class_name)
40
+ if validate:
41
+ validator = import_class(infos.spec.module, infos.spec.parameters_validator)
42
+ kwargs = validator(**kwargs).dict(by_alias=True, exclude_none=True)
43
+ return spec(**kwargs)
@@ -0,0 +1,62 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.state import State
6
+ from digitalhub.registry.registry import registry
7
+ from digitalhub.registry.utils import import_class
8
+
9
+ if typing.TYPE_CHECKING:
10
+ from digitalhub.entities._base.status.base import Status
11
+ from digitalhub.registry.models import RegistryEntry
12
+
13
+
14
+ def build_status(kind: str, **kwargs) -> Status:
15
+ """
16
+ Build entity status object. The builder takes as input
17
+ the kind of status's object to build and the keyword
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.
23
+
24
+ Parameters
25
+ ----------
26
+ kind : str
27
+ Registry entry kind.
28
+ **kwargs : dict
29
+ Keyword arguments for the constructor.
30
+
31
+ Returns
32
+ -------
33
+ Status
34
+ Status object.
35
+ """
36
+ infos: RegistryEntry = getattr(registry, kind)
37
+ status = import_class(infos.status.module, infos.status.class_name)
38
+ kwargs = parse_arguments(**kwargs)
39
+ return status(**kwargs)
40
+
41
+
42
+ def parse_arguments(**kwargs) -> dict:
43
+ """
44
+ Parse keyword arguments and add default values if necessary.
45
+
46
+ Parameters
47
+ ----------
48
+ **kwargs : dict
49
+ Keyword arguments.
50
+
51
+ Returns
52
+ -------
53
+ dict
54
+ Keyword arguments with default values.
55
+ """
56
+ state = kwargs.get("state")
57
+ if state is None:
58
+ kwargs["state"] = State.CREATED.value
59
+ else:
60
+ if kwargs["state"] not in State.__members__:
61
+ raise ValueError(f"Invalid state: {state}")
62
+ return kwargs
@@ -2,7 +2,15 @@ from __future__ import annotations
2
2
 
3
3
  from uuid import uuid4
4
4
 
5
- from digitalhub.utils.generic_utils import slugify_string
5
+ from pydantic import UUID4, BaseModel
6
+
7
+
8
+ class UUIDValidator(BaseModel):
9
+ """
10
+ Validate UUID format.
11
+ """
12
+
13
+ uuid: UUID4
6
14
 
7
15
 
8
16
  def build_uuid(uuid: str | None = None) -> str:
@@ -12,7 +20,7 @@ def build_uuid(uuid: str | None = None) -> str:
12
20
  Parameters
13
21
  ----------
14
22
  uuid : str
15
- ID of the object.
23
+ ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
16
24
 
17
25
  Returns
18
26
  -------
@@ -20,7 +28,6 @@ def build_uuid(uuid: str | None = None) -> str:
20
28
  Validated UUID4.
21
29
  """
22
30
  if uuid is not None:
23
- if slugify_string(uuid) != uuid:
24
- raise ValueError(f"Invalid ID: {uuid}. Must pass slugified ID.")
31
+ UUIDValidator(uuid=uuid)
25
32
  return uuid
26
33
  return str(uuid4())
@@ -0,0 +1,133 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._builders.metadata import build_metadata
6
+ from digitalhub.entities._builders.name import build_name
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
+ from digitalhub.utils.exceptions import EntityError
11
+
12
+ if typing.TYPE_CHECKING:
13
+ from digitalhub.entities.artifact.entity._base import Artifact
14
+
15
+ # Manage class mapper
16
+ cls_mapper = {}
17
+
18
+ try:
19
+ from digitalhub.entities.artifact.entity.artifact import ArtifactArtifact
20
+
21
+ cls_mapper["artifact"] = ArtifactArtifact
22
+ except ImportError:
23
+ pass
24
+
25
+
26
+ def _choose_artifact_type(kind: str) -> type[Artifact]:
27
+ """
28
+ Choose class based on kind.
29
+
30
+ Parameters
31
+ ----------
32
+ kind : str
33
+ Kind the object.
34
+
35
+ Returns
36
+ -------
37
+ type[Artifact]
38
+ Class of the artifact.
39
+ """
40
+ try:
41
+ return cls_mapper[kind]
42
+ except KeyError:
43
+ raise EntityError(f"Unknown artifact kind: {kind}")
44
+
45
+
46
+ def artifact_from_parameters(
47
+ project: str,
48
+ name: str,
49
+ kind: str,
50
+ uuid: str | None = None,
51
+ description: str | None = None,
52
+ labels: list[str] | None = None,
53
+ embedded: bool = True,
54
+ path: str | None = None,
55
+ **kwargs,
56
+ ) -> Artifact:
57
+ """
58
+ Create a new object.
59
+
60
+ Parameters
61
+ ----------
62
+ project : str
63
+ Project name.
64
+ name : str
65
+ Object name.
66
+ kind : str
67
+ Kind the object.
68
+ uuid : str
69
+ ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
70
+ description : str
71
+ Description of the object (human readable).
72
+ labels : list[str]
73
+ List of labels.
74
+ embedded : bool
75
+ Flag to determine if object spec must be embedded in project spec.
76
+ path : str
77
+ Object path on local file system or remote storage. It is also the destination path of upload() method.
78
+ **kwargs : dict
79
+ Spec keyword arguments.
80
+
81
+ Returns
82
+ -------
83
+ Artifact
84
+ Object instance.
85
+ """
86
+ if path is None:
87
+ raise EntityError("Path must be provided.")
88
+ name = build_name(name)
89
+ uuid = build_uuid(uuid)
90
+ metadata = build_metadata(
91
+ kind,
92
+ project=project,
93
+ name=name,
94
+ version=uuid,
95
+ description=description,
96
+ labels=labels,
97
+ embedded=embedded,
98
+ )
99
+ spec = build_spec(
100
+ kind,
101
+ path=path,
102
+ **kwargs,
103
+ )
104
+ status = build_status(kind)
105
+ cls = _choose_artifact_type(kind)
106
+ return cls(
107
+ project=project,
108
+ name=name,
109
+ uuid=uuid,
110
+ kind=kind,
111
+ metadata=metadata,
112
+ spec=spec,
113
+ status=status,
114
+ )
115
+
116
+
117
+ def artifact_from_dict(obj: dict) -> Artifact:
118
+ """
119
+ Create a new object from dictionary.
120
+
121
+ Parameters
122
+ ----------
123
+ obj : dict
124
+ Dictionary to create object from.
125
+
126
+ Returns
127
+ -------
128
+ Artifact
129
+ Object instance.
130
+ """
131
+ kind = obj.get("kind")
132
+ cls = _choose_artifact_type(kind)
133
+ return cls.from_dict(obj)
@@ -2,21 +2,22 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
+ from digitalhub.context.builder import check_context
5
6
  from digitalhub.entities._base.crud import (
6
- delete_entity,
7
- get_material_entity,
8
- get_material_entity_versions,
9
- import_context_entity,
10
- list_material_entities,
11
- new_context_entity,
7
+ delete_entity_api_ctx,
8
+ list_entity_api_ctx,
9
+ read_entity_api_ctx,
10
+ read_entity_api_ctx_versions,
12
11
  )
13
- from digitalhub.entities._base.entity._constructors.uuid import build_uuid
14
- from digitalhub.entities.artifact._base.entity import Artifact
15
- from digitalhub.entities.utils.entity_types import EntityTypes
16
- from digitalhub.entities.utils.utils import build_log_path_from_source, eval_local_source
12
+ from digitalhub.entities._builders.uuid import build_uuid
13
+ from digitalhub.entities.artifact.builder import artifact_from_dict, artifact_from_parameters
14
+ from digitalhub.entities.entity_types import EntityTypes
15
+ from digitalhub.entities.utils import build_log_path_from_source, eval_local_source
16
+ from digitalhub.utils.exceptions import EntityAlreadyExistsError
17
+ from digitalhub.utils.io_utils import read_yaml
17
18
 
18
19
  if typing.TYPE_CHECKING:
19
- from digitalhub.entities.artifact._base.entity import Artifact
20
+ from digitalhub.entities.artifact.entity._base import Artifact
20
21
 
21
22
 
22
23
  ENTITY_TYPE = EntityTypes.ARTIFACT.value
@@ -29,7 +30,7 @@ def new_artifact(
29
30
  uuid: str | None = None,
30
31
  description: str | None = None,
31
32
  labels: list[str] | None = None,
32
- embedded: bool = False,
33
+ embedded: bool = True,
33
34
  path: str | None = None,
34
35
  **kwargs,
35
36
  ) -> Artifact:
@@ -45,7 +46,7 @@ def new_artifact(
45
46
  kind : str
46
47
  Kind the object.
47
48
  uuid : str
48
- ID of the object.
49
+ ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
49
50
  description : str
50
51
  Description of the object (human readable).
51
52
  labels : list[str]
@@ -69,7 +70,8 @@ def new_artifact(
69
70
  >>> kind="artifact",
70
71
  >>> path="s3://my-bucket/my-key")
71
72
  """
72
- return new_context_entity(
73
+ check_context(project)
74
+ obj = artifact_from_parameters(
73
75
  project=project,
74
76
  name=name,
75
77
  kind=kind,
@@ -80,6 +82,8 @@ def new_artifact(
80
82
  path=path,
81
83
  **kwargs,
82
84
  )
85
+ obj.save()
86
+ return obj
83
87
 
84
88
 
85
89
  def log_artifact(
@@ -167,13 +171,16 @@ def get_artifact(
167
171
  >>> project="my-project",
168
172
  >>> entity_id="my-artifact-id")
169
173
  """
170
- return get_material_entity(
171
- identifier=identifier,
172
- entity_type=ENTITY_TYPE,
174
+ obj = read_entity_api_ctx(
175
+ identifier,
176
+ ENTITY_TYPE,
173
177
  project=project,
174
178
  entity_id=entity_id,
175
179
  **kwargs,
176
180
  )
181
+ entity = artifact_from_dict(obj)
182
+ entity._get_files_info()
183
+ return entity
177
184
 
178
185
 
179
186
  def get_artifact_versions(
@@ -207,12 +214,18 @@ def get_artifact_versions(
207
214
  >>> obj = get_artifact_versions("my-artifact-name"
208
215
  >>> project="my-project")
209
216
  """
210
- return get_material_entity_versions(
211
- identifier=identifier,
217
+ objs = read_entity_api_ctx_versions(
218
+ identifier,
212
219
  entity_type=ENTITY_TYPE,
213
220
  project=project,
214
221
  **kwargs,
215
222
  )
223
+ objects = []
224
+ for o in objs:
225
+ entity = artifact_from_dict(o)
226
+ entity._get_files_info()
227
+ objects.append(entity)
228
+ return objects
216
229
 
217
230
 
218
231
  def list_artifacts(project: str, **kwargs) -> list[Artifact]:
@@ -235,11 +248,17 @@ def list_artifacts(project: str, **kwargs) -> list[Artifact]:
235
248
  --------
236
249
  >>> objs = list_artifacts(project="my-project")
237
250
  """
238
- return list_material_entities(
251
+ objs = list_entity_api_ctx(
239
252
  project=project,
240
253
  entity_type=ENTITY_TYPE,
241
254
  **kwargs,
242
255
  )
256
+ objects = []
257
+ for o in objs:
258
+ entity = artifact_from_dict(o)
259
+ entity._get_files_info()
260
+ objects.append(entity)
261
+ return objects
243
262
 
244
263
 
245
264
  def import_artifact(file: str) -> Artifact:
@@ -260,7 +279,14 @@ def import_artifact(file: str) -> Artifact:
260
279
  --------
261
280
  >>> obj = import_artifact("my-artifact.yaml")
262
281
  """
263
- return import_context_entity(file)
282
+ dict_obj: dict = read_yaml(file)
283
+ obj = artifact_from_dict(dict_obj)
284
+ try:
285
+ obj.save()
286
+ except EntityAlreadyExistsError:
287
+ pass
288
+ finally:
289
+ return obj
264
290
 
265
291
 
266
292
  def update_artifact(entity: Artifact) -> Artifact:
@@ -322,7 +348,7 @@ def delete_artifact(
322
348
  >>> project="my-project",
323
349
  >>> delete_all_versions=True)
324
350
  """
325
- return delete_entity(
351
+ return delete_entity_api_ctx(
326
352
  identifier=identifier,
327
353
  entity_type=ENTITY_TYPE,
328
354
  project=project,
@@ -2,13 +2,13 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.entities._base.material.entity import MaterialEntity
6
- from digitalhub.entities.utils.entity_types import EntityTypes
5
+ from digitalhub.entities._base.entity.material import MaterialEntity
6
+ from digitalhub.entities.entity_types import EntityTypes
7
7
 
8
8
  if typing.TYPE_CHECKING:
9
- from digitalhub.entities._base.entity.metadata import Metadata
10
- from digitalhub.entities.artifact._base.spec import ArtifactSpec
11
- from digitalhub.entities.artifact._base.status import ArtifactStatus
9
+ from digitalhub.entities._base.metadata import Metadata
10
+ from digitalhub.entities.artifact.spec import ArtifactSpec
11
+ from digitalhub.entities.artifact.status import ArtifactStatus
12
12
 
13
13
 
14
14
  class Artifact(MaterialEntity):
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities.artifact.entity._base import Artifact
4
+
5
+
6
+ class ArtifactArtifact(Artifact):
7
+ """
8
+ Artifact class.
9
+ """
@@ -1,11 +1,23 @@
1
1
  from __future__ import annotations
2
2
 
3
- from digitalhub.entities.artifact._base.spec import ArtifactSpec, ArtifactValidator
3
+ from digitalhub.entities._base.spec.material import MaterialParams, MaterialSpec
4
+
5
+
6
+ class ArtifactSpec(MaterialSpec):
7
+ """
8
+ Artifact specification.
9
+ """
10
+
11
+
12
+ class ArtifactParams(MaterialParams):
13
+ """
14
+ Artifact base parameters.
15
+ """
4
16
 
5
17
 
6
18
  class ArtifactSpecArtifact(ArtifactSpec):
7
19
  """
8
- ArtifactSpecArtifact specifications.
20
+ Artifact specification.
9
21
  """
10
22
 
11
23
  def __init__(
@@ -18,9 +30,9 @@ class ArtifactSpecArtifact(ArtifactSpec):
18
30
  self.src_path = src_path
19
31
 
20
32
 
21
- class ArtifactValidatorArtifact(ArtifactValidator):
33
+ class ArtifactParamsArtifact(ArtifactParams):
22
34
  """
23
- ArtifactValidatorArtifact validator.
35
+ Artifact parameters.
24
36
  """
25
37
 
26
38
  src_path: str = None
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from digitalhub.entities._base.material.status import MaterialStatus
3
+ from digitalhub.entities._base.status.material import MaterialStatus
4
4
 
5
5
 
6
6
  class ArtifactStatus(MaterialStatus):
@@ -0,0 +1,144 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._builders.metadata import build_metadata
6
+ from digitalhub.entities._builders.name import build_name
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
+ from digitalhub.utils.exceptions import EntityError
11
+
12
+ if typing.TYPE_CHECKING:
13
+ from digitalhub.entities.dataitem.entity._base import Dataitem
14
+
15
+ # Manage class mapper
16
+ cls_mapper = {}
17
+ try:
18
+ from digitalhub.entities.dataitem.entity.dataitem import DataitemDataitem
19
+
20
+ cls_mapper["dataitem"] = DataitemDataitem
21
+ except ImportError:
22
+ ...
23
+ try:
24
+ from digitalhub.entities.dataitem.entity.table import DataitemTable
25
+
26
+ cls_mapper["table"] = DataitemTable
27
+ except ImportError:
28
+ ...
29
+ try:
30
+ from digitalhub.entities.dataitem.entity.iceberg import DataitemIceberg
31
+
32
+ cls_mapper["iceberg"] = DataitemIceberg
33
+ except ImportError:
34
+ pass
35
+
36
+
37
+ def _choose_dataitem_type(kind: str) -> type[Dataitem]:
38
+ """
39
+ Choose class based on kind.
40
+
41
+ Parameters
42
+ ----------
43
+ kind : str
44
+ Kind the object.
45
+
46
+ Returns
47
+ -------
48
+ type[Dataitem]
49
+ Class of the dataitem.
50
+ """
51
+ try:
52
+ return cls_mapper[kind]
53
+ except KeyError:
54
+ raise EntityError(f"Unknown dataitem kind: {kind}")
55
+
56
+
57
+ def dataitem_from_parameters(
58
+ project: str,
59
+ name: str,
60
+ kind: str,
61
+ uuid: str | None = None,
62
+ description: str | None = None,
63
+ labels: list[str] | None = None,
64
+ embedded: bool = True,
65
+ path: str | None = None,
66
+ **kwargs,
67
+ ) -> Dataitem:
68
+ """
69
+ Create a new object.
70
+
71
+ Parameters
72
+ ----------
73
+ project : str
74
+ Project name.
75
+ name : str
76
+ Object name.
77
+ kind : str
78
+ Kind the object.
79
+ uuid : str
80
+ ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
81
+ description : str
82
+ Description of the object (human readable).
83
+ labels : list[str]
84
+ List of labels.
85
+ embedded : bool
86
+ Flag to determine if object spec must be embedded in project spec.
87
+ path : str
88
+ Object path on local file system or remote storage. It is also the destination path of upload() method.
89
+ **kwargs : dict
90
+ Spec keyword arguments.
91
+
92
+ Returns
93
+ -------
94
+ Dataitem
95
+ Object instance.
96
+ """
97
+ if path is None:
98
+ raise EntityError("Dataitem path must be provided")
99
+ name = build_name(name)
100
+ uuid = build_uuid(uuid)
101
+ metadata = build_metadata(
102
+ kind,
103
+ project=project,
104
+ name=name,
105
+ version=uuid,
106
+ description=description,
107
+ labels=labels,
108
+ embedded=embedded,
109
+ )
110
+ spec = build_spec(
111
+ kind,
112
+ path=path,
113
+ **kwargs,
114
+ )
115
+ status = build_status(kind)
116
+ cls = _choose_dataitem_type(kind)
117
+ return cls(
118
+ project=project,
119
+ name=name,
120
+ uuid=uuid,
121
+ kind=kind,
122
+ metadata=metadata,
123
+ spec=spec,
124
+ status=status,
125
+ )
126
+
127
+
128
+ def dataitem_from_dict(obj: dict) -> Dataitem:
129
+ """
130
+ Create a new object from dictionary.
131
+
132
+ Parameters
133
+ ----------
134
+ obj : dict
135
+ Dictionary to create object from.
136
+
137
+ Returns
138
+ -------
139
+ Dataitem
140
+ Object instance.
141
+ """
142
+ kind = obj.get("kind")
143
+ cls = _choose_dataitem_type(kind)
144
+ return cls.from_dict(obj)