digitalhub-runtime-python 0.5.0b6__tar.gz → 0.5.0b8__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 (31) hide show
  1. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/PKG-INFO +1 -1
  2. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/runtimes/runtime.py +4 -15
  3. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/utils/configuration.py +48 -18
  4. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/utils/inputs.py +10 -14
  5. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/utils/outputs.py +12 -25
  6. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python.egg-info/PKG-INFO +1 -1
  7. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/pyproject.toml +2 -2
  8. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/LICENSE.txt +0 -0
  9. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/README.md +0 -0
  10. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/__init__.py +0 -0
  11. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/__init__.py +0 -0
  12. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/functions/__init__.py +0 -0
  13. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/functions/metadata.py +0 -0
  14. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/functions/spec.py +0 -0
  15. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/functions/status.py +0 -0
  16. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/runs/__init__.py +0 -0
  17. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/runs/metadata.py +0 -0
  18. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/runs/spec.py +0 -0
  19. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/runs/status.py +0 -0
  20. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/tasks/__init__.py +0 -0
  21. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/tasks/metadata.py +0 -0
  22. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/tasks/models.py +0 -0
  23. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/tasks/spec.py +0 -0
  24. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/entities/tasks/status.py +0 -0
  25. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/runtimes/__init__.py +0 -0
  26. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python/utils/utils.py +0 -0
  27. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python.egg-info/SOURCES.txt +0 -0
  28. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python.egg-info/dependency_links.txt +0 -0
  29. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python.egg-info/requires.txt +0 -0
  30. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/digitalhub_runtime_python.egg-info/top_level.txt +0 -0
  31. {digitalhub_runtime_python-0.5.0b6 → digitalhub_runtime_python-0.5.0b8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: digitalhub-runtime-python
3
- Version: 0.5.0b6
3
+ Version: 0.5.0b8
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,7 +9,6 @@ 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
13
  from digitalhub_runtime_python.utils.outputs import build_status, parse_outputs
15
14
 
@@ -81,16 +80,9 @@ class RuntimePython(Runtime):
81
80
  else:
82
81
  exec_result = self._execute(fnc, **fnc_args)
83
82
  LOGGER.info("Collecting outputs.")
84
- results = parse_outputs(exec_result,
85
- list(spec.get("outputs", {})),
86
- list(spec.get("values", [])),
87
- project)
88
-
89
- status = build_status(
90
- results,
91
- spec.get("outputs"),
92
- spec.get("values"),
93
- )
83
+ results = parse_outputs(exec_result, list(spec.get("outputs", {})), project)
84
+
85
+ status = build_status(results, spec.get("outputs"))
94
86
 
95
87
  # Return run status
96
88
  LOGGER.info("Task completed, returning run status.")
@@ -111,8 +103,6 @@ class RuntimePython(Runtime):
111
103
  Callable
112
104
  Function to execute.
113
105
  """
114
- if action == "job":
115
- return run_python
116
106
  raise NotImplementedError
117
107
 
118
108
  ####################
@@ -165,5 +155,4 @@ class RuntimePython(Runtime):
165
155
  self.root_path,
166
156
  spec.get("source", {}),
167
157
  )
168
- return fnc, hasattr(fnc, '__wrapped__')
169
-
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:
@@ -13,18 +13,17 @@ from digitalhub_ml.entities.models.crud import model_from_dict
13
13
  if typing.TYPE_CHECKING:
14
14
  from digitalhub_core.entities._base.entity import Entity
15
15
  from digitalhub_core.entities.artifacts.entity import Artifact
16
- from digitalhub_data.entities.dataitems.entity._base import Dataitem
16
+ from digitalhub_data.entities.dataitems.entity.table import DataitemTable
17
17
  from digitalhub_ml.entities.models.entity import Model
18
- from pandas import DataFrame
19
18
 
20
19
 
21
- def persist_dataitem(dataitem: Dataitem, tmp_dir: Path) -> str:
20
+ def persist_dataitem(dataitem: DataitemTable, tmp_dir: Path) -> str:
22
21
  """
23
22
  Persist dataitem locally.
24
23
 
25
24
  Parameters
26
25
  ----------
27
- dataitem : Dataitem
26
+ dataitem : DataitemTable
28
27
  The dataitem to persist.
29
28
  tmp_dir : Path
30
29
  Temporary download directory.
@@ -42,10 +41,9 @@ def persist_dataitem(dataitem: Dataitem, tmp_dir: Path) -> str:
42
41
  name = dataitem.name
43
42
  try:
44
43
  LOGGER.info(f"Persisting dataitem '{name}' locally.")
45
- tmp_path = tmp_dir / f"{name}.csv"
46
- dataframe: DataFrame = dataitem.as_df()
47
- dataframe.to_csv(tmp_path, sep=",", index=False)
48
- return str(tmp_path)
44
+ tmp_path = str(tmp_dir / f"{name}.csv")
45
+ dataitem.write_df(target_path=tmp_path, extension="csv", sep=",")
46
+ return tmp_path
49
47
  except Exception as e:
50
48
  msg = f"Error during dataitem '{name}' collection. Exception: {e.__class__}. Error: {e.args}"
51
49
  LOGGER.exception(msg)
@@ -77,9 +75,8 @@ def persist_artifact(artifact: Artifact, tmp_dir: Path) -> str:
77
75
  try:
78
76
  LOGGER.info(f"Persisting artifact '{name}' locally.")
79
77
  filename = Path(artifact.spec.path).name
80
- dst = tmp_dir / filename
81
- tmp_path = artifact.download(dst=dst)
82
- return str(tmp_path)
78
+ dst = str(tmp_dir / filename)
79
+ return artifact.download(dst=dst)
83
80
  except Exception as e:
84
81
  msg = f"Error during artifact '{name}' collection. Exception: {e.__class__}. Error: {e.args}"
85
82
  LOGGER.exception(msg)
@@ -111,9 +108,8 @@ def persist_model(model: Model, tmp_dir: Path) -> str:
111
108
  try:
112
109
  LOGGER.info(f"Persisting model '{name}' locally.")
113
110
  filename = Path(model.spec.path).name
114
- dst = tmp_dir / filename
115
- tmp_path = model.download(dst=dst)
116
- return str(tmp_path)
111
+ dst = str(tmp_dir / filename)
112
+ return model.download(dst=dst)
117
113
  except Exception as e:
118
114
  msg = f"Error during model '{name}' collection. Exception: {e.__class__}. Error: {e.args}"
119
115
  LOGGER.exception(msg)
@@ -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,7 +49,7 @@ def collect_outputs(results: Any, outputs: list[str], project_name: str) -> dict
52
49
  return objects
53
50
 
54
51
 
55
- def parse_outputs(results: Any, run_outputs: list, run_values: list, project_name: str) -> dict:
52
+ def parse_outputs(results: Any, run_outputs: list, project_name: str) -> dict:
56
53
  """
57
54
  Parse outputs.
58
55
 
@@ -70,16 +67,14 @@ def parse_outputs(results: Any, run_outputs: list, run_values: list, project_nam
70
67
  """
71
68
  results_list = listify_results(results)
72
69
  out_list = []
73
- for idx, item in enumerate(results_list):
70
+ for idx, _ in enumerate(results_list):
74
71
  try:
75
- if isinstance(item, (str, int, float, bool, bytes)):
76
- out_list.append(run_values.pop(0))
77
- else:
78
- out_list.append(run_outputs.pop(0))
72
+ out_list.append(run_outputs.pop(0))
79
73
  except IndexError:
80
74
  out_list.append(f"output_{idx}")
81
75
  return collect_outputs(results, out_list, project_name)
82
76
 
77
+
83
78
  def listify_results(results: Any) -> list:
84
79
  """
85
80
  Listify results.
@@ -170,7 +165,6 @@ def build_and_load_artifact(name: str, project_name: str, data: Any) -> Artifact
170
165
  def build_status(
171
166
  parsed_execution: dict,
172
167
  mapped_outputs: dict | None = None,
173
- values_list: list | None = None,
174
168
  ) -> dict:
175
169
  """
176
170
  Collect outputs.
@@ -181,31 +175,24 @@ def build_status(
181
175
  Parsed execution dict.
182
176
  mapped_outputs : dict
183
177
  Mapped outputs.
184
- values_list : list
185
- Values list.
186
178
 
187
179
  Returns
188
180
  -------
189
181
  dict
190
182
  Status dict.
191
183
  """
184
+ results = {}
192
185
  outputs = {}
193
186
  if mapped_outputs is None:
194
187
  mapped_outputs = {}
195
188
 
196
- results = {}
197
- if values_list is None:
198
- values_list = []
199
-
200
189
  try:
201
- for key, value in mapped_outputs.items():
190
+ for key, _ in mapped_outputs.items():
202
191
  if key in parsed_execution:
203
- outputs[key] = parsed_execution[key].key
204
-
205
- for value in values_list:
206
- if value in parsed_execution:
207
- results[value] = parsed_execution[value]
208
-
192
+ if isinstance(parsed_execution[key], (DataitemTable, Artifact)):
193
+ outputs[key] = parsed_execution[key].key
194
+ else:
195
+ results[key] = parsed_execution[key]
209
196
  return {
210
197
  "state": State.COMPLETED.value,
211
198
  "outputs": outputs,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: digitalhub-runtime-python
3
- Version: 0.5.0b6
3
+ Version: 0.5.0b8
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "digitalhub-runtime-python"
7
- version = "0.5.0b6"
7
+ version = "0.5.0b8"
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.0b6"
42
+ current_version = "0.5.0b8"
43
43
  version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
44
44
  commit_message = "Bump version {old_version} -> {new_version}"
45
45
  commit = false