digitalhub-runtime-python 0.5.0b5__tar.gz → 0.5.0b7__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 (32) hide show
  1. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/PKG-INFO +1 -1
  2. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/runtimes/runtime.py +13 -16
  3. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/utils/configuration.py +48 -18
  4. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/utils/outputs.py +34 -19
  5. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python.egg-info/PKG-INFO +1 -1
  6. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python.egg-info/SOURCES.txt +0 -1
  7. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/pyproject.toml +2 -2
  8. digitalhub_runtime_python-0.5.0b5/digitalhub_runtime_python/utils/functions.py +0 -24
  9. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/LICENSE.txt +0 -0
  10. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/README.md +0 -0
  11. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/__init__.py +0 -0
  12. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/__init__.py +0 -0
  13. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/functions/__init__.py +0 -0
  14. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/functions/metadata.py +0 -0
  15. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/functions/spec.py +0 -0
  16. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/functions/status.py +0 -0
  17. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/runs/__init__.py +0 -0
  18. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/runs/metadata.py +0 -0
  19. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/runs/spec.py +0 -0
  20. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/runs/status.py +0 -0
  21. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/tasks/__init__.py +0 -0
  22. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/tasks/metadata.py +0 -0
  23. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/tasks/models.py +0 -0
  24. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/tasks/spec.py +0 -0
  25. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/entities/tasks/status.py +0 -0
  26. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/runtimes/__init__.py +0 -0
  27. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/utils/inputs.py +0 -0
  28. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python/utils/utils.py +0 -0
  29. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python.egg-info/dependency_links.txt +0 -0
  30. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python.egg-info/requires.txt +0 -0
  31. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/digitalhub_runtime_python.egg-info/top_level.txt +0 -0
  32. {digitalhub_runtime_python-0.5.0b5 → digitalhub_runtime_python-0.5.0b7}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: digitalhub-runtime-python
3
- Version: 0.5.0b5
3
+ Version: 0.5.0b7
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,9 +9,8 @@ from typing import Callable
9
9
  from digitalhub_core.runtimes.base import Runtime
10
10
  from digitalhub_core.utils.logger import LOGGER
11
11
  from digitalhub_runtime_python.utils.configuration import get_function_from_source
12
- from digitalhub_runtime_python.utils.functions import run_python
13
12
  from digitalhub_runtime_python.utils.inputs import get_inputs_parameters
14
- from digitalhub_runtime_python.utils.outputs import build_status
13
+ from digitalhub_runtime_python.utils.outputs import build_status, parse_outputs
15
14
 
16
15
 
17
16
  class RuntimePython(Runtime):
@@ -63,8 +62,7 @@ class RuntimePython(Runtime):
63
62
  Status of the executed run.
64
63
  """
65
64
  LOGGER.info("Validating task.")
66
- action = self._validate_task(run)
67
- executable = self._get_executable(action)
65
+ self._validate_task(run)
68
66
 
69
67
  LOGGER.info("Starting task.")
70
68
  spec = run.get("spec")
@@ -74,17 +72,17 @@ class RuntimePython(Runtime):
74
72
  fnc_args = self._collect_inputs(spec)
75
73
 
76
74
  LOGGER.info("Configuring execution.")
77
- fnc = self._configure_execution(spec)
75
+ fnc, wrapped = self._configure_execution(spec)
78
76
 
79
77
  LOGGER.info("Executing run.")
80
- results = self._execute(executable, fnc, project, **fnc_args)
78
+ if wrapped:
79
+ results: dict = self._execute(fnc, project, **fnc_args)
80
+ else:
81
+ exec_result = self._execute(fnc, **fnc_args)
82
+ LOGGER.info("Collecting outputs.")
83
+ results = parse_outputs(exec_result, list(spec.get("outputs", {})), project)
81
84
 
82
- LOGGER.info("Collecting outputs.")
83
- status = build_status(
84
- results,
85
- spec.get("outputs", {}),
86
- spec.get("values", {}),
87
- )
85
+ status = build_status(results, spec.get("outputs"))
88
86
 
89
87
  # Return run status
90
88
  LOGGER.info("Task completed, returning run status.")
@@ -105,8 +103,6 @@ class RuntimePython(Runtime):
105
103
  Callable
106
104
  Function to execute.
107
105
  """
108
- if action == "job":
109
- return run_python
110
106
  raise NotImplementedError
111
107
 
112
108
  ####################
@@ -141,7 +137,7 @@ class RuntimePython(Runtime):
141
137
  # Configuration
142
138
  ####################
143
139
 
144
- def _configure_execution(self, spec: dict) -> Callable:
140
+ def _configure_execution(self, spec: dict) -> tuple[Callable, bool]:
145
141
  """
146
142
  Configure execution.
147
143
 
@@ -155,7 +151,8 @@ class RuntimePython(Runtime):
155
151
  Callable
156
152
  Function to execute.
157
153
  """
158
- return get_function_from_source(
154
+ fnc = get_function_from_source(
159
155
  self.root_path,
160
156
  spec.get("source", {}),
161
157
  )
158
+ return fnc, hasattr(fnc, "__wrapped__")
@@ -13,6 +13,7 @@ from digitalhub_core.utils.generic_utils import (
13
13
  )
14
14
  from digitalhub_core.utils.git_utils import clone_repository
15
15
  from digitalhub_core.utils.logger import LOGGER
16
+ from digitalhub_core.utils.uri_utils import map_uri_scheme
16
17
 
17
18
 
18
19
  def get_function_from_source(path: Path, source_spec: dict) -> Callable:
@@ -33,14 +34,35 @@ def get_function_from_source(path: Path, source_spec: dict) -> Callable:
33
34
  """
34
35
  try:
35
36
  function_code = save_function_source(path, source_spec)
36
- handler = source_spec["handler"]
37
- return import_function(function_code, handler)
37
+ handler_path, function_name = parse_handler(source_spec["handler"])
38
+ function_path = (function_code / handler_path).with_suffix(".py")
39
+ return import_function(function_path, function_name)
38
40
  except Exception as e:
39
41
  msg = f"Some error occurred while getting function. Exception: {e.__class__}. Error: {e.args}"
40
42
  LOGGER.exception(msg)
41
43
  raise RuntimeError(msg) from e
42
44
 
43
45
 
46
+ def parse_handler(handler: str) -> tuple:
47
+ """
48
+ Parse handler.
49
+
50
+ Parameters
51
+ ----------
52
+ handler : str
53
+ Function handler
54
+
55
+ Returns
56
+ -------
57
+ str
58
+ Function handler.
59
+ """
60
+ parsed = handler.split(":")
61
+ if len(parsed) == 1:
62
+ return Path(""), parsed[0]
63
+ return Path(*parsed[0].split(".")), parsed[1]
64
+
65
+
44
66
  def save_function_source(path: Path, source_spec: dict) -> Path:
45
67
  """
46
68
  Save function source.
@@ -63,38 +85,46 @@ def save_function_source(path: Path, source_spec: dict) -> Path:
63
85
  # Get relevant information
64
86
  base64 = source_spec.get("base64")
65
87
  source = source_spec.get("source")
66
- handler = source_spec.get("handler")
67
88
 
89
+ scheme = None
90
+ if source is not None:
91
+ scheme = map_uri_scheme(source)
92
+
93
+ # Base64
68
94
  if base64 is not None:
69
- path = path / "main.py"
70
- path.write_text(decode_base64(base64))
71
- return path
72
95
 
73
- scheme = source.split("://")[0]
96
+ filename = "main.py"
97
+ if scheme == "local":
98
+ filename = Path(source).name
99
+
100
+ base64_path = path / filename
101
+ base64_path.write_text(decode_base64(base64))
102
+
103
+ if scheme is None or scheme == "local":
104
+ return base64_path
105
+
106
+ # Git repo
107
+ if scheme == "git":
108
+ get_repository(path, source)
74
109
 
75
110
  # Http(s) or s3 presigned urls
76
- if scheme in ["http", "https"]:
111
+ elif scheme == "remote":
77
112
  filename = path / "archive.zip"
78
113
  get_remote_source(source, filename)
79
114
  unzip(path, filename)
80
- return path / handler
81
-
82
- # Git repo
83
- if scheme == "git+https":
84
- path = path / "repository"
85
- get_repository(path, source)
86
- return path / handler
87
115
 
88
116
  # S3 path
89
- if scheme == "zip+s3":
117
+ elif scheme == "s3":
90
118
  filename = path / "archive.zip"
91
119
  bucket, key = get_bucket_and_key(source)
92
120
  get_s3_source(bucket, key, filename)
93
121
  unzip(path, filename)
94
- return path / handler
95
122
 
96
123
  # Unsupported scheme
97
- raise RuntimeError(f"Unsupported scheme: {scheme}")
124
+ else:
125
+ raise RuntimeError(f"Unsupported scheme: {scheme}")
126
+
127
+ return path
98
128
 
99
129
 
100
130
  def get_remote_source(source: str, filename: Path) -> None:
@@ -1,19 +1,16 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import pickle
4
- import typing
5
4
  from typing import Any
6
5
 
7
6
  from digitalhub_core.entities._base.status import State
8
7
  from digitalhub_core.entities.artifacts.crud import new_artifact
8
+ from digitalhub_core.entities.artifacts.entity import Artifact
9
9
  from digitalhub_core.utils.logger import LOGGER
10
10
  from digitalhub_data.entities.dataitems.crud import new_dataitem
11
+ from digitalhub_data.entities.dataitems.entity.table import DataitemTable
11
12
  from digitalhub_data.readers.registry import DATAFRAME_TYPES
12
13
 
13
- if typing.TYPE_CHECKING:
14
- from digitalhub_core.entities.artifacts.entity import Artifact
15
- from digitalhub_data.entities.dataitems.entity.table import DataitemTable
16
-
17
14
 
18
15
  def collect_outputs(results: Any, outputs: list[str], project_name: str) -> dict:
19
16
  """
@@ -52,6 +49,32 @@ def collect_outputs(results: Any, outputs: list[str], project_name: str) -> dict
52
49
  return objects
53
50
 
54
51
 
52
+ def parse_outputs(results: Any, run_outputs: list, project_name: str) -> dict:
53
+ """
54
+ Parse outputs.
55
+
56
+ Parameters
57
+ ----------
58
+ results : Any
59
+ Function outputs.
60
+ project : Project
61
+ Project object.
62
+
63
+ Returns
64
+ -------
65
+ dict
66
+ Function outputs.
67
+ """
68
+ results_list = listify_results(results)
69
+ out_list = []
70
+ for idx, _ in enumerate(results_list):
71
+ try:
72
+ out_list.append(run_outputs.pop(0))
73
+ except IndexError:
74
+ out_list.append(f"output_{idx}")
75
+ return collect_outputs(results, out_list, project_name)
76
+
77
+
55
78
  def listify_results(results: Any) -> list:
56
79
  """
57
80
  Listify results.
@@ -142,7 +165,6 @@ def build_and_load_artifact(name: str, project_name: str, data: Any) -> Artifact
142
165
  def build_status(
143
166
  parsed_execution: dict,
144
167
  mapped_outputs: dict | None = None,
145
- values_list: list | None = None,
146
168
  ) -> dict:
147
169
  """
148
170
  Collect outputs.
@@ -153,31 +175,24 @@ def build_status(
153
175
  Parsed execution dict.
154
176
  mapped_outputs : dict
155
177
  Mapped outputs.
156
- values_list : list
157
- Values list.
158
178
 
159
179
  Returns
160
180
  -------
161
181
  dict
162
182
  Status dict.
163
183
  """
184
+ results = {}
164
185
  outputs = {}
165
186
  if mapped_outputs is None:
166
187
  mapped_outputs = {}
167
188
 
168
- results = {}
169
- if values_list is None:
170
- values_list = []
171
-
172
189
  try:
173
- for key, value in mapped_outputs.items():
190
+ for key, _ in mapped_outputs.items():
174
191
  if key in parsed_execution:
175
- outputs[key] = parsed_execution[key].key
176
-
177
- for value in values_list:
178
- if value in parsed_execution:
179
- results[value] = parsed_execution[value]
180
-
192
+ if isinstance(parsed_execution[key], (DataitemTable, Artifact)):
193
+ outputs[key] = parsed_execution[key].key
194
+ else:
195
+ results[key] = parsed_execution[key]
181
196
  return {
182
197
  "state": State.COMPLETED.value,
183
198
  "outputs": outputs,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: digitalhub-runtime-python
3
- Version: 0.5.0b5
3
+ Version: 0.5.0b7
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
@@ -24,7 +24,6 @@ digitalhub_runtime_python/entities/tasks/status.py
24
24
  digitalhub_runtime_python/runtimes/__init__.py
25
25
  digitalhub_runtime_python/runtimes/runtime.py
26
26
  digitalhub_runtime_python/utils/configuration.py
27
- digitalhub_runtime_python/utils/functions.py
28
27
  digitalhub_runtime_python/utils/inputs.py
29
28
  digitalhub_runtime_python/utils/outputs.py
30
29
  digitalhub_runtime_python/utils/utils.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "digitalhub-runtime-python"
7
- version = "0.5.0b5"
7
+ version = "0.5.0b7"
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.5.0b5"
42
+ current_version = "0.5.0b7"
43
43
  version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
44
44
  commit_message = "Bump version {old_version} -> {new_version}"
45
45
  commit = false
@@ -1,24 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import Callable
4
-
5
-
6
- def run_python(func: Callable, *args, **kwargs) -> dict:
7
- """
8
- Execute function.
9
-
10
- Parameters
11
- ----------
12
- func : Callable
13
- Function.
14
- args : tuple
15
- Function arguments.
16
- kwargs : dict
17
- Function keyword arguments.
18
-
19
- Returns
20
- -------
21
- dict
22
- Outputs from the function.
23
- """
24
- return func(*args, **kwargs)