digitalhub-runtime-python 0.6.0b8__tar.gz → 0.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/PKG-INFO +1 -1
  2. digitalhub_runtime_python-0.6.1/digitalhub_runtime_python/entities/functions/models.py +101 -0
  3. digitalhub_runtime_python-0.6.1/digitalhub_runtime_python/entities/functions/spec.py +108 -0
  4. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/utils/configuration.py +4 -33
  5. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python.egg-info/PKG-INFO +1 -1
  6. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python.egg-info/SOURCES.txt +1 -0
  7. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/pyproject.toml +2 -2
  8. digitalhub_runtime_python-0.6.0b8/digitalhub_runtime_python/entities/functions/spec.py +0 -239
  9. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/LICENSE.txt +0 -0
  10. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/README.md +0 -0
  11. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/__init__.py +0 -0
  12. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/entities/__init__.py +0 -0
  13. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/entities/functions/__init__.py +0 -0
  14. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/entities/functions/status.py +0 -0
  15. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/entities/runs/__init__.py +0 -0
  16. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/entities/runs/spec.py +0 -0
  17. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/entities/runs/status.py +0 -0
  18. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/entities/tasks/__init__.py +0 -0
  19. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/entities/tasks/models.py +0 -0
  20. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/entities/tasks/spec.py +0 -0
  21. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/entities/tasks/status.py +0 -0
  22. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/runtimes/__init__.py +0 -0
  23. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/runtimes/kind_registry.py +0 -0
  24. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/runtimes/runtime.py +0 -0
  25. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/utils/env.py +0 -0
  26. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/utils/inputs.py +0 -0
  27. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/utils/nuclio_configuration.py +0 -0
  28. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/utils/outputs.py +0 -0
  29. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python/utils/utils.py +0 -0
  30. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python.egg-info/dependency_links.txt +0 -0
  31. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python.egg-info/requires.txt +0 -0
  32. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/digitalhub_runtime_python.egg-info/top_level.txt +0 -0
  33. {digitalhub_runtime_python-0.6.0b8 → digitalhub_runtime_python-0.6.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: digitalhub-runtime-python
3
- Version: 0.6.0b8
3
+ Version: 0.6.1
4
4
  Summary: Python runtime for DHCore
5
5
  Author-email: Fondazione Bruno Kessler <dslab@fbk.eu>, Matteo Martini <mmartini@fbk.eu>
6
6
  License: Apache License
@@ -0,0 +1,101 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ from digitalhub_core.entities.functions.models import SourceCodeParams, SourceCodeStruct
6
+ from digitalhub_core.utils.exceptions import EntityError
7
+ from digitalhub_core.utils.generic_utils import encode_source, encode_string
8
+ from digitalhub_core.utils.uri_utils import map_uri_scheme
9
+
10
+
11
+ class SourceCodeStructPython(SourceCodeStruct):
12
+ """
13
+ Source code struct for python.
14
+ """
15
+
16
+ def __init__(
17
+ self,
18
+ source: str | None = None,
19
+ handler: str | None = None,
20
+ code: str | None = None,
21
+ base64: str | None = None,
22
+ lang: str | None = None,
23
+ init_function: str | None = None,
24
+ ) -> None:
25
+ super().__init__(
26
+ source=source,
27
+ handler=handler,
28
+ code=code,
29
+ base64=base64,
30
+ lang=lang,
31
+ )
32
+ self.init_function = init_function
33
+
34
+ @staticmethod
35
+ def source_check(source: dict) -> dict:
36
+ """
37
+ Check source. Overrides SourceCodeStruct.source_check.
38
+
39
+ Parameters
40
+ ----------
41
+ source : dict
42
+ Source.
43
+
44
+ Returns
45
+ -------
46
+ dict
47
+ Checked source.
48
+ """
49
+ # Source check
50
+ source_path = source.get("source")
51
+ code = source.get("code")
52
+ base64 = source.get("base64")
53
+ handler = source.get("handler")
54
+ source["lang"] = "python"
55
+
56
+ if handler is None:
57
+ raise EntityError("Handler must be provided.")
58
+
59
+ if source_path is None and code is None and base64 is None:
60
+ raise EntityError("Source must be provided.")
61
+
62
+ if base64 is not None:
63
+ return source
64
+
65
+ if code is not None:
66
+ source["base64"] = encode_string(code)
67
+ return source
68
+
69
+ if source_path is not None:
70
+ if map_uri_scheme(source_path) == "local":
71
+ if not (Path(source_path).suffix == ".py" and Path(source_path).is_file()):
72
+ raise EntityError("Source is not a valid python file.")
73
+ source["base64"] = encode_source(source_path)
74
+ else:
75
+ if handler is None:
76
+ raise EntityError("Handler must be provided if source is not local.")
77
+
78
+ return source
79
+
80
+ def to_dict(self) -> dict:
81
+ """
82
+ Convert to dictionary.
83
+
84
+ Returns
85
+ -------
86
+ dict
87
+ Dictionary representation of the object.
88
+ """
89
+ dict_ = super().to_dict()
90
+ if self.init_function is not None:
91
+ dict_["init_function"] = self.init_function
92
+ return dict_
93
+
94
+
95
+ class SourceCodeParamsPython(SourceCodeParams):
96
+ """
97
+ Source code params for python.
98
+ """
99
+
100
+ init_function: str = None
101
+ """Handler for init function."""
@@ -0,0 +1,108 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Literal
4
+
5
+ from digitalhub_core.entities.functions.spec import FunctionParams, FunctionSpec
6
+ from digitalhub_runtime_python.entities.functions.models import SourceCodeParamsPython, SourceCodeStructPython
7
+
8
+
9
+ class FunctionSpecPython(FunctionSpec):
10
+ """
11
+ Specification for a Function job.
12
+ """
13
+
14
+ def __init__(
15
+ self,
16
+ source: dict | None = None,
17
+ code_src: str | None = None,
18
+ handler: str | None = None,
19
+ code: str | None = None,
20
+ base64: str | None = None,
21
+ init_function: str | None = None,
22
+ lang: str | None = None,
23
+ image: str | None = None,
24
+ base_image: str | None = None,
25
+ python_version: str | None = None,
26
+ requirements: list | None = None,
27
+ ) -> None:
28
+ super().__init__()
29
+
30
+ self.image = image
31
+ self.base_image = base_image
32
+ self.python_version = python_version
33
+ self.requirements = requirements
34
+
35
+ # Give source precedence
36
+ if source is not None:
37
+ source_dict = source
38
+ else:
39
+ source_dict = {
40
+ "source": code_src,
41
+ "handler": handler,
42
+ "code": code,
43
+ "base64": base64,
44
+ "lang": lang,
45
+ "init_function": init_function,
46
+ }
47
+
48
+ source_checked = self.source_check(source_dict)
49
+ self.source = SourceCodeStructPython(**source_checked)
50
+
51
+ @staticmethod
52
+ def source_check(source: dict) -> dict:
53
+ """
54
+ Check source.
55
+
56
+ Parameters
57
+ ----------
58
+ source : dict
59
+ Source.
60
+
61
+ Returns
62
+ -------
63
+ dict
64
+ Checked source.
65
+ """
66
+ return SourceCodeStructPython.source_check(source)
67
+
68
+ def show_source_code(self) -> str:
69
+ """
70
+ Show source code.
71
+
72
+ Returns
73
+ -------
74
+ str
75
+ Source code.
76
+ """
77
+ return self.source.show_source_code()
78
+
79
+ def to_dict(self) -> dict:
80
+ """
81
+ Override to_dict to exclude code from source.
82
+
83
+ Returns
84
+ -------
85
+ dict
86
+ Dictionary representation of the object.
87
+ """
88
+ dict_ = super().to_dict()
89
+ dict_["source"] = self.source.to_dict()
90
+ return dict_
91
+
92
+
93
+ class FunctionParamsPython(FunctionParams, SourceCodeParamsPython):
94
+ """
95
+ Function python parameters model.
96
+ """
97
+
98
+ python_version: Literal["PYTHON3_9", "PYTHON3_10", "PYTHON3_11"]
99
+ "Python version"
100
+
101
+ image: str = None
102
+ "Image where the function will be executed"
103
+
104
+ base_image: str = None
105
+ "Base image used to build the image where the function will be executed"
106
+
107
+ requirements: list = None
108
+ "Requirements list to be installed in the image where the function will be executed"
@@ -33,9 +33,9 @@ def get_function_from_source(path: Path, source_spec: dict) -> Callable:
33
33
  Function.
34
34
  """
35
35
  try:
36
- function_code = save_function_source(path, source_spec)
36
+ source_path = save_function_source(path, source_spec)
37
37
  handler_path, function_name = parse_handler(source_spec["handler"])
38
- function_path = (function_code / handler_path).with_suffix(".py")
38
+ function_path = (source_path / handler_path).with_suffix(".py")
39
39
  return import_function(function_path, function_name)
40
40
  except Exception as e:
41
41
  msg = f"Some error occurred while getting function. Exception: {e.__class__}. Error: {e.args}"
@@ -43,35 +43,6 @@ def get_function_from_source(path: Path, source_spec: dict) -> Callable:
43
43
  raise RuntimeError(msg) from e
44
44
 
45
45
 
46
- def get_init_function(path: Path, source_spec: dict) -> Callable:
47
- """
48
- Get function from source.
49
-
50
- Parameters
51
- ----------
52
- path : Path
53
- Path where to save the function source.
54
- source_spec : dict
55
- Funcrion source spec.
56
-
57
- Returns
58
- -------
59
- Callable
60
- Function.
61
- """
62
- try:
63
- if "init_function" not in source_spec:
64
- return
65
- function_code = save_function_source(path, source_spec)
66
- handler_path, _ = parse_handler(source_spec["handler"])
67
- function_path = (function_code / handler_path).with_suffix(".py")
68
- return import_function(function_path, source_spec["init_function"])
69
- except Exception as e:
70
- msg = f"Some error occurred while getting init function. Exception: {e.__class__}. Error: {e.args}"
71
- LOGGER.exception(msg)
72
- raise RuntimeError(msg) from e
73
-
74
-
75
46
  def parse_handler(handler: str) -> tuple:
76
47
  """
77
48
  Parse handler.
@@ -203,7 +174,7 @@ def unzip(path: Path, filename: Path) -> None:
203
174
  raise RuntimeError(msg) from e
204
175
 
205
176
 
206
- def get_repository(path: Path, source: str) -> str:
177
+ def get_repository(path: Path, source: str) -> None:
207
178
  """
208
179
  Get repository.
209
180
 
@@ -219,7 +190,7 @@ def get_repository(path: Path, source: str) -> str:
219
190
  None
220
191
  """
221
192
  try:
222
- clone_repository(path, source)
193
+ clone_repository(source, path)
223
194
  except Exception as e:
224
195
  msg = f"Some error occurred while downloading function repo source. Exception: {e.__class__}. Error: {e.args}"
225
196
  LOGGER.exception(msg)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: digitalhub-runtime-python
3
- Version: 0.6.0b8
3
+ Version: 0.6.1
4
4
  Summary: Python runtime for DHCore
5
5
  Author-email: Fondazione Bruno Kessler <dslab@fbk.eu>, Matteo Martini <mmartini@fbk.eu>
6
6
  License: Apache License
@@ -9,6 +9,7 @@ digitalhub_runtime_python.egg-info/requires.txt
9
9
  digitalhub_runtime_python.egg-info/top_level.txt
10
10
  digitalhub_runtime_python/entities/__init__.py
11
11
  digitalhub_runtime_python/entities/functions/__init__.py
12
+ digitalhub_runtime_python/entities/functions/models.py
12
13
  digitalhub_runtime_python/entities/functions/spec.py
13
14
  digitalhub_runtime_python/entities/functions/status.py
14
15
  digitalhub_runtime_python/entities/runs/__init__.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "digitalhub-runtime-python"
7
- version = "0.6.0b8"
7
+ version = "0.6.1"
8
8
  description = "Python runtime for DHCore"
9
9
  readme = "README.md"
10
10
  authors = [
@@ -39,7 +39,7 @@ line-length = 120
39
39
  convention = "numpy"
40
40
 
41
41
  [tool.bumpver]
42
- current_version = "0.6.0b8"
42
+ current_version = "0.6.1"
43
43
  version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
44
44
  commit_message = "Bump version {old_version} -> {new_version}"
45
45
  commit = false
@@ -1,239 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pathlib import Path
4
- from typing import Literal
5
-
6
- from digitalhub_core.entities.functions.spec import FunctionParams, FunctionSpec
7
- from digitalhub_core.utils.exceptions import EntityError
8
- from digitalhub_core.utils.generic_utils import decode_string, encode_source, encode_string
9
- from digitalhub_core.utils.uri_utils import map_uri_scheme
10
-
11
-
12
- class FunctionSpecPython(FunctionSpec):
13
- """
14
- Specification for a Function job.
15
- """
16
-
17
- def __init__(
18
- self,
19
- source: str | dict | None = None,
20
- code_src: str | None = None,
21
- handler: str | None = None,
22
- code: str | None = None,
23
- base64: str | None = None,
24
- init_function: str | None = None,
25
- lang: str | None = None,
26
- image: str | None = None,
27
- base_image: str | None = None,
28
- python_version: str | None = None,
29
- requirements: list | None = None,
30
- ) -> None:
31
- super().__init__()
32
-
33
- self.image = image
34
- self.base_image = base_image
35
- self.python_version = python_version
36
- self.requirements = requirements
37
-
38
- # Give source precedence
39
- if source is not None:
40
- source_dict = source
41
- else:
42
- source_dict = {
43
- "source": code_src,
44
- "handler": handler,
45
- "code": code,
46
- "base64": base64,
47
- "init_function": init_function,
48
- "lang": lang,
49
- }
50
-
51
- source_checked = self._source_check(source_dict)
52
- self.source = SourceCodeStruct(**source_checked)
53
-
54
- @staticmethod
55
- def _source_check(source: dict) -> dict:
56
- """
57
- Check source.
58
-
59
- Parameters
60
- ----------
61
- source : dict
62
- Source.
63
-
64
- Returns
65
- -------
66
- dict
67
- Checked source.
68
- """
69
- # Source check
70
- source_path = source.get("source")
71
- code = source.get("code")
72
- base64 = source.get("base64")
73
- handler = source.get("handler")
74
- source["lang"] = "python"
75
-
76
- if handler is None:
77
- raise EntityError("Handler must be provided.")
78
-
79
- if source_path is None and code is None and base64 is None:
80
- raise EntityError("Source must be provided.")
81
-
82
- if base64 is not None:
83
- return source
84
-
85
- if code is not None:
86
- source["base64"] = encode_string(code)
87
- return source
88
-
89
- if source_path is not None:
90
- if map_uri_scheme(source_path) == "local":
91
- if not (Path(source_path).suffix == ".py" and Path(source_path).is_file()):
92
- raise EntityError("Source is not a valid python file.")
93
- source["base64"] = encode_source(source_path)
94
- else:
95
- if handler is None:
96
- raise EntityError("Handler must be provided if source is not local.")
97
-
98
- return source
99
-
100
- def show_source_code(self) -> str:
101
- """
102
- Show source code.
103
-
104
- Returns
105
- -------
106
- str
107
- Source code.
108
- """
109
- if self.source.code is not None:
110
- return str(self.source.code)
111
- if self.source.base64 is not None:
112
- try:
113
- return decode_string(self.source.base64)
114
- except Exception:
115
- raise EntityError("Something got wrong during source code decoding.")
116
- if (self.source.source is not None) and (map_uri_scheme(self.source.source) == "local"):
117
- try:
118
- return Path(self.source.source).read_text()
119
- except Exception:
120
- raise EntityError("Cannot access source code.")
121
- return ""
122
-
123
- def to_dict(self) -> dict:
124
- """
125
- Override to_dict to exclude code from source.
126
-
127
- Returns
128
- -------
129
- dict
130
- Dictionary representation of the object.
131
- """
132
- dict_ = super().to_dict()
133
- dict_["source"] = self.source.to_dict()
134
- return dict_
135
-
136
-
137
- class FunctionParamsPython(FunctionParams):
138
- """
139
- Function python parameters model.
140
- """
141
-
142
- source: dict = None
143
- "Source code details as dictionary"
144
-
145
- code_src: str = None
146
- "Pointer to source code"
147
-
148
- handler: str = None
149
- "Function entrypoint"
150
-
151
- code: str = None
152
- "Source code (plain text)"
153
-
154
- base64: str = None
155
- "Source code (base64 encoded)"
156
-
157
- init_function: str = None
158
- "Init function for remote nuclio execution"
159
-
160
- lang: str = None
161
- "Source code language (hint)"
162
-
163
- python_version: Literal["PYTHON3_9", "PYTHON3_10", "PYTHON3_11"]
164
- "Python version"
165
-
166
- image: str = None
167
- "Image where the function will be executed"
168
-
169
- base_image: str = None
170
- "Base image used to build the image where the function will be executed"
171
-
172
- requirements: list = None
173
- "Requirements list to be installed in the image where the function will be executed"
174
-
175
-
176
- class SourceCodeStruct:
177
- """
178
- Source code struct.
179
- """
180
-
181
- def __init__(
182
- self,
183
- source: str | None = None,
184
- handler: str | None = None,
185
- code: str | None = None,
186
- base64: str | None = None,
187
- init_function: str | None = None,
188
- lang: str | None = None,
189
- ) -> None:
190
- """
191
- Constructor.
192
-
193
- Parameters
194
- ----------
195
- source : str
196
- Source reference.
197
- handler : str
198
- Function entrypoint.
199
- code : str
200
- Source code (plain).
201
- base64 : str
202
- Source code (base64 encoded).
203
- init_function : str
204
- Init function for remote execution.
205
- lang : str
206
- Source code language (hint).
207
- """
208
- self.source = source
209
- self.handler = handler
210
- self.code = code
211
- self.base64 = base64
212
- self.init_function = init_function
213
- self.lang = lang
214
-
215
- def to_dict(self) -> dict:
216
- """
217
- Convert to dictionary.
218
-
219
- Returns
220
- -------
221
- dict
222
- Dictionary representation of the object.
223
- """
224
- dict_ = {}
225
- if self.source is not None:
226
- dict_["source"] = self.source
227
- if self.handler is not None:
228
- dict_["handler"] = self.handler
229
- if self.base64 is not None:
230
- dict_["base64"] = self.base64
231
- if self.init_function is not None:
232
- dict_["init_function"] = self.init_function
233
- if self.lang is not None:
234
- dict_["lang"] = self.lang
235
-
236
- return dict_
237
-
238
- def __repr__(self) -> str:
239
- return str(self.to_dict())