digitalhub-runtime-python 0.9.0b1__tar.gz → 0.10.0b0__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.
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/LICENSE.txt +1 -1
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/PKG-INFO +4 -4
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/function/python/utils.py +3 -3
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/run/python_run/status.py +2 -1
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/runtimes/runtime.py +2 -2
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/utils/configuration.py +95 -68
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/utils/inputs.py +43 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python.egg-info/PKG-INFO +4 -4
- digitalhub_runtime_python-0.10.0b0/digitalhub_runtime_python.egg-info/requires.txt +1 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/pyproject.toml +3 -3
- digitalhub_runtime_python-0.9.0b1/digitalhub_runtime_python.egg-info/requires.txt +0 -1
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/README.md +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/_base/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/_base/runtime_entity/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/_base/runtime_entity/builder.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/_commons/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/_commons/enums.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/function/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/function/python/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/function/python/builder.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/function/python/entity.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/function/python/models.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/function/python/spec.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/function/python/status.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/run/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/run/python_run/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/run/python_run/builder.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/run/python_run/entity.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/run/python_run/spec.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/run/python_run/utils.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_build/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_build/builder.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_build/entity.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_build/spec.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_build/status.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_job/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_job/builder.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_job/entity.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_job/models.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_job/spec.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_job/status.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_serve/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_serve/builder.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_serve/entity.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_serve/spec.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/entities/task/python_serve/status.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/runtimes/__init__.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/runtimes/builder.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/utils/env.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/utils/outputs.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python/utils/utils.py +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python.egg-info/SOURCES.txt +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python.egg-info/dependency_links.txt +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/digitalhub_runtime_python.egg-info/top_level.txt +0 -0
- {digitalhub_runtime_python-0.9.0b1 → digitalhub_runtime_python-0.10.0b0}/setup.cfg +0 -0
|
@@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2024 DSLab, Fondazione Bruno Kessler
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: digitalhub-runtime-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0b0
|
|
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
|
|
@@ -191,7 +191,7 @@ License: Apache License
|
|
|
191
191
|
same "printed page" as the copyright notice for easier
|
|
192
192
|
identification within third-party archives.
|
|
193
193
|
|
|
194
|
-
Copyright
|
|
194
|
+
Copyright 2024 DSLab, Fondazione Bruno Kessler
|
|
195
195
|
|
|
196
196
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
197
|
you may not use this file except in compliance with the License.
|
|
@@ -229,6 +229,6 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
229
229
|
Requires-Python: >=3.9
|
|
230
230
|
Description-Content-Type: text/markdown
|
|
231
231
|
License-File: LICENSE.txt
|
|
232
|
-
Requires-Dist: digitalhub[full]<0.
|
|
232
|
+
Requires-Dist: digitalhub[full]<0.11,>=0.10.0b
|
|
233
233
|
|
|
234
234
|
# SDK for DHCore
|
|
@@ -4,10 +4,10 @@ import typing
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
|
|
6
6
|
from digitalhub.stores.api import get_store
|
|
7
|
+
from digitalhub.stores.s3.utils import get_s3_bucket_from_env
|
|
7
8
|
from digitalhub.utils.exceptions import EntityError
|
|
8
9
|
from digitalhub.utils.file_utils import eval_py_type, eval_zip_type
|
|
9
10
|
from digitalhub.utils.generic_utils import encode_source, encode_string
|
|
10
|
-
from digitalhub.utils.s3_utils import get_s3_bucket
|
|
11
11
|
from digitalhub.utils.uri_utils import has_local_scheme
|
|
12
12
|
|
|
13
13
|
from digitalhub_runtime_python.entities.function.python.models import Lang
|
|
@@ -143,8 +143,8 @@ def source_post_check(exec: FunctionPython) -> FunctionPython:
|
|
|
143
143
|
# Check zip
|
|
144
144
|
elif eval_zip_type(code_src):
|
|
145
145
|
filename = Path(code_src).name
|
|
146
|
-
dst = f"zip+s3://{
|
|
147
|
-
get_store(dst).upload(code_src, dst)
|
|
146
|
+
dst = f"zip+s3://{get_s3_bucket_from_env()}/{exec.project}/{exec.ENTITY_TYPE}/{exec.name}/{exec.id}/{filename}"
|
|
147
|
+
get_store(exec.project, dst).upload(code_src, dst)
|
|
148
148
|
exec.spec.source["source"] = dst
|
|
149
149
|
if ":" not in exec.spec.source["handler"]:
|
|
150
150
|
exec.spec.source["handler"] = f"{Path(code_src).stem}:{exec.spec.source['handler']}"
|
|
@@ -14,12 +14,13 @@ class RunStatusPythonRun(RunStatus):
|
|
|
14
14
|
message: str | None = None,
|
|
15
15
|
transitions: list[dict] | None = None,
|
|
16
16
|
k8s: dict | None = None,
|
|
17
|
+
metrics: dict[str, list] | None = None,
|
|
17
18
|
outputs: dict | None = None,
|
|
18
19
|
results: dict | None = None,
|
|
19
20
|
service: dict | None = None,
|
|
20
21
|
**kwargs,
|
|
21
22
|
) -> None:
|
|
22
|
-
super().__init__(state, message, transitions, k8s, **kwargs)
|
|
23
|
+
super().__init__(state, message, transitions, k8s, metrics, **kwargs)
|
|
23
24
|
self.outputs = outputs
|
|
24
25
|
self.results = results
|
|
25
26
|
self.service = service
|
|
@@ -7,7 +7,7 @@ from digitalhub.runtimes._base import Runtime
|
|
|
7
7
|
from digitalhub.utils.logger import LOGGER
|
|
8
8
|
|
|
9
9
|
from digitalhub_runtime_python.entities._commons.enums import EntityKinds
|
|
10
|
-
from digitalhub_runtime_python.utils.configuration import
|
|
10
|
+
from digitalhub_runtime_python.utils.configuration import import_function_from_source
|
|
11
11
|
from digitalhub_runtime_python.utils.inputs import compose_inputs
|
|
12
12
|
from digitalhub_runtime_python.utils.outputs import build_status, parse_outputs
|
|
13
13
|
|
|
@@ -125,7 +125,7 @@ class RuntimePython(Runtime):
|
|
|
125
125
|
Callable
|
|
126
126
|
Function to execute.
|
|
127
127
|
"""
|
|
128
|
-
fnc =
|
|
128
|
+
fnc = import_function_from_source(
|
|
129
129
|
self.runtime_dir,
|
|
130
130
|
spec.get("source", {}),
|
|
131
131
|
)
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
from typing import Callable, Union
|
|
5
5
|
|
|
6
|
+
from digitalhub.stores.s3.utils import get_bucket_and_key, get_s3_source
|
|
6
7
|
from digitalhub.utils.generic_utils import (
|
|
7
8
|
decode_base64_string,
|
|
8
9
|
extract_archive,
|
|
@@ -11,11 +12,17 @@ from digitalhub.utils.generic_utils import (
|
|
|
11
12
|
)
|
|
12
13
|
from digitalhub.utils.git_utils import clone_repository
|
|
13
14
|
from digitalhub.utils.logger import LOGGER
|
|
14
|
-
from digitalhub.utils.
|
|
15
|
-
|
|
15
|
+
from digitalhub.utils.uri_utils import (
|
|
16
|
+
get_filename_from_uri,
|
|
17
|
+
has_git_scheme,
|
|
18
|
+
has_local_scheme,
|
|
19
|
+
has_remote_scheme,
|
|
20
|
+
has_s3_scheme,
|
|
21
|
+
has_zip_scheme,
|
|
22
|
+
)
|
|
16
23
|
|
|
17
24
|
|
|
18
|
-
def
|
|
25
|
+
def import_function_from_source(path: Path, source_spec: dict) -> Callable:
|
|
19
26
|
"""
|
|
20
27
|
Get function from source.
|
|
21
28
|
|
|
@@ -42,61 +49,6 @@ def get_function_from_source(path: Path, source_spec: dict) -> Callable:
|
|
|
42
49
|
raise RuntimeError(msg) from e
|
|
43
50
|
|
|
44
51
|
|
|
45
|
-
def get_function_source(source_spec: dict) -> Path:
|
|
46
|
-
"""
|
|
47
|
-
Get function source.
|
|
48
|
-
|
|
49
|
-
Parameters
|
|
50
|
-
----------
|
|
51
|
-
source : dict
|
|
52
|
-
Function source.
|
|
53
|
-
|
|
54
|
-
Returns
|
|
55
|
-
-------
|
|
56
|
-
Path
|
|
57
|
-
Path to function source.
|
|
58
|
-
"""
|
|
59
|
-
path = Path("/shared")
|
|
60
|
-
|
|
61
|
-
# Get relevant information
|
|
62
|
-
base64 = source_spec.get("base64")
|
|
63
|
-
source = source_spec.get("source", "main.py")
|
|
64
|
-
handler = source_spec.get("handler")
|
|
65
|
-
|
|
66
|
-
handler_path, _ = parse_handler(handler)
|
|
67
|
-
|
|
68
|
-
# Check base64. If it is set, it means
|
|
69
|
-
# that the source comes from a local file
|
|
70
|
-
if base64 is not None:
|
|
71
|
-
if has_local_scheme(source):
|
|
72
|
-
return path / handler_path / Path(source)
|
|
73
|
-
raise RuntimeError("Source is not a local file.")
|
|
74
|
-
|
|
75
|
-
if handler_path != Path(""):
|
|
76
|
-
return path / handler_path.with_suffix(".py")
|
|
77
|
-
raise RuntimeError("Must provide handler path in handler in form <root>.<dir>.<module>:<function_name>.")
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def parse_handler(handler: str) -> tuple[Path, str]:
|
|
81
|
-
"""
|
|
82
|
-
Parse handler.
|
|
83
|
-
|
|
84
|
-
Parameters
|
|
85
|
-
----------
|
|
86
|
-
handler : str
|
|
87
|
-
Function handler.
|
|
88
|
-
|
|
89
|
-
Returns
|
|
90
|
-
-------
|
|
91
|
-
tuple[Path, str]
|
|
92
|
-
Handler path and function name.
|
|
93
|
-
"""
|
|
94
|
-
parsed = handler.split(":")
|
|
95
|
-
if len(parsed) == 1:
|
|
96
|
-
return Path(""), parsed[0]
|
|
97
|
-
return Path(*parsed[0].split(".")), parsed[1]
|
|
98
|
-
|
|
99
|
-
|
|
100
52
|
def save_function_source(path: Path, source_spec: dict) -> Path:
|
|
101
53
|
"""
|
|
102
54
|
Save function source.
|
|
@@ -126,22 +78,32 @@ def save_function_source(path: Path, source_spec: dict) -> Path:
|
|
|
126
78
|
base64_path.write_text(decode_base64_string(base64))
|
|
127
79
|
return base64_path
|
|
128
80
|
|
|
81
|
+
if source is None:
|
|
82
|
+
raise RuntimeError("Function source not found in spec.")
|
|
83
|
+
|
|
129
84
|
# Git repo
|
|
130
85
|
if has_git_scheme(source):
|
|
131
86
|
clone_repository(path, source)
|
|
132
87
|
|
|
133
88
|
# Http(s) or s3 presigned urls
|
|
134
89
|
elif has_remote_scheme(source):
|
|
135
|
-
filename = path /
|
|
136
|
-
|
|
137
|
-
|
|
90
|
+
filename = path / get_filename_from_uri(source)
|
|
91
|
+
if has_zip_scheme(source):
|
|
92
|
+
requests_chunk_download(source.removeprefix("zip+"), filename)
|
|
93
|
+
extract_archive(path, filename)
|
|
94
|
+
filename.unlink()
|
|
95
|
+
else:
|
|
96
|
+
requests_chunk_download(source, filename)
|
|
138
97
|
|
|
139
98
|
# S3 path
|
|
140
99
|
elif has_s3_scheme(source):
|
|
141
|
-
|
|
100
|
+
if not has_zip_scheme(source):
|
|
101
|
+
raise RuntimeError("S3 source must be a zip file with scheme zip+s3://.")
|
|
102
|
+
filename = path / get_filename_from_uri(source)
|
|
142
103
|
bucket, key = get_bucket_and_key(source)
|
|
143
104
|
get_s3_source(bucket, key, filename)
|
|
144
105
|
extract_archive(path, filename)
|
|
106
|
+
filename.unlink()
|
|
145
107
|
|
|
146
108
|
# Unsupported scheme
|
|
147
109
|
else:
|
|
@@ -150,14 +112,22 @@ def save_function_source(path: Path, source_spec: dict) -> Path:
|
|
|
150
112
|
return path
|
|
151
113
|
|
|
152
114
|
|
|
153
|
-
def
|
|
115
|
+
def import_function_and_init_from_source(
|
|
116
|
+
path: Path,
|
|
117
|
+
source_spec: dict,
|
|
118
|
+
default_py: str,
|
|
119
|
+
) -> tuple[Callable, Union[Callable, None]]:
|
|
154
120
|
"""
|
|
155
|
-
Import function from source.
|
|
121
|
+
Import function and init from source.
|
|
156
122
|
|
|
157
123
|
Parameters
|
|
158
124
|
----------
|
|
159
|
-
|
|
125
|
+
path : Path
|
|
126
|
+
Path where the function source is or must be saved.
|
|
127
|
+
source_spec : dict
|
|
160
128
|
Function source.
|
|
129
|
+
default_py : str
|
|
130
|
+
Default python file.
|
|
161
131
|
|
|
162
132
|
Returns
|
|
163
133
|
-------
|
|
@@ -166,16 +136,73 @@ def import_function_and_init(source: dict) -> tuple[Callable, Union[Callable, No
|
|
|
166
136
|
"""
|
|
167
137
|
|
|
168
138
|
# Get function source
|
|
169
|
-
function_path = get_function_source(
|
|
170
|
-
_, handler_name = parse_handler(
|
|
139
|
+
function_path = get_function_source(path, source_spec, default_py)
|
|
140
|
+
_, handler_name = parse_handler(source_spec.get("handler"))
|
|
171
141
|
|
|
172
142
|
# Import function
|
|
173
143
|
fnc = import_function(function_path, handler_name)
|
|
174
144
|
|
|
175
145
|
# Get init function
|
|
176
146
|
init_fnc: Callable | None = None
|
|
177
|
-
init_handler: str | None =
|
|
147
|
+
init_handler: str | None = source_spec.get("init_function")
|
|
178
148
|
if init_handler is not None:
|
|
179
149
|
init_fnc = import_function(function_path, init_handler)
|
|
180
150
|
|
|
181
151
|
return fnc, init_fnc
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def get_function_source(path: Path, source_spec: dict, default_py: str) -> Path:
|
|
155
|
+
"""
|
|
156
|
+
Get function source.
|
|
157
|
+
|
|
158
|
+
Parameters
|
|
159
|
+
----------
|
|
160
|
+
path : Path
|
|
161
|
+
Path where the function source is or must be saved.
|
|
162
|
+
source_spec : dict
|
|
163
|
+
Function source.
|
|
164
|
+
default_py : str
|
|
165
|
+
Default python file.
|
|
166
|
+
|
|
167
|
+
Returns
|
|
168
|
+
-------
|
|
169
|
+
Path
|
|
170
|
+
Path to function source.
|
|
171
|
+
"""
|
|
172
|
+
# Get relevant information
|
|
173
|
+
base64 = source_spec.get("base64")
|
|
174
|
+
source = source_spec.get("source", default_py)
|
|
175
|
+
handler = source_spec.get("handler")
|
|
176
|
+
|
|
177
|
+
handler_path, _ = parse_handler(handler)
|
|
178
|
+
|
|
179
|
+
# Check base64. If it is set, it means
|
|
180
|
+
# that the source comes from a local file
|
|
181
|
+
if base64 is not None:
|
|
182
|
+
if has_local_scheme(source):
|
|
183
|
+
return path / handler_path / Path(source)
|
|
184
|
+
raise RuntimeError("Source is not a local file.")
|
|
185
|
+
|
|
186
|
+
if handler_path != Path(""):
|
|
187
|
+
return path / handler_path.with_suffix(".py")
|
|
188
|
+
raise RuntimeError("Must provide handler path in handler in form <root>.<dir>.<module>:<function_name>.")
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def parse_handler(handler: str) -> tuple[Path, str]:
|
|
192
|
+
"""
|
|
193
|
+
Parse handler.
|
|
194
|
+
|
|
195
|
+
Parameters
|
|
196
|
+
----------
|
|
197
|
+
handler : str
|
|
198
|
+
Function handler.
|
|
199
|
+
|
|
200
|
+
Returns
|
|
201
|
+
-------
|
|
202
|
+
tuple[Path, str]
|
|
203
|
+
Handler path and function name.
|
|
204
|
+
"""
|
|
205
|
+
parsed = handler.split(":")
|
|
206
|
+
if len(parsed) == 1:
|
|
207
|
+
return Path(""), parsed[0]
|
|
208
|
+
return Path(*parsed[0].split(".")), parsed[1]
|
|
@@ -13,6 +13,8 @@ if typing.TYPE_CHECKING:
|
|
|
13
13
|
from digitalhub.entities._base.entity.entity import Entity
|
|
14
14
|
from digitalhub.entities.project._base.entity import Project
|
|
15
15
|
|
|
16
|
+
from digitalhub_runtime_python.entities.run.python_run.entity import RunPythonRun
|
|
17
|
+
|
|
16
18
|
|
|
17
19
|
def get_project_(project_name: str) -> Project:
|
|
18
20
|
"""
|
|
@@ -37,6 +39,33 @@ def get_project_(project_name: str) -> Project:
|
|
|
37
39
|
raise RuntimeError(msg)
|
|
38
40
|
|
|
39
41
|
|
|
42
|
+
def get_run_(project_name: str) -> RunPythonRun:
|
|
43
|
+
"""
|
|
44
|
+
Get run.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
project_name : str
|
|
49
|
+
Project name.
|
|
50
|
+
run_id : str
|
|
51
|
+
Run id.
|
|
52
|
+
|
|
53
|
+
Returns
|
|
54
|
+
-------
|
|
55
|
+
Run
|
|
56
|
+
Run.
|
|
57
|
+
"""
|
|
58
|
+
try:
|
|
59
|
+
ctx = get_context(project_name)
|
|
60
|
+
proj = get_project(project_name, local=ctx.local)
|
|
61
|
+
run_key = ctx.get_run_ctx()
|
|
62
|
+
return proj.get_run(run_key)
|
|
63
|
+
except Exception as e:
|
|
64
|
+
msg = f"Error during run collection. Exception: {e.__class__}. Error: {e.args}"
|
|
65
|
+
LOGGER.exception(msg)
|
|
66
|
+
raise RuntimeError(msg)
|
|
67
|
+
|
|
68
|
+
|
|
40
69
|
def get_entity_inputs(inputs: dict) -> dict[str, Entity]:
|
|
41
70
|
"""
|
|
42
71
|
Set inputs.
|
|
@@ -104,6 +133,7 @@ def compose_inputs(
|
|
|
104
133
|
fnc_parameters = inspect.signature(func).parameters
|
|
105
134
|
|
|
106
135
|
_has_project = "project" in fnc_parameters
|
|
136
|
+
_has_run = "run" in fnc_parameters
|
|
107
137
|
_has_context = "context" in fnc_parameters
|
|
108
138
|
_has_event = "event" in fnc_parameters
|
|
109
139
|
|
|
@@ -117,6 +147,19 @@ def compose_inputs(
|
|
|
117
147
|
else:
|
|
118
148
|
fnc_args["project"] = project
|
|
119
149
|
|
|
150
|
+
if _has_context and not local_execution:
|
|
151
|
+
project_name: str = context.project.name
|
|
152
|
+
elif isinstance(project, str):
|
|
153
|
+
project_name = project
|
|
154
|
+
else:
|
|
155
|
+
project_name = project.name
|
|
156
|
+
|
|
157
|
+
if _has_run:
|
|
158
|
+
if _has_context and not local_execution:
|
|
159
|
+
fnc_args["run"] = context.run
|
|
160
|
+
else:
|
|
161
|
+
fnc_args["run"] = get_run_(project_name)
|
|
162
|
+
|
|
120
163
|
# Context and event are reserved keyword arguments
|
|
121
164
|
# only in remote executions
|
|
122
165
|
if not local_execution:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: digitalhub-runtime-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0b0
|
|
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
|
|
@@ -191,7 +191,7 @@ License: Apache License
|
|
|
191
191
|
same "printed page" as the copyright notice for easier
|
|
192
192
|
identification within third-party archives.
|
|
193
193
|
|
|
194
|
-
Copyright
|
|
194
|
+
Copyright 2024 DSLab, Fondazione Bruno Kessler
|
|
195
195
|
|
|
196
196
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
197
|
you may not use this file except in compliance with the License.
|
|
@@ -229,6 +229,6 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
229
229
|
Requires-Python: >=3.9
|
|
230
230
|
Description-Content-Type: text/markdown
|
|
231
231
|
License-File: LICENSE.txt
|
|
232
|
-
Requires-Dist: digitalhub[full]<0.
|
|
232
|
+
Requires-Dist: digitalhub[full]<0.11,>=0.10.0b
|
|
233
233
|
|
|
234
234
|
# SDK for DHCore
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
digitalhub[full]<0.11,>=0.10.0b
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "digitalhub-runtime-python"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.10.0b0"
|
|
8
8
|
description = "Python runtime for DHCore"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
@@ -21,7 +21,7 @@ classifiers = [
|
|
|
21
21
|
keywords = ["data", "dataops", "kubernetes"]
|
|
22
22
|
requires-python = ">=3.9"
|
|
23
23
|
dependencies = [
|
|
24
|
-
"digitalhub[full]>=0.
|
|
24
|
+
"digitalhub[full]>=0.10.0b, <0.11",
|
|
25
25
|
]
|
|
26
26
|
|
|
27
27
|
[project.urls]
|
|
@@ -40,7 +40,7 @@ line-length = 120
|
|
|
40
40
|
convention = "numpy"
|
|
41
41
|
|
|
42
42
|
[tool.bumpver]
|
|
43
|
-
current_version = "0.
|
|
43
|
+
current_version = "0.10.0b0"
|
|
44
44
|
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
|
|
45
45
|
commit_message = "Bump version {old_version} -> {new_version}"
|
|
46
46
|
commit = false
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
digitalhub[full]<0.10,>=0.9.0b
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|