digitalhub 0.7.0b2__py3-none-any.whl → 0.8.0__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 (232) hide show
  1. digitalhub/__init__.py +63 -93
  2. digitalhub/client/__init__.py +0 -0
  3. digitalhub/client/_base/__init__.py +0 -0
  4. digitalhub/client/_base/client.py +56 -0
  5. digitalhub/client/api.py +63 -0
  6. digitalhub/client/builder.py +50 -0
  7. digitalhub/client/dhcore/__init__.py +0 -0
  8. digitalhub/client/dhcore/client.py +669 -0
  9. digitalhub/client/dhcore/env.py +21 -0
  10. digitalhub/client/dhcore/models.py +46 -0
  11. digitalhub/client/dhcore/utils.py +111 -0
  12. digitalhub/client/local/__init__.py +0 -0
  13. digitalhub/client/local/client.py +533 -0
  14. digitalhub/context/__init__.py +0 -0
  15. digitalhub/context/api.py +93 -0
  16. digitalhub/context/builder.py +94 -0
  17. digitalhub/context/context.py +136 -0
  18. digitalhub/datastores/__init__.py +0 -0
  19. digitalhub/datastores/_base/__init__.py +0 -0
  20. digitalhub/datastores/_base/datastore.py +85 -0
  21. digitalhub/datastores/api.py +37 -0
  22. digitalhub/datastores/builder.py +110 -0
  23. digitalhub/datastores/local/__init__.py +0 -0
  24. digitalhub/datastores/local/datastore.py +50 -0
  25. digitalhub/datastores/remote/__init__.py +0 -0
  26. digitalhub/datastores/remote/datastore.py +31 -0
  27. digitalhub/datastores/s3/__init__.py +0 -0
  28. digitalhub/datastores/s3/datastore.py +46 -0
  29. digitalhub/datastores/sql/__init__.py +0 -0
  30. digitalhub/datastores/sql/datastore.py +68 -0
  31. digitalhub/entities/__init__.py +0 -0
  32. digitalhub/entities/_base/__init__.py +0 -0
  33. digitalhub/entities/_base/_base/__init__.py +0 -0
  34. digitalhub/entities/_base/_base/entity.py +82 -0
  35. digitalhub/entities/_base/api_utils.py +620 -0
  36. digitalhub/entities/_base/context/__init__.py +0 -0
  37. digitalhub/entities/_base/context/entity.py +118 -0
  38. digitalhub/entities/_base/crud.py +468 -0
  39. digitalhub/entities/_base/entity/__init__.py +0 -0
  40. digitalhub/entities/_base/entity/_constructors/__init__.py +0 -0
  41. digitalhub/entities/_base/entity/_constructors/metadata.py +44 -0
  42. digitalhub/entities/_base/entity/_constructors/name.py +31 -0
  43. digitalhub/entities/_base/entity/_constructors/spec.py +33 -0
  44. digitalhub/entities/_base/entity/_constructors/status.py +52 -0
  45. digitalhub/entities/_base/entity/_constructors/uuid.py +26 -0
  46. digitalhub/entities/_base/entity/builder.py +175 -0
  47. digitalhub/entities/_base/entity/entity.py +106 -0
  48. digitalhub/entities/_base/entity/metadata.py +59 -0
  49. digitalhub/entities/_base/entity/spec.py +58 -0
  50. digitalhub/entities/_base/entity/status.py +43 -0
  51. digitalhub/entities/_base/executable/__init__.py +0 -0
  52. digitalhub/entities/_base/executable/entity.py +405 -0
  53. digitalhub/entities/_base/material/__init__.py +0 -0
  54. digitalhub/entities/_base/material/entity.py +214 -0
  55. digitalhub/entities/_base/material/spec.py +22 -0
  56. digitalhub/entities/_base/material/status.py +49 -0
  57. digitalhub/entities/_base/runtime_entity/__init__.py +0 -0
  58. digitalhub/entities/_base/runtime_entity/builder.py +106 -0
  59. digitalhub/entities/_base/unversioned/__init__.py +0 -0
  60. digitalhub/entities/_base/unversioned/builder.py +66 -0
  61. digitalhub/entities/_base/unversioned/entity.py +49 -0
  62. digitalhub/entities/_base/versioned/__init__.py +0 -0
  63. digitalhub/entities/_base/versioned/builder.py +68 -0
  64. digitalhub/entities/_base/versioned/entity.py +53 -0
  65. digitalhub/entities/artifact/__init__.py +0 -0
  66. digitalhub/entities/artifact/_base/__init__.py +0 -0
  67. digitalhub/entities/artifact/_base/builder.py +86 -0
  68. digitalhub/entities/artifact/_base/entity.py +39 -0
  69. digitalhub/entities/artifact/_base/spec.py +15 -0
  70. digitalhub/entities/artifact/_base/status.py +9 -0
  71. digitalhub/entities/artifact/artifact/__init__.py +0 -0
  72. digitalhub/entities/artifact/artifact/builder.py +18 -0
  73. digitalhub/entities/artifact/artifact/entity.py +32 -0
  74. digitalhub/entities/artifact/artifact/spec.py +27 -0
  75. digitalhub/entities/artifact/artifact/status.py +15 -0
  76. digitalhub/entities/artifact/crud.py +332 -0
  77. digitalhub/entities/builders.py +63 -0
  78. digitalhub/entities/dataitem/__init__.py +0 -0
  79. digitalhub/entities/dataitem/_base/__init__.py +0 -0
  80. digitalhub/entities/dataitem/_base/builder.py +86 -0
  81. digitalhub/entities/dataitem/_base/entity.py +75 -0
  82. digitalhub/entities/dataitem/_base/spec.py +15 -0
  83. digitalhub/entities/dataitem/_base/status.py +20 -0
  84. digitalhub/entities/dataitem/crud.py +372 -0
  85. digitalhub/entities/dataitem/dataitem/__init__.py +0 -0
  86. digitalhub/entities/dataitem/dataitem/builder.py +18 -0
  87. digitalhub/entities/dataitem/dataitem/entity.py +32 -0
  88. digitalhub/entities/dataitem/dataitem/spec.py +15 -0
  89. digitalhub/entities/dataitem/dataitem/status.py +9 -0
  90. digitalhub/entities/dataitem/iceberg/__init__.py +0 -0
  91. digitalhub/entities/dataitem/iceberg/builder.py +18 -0
  92. digitalhub/entities/dataitem/iceberg/entity.py +32 -0
  93. digitalhub/entities/dataitem/iceberg/spec.py +15 -0
  94. digitalhub/entities/dataitem/iceberg/status.py +9 -0
  95. digitalhub/entities/dataitem/table/__init__.py +0 -0
  96. digitalhub/entities/dataitem/table/builder.py +18 -0
  97. digitalhub/entities/dataitem/table/entity.py +146 -0
  98. digitalhub/entities/dataitem/table/models.py +62 -0
  99. digitalhub/entities/dataitem/table/spec.py +25 -0
  100. digitalhub/entities/dataitem/table/status.py +9 -0
  101. digitalhub/entities/function/__init__.py +0 -0
  102. digitalhub/entities/function/_base/__init__.py +0 -0
  103. digitalhub/entities/function/_base/builder.py +79 -0
  104. digitalhub/entities/function/_base/entity.py +98 -0
  105. digitalhub/entities/function/_base/models.py +118 -0
  106. digitalhub/entities/function/_base/spec.py +15 -0
  107. digitalhub/entities/function/_base/status.py +9 -0
  108. digitalhub/entities/function/crud.py +279 -0
  109. digitalhub/entities/model/__init__.py +0 -0
  110. digitalhub/entities/model/_base/__init__.py +0 -0
  111. digitalhub/entities/model/_base/builder.py +86 -0
  112. digitalhub/entities/model/_base/entity.py +34 -0
  113. digitalhub/entities/model/_base/spec.py +49 -0
  114. digitalhub/entities/model/_base/status.py +9 -0
  115. digitalhub/entities/model/crud.py +331 -0
  116. digitalhub/entities/model/huggingface/__init__.py +0 -0
  117. digitalhub/entities/model/huggingface/builder.py +18 -0
  118. digitalhub/entities/model/huggingface/entity.py +32 -0
  119. digitalhub/entities/model/huggingface/spec.py +36 -0
  120. digitalhub/entities/model/huggingface/status.py +9 -0
  121. digitalhub/entities/model/mlflow/__init__.py +0 -0
  122. digitalhub/entities/model/mlflow/builder.py +18 -0
  123. digitalhub/entities/model/mlflow/entity.py +32 -0
  124. digitalhub/entities/model/mlflow/models.py +26 -0
  125. digitalhub/entities/model/mlflow/spec.py +44 -0
  126. digitalhub/entities/model/mlflow/status.py +9 -0
  127. digitalhub/entities/model/mlflow/utils.py +81 -0
  128. digitalhub/entities/model/model/__init__.py +0 -0
  129. digitalhub/entities/model/model/builder.py +18 -0
  130. digitalhub/entities/model/model/entity.py +32 -0
  131. digitalhub/entities/model/model/spec.py +15 -0
  132. digitalhub/entities/model/model/status.py +9 -0
  133. digitalhub/entities/model/sklearn/__init__.py +0 -0
  134. digitalhub/entities/model/sklearn/builder.py +18 -0
  135. digitalhub/entities/model/sklearn/entity.py +32 -0
  136. digitalhub/entities/model/sklearn/spec.py +15 -0
  137. digitalhub/entities/model/sklearn/status.py +9 -0
  138. digitalhub/entities/project/__init__.py +0 -0
  139. digitalhub/entities/project/_base/__init__.py +0 -0
  140. digitalhub/entities/project/_base/builder.py +128 -0
  141. digitalhub/entities/project/_base/entity.py +2078 -0
  142. digitalhub/entities/project/_base/spec.py +50 -0
  143. digitalhub/entities/project/_base/status.py +9 -0
  144. digitalhub/entities/project/crud.py +357 -0
  145. digitalhub/entities/run/__init__.py +0 -0
  146. digitalhub/entities/run/_base/__init__.py +0 -0
  147. digitalhub/entities/run/_base/builder.py +94 -0
  148. digitalhub/entities/run/_base/entity.py +307 -0
  149. digitalhub/entities/run/_base/spec.py +50 -0
  150. digitalhub/entities/run/_base/status.py +9 -0
  151. digitalhub/entities/run/crud.py +219 -0
  152. digitalhub/entities/secret/__init__.py +0 -0
  153. digitalhub/entities/secret/_base/__init__.py +0 -0
  154. digitalhub/entities/secret/_base/builder.py +81 -0
  155. digitalhub/entities/secret/_base/entity.py +74 -0
  156. digitalhub/entities/secret/_base/spec.py +35 -0
  157. digitalhub/entities/secret/_base/status.py +9 -0
  158. digitalhub/entities/secret/crud.py +290 -0
  159. digitalhub/entities/task/__init__.py +0 -0
  160. digitalhub/entities/task/_base/__init__.py +0 -0
  161. digitalhub/entities/task/_base/builder.py +91 -0
  162. digitalhub/entities/task/_base/entity.py +136 -0
  163. digitalhub/entities/task/_base/models.py +208 -0
  164. digitalhub/entities/task/_base/spec.py +53 -0
  165. digitalhub/entities/task/_base/status.py +9 -0
  166. digitalhub/entities/task/crud.py +228 -0
  167. digitalhub/entities/utils/__init__.py +0 -0
  168. digitalhub/entities/utils/api.py +346 -0
  169. digitalhub/entities/utils/entity_types.py +19 -0
  170. digitalhub/entities/utils/state.py +31 -0
  171. digitalhub/entities/utils/utils.py +202 -0
  172. digitalhub/entities/workflow/__init__.py +0 -0
  173. digitalhub/entities/workflow/_base/__init__.py +0 -0
  174. digitalhub/entities/workflow/_base/builder.py +79 -0
  175. digitalhub/entities/workflow/_base/entity.py +74 -0
  176. digitalhub/entities/workflow/_base/spec.py +15 -0
  177. digitalhub/entities/workflow/_base/status.py +9 -0
  178. digitalhub/entities/workflow/crud.py +278 -0
  179. digitalhub/factory/__init__.py +0 -0
  180. digitalhub/factory/api.py +277 -0
  181. digitalhub/factory/factory.py +268 -0
  182. digitalhub/factory/utils.py +90 -0
  183. digitalhub/readers/__init__.py +0 -0
  184. digitalhub/readers/_base/__init__.py +0 -0
  185. digitalhub/readers/_base/builder.py +26 -0
  186. digitalhub/readers/_base/reader.py +70 -0
  187. digitalhub/readers/api.py +80 -0
  188. digitalhub/readers/factory.py +133 -0
  189. digitalhub/readers/pandas/__init__.py +0 -0
  190. digitalhub/readers/pandas/builder.py +29 -0
  191. digitalhub/readers/pandas/reader.py +207 -0
  192. digitalhub/runtimes/__init__.py +0 -0
  193. digitalhub/runtimes/_base.py +102 -0
  194. digitalhub/runtimes/builder.py +32 -0
  195. digitalhub/stores/__init__.py +0 -0
  196. digitalhub/stores/_base/__init__.py +0 -0
  197. digitalhub/stores/_base/store.py +189 -0
  198. digitalhub/stores/api.py +54 -0
  199. digitalhub/stores/builder.py +211 -0
  200. digitalhub/stores/local/__init__.py +0 -0
  201. digitalhub/stores/local/store.py +230 -0
  202. digitalhub/stores/remote/__init__.py +0 -0
  203. digitalhub/stores/remote/store.py +143 -0
  204. digitalhub/stores/s3/__init__.py +0 -0
  205. digitalhub/stores/s3/store.py +563 -0
  206. digitalhub/stores/sql/__init__.py +0 -0
  207. digitalhub/stores/sql/store.py +328 -0
  208. digitalhub/utils/__init__.py +0 -0
  209. digitalhub/utils/data_utils.py +127 -0
  210. digitalhub/utils/exceptions.py +67 -0
  211. digitalhub/utils/file_utils.py +204 -0
  212. digitalhub/utils/generic_utils.py +183 -0
  213. digitalhub/utils/git_utils.py +148 -0
  214. digitalhub/utils/io_utils.py +116 -0
  215. digitalhub/utils/logger.py +17 -0
  216. digitalhub/utils/s3_utils.py +58 -0
  217. digitalhub/utils/uri_utils.py +56 -0
  218. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/METADATA +30 -13
  219. digitalhub-0.8.0.dist-info/RECORD +231 -0
  220. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/WHEEL +1 -1
  221. test/local/CRUD/test_artifacts.py +96 -0
  222. test/local/CRUD/test_dataitems.py +96 -0
  223. test/local/CRUD/test_models.py +95 -0
  224. test/test_crud_functions.py +1 -1
  225. test/test_crud_runs.py +1 -1
  226. test/test_crud_tasks.py +1 -1
  227. digitalhub-0.7.0b2.dist-info/RECORD +0 -14
  228. test/test_crud_artifacts.py +0 -96
  229. test/test_crud_dataitems.py +0 -96
  230. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/LICENSE.txt +0 -0
  231. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/top_level.txt +0 -0
  232. /test/{test_imports.py → local/imports/test_imports.py} +0 -0
@@ -0,0 +1,62 @@
1
+ from __future__ import annotations
2
+
3
+ from enum import Enum
4
+
5
+ from pydantic import BaseModel, Field
6
+
7
+
8
+ class FieldType(str, Enum):
9
+ """
10
+ Field type enum.
11
+ """
12
+
13
+ STRING = "string"
14
+ NUMBER = "number"
15
+ INTEGER = "integer"
16
+ BOOLEAN = "boolean"
17
+ OBJECT = "object"
18
+ ARRAY = "array"
19
+ DATE = "date"
20
+ TIME = "time"
21
+ DATETIME = "datetime"
22
+ YEAR = "year"
23
+ YEARMONTH = "yearmonth"
24
+ DURATION = "duration"
25
+ GEOPOINT = "geopoint"
26
+ GEOJSON = "geojson"
27
+ ANY = "any"
28
+
29
+
30
+ class TableSchemaFieldEntry(BaseModel):
31
+ """
32
+ Table schema field entry model.
33
+ """
34
+
35
+ name: str
36
+ """Field name."""
37
+
38
+ type_: FieldType = Field(alias="type")
39
+ """Field type."""
40
+
41
+ title: str = None
42
+ """Field title."""
43
+
44
+ format_: str = Field(default=None, alias="format")
45
+ """Field format."""
46
+
47
+ example: str = None
48
+ """Field example."""
49
+
50
+ description: str = None
51
+ """Field description."""
52
+
53
+ class Config:
54
+ use_enum_values = True
55
+
56
+
57
+ class TableSchema(BaseModel):
58
+ """
59
+ Table schema model.
60
+ """
61
+
62
+ fields: list[TableSchemaFieldEntry]
@@ -0,0 +1,25 @@
1
+ from __future__ import annotations
2
+
3
+ from pydantic import Field
4
+
5
+ from digitalhub.entities.dataitem._base.spec import DataitemSpec, DataitemValidator
6
+ from digitalhub.entities.dataitem.table.models import TableSchema
7
+
8
+
9
+ class DataitemSpecTable(DataitemSpec):
10
+ """
11
+ DataitemSpecTable specifications.
12
+ """
13
+
14
+ def __init__(self, path: str, schema: dict | None = None) -> None:
15
+ super().__init__(path)
16
+ self.schema = schema
17
+
18
+
19
+ class DataitemValidatorTable(DataitemValidator):
20
+ """
21
+ DataitemValidatorTable validator.
22
+ """
23
+
24
+ schema_: TableSchema = Field(default=None, alias="schema")
25
+ """The schema of the dataitem in table schema format."""
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities.dataitem._base.status import DataitemStatus
4
+
5
+
6
+ class DataitemStatusTable(DataitemStatus):
7
+ """
8
+ DataitemStatusTable status.
9
+ """
File without changes
File without changes
@@ -0,0 +1,79 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.runtime_entity.builder import RuntimeEntityBuilder
6
+ from digitalhub.entities._base.versioned.builder import VersionedBuilder
7
+ from digitalhub.entities.utils.entity_types import EntityTypes
8
+
9
+ if typing.TYPE_CHECKING:
10
+ from digitalhub.entities.function._base.entity import Function
11
+
12
+
13
+ class FunctionBuilder(VersionedBuilder, RuntimeEntityBuilder):
14
+ """
15
+ Function builder.
16
+ """
17
+
18
+ ENTITY_TYPE = EntityTypes.FUNCTION.value
19
+
20
+ def build(
21
+ self,
22
+ kind: str,
23
+ project: str,
24
+ name: str,
25
+ uuid: str | None = None,
26
+ description: str | None = None,
27
+ labels: list[str] | None = None,
28
+ embedded: bool = False,
29
+ **kwargs,
30
+ ) -> Function:
31
+ """
32
+ Create a new object.
33
+
34
+ Parameters
35
+ ----------
36
+ project : str
37
+ Project name.
38
+ name : str
39
+ Object name.
40
+ kind : str
41
+ Kind the object.
42
+ uuid : str
43
+ ID of the object.
44
+ description : str
45
+ Description of the object (human readable).
46
+ labels : list[str]
47
+ List of labels.
48
+ embedded : bool
49
+ Flag to determine if object spec must be embedded in project spec.
50
+ **kwargs : dict
51
+ Spec keyword arguments.
52
+
53
+ Returns
54
+ -------
55
+ Function
56
+ Object instance.
57
+ """
58
+ name = self.build_name(name)
59
+ uuid = self.build_uuid(uuid)
60
+ metadata = self.build_metadata(
61
+ project=project,
62
+ name=name,
63
+ description=description,
64
+ labels=labels,
65
+ embedded=embedded,
66
+ )
67
+ spec = self.build_spec(
68
+ **kwargs,
69
+ )
70
+ status = self.build_status()
71
+ return self.build_entity(
72
+ project=project,
73
+ name=name,
74
+ uuid=uuid,
75
+ kind=kind,
76
+ metadata=metadata,
77
+ spec=spec,
78
+ status=status,
79
+ )
@@ -0,0 +1,98 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+ from concurrent.futures import ThreadPoolExecutor
5
+
6
+ from digitalhub.entities._base.executable.entity import ExecutableEntity
7
+ from digitalhub.entities.utils.entity_types import EntityTypes
8
+ from digitalhub.factory.api import get_run_kind, get_task_kind_from_action
9
+ from digitalhub.utils.exceptions import BackendError
10
+
11
+ if typing.TYPE_CHECKING:
12
+ from digitalhub.entities._base.entity.metadata import Metadata
13
+ from digitalhub.entities.function._base.spec import FunctionSpec
14
+ from digitalhub.entities.function._base.status import FunctionStatus
15
+ from digitalhub.entities.run._base.entity import Run
16
+
17
+
18
+ class Function(ExecutableEntity):
19
+ """
20
+ A class representing a function.
21
+ """
22
+
23
+ ENTITY_TYPE = EntityTypes.FUNCTION.value
24
+
25
+ def __init__(
26
+ self,
27
+ project: str,
28
+ name: str,
29
+ uuid: str,
30
+ kind: str,
31
+ metadata: Metadata,
32
+ spec: FunctionSpec,
33
+ status: FunctionStatus,
34
+ user: str | None = None,
35
+ ) -> None:
36
+ super().__init__(project, name, uuid, kind, metadata, spec, status, user)
37
+
38
+ self.spec: FunctionSpec
39
+ self.status: FunctionStatus
40
+
41
+ ##############################
42
+ # Function Methods
43
+ ##############################
44
+
45
+ def run(
46
+ self,
47
+ action: str,
48
+ local_execution: bool = False,
49
+ wait: bool = False,
50
+ log_info: bool = True,
51
+ **kwargs,
52
+ ) -> Run:
53
+ """
54
+ Run function. This method creates a new run and executes it.
55
+
56
+ Parameters
57
+ ----------
58
+ action : str
59
+ Action to execute.
60
+ local_execution : bool
61
+ Flag to determine if object has local execution.
62
+ wait : bool
63
+ Flag to wait for execution.
64
+ log_info : bool
65
+ Flag to log information while waiting.
66
+ **kwargs : dict
67
+ Keyword arguments passed to Run builder.
68
+
69
+ Returns
70
+ -------
71
+ Run
72
+ Run instance.
73
+ """
74
+ # Get task and run kind
75
+ task_kind = get_task_kind_from_action(self.kind, action)
76
+ run_kind = get_run_kind(self.kind)
77
+
78
+ # Create or update new task
79
+ task = self._get_or_create_task(task_kind)
80
+
81
+ # Run function from task
82
+ run = task.run(run_kind, local_execution, **kwargs)
83
+
84
+ # If execution is done by DHCore backend, return the object
85
+ if not local_execution:
86
+ if self._context().local:
87
+ raise BackendError("Cannot run remote function with local backend.")
88
+ if wait:
89
+ return run.wait(log_info=log_info)
90
+ return run
91
+
92
+ # If local execution, build and launch run.
93
+ # Detach the run from the main thread
94
+ run.build()
95
+ with ThreadPoolExecutor(max_workers=1) as executor:
96
+ result = executor.submit(run.run)
97
+ r = result.result()
98
+ return r
@@ -0,0 +1,118 @@
1
+ from __future__ import annotations
2
+
3
+ from abc import abstractmethod
4
+ from pathlib import Path
5
+
6
+ from pydantic import BaseModel
7
+
8
+ from digitalhub.utils.exceptions import EntityError
9
+ from digitalhub.utils.generic_utils import decode_string
10
+ from digitalhub.utils.uri_utils import map_uri_scheme
11
+
12
+
13
+ class SourceCodeStruct:
14
+ """
15
+ Source code struct.
16
+ """
17
+
18
+ def __init__(
19
+ self,
20
+ source: str | None = None,
21
+ code: str | None = None,
22
+ base64: str | None = None,
23
+ handler: str | None = None,
24
+ lang: str | None = None,
25
+ ) -> None:
26
+ self.source = source
27
+ self.code = code
28
+ self.base64 = base64
29
+ self.handler = handler
30
+ self.lang = lang
31
+
32
+ @staticmethod
33
+ @abstractmethod
34
+ def source_check(source: dict) -> dict:
35
+ """
36
+ Check source.
37
+
38
+ Parameters
39
+ ----------
40
+ source : dict
41
+ Source.
42
+
43
+ Returns
44
+ -------
45
+ dict
46
+ Checked source.
47
+ """
48
+
49
+ def show_source_code(self) -> str:
50
+ """
51
+ Show source code.
52
+
53
+ Returns
54
+ -------
55
+ str
56
+ Source code.
57
+ """
58
+ if self.code is not None:
59
+ return self.code
60
+ if self.base64 is not None:
61
+ try:
62
+ return decode_string(self.base64)
63
+ except Exception:
64
+ raise EntityError("Something got wrong during source code decoding.")
65
+ if (self.source is not None) and (map_uri_scheme(self.source) == "local"):
66
+ try:
67
+ return Path(self.source).read_text()
68
+ except Exception:
69
+ raise EntityError("Cannot access source code.")
70
+ return ""
71
+
72
+ def to_dict(self) -> dict:
73
+ """
74
+ Convert to dictionary.
75
+
76
+ Returns
77
+ -------
78
+ dict
79
+ Dictionary representation of the object.
80
+ """
81
+ dict_ = {}
82
+ if self.source is not None:
83
+ dict_["source"] = self.source
84
+ if self.base64 is not None:
85
+ dict_["base64"] = self.base64
86
+ if self.handler is not None:
87
+ dict_["handler"] = self.handler
88
+ if self.lang is not None:
89
+ dict_["lang"] = self.lang
90
+
91
+ return dict_
92
+
93
+ def __repr__(self) -> str:
94
+ return str(self.to_dict())
95
+
96
+
97
+ class SourceCodeValidator(BaseModel):
98
+ """
99
+ Source code params.
100
+ """
101
+
102
+ source: dict = None
103
+ "Source code details as dictionary"
104
+
105
+ code_src: str = None
106
+ "Pointer to source code"
107
+
108
+ handler: str = None
109
+ "Function entrypoint"
110
+
111
+ code: str = None
112
+ "Source code (plain text)"
113
+
114
+ base64: str = None
115
+ "Source code (base64 encoded)"
116
+
117
+ lang: str = None
118
+ "Source code language (hint)"
@@ -0,0 +1,15 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.entity.spec import Spec, SpecValidator
4
+
5
+
6
+ class FunctionSpec(Spec):
7
+ """
8
+ FunctionSpec specifications.
9
+ """
10
+
11
+
12
+ class FunctionValidator(SpecValidator):
13
+ """
14
+ FunctionValidator validator.
15
+ """
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.entity.status import Status
4
+
5
+
6
+ class FunctionStatus(Status):
7
+ """
8
+ FunctionStatus status.
9
+ """
@@ -0,0 +1,279 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.crud import (
6
+ delete_entity,
7
+ get_context_entity_versions,
8
+ get_versioned_entity,
9
+ import_executable_entity,
10
+ list_context_entities,
11
+ new_context_entity,
12
+ )
13
+ from digitalhub.entities.utils.entity_types import EntityTypes
14
+
15
+ if typing.TYPE_CHECKING:
16
+ from digitalhub.entities.function._base.entity import Function
17
+
18
+ ENTITY_TYPE = EntityTypes.FUNCTION.value
19
+
20
+
21
+ def new_function(
22
+ project: str,
23
+ name: str,
24
+ kind: str,
25
+ uuid: str | None = None,
26
+ description: str | None = None,
27
+ labels: list[str] | None = None,
28
+ embedded: bool = False,
29
+ **kwargs,
30
+ ) -> Function:
31
+ """
32
+ Create a Function instance with the given parameters.
33
+
34
+ Parameters
35
+ ----------
36
+ project : str
37
+ Project name.
38
+ name : str
39
+ Object name.
40
+ kind : str
41
+ Kind the object.
42
+ uuid : str
43
+ ID of the object.
44
+ description : str
45
+ Description of the object (human readable).
46
+ labels : list[str]
47
+ List of labels.
48
+ embedded : bool
49
+ Flag to determine if object spec must be embedded in project spec.
50
+ **kwargs : dict
51
+ Spec keyword arguments.
52
+
53
+ Returns
54
+ -------
55
+ Function
56
+ Object instance.
57
+
58
+ Examples
59
+ --------
60
+ >>> obj = new_function(project="my-project",
61
+ >>> name="my-function",
62
+ >>> kind="python",
63
+ >>> code_src="function.py",
64
+ >>> handler="function-handler")
65
+ """
66
+ return new_context_entity(
67
+ project=project,
68
+ name=name,
69
+ kind=kind,
70
+ uuid=uuid,
71
+ description=description,
72
+ labels=labels,
73
+ embedded=embedded,
74
+ **kwargs,
75
+ )
76
+
77
+
78
+ def get_function(
79
+ identifier: str,
80
+ project: str | None = None,
81
+ entity_id: str | None = None,
82
+ **kwargs,
83
+ ) -> Function:
84
+ """
85
+ Get object from backend.
86
+
87
+ Parameters
88
+ ----------
89
+ identifier : str
90
+ Entity key (store://...) or entity name.
91
+ project : str
92
+ Project name.
93
+ entity_id : str
94
+ Entity ID.
95
+ **kwargs : dict
96
+ Parameters to pass to the API call.
97
+
98
+ Returns
99
+ -------
100
+ Function
101
+ Object instance.
102
+
103
+ Examples
104
+ --------
105
+ Using entity key:
106
+ >>> obj = get_function("store://my-function-key")
107
+
108
+ Using entity name:
109
+ >>> obj = get_function("my-function-name"
110
+ >>> project="my-project",
111
+ >>> entity_id="my-function-id")
112
+ """
113
+ return get_versioned_entity(
114
+ identifier,
115
+ entity_type=ENTITY_TYPE,
116
+ project=project,
117
+ entity_id=entity_id,
118
+ **kwargs,
119
+ )
120
+
121
+
122
+ def get_function_versions(
123
+ identifier: str,
124
+ project: str | None = None,
125
+ **kwargs,
126
+ ) -> list[Function]:
127
+ """
128
+ Get object versions from backend.
129
+
130
+ Parameters
131
+ ----------
132
+ identifier : str
133
+ Entity key (store://...) or entity name.
134
+ project : str
135
+ Project name.
136
+ **kwargs : dict
137
+ Parameters to pass to the API call.
138
+
139
+ Returns
140
+ -------
141
+ list[Function]
142
+ List of object instances.
143
+
144
+ Examples
145
+ --------
146
+ Using entity key:
147
+ >>> obj = get_function_versions("store://my-function-key")
148
+
149
+ Using entity name:
150
+ >>> obj = get_function_versions("my-function-name"
151
+ >>> project="my-project")
152
+ """
153
+ return get_context_entity_versions(
154
+ identifier,
155
+ entity_type=ENTITY_TYPE,
156
+ project=project,
157
+ **kwargs,
158
+ )
159
+
160
+
161
+ def list_functions(project: str, **kwargs) -> list[Function]:
162
+ """
163
+ List all latest version objects from backend.
164
+
165
+ Parameters
166
+ ----------
167
+ project : str
168
+ Project name.
169
+ **kwargs : dict
170
+ Parameters to pass to the API call.
171
+
172
+ Returns
173
+ -------
174
+ list[Function]
175
+ List of object instances.
176
+
177
+ Examples
178
+ --------
179
+ >>> objs = list_functions(project="my-project")
180
+ """
181
+ return list_context_entities(
182
+ project=project,
183
+ entity_type=ENTITY_TYPE,
184
+ **kwargs,
185
+ )
186
+
187
+
188
+ def import_function(file: str) -> Function:
189
+ """
190
+ Get object from file.
191
+
192
+ Parameters
193
+ ----------
194
+ file : str
195
+ Path to YAML file.
196
+
197
+ Returns
198
+ -------
199
+ Function
200
+ Object instance.
201
+
202
+ Examples
203
+ --------
204
+ >>> obj = import_function("my-function.yaml")
205
+ """
206
+ return import_executable_entity(file)
207
+
208
+
209
+ def update_function(entity: Function) -> Function:
210
+ """
211
+ Update object. Note that object spec are immutable.
212
+
213
+ Parameters
214
+ ----------
215
+ entity : Function
216
+ Object to update.
217
+
218
+ Returns
219
+ -------
220
+ Function
221
+ Entity updated.
222
+
223
+ Examples
224
+ --------
225
+ >>> obj = update_function(obj)
226
+ """
227
+ return entity.save(update=True)
228
+
229
+
230
+ def delete_function(
231
+ identifier: str,
232
+ project: str | None = None,
233
+ entity_id: str | None = None,
234
+ delete_all_versions: bool = False,
235
+ cascade: bool = True,
236
+ **kwargs,
237
+ ) -> dict:
238
+ """
239
+ Delete object from backend.
240
+
241
+ Parameters
242
+ ----------
243
+ identifier : str
244
+ Entity key (store://...) or entity name.
245
+ project : str
246
+ Project name.
247
+ entity_id : str
248
+ Entity ID.
249
+ delete_all_versions : bool
250
+ Delete all versions of the named entity. If True, use entity name instead of entity key as identifier.
251
+ cascade : bool
252
+ Cascade delete.
253
+ **kwargs : dict
254
+ Parameters to pass to the API call.
255
+
256
+ Returns
257
+ -------
258
+ dict
259
+ Response from backend.
260
+
261
+ Examples
262
+ --------
263
+ If delete_all_versions is False:
264
+ >>> obj = delete_function("store://my-function-key")
265
+
266
+ Otherwise:
267
+ >>> obj = delete_function("function-name",
268
+ >>> project="my-project",
269
+ >>> delete_all_versions=True)
270
+ """
271
+ return delete_entity(
272
+ identifier=identifier,
273
+ entity_type=ENTITY_TYPE,
274
+ project=project,
275
+ entity_id=entity_id,
276
+ delete_all_versions=delete_all_versions,
277
+ cascade=cascade,
278
+ **kwargs,
279
+ )
File without changes
File without changes