digitalhub-runtime-python 0.16.0b2__py3-none-any.whl → 0.16.0b3__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.
- digitalhub_runtime_python/entities/_base/runtime_entity/builder.py +1 -1
- digitalhub_runtime_python/entities/_commons/requirement_parser/parser.py +9 -1
- digitalhub_runtime_python/entities/{function/python → _commons}/utils.py +42 -7
- digitalhub_runtime_python/entities/function/_base/__init__.py +3 -0
- digitalhub_runtime_python/entities/function/_base/builder.py +38 -0
- digitalhub_runtime_python/entities/function/_base/entity.py +134 -0
- digitalhub_runtime_python/entities/function/guardrail/builder.py +2 -70
- digitalhub_runtime_python/entities/function/guardrail/entity.py +2 -46
- digitalhub_runtime_python/entities/function/hydra/builder.py +6 -69
- digitalhub_runtime_python/entities/function/hydra/entity.py +2 -58
- digitalhub_runtime_python/entities/function/hydra/utils.py +3 -2
- digitalhub_runtime_python/entities/function/openinference/builder.py +2 -70
- digitalhub_runtime_python/entities/function/openinference/entity.py +2 -46
- digitalhub_runtime_python/entities/function/python/builder.py +2 -70
- digitalhub_runtime_python/entities/function/python/entity.py +2 -46
- digitalhub_runtime_python/entities/run/_base/entity.py +1 -1
- {digitalhub_runtime_python-0.16.0b2.dist-info → digitalhub_runtime_python-0.16.0b3.dist-info}/METADATA +2 -2
- {digitalhub_runtime_python-0.16.0b2.dist-info → digitalhub_runtime_python-0.16.0b3.dist-info}/RECORD +21 -18
- {digitalhub_runtime_python-0.16.0b2.dist-info → digitalhub_runtime_python-0.16.0b3.dist-info}/WHEEL +1 -1
- {digitalhub_runtime_python-0.16.0b2.dist-info → digitalhub_runtime_python-0.16.0b3.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub_runtime_python-0.16.0b2.dist-info → digitalhub_runtime_python-0.16.0b3.dist-info}/licenses/LICENSE +0 -0
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
-
from digitalhub.entities._base.runtime_entity.builder import RuntimeEntityBuilder
|
|
8
7
|
from digitalhub.entities._commons.utils import map_actions
|
|
8
|
+
from digitalhub.entities._mixin.runtime_entity.builder import RuntimeEntityBuilder
|
|
9
9
|
|
|
10
10
|
from digitalhub_runtime_python.entities._commons.enums import Actions, EntityKinds
|
|
11
11
|
|
|
@@ -5,10 +5,13 @@ from __future__ import annotations
|
|
|
5
5
|
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
|
|
8
|
+
from digitalhub.utils.logger.logger import get_logger
|
|
8
9
|
from pip._internal.operations import freeze
|
|
9
10
|
|
|
10
11
|
from digitalhub_runtime_python.entities._commons.requirement_parser.factory import RequirementParserFactory
|
|
11
12
|
|
|
13
|
+
logger = get_logger(__file__)
|
|
14
|
+
|
|
12
15
|
|
|
13
16
|
class RequirementParser:
|
|
14
17
|
"""
|
|
@@ -88,7 +91,12 @@ class RequirementParser:
|
|
|
88
91
|
normalized_name = req.lower().replace("_", "-")
|
|
89
92
|
if normalized_name in installed_map:
|
|
90
93
|
# Use the installed version
|
|
91
|
-
|
|
94
|
+
installed_requirement = installed_map[normalized_name]
|
|
95
|
+
logger.warning(
|
|
96
|
+
f"Warning: {req} version unspecified, using version {installed_requirement} inferred "
|
|
97
|
+
"from local environment. To override set an explicit version."
|
|
98
|
+
)
|
|
99
|
+
result.append(installed_requirement)
|
|
92
100
|
else:
|
|
93
101
|
# Package not found in environment, keep without version
|
|
94
102
|
result.append(req)
|
|
@@ -11,7 +11,8 @@ from digitalhub.entities._commons.utils import build_zip_path
|
|
|
11
11
|
from digitalhub.stores.data.api import get_store
|
|
12
12
|
from digitalhub.utils.exceptions import EntityError
|
|
13
13
|
from digitalhub.utils.file_utils import eval_py_type, eval_zip_type
|
|
14
|
-
from digitalhub.utils.generic_utils import create_archive, encode_string, read_source
|
|
14
|
+
from digitalhub.utils.generic_utils import create_archive, decode_base64_string, encode_string, read_source
|
|
15
|
+
from digitalhub.utils.io_utils import write_text
|
|
15
16
|
from digitalhub.utils.uri_utils import has_local_scheme
|
|
16
17
|
|
|
17
18
|
from digitalhub_runtime_python.entities.function.python.models import Lang
|
|
@@ -20,6 +21,38 @@ if typing.TYPE_CHECKING:
|
|
|
20
21
|
from digitalhub_runtime_python.entities.function.python.entity import FunctionPython
|
|
21
22
|
|
|
22
23
|
|
|
24
|
+
class _LocalSourceExport:
|
|
25
|
+
def __init__(self, source: dict, root: Path) -> None:
|
|
26
|
+
self.source = source
|
|
27
|
+
self.root = root
|
|
28
|
+
self.base64 = None
|
|
29
|
+
|
|
30
|
+
def __enter__(self) -> None:
|
|
31
|
+
# Strip base64 from source at following conditions:
|
|
32
|
+
# - source is local path
|
|
33
|
+
# - base64 is not None
|
|
34
|
+
source_path = self.source.get("source")
|
|
35
|
+
if source_path is None or not has_local_scheme(source_path):
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
# Check base64. If it is set, decode it in a local file
|
|
39
|
+
# save in variable to restore on object after export
|
|
40
|
+
self.base64 = self.source.pop("base64", None)
|
|
41
|
+
if self.base64 is not None:
|
|
42
|
+
# Write local file
|
|
43
|
+
write_text(self.root / source_path, decode_base64_string(self.base64))
|
|
44
|
+
return
|
|
45
|
+
|
|
46
|
+
def __exit__(self, exc_type, exc_value, traceback) -> None:
|
|
47
|
+
# Restore base64 after export, including when export raises an exception.
|
|
48
|
+
if self.base64 is not None:
|
|
49
|
+
self.source["base64"] = self.base64
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def export_local_source(source: dict, root: Path) -> _LocalSourceExport:
|
|
53
|
+
return _LocalSourceExport(source, root)
|
|
54
|
+
|
|
55
|
+
|
|
23
56
|
def source_check(**kwargs) -> dict:
|
|
24
57
|
"""
|
|
25
58
|
Check source code.
|
|
@@ -43,6 +76,7 @@ def source_check(**kwargs) -> dict:
|
|
|
43
76
|
lang = kwargs.pop("lang", None)
|
|
44
77
|
|
|
45
78
|
if source is not None:
|
|
79
|
+
source = source.copy()
|
|
46
80
|
code_src = source.pop("source", None)
|
|
47
81
|
code = source.pop("code", None)
|
|
48
82
|
base64 = source.pop("base64", None)
|
|
@@ -101,8 +135,7 @@ def _check_params(
|
|
|
101
135
|
if init_function is not None:
|
|
102
136
|
source["init_function"] = init_function
|
|
103
137
|
|
|
104
|
-
if lang is None
|
|
105
|
-
source["lang"] = Lang.PYTHON.value
|
|
138
|
+
source["lang"] = lang if lang is not None else Lang.PYTHON.value
|
|
106
139
|
|
|
107
140
|
if code_src is None and code is None and base64 is None:
|
|
108
141
|
raise EntityError("Source must be provided.")
|
|
@@ -148,10 +181,12 @@ def source_post_check(exec: FunctionPython) -> FunctionPython:
|
|
|
148
181
|
# If source is a folder, zip it and upload it
|
|
149
182
|
if not path_src.is_file():
|
|
150
183
|
archive_path = create_archive(path_src)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
184
|
+
try:
|
|
185
|
+
dst = build_zip_path(exec, archive_path.name)
|
|
186
|
+
get_store(dst).upload(str(archive_path), dst)
|
|
187
|
+
exec.spec.source["source"] = dst
|
|
188
|
+
finally:
|
|
189
|
+
archive_path.unlink(missing_ok=True)
|
|
155
190
|
|
|
156
191
|
# If source is a file, read it and encode it in base64
|
|
157
192
|
elif eval_py_type(code_src):
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from digitalhub.entities.function._base.builder import FunctionBuilder
|
|
8
|
+
|
|
9
|
+
from digitalhub_runtime_python.entities._base.runtime_entity.builder import RuntimeEntityBuilder
|
|
10
|
+
from digitalhub_runtime_python.entities._commons.utils import source_check, source_post_check
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FunctionBaseBuilder(FunctionBuilder, RuntimeEntityBuilder):
|
|
14
|
+
"""
|
|
15
|
+
Base builder for runtime Python functions.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def _prepare_kwargs(self, kwargs: dict) -> dict:
|
|
19
|
+
return source_check(**kwargs)
|
|
20
|
+
|
|
21
|
+
def _prepare_source(self, source: dict) -> dict:
|
|
22
|
+
return source_check(source=source)["source"]
|
|
23
|
+
|
|
24
|
+
def build(self, *args, **kwargs):
|
|
25
|
+
kwargs = self._prepare_kwargs(kwargs)
|
|
26
|
+
return source_post_check(super().build(*args, **kwargs))
|
|
27
|
+
|
|
28
|
+
def from_dict(self, obj: dict):
|
|
29
|
+
return source_post_check(super().from_dict(obj))
|
|
30
|
+
|
|
31
|
+
def _parse_dict(self, obj: dict) -> dict:
|
|
32
|
+
if spec_dict := obj.get("spec", {}):
|
|
33
|
+
# Check source
|
|
34
|
+
source = spec_dict.get("source", {})
|
|
35
|
+
if source:
|
|
36
|
+
spec_dict["source"] = self._prepare_source(source)
|
|
37
|
+
|
|
38
|
+
return super()._parse_dict(obj)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from digitalhub.entities.function._base.entity import Function
|
|
8
|
+
from digitalhub.utils.generic_utils import decode_base64_string
|
|
9
|
+
from digitalhub.utils.io_utils import write_text
|
|
10
|
+
|
|
11
|
+
from digitalhub_runtime_python.entities._commons.enums import Actions
|
|
12
|
+
from digitalhub_runtime_python.entities._commons.requirement_parser.parser import RequirementParser
|
|
13
|
+
from digitalhub_runtime_python.entities._commons.utils import export_local_source
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class FunctionBaseFunction(Function):
|
|
17
|
+
"""
|
|
18
|
+
Base class for runtime Python functions.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def _post_create_hook_before_save(self) -> None:
|
|
22
|
+
"""
|
|
23
|
+
Parse function requirements before saving the entity.
|
|
24
|
+
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
None
|
|
28
|
+
This method updates the function requirements in place.
|
|
29
|
+
"""
|
|
30
|
+
self.spec.requirements = RequirementParser().parse(self.spec.requirements)
|
|
31
|
+
|
|
32
|
+
def export(self) -> str:
|
|
33
|
+
"""
|
|
34
|
+
Export the function to the context folder.
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
-------
|
|
38
|
+
str
|
|
39
|
+
Exported filepath.
|
|
40
|
+
"""
|
|
41
|
+
with export_local_source(self.spec.source, self._context().root):
|
|
42
|
+
config = getattr(self.spec, "config", None)
|
|
43
|
+
# Check base64. If it is set, decode it in a local file
|
|
44
|
+
# save in variable to restore on object after export
|
|
45
|
+
base64 = None
|
|
46
|
+
if config is not None:
|
|
47
|
+
base64 = config.pop("base64", None)
|
|
48
|
+
if base64 is not None:
|
|
49
|
+
# Write local file
|
|
50
|
+
config_pth = self._context().root / "config.yaml"
|
|
51
|
+
write_text(config_pth, decode_base64_string(base64))
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
return super().export()
|
|
55
|
+
finally:
|
|
56
|
+
if config is not None and base64 is not None:
|
|
57
|
+
config["base64"] = base64
|
|
58
|
+
|
|
59
|
+
def build(
|
|
60
|
+
self,
|
|
61
|
+
wait: bool = True,
|
|
62
|
+
log_info: bool = True,
|
|
63
|
+
extensions: list[dict] | None = None,
|
|
64
|
+
**kwargs,
|
|
65
|
+
):
|
|
66
|
+
"""
|
|
67
|
+
Build the function using the build action.
|
|
68
|
+
|
|
69
|
+
Parameters
|
|
70
|
+
----------
|
|
71
|
+
wait : bool
|
|
72
|
+
Whether to wait for the build to complete.
|
|
73
|
+
log_info : bool
|
|
74
|
+
Whether to log information while waiting.
|
|
75
|
+
extensions : list[dict] | None
|
|
76
|
+
List of extensions to apply.
|
|
77
|
+
**kwargs : dict
|
|
78
|
+
Keyword arguments passed to the run builder.
|
|
79
|
+
|
|
80
|
+
Returns
|
|
81
|
+
-------
|
|
82
|
+
Run
|
|
83
|
+
Build run instance.
|
|
84
|
+
"""
|
|
85
|
+
return super().run(
|
|
86
|
+
Actions.BUILD.value,
|
|
87
|
+
wait=wait,
|
|
88
|
+
log_info=log_info,
|
|
89
|
+
extensions=extensions,
|
|
90
|
+
**kwargs,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def run(
|
|
94
|
+
self,
|
|
95
|
+
action: str,
|
|
96
|
+
wait: bool = False,
|
|
97
|
+
log_info: bool = True,
|
|
98
|
+
extensions: list[dict] | None = None,
|
|
99
|
+
auto_build: bool = True,
|
|
100
|
+
**kwargs,
|
|
101
|
+
):
|
|
102
|
+
"""
|
|
103
|
+
Run the function, building it first when no image is available.
|
|
104
|
+
|
|
105
|
+
Parameters
|
|
106
|
+
----------
|
|
107
|
+
action : str
|
|
108
|
+
Action to execute.
|
|
109
|
+
wait : bool
|
|
110
|
+
Whether to wait for execution to complete.
|
|
111
|
+
log_info : bool
|
|
112
|
+
Whether to log information while waiting.
|
|
113
|
+
extensions : list[dict] | None
|
|
114
|
+
List of extensions to apply.
|
|
115
|
+
auto_build : bool
|
|
116
|
+
Whether to build the function when ``spec.image`` is ``None``.
|
|
117
|
+
**kwargs : dict
|
|
118
|
+
Keyword arguments passed to the run builder.
|
|
119
|
+
|
|
120
|
+
Returns
|
|
121
|
+
-------
|
|
122
|
+
Run
|
|
123
|
+
Run instance.
|
|
124
|
+
"""
|
|
125
|
+
if auto_build and self.spec.image is None:
|
|
126
|
+
self.build(wait=True, log_info=log_info)
|
|
127
|
+
|
|
128
|
+
return super().run(
|
|
129
|
+
action,
|
|
130
|
+
wait=wait,
|
|
131
|
+
log_info=log_info,
|
|
132
|
+
extensions=extensions,
|
|
133
|
+
**kwargs,
|
|
134
|
+
)
|
|
@@ -4,20 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
-
from digitalhub.entities.function._base.builder import FunctionBuilder
|
|
8
|
-
|
|
9
7
|
from digitalhub_runtime_python.entities._base.runtime_entity.builder import RuntimeEntityBuilderGuardrail
|
|
10
8
|
from digitalhub_runtime_python.entities._commons.enums import EntityKinds
|
|
9
|
+
from digitalhub_runtime_python.entities.function._base.builder import FunctionBaseBuilder
|
|
11
10
|
from digitalhub_runtime_python.entities.function.guardrail.entity import FunctionGuardrail
|
|
12
11
|
from digitalhub_runtime_python.entities.function.guardrail.spec import (
|
|
13
12
|
FunctionSpecGuardrail,
|
|
14
13
|
FunctionValidatorGuardrail,
|
|
15
14
|
)
|
|
16
15
|
from digitalhub_runtime_python.entities.function.guardrail.status import FunctionStatusGuardrail
|
|
17
|
-
from digitalhub_runtime_python.entities.function.python.utils import source_check, source_post_check
|
|
18
16
|
|
|
19
17
|
|
|
20
|
-
class FunctionGuardrailBuilder(
|
|
18
|
+
class FunctionGuardrailBuilder(FunctionBaseBuilder, RuntimeEntityBuilderGuardrail):
|
|
21
19
|
"""
|
|
22
20
|
FunctionGuardrail builder.
|
|
23
21
|
"""
|
|
@@ -27,69 +25,3 @@ class FunctionGuardrailBuilder(FunctionBuilder, RuntimeEntityBuilderGuardrail):
|
|
|
27
25
|
ENTITY_SPEC_VALIDATOR = FunctionValidatorGuardrail
|
|
28
26
|
ENTITY_STATUS_CLASS = FunctionStatusGuardrail
|
|
29
27
|
ENTITY_KIND = EntityKinds.FUNCTION_GUARDRAIL.value
|
|
30
|
-
|
|
31
|
-
def build(
|
|
32
|
-
self,
|
|
33
|
-
kind: str,
|
|
34
|
-
project: str,
|
|
35
|
-
name: str,
|
|
36
|
-
uuid: str | None = None,
|
|
37
|
-
version: str | None = None,
|
|
38
|
-
description: str | None = None,
|
|
39
|
-
labels: list[str] | None = None,
|
|
40
|
-
embedded: bool = False,
|
|
41
|
-
**kwargs,
|
|
42
|
-
) -> FunctionGuardrail:
|
|
43
|
-
kwargs = source_check(**kwargs)
|
|
44
|
-
obj = super().build(
|
|
45
|
-
kind=kind,
|
|
46
|
-
project=project,
|
|
47
|
-
name=name,
|
|
48
|
-
uuid=uuid,
|
|
49
|
-
version=version,
|
|
50
|
-
description=description,
|
|
51
|
-
labels=labels,
|
|
52
|
-
embedded=embedded,
|
|
53
|
-
**kwargs,
|
|
54
|
-
)
|
|
55
|
-
return source_post_check(obj)
|
|
56
|
-
|
|
57
|
-
def from_dict(self, obj: dict) -> FunctionGuardrail:
|
|
58
|
-
"""
|
|
59
|
-
Create a new object from dictionary.
|
|
60
|
-
|
|
61
|
-
Parameters
|
|
62
|
-
----------
|
|
63
|
-
obj : dict
|
|
64
|
-
Dictionary to create object from.
|
|
65
|
-
|
|
66
|
-
Returns
|
|
67
|
-
-------
|
|
68
|
-
FunctionGuardrail
|
|
69
|
-
Object instance.
|
|
70
|
-
"""
|
|
71
|
-
entity = super().from_dict(obj)
|
|
72
|
-
return source_post_check(entity)
|
|
73
|
-
|
|
74
|
-
def _parse_dict(self, obj: dict) -> dict:
|
|
75
|
-
"""
|
|
76
|
-
Get dictionary and parse it to a valid entity dictionary.
|
|
77
|
-
|
|
78
|
-
Parameters
|
|
79
|
-
----------
|
|
80
|
-
obj : dict
|
|
81
|
-
Dictionary to parse.
|
|
82
|
-
|
|
83
|
-
Returns
|
|
84
|
-
-------
|
|
85
|
-
dict
|
|
86
|
-
A dictionary containing the attributes of the entity instance.
|
|
87
|
-
"""
|
|
88
|
-
# Look for source in spec
|
|
89
|
-
if spec_dict := obj.get("spec", {}):
|
|
90
|
-
# Check source
|
|
91
|
-
source = spec_dict.get("source", {})
|
|
92
|
-
if source:
|
|
93
|
-
spec_dict["source"] = source_check(source=source)["source"]
|
|
94
|
-
|
|
95
|
-
return super()._parse_dict(obj)
|
|
@@ -6,19 +6,14 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
|
-
from
|
|
10
|
-
from digitalhub.utils.generic_utils import decode_base64_string
|
|
11
|
-
from digitalhub.utils.io_utils import write_text
|
|
12
|
-
from digitalhub.utils.uri_utils import has_local_scheme
|
|
13
|
-
|
|
14
|
-
from digitalhub_runtime_python.entities._commons.requirement_parser.parser import RequirementParser
|
|
9
|
+
from digitalhub_runtime_python.entities.function._base.entity import FunctionBaseFunction
|
|
15
10
|
|
|
16
11
|
if typing.TYPE_CHECKING:
|
|
17
12
|
from digitalhub_runtime_python.entities.function.guardrail.spec import FunctionSpecGuardrail
|
|
18
13
|
from digitalhub_runtime_python.entities.function.guardrail.status import FunctionStatusGuardrail
|
|
19
14
|
|
|
20
15
|
|
|
21
|
-
class FunctionGuardrail(
|
|
16
|
+
class FunctionGuardrail(FunctionBaseFunction):
|
|
22
17
|
"""
|
|
23
18
|
FunctionGuardrail class.
|
|
24
19
|
"""
|
|
@@ -28,42 +23,3 @@ class FunctionGuardrail(Function):
|
|
|
28
23
|
|
|
29
24
|
self.spec: FunctionSpecGuardrail
|
|
30
25
|
self.status: FunctionStatusGuardrail
|
|
31
|
-
|
|
32
|
-
def export(self) -> str:
|
|
33
|
-
"""
|
|
34
|
-
Export object as a YAML file in the context folder.
|
|
35
|
-
|
|
36
|
-
Returns
|
|
37
|
-
-------
|
|
38
|
-
str
|
|
39
|
-
Exported filepath.
|
|
40
|
-
"""
|
|
41
|
-
# Strip base64 from source at following conditions:
|
|
42
|
-
# - source is local path
|
|
43
|
-
# - base64 is not None
|
|
44
|
-
|
|
45
|
-
# Check source
|
|
46
|
-
source = self.spec.source.get("source")
|
|
47
|
-
if source is not None and has_local_scheme(source):
|
|
48
|
-
# Check base64. If it is set, decode it in a local file
|
|
49
|
-
# save in variable to restore on object after export
|
|
50
|
-
base64 = self.spec.source.pop("base64", None)
|
|
51
|
-
if base64 is not None:
|
|
52
|
-
# Write local file
|
|
53
|
-
src_pth = self._context().root / source
|
|
54
|
-
write_text(src_pth, decode_base64_string(base64))
|
|
55
|
-
|
|
56
|
-
# Export and restore base64, then return
|
|
57
|
-
pth = super().export()
|
|
58
|
-
self.spec.source["base64"] = base64
|
|
59
|
-
return pth
|
|
60
|
-
|
|
61
|
-
return super().export()
|
|
62
|
-
|
|
63
|
-
def _post_create_hook_before_save(self) -> None:
|
|
64
|
-
"""
|
|
65
|
-
Hook method called after the creation of the entity but before saving
|
|
66
|
-
in Core.
|
|
67
|
-
Can be overridden in subclasses to implement custom behavior.
|
|
68
|
-
"""
|
|
69
|
-
self.spec.requirements = RequirementParser().parse(self.spec.requirements)
|
|
@@ -4,18 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
-
from digitalhub.entities.function._base.builder import FunctionBuilder
|
|
8
|
-
|
|
9
7
|
from digitalhub_runtime_python.entities._base.runtime_entity.builder import RuntimeEntityBuilderHydra
|
|
10
8
|
from digitalhub_runtime_python.entities._commons.enums import EntityKinds
|
|
9
|
+
from digitalhub_runtime_python.entities.function._base.builder import FunctionBaseBuilder
|
|
11
10
|
from digitalhub_runtime_python.entities.function.hydra.entity import FunctionHydra
|
|
12
11
|
from digitalhub_runtime_python.entities.function.hydra.spec import FunctionSpecHydra, FunctionValidatorHydra
|
|
13
12
|
from digitalhub_runtime_python.entities.function.hydra.status import FunctionStatusHydra
|
|
14
13
|
from digitalhub_runtime_python.entities.function.hydra.utils import config_check, source_check
|
|
15
|
-
from digitalhub_runtime_python.entities.function.python.utils import source_post_check
|
|
16
14
|
|
|
17
15
|
|
|
18
|
-
class FunctionHydraBuilder(
|
|
16
|
+
class FunctionHydraBuilder(FunctionBaseBuilder, RuntimeEntityBuilderHydra):
|
|
19
17
|
"""
|
|
20
18
|
FunctionHydra builder.
|
|
21
19
|
"""
|
|
@@ -26,69 +24,8 @@ class FunctionHydraBuilder(FunctionBuilder, RuntimeEntityBuilderHydra):
|
|
|
26
24
|
ENTITY_STATUS_CLASS = FunctionStatusHydra
|
|
27
25
|
ENTITY_KIND = EntityKinds.FUNCTION_HYDRA.value
|
|
28
26
|
|
|
29
|
-
def
|
|
30
|
-
|
|
31
|
-
kind: str,
|
|
32
|
-
project: str,
|
|
33
|
-
name: str,
|
|
34
|
-
uuid: str | None = None,
|
|
35
|
-
version: str | None = None,
|
|
36
|
-
description: str | None = None,
|
|
37
|
-
labels: list[str] | None = None,
|
|
38
|
-
embedded: bool = False,
|
|
39
|
-
**kwargs,
|
|
40
|
-
) -> FunctionHydra:
|
|
41
|
-
kwargs = source_check(**kwargs)
|
|
42
|
-
kwargs = config_check(**kwargs)
|
|
43
|
-
obj = super().build(
|
|
44
|
-
kind=kind,
|
|
45
|
-
project=project,
|
|
46
|
-
name=name,
|
|
47
|
-
uuid=uuid,
|
|
48
|
-
version=version,
|
|
49
|
-
description=description,
|
|
50
|
-
labels=labels,
|
|
51
|
-
embedded=embedded,
|
|
52
|
-
**kwargs,
|
|
53
|
-
)
|
|
54
|
-
return source_post_check(obj)
|
|
55
|
-
|
|
56
|
-
def from_dict(self, obj: dict) -> FunctionHydra:
|
|
57
|
-
"""
|
|
58
|
-
Create a new object from dictionary.
|
|
59
|
-
|
|
60
|
-
Parameters
|
|
61
|
-
----------
|
|
62
|
-
obj : dict
|
|
63
|
-
Dictionary to create object from.
|
|
64
|
-
|
|
65
|
-
Returns
|
|
66
|
-
-------
|
|
67
|
-
FunctionHydra
|
|
68
|
-
Object instance.
|
|
69
|
-
"""
|
|
70
|
-
entity = super().from_dict(obj)
|
|
71
|
-
return source_post_check(entity)
|
|
72
|
-
|
|
73
|
-
def _parse_dict(self, obj: dict) -> dict:
|
|
74
|
-
"""
|
|
75
|
-
Get dictionary and parse it to a valid entity dictionary.
|
|
76
|
-
|
|
77
|
-
Parameters
|
|
78
|
-
----------
|
|
79
|
-
obj : dict
|
|
80
|
-
Dictionary to parse.
|
|
81
|
-
|
|
82
|
-
Returns
|
|
83
|
-
-------
|
|
84
|
-
dict
|
|
85
|
-
A dictionary containing the attributes of the entity instance.
|
|
86
|
-
"""
|
|
87
|
-
# Look for source in spec
|
|
88
|
-
if spec_dict := obj.get("spec", {}):
|
|
89
|
-
# Check source
|
|
90
|
-
source = spec_dict.get("source", {})
|
|
91
|
-
if source:
|
|
92
|
-
spec_dict["source"] = source_check(source=source)["source"]
|
|
27
|
+
def _prepare_kwargs(self, kwargs: dict) -> dict:
|
|
28
|
+
return config_check(**source_check(**kwargs))
|
|
93
29
|
|
|
94
|
-
|
|
30
|
+
def _prepare_source(self, source: dict) -> dict:
|
|
31
|
+
return source_check(source=source)["source"]
|
|
@@ -6,19 +6,14 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
|
-
from
|
|
10
|
-
from digitalhub.utils.generic_utils import decode_base64_string
|
|
11
|
-
from digitalhub.utils.io_utils import write_text
|
|
12
|
-
from digitalhub.utils.uri_utils import has_local_scheme
|
|
13
|
-
|
|
14
|
-
from digitalhub_runtime_python.entities._commons.requirement_parser.parser import RequirementParser
|
|
9
|
+
from digitalhub_runtime_python.entities.function._base.entity import FunctionBaseFunction
|
|
15
10
|
|
|
16
11
|
if typing.TYPE_CHECKING:
|
|
17
12
|
from digitalhub_runtime_python.entities.function.hydra.spec import FunctionSpecHydra
|
|
18
13
|
from digitalhub_runtime_python.entities.function.hydra.status import FunctionStatusHydra
|
|
19
14
|
|
|
20
15
|
|
|
21
|
-
class FunctionHydra(
|
|
16
|
+
class FunctionHydra(FunctionBaseFunction):
|
|
22
17
|
"""
|
|
23
18
|
FunctionHydra class.
|
|
24
19
|
"""
|
|
@@ -28,54 +23,3 @@ class FunctionHydra(Function):
|
|
|
28
23
|
|
|
29
24
|
self.spec: FunctionSpecHydra
|
|
30
25
|
self.status: FunctionStatusHydra
|
|
31
|
-
|
|
32
|
-
def export(self) -> str:
|
|
33
|
-
"""
|
|
34
|
-
Export object as a YAML file in the context folder.
|
|
35
|
-
|
|
36
|
-
Returns
|
|
37
|
-
-------
|
|
38
|
-
str
|
|
39
|
-
Exported filepath.
|
|
40
|
-
"""
|
|
41
|
-
# Strip base64 from source at following conditions:
|
|
42
|
-
# - source is local path
|
|
43
|
-
# - base64 is not None
|
|
44
|
-
|
|
45
|
-
# Check source
|
|
46
|
-
source = self.spec.source.get("source")
|
|
47
|
-
if source is not None and has_local_scheme(source):
|
|
48
|
-
# Check base64. If it is set, decode it in a local file
|
|
49
|
-
# save in variable to restore on object after export
|
|
50
|
-
base64 = self.spec.source.pop("base64", None)
|
|
51
|
-
if base64 is not None:
|
|
52
|
-
# Write local file
|
|
53
|
-
src_pth = self._context().root / source
|
|
54
|
-
write_text(src_pth, decode_base64_string(base64))
|
|
55
|
-
|
|
56
|
-
# Export and restore base64, then return
|
|
57
|
-
super().export()
|
|
58
|
-
self.spec.source["base64"] = base64
|
|
59
|
-
|
|
60
|
-
config = self.spec.config
|
|
61
|
-
# Check base64. If it is set, decode it in a local file
|
|
62
|
-
# save in variable to restore on object after export
|
|
63
|
-
if config is not None:
|
|
64
|
-
base64 = config.pop("base64", None)
|
|
65
|
-
if base64 is not None:
|
|
66
|
-
# Write local file
|
|
67
|
-
config_pth = self._context().root / "config.yaml"
|
|
68
|
-
write_text(config_pth, decode_base64_string(base64))
|
|
69
|
-
|
|
70
|
-
# Export and restore base64, then return
|
|
71
|
-
self.spec.config = base64
|
|
72
|
-
|
|
73
|
-
return super().export()
|
|
74
|
-
|
|
75
|
-
def _post_create_hook_before_save(self) -> None:
|
|
76
|
-
"""
|
|
77
|
-
Hook method called after the creation of the entity but before saving
|
|
78
|
-
in Core.
|
|
79
|
-
Can be overridden in subclasses to implement custom behavior.
|
|
80
|
-
"""
|
|
81
|
-
self.spec.requirements = RequirementParser().parse(self.spec.requirements)
|
|
@@ -37,6 +37,7 @@ def source_check(**kwargs) -> dict:
|
|
|
37
37
|
lang = kwargs.pop("lang", None)
|
|
38
38
|
|
|
39
39
|
if source is not None:
|
|
40
|
+
source = source.copy()
|
|
40
41
|
code_src = source.pop("source", None)
|
|
41
42
|
code = source.pop("code", None)
|
|
42
43
|
base64 = source.pop("base64", None)
|
|
@@ -103,8 +104,7 @@ def _check_params(
|
|
|
103
104
|
if complete_function is not None:
|
|
104
105
|
source["complete_function"] = complete_function
|
|
105
106
|
|
|
106
|
-
if lang is None
|
|
107
|
-
source["lang"] = Lang.PYTHON.value
|
|
107
|
+
source["lang"] = lang if lang is not None else Lang.PYTHON.value
|
|
108
108
|
|
|
109
109
|
if code_src is None and code is None and base64 is None:
|
|
110
110
|
raise EntityError("Source must be provided.")
|
|
@@ -143,6 +143,7 @@ def config_check(**kwargs) -> dict:
|
|
|
143
143
|
config_path = kwargs.pop("config_path", None)
|
|
144
144
|
|
|
145
145
|
if config is not None:
|
|
146
|
+
config = config.copy()
|
|
146
147
|
config_src = config.pop("source", None)
|
|
147
148
|
config_base64 = config.pop("base64", None)
|
|
148
149
|
config_content = None
|
|
@@ -4,20 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
-
from digitalhub.entities.function._base.builder import FunctionBuilder
|
|
8
|
-
|
|
9
7
|
from digitalhub_runtime_python.entities._base.runtime_entity.builder import RuntimeEntityBuilderOpeninference
|
|
10
8
|
from digitalhub_runtime_python.entities._commons.enums import EntityKinds
|
|
9
|
+
from digitalhub_runtime_python.entities.function._base.builder import FunctionBaseBuilder
|
|
11
10
|
from digitalhub_runtime_python.entities.function.openinference.entity import FunctionOpeninference
|
|
12
11
|
from digitalhub_runtime_python.entities.function.openinference.spec import (
|
|
13
12
|
FunctionSpecOpeninference,
|
|
14
13
|
FunctionValidatorOpeninference,
|
|
15
14
|
)
|
|
16
15
|
from digitalhub_runtime_python.entities.function.openinference.status import FunctionStatusOpeninference
|
|
17
|
-
from digitalhub_runtime_python.entities.function.python.utils import source_check, source_post_check
|
|
18
16
|
|
|
19
17
|
|
|
20
|
-
class FunctionOpeninferenceBuilder(
|
|
18
|
+
class FunctionOpeninferenceBuilder(FunctionBaseBuilder, RuntimeEntityBuilderOpeninference):
|
|
21
19
|
"""
|
|
22
20
|
FunctionOpeninference builder.
|
|
23
21
|
"""
|
|
@@ -27,69 +25,3 @@ class FunctionOpeninferenceBuilder(FunctionBuilder, RuntimeEntityBuilderOpeninfe
|
|
|
27
25
|
ENTITY_SPEC_VALIDATOR = FunctionValidatorOpeninference
|
|
28
26
|
ENTITY_STATUS_CLASS = FunctionStatusOpeninference
|
|
29
27
|
ENTITY_KIND = EntityKinds.FUNCTION_OPENINFERENCE.value
|
|
30
|
-
|
|
31
|
-
def build(
|
|
32
|
-
self,
|
|
33
|
-
kind: str,
|
|
34
|
-
project: str,
|
|
35
|
-
name: str,
|
|
36
|
-
uuid: str | None = None,
|
|
37
|
-
version: str | None = None,
|
|
38
|
-
description: str | None = None,
|
|
39
|
-
labels: list[str] | None = None,
|
|
40
|
-
embedded: bool = False,
|
|
41
|
-
**kwargs,
|
|
42
|
-
) -> FunctionOpeninference:
|
|
43
|
-
kwargs = source_check(**kwargs)
|
|
44
|
-
obj = super().build(
|
|
45
|
-
kind=kind,
|
|
46
|
-
project=project,
|
|
47
|
-
name=name,
|
|
48
|
-
uuid=uuid,
|
|
49
|
-
version=version,
|
|
50
|
-
description=description,
|
|
51
|
-
labels=labels,
|
|
52
|
-
embedded=embedded,
|
|
53
|
-
**kwargs,
|
|
54
|
-
)
|
|
55
|
-
return source_post_check(obj)
|
|
56
|
-
|
|
57
|
-
def from_dict(self, obj: dict) -> FunctionOpeninference:
|
|
58
|
-
"""
|
|
59
|
-
Create a new object from dictionary.
|
|
60
|
-
|
|
61
|
-
Parameters
|
|
62
|
-
----------
|
|
63
|
-
obj : dict
|
|
64
|
-
Dictionary to create object from.
|
|
65
|
-
|
|
66
|
-
Returns
|
|
67
|
-
-------
|
|
68
|
-
FunctionOpeninference
|
|
69
|
-
Object instance.
|
|
70
|
-
"""
|
|
71
|
-
entity = super().from_dict(obj)
|
|
72
|
-
return source_post_check(entity)
|
|
73
|
-
|
|
74
|
-
def _parse_dict(self, obj: dict) -> dict:
|
|
75
|
-
"""
|
|
76
|
-
Get dictionary and parse it to a valid entity dictionary.
|
|
77
|
-
|
|
78
|
-
Parameters
|
|
79
|
-
----------
|
|
80
|
-
obj : dict
|
|
81
|
-
Dictionary to parse.
|
|
82
|
-
|
|
83
|
-
Returns
|
|
84
|
-
-------
|
|
85
|
-
dict
|
|
86
|
-
A dictionary containing the attributes of the entity instance.
|
|
87
|
-
"""
|
|
88
|
-
# Look for source in spec
|
|
89
|
-
if spec_dict := obj.get("spec", {}):
|
|
90
|
-
# Check source
|
|
91
|
-
source = spec_dict.get("source", {})
|
|
92
|
-
if source:
|
|
93
|
-
spec_dict["source"] = source_check(source=source)["source"]
|
|
94
|
-
|
|
95
|
-
return super()._parse_dict(obj)
|
|
@@ -6,19 +6,14 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
|
-
from
|
|
10
|
-
from digitalhub.utils.generic_utils import decode_base64_string
|
|
11
|
-
from digitalhub.utils.io_utils import write_text
|
|
12
|
-
from digitalhub.utils.uri_utils import has_local_scheme
|
|
13
|
-
|
|
14
|
-
from digitalhub_runtime_python.entities._commons.requirement_parser.parser import RequirementParser
|
|
9
|
+
from digitalhub_runtime_python.entities.function._base.entity import FunctionBaseFunction
|
|
15
10
|
|
|
16
11
|
if typing.TYPE_CHECKING:
|
|
17
12
|
from digitalhub_runtime_python.entities.function.openinference.spec import FunctionSpecOpeninference
|
|
18
13
|
from digitalhub_runtime_python.entities.function.openinference.status import FunctionStatusOpeninference
|
|
19
14
|
|
|
20
15
|
|
|
21
|
-
class FunctionOpeninference(
|
|
16
|
+
class FunctionOpeninference(FunctionBaseFunction):
|
|
22
17
|
"""
|
|
23
18
|
FunctionOpeninference class.
|
|
24
19
|
"""
|
|
@@ -28,42 +23,3 @@ class FunctionOpeninference(Function):
|
|
|
28
23
|
|
|
29
24
|
self.spec: FunctionSpecOpeninference
|
|
30
25
|
self.status: FunctionStatusOpeninference
|
|
31
|
-
|
|
32
|
-
def export(self) -> str:
|
|
33
|
-
"""
|
|
34
|
-
Export object as a YAML file in the context folder.
|
|
35
|
-
|
|
36
|
-
Returns
|
|
37
|
-
-------
|
|
38
|
-
str
|
|
39
|
-
Exported filepath.
|
|
40
|
-
"""
|
|
41
|
-
# Strip base64 from source at following conditions:
|
|
42
|
-
# - source is local path
|
|
43
|
-
# - base64 is not None
|
|
44
|
-
|
|
45
|
-
# Check source
|
|
46
|
-
source = self.spec.source.get("source")
|
|
47
|
-
if source is not None and has_local_scheme(source):
|
|
48
|
-
# Check base64. If it is set, decode it in a local file
|
|
49
|
-
# save in variable to restore on object after export
|
|
50
|
-
base64 = self.spec.source.pop("base64", None)
|
|
51
|
-
if base64 is not None:
|
|
52
|
-
# Write local file
|
|
53
|
-
src_pth = self._context().root / source
|
|
54
|
-
write_text(src_pth, decode_base64_string(base64))
|
|
55
|
-
|
|
56
|
-
# Export and restore base64, then return
|
|
57
|
-
pth = super().export()
|
|
58
|
-
self.spec.source["base64"] = base64
|
|
59
|
-
return pth
|
|
60
|
-
|
|
61
|
-
return super().export()
|
|
62
|
-
|
|
63
|
-
def _post_create_hook_before_save(self) -> None:
|
|
64
|
-
"""
|
|
65
|
-
Hook method called after the creation of the entity but before saving
|
|
66
|
-
in Core.
|
|
67
|
-
Can be overridden in subclasses to implement custom behavior.
|
|
68
|
-
"""
|
|
69
|
-
self.spec.requirements = RequirementParser().parse(self.spec.requirements)
|
|
@@ -4,17 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
-
from digitalhub.entities.function._base.builder import FunctionBuilder
|
|
8
|
-
|
|
9
7
|
from digitalhub_runtime_python.entities._base.runtime_entity.builder import RuntimeEntityBuilderPython
|
|
10
8
|
from digitalhub_runtime_python.entities._commons.enums import EntityKinds
|
|
9
|
+
from digitalhub_runtime_python.entities.function._base.builder import FunctionBaseBuilder
|
|
11
10
|
from digitalhub_runtime_python.entities.function.python.entity import FunctionPython
|
|
12
11
|
from digitalhub_runtime_python.entities.function.python.spec import FunctionSpecPython, FunctionValidatorPython
|
|
13
12
|
from digitalhub_runtime_python.entities.function.python.status import FunctionStatusPython
|
|
14
|
-
from digitalhub_runtime_python.entities.function.python.utils import source_check, source_post_check
|
|
15
13
|
|
|
16
14
|
|
|
17
|
-
class FunctionPythonBuilder(
|
|
15
|
+
class FunctionPythonBuilder(FunctionBaseBuilder, RuntimeEntityBuilderPython):
|
|
18
16
|
"""
|
|
19
17
|
FunctionPython builder.
|
|
20
18
|
"""
|
|
@@ -24,69 +22,3 @@ class FunctionPythonBuilder(FunctionBuilder, RuntimeEntityBuilderPython):
|
|
|
24
22
|
ENTITY_SPEC_VALIDATOR = FunctionValidatorPython
|
|
25
23
|
ENTITY_STATUS_CLASS = FunctionStatusPython
|
|
26
24
|
ENTITY_KIND = EntityKinds.FUNCTION_PYTHON.value
|
|
27
|
-
|
|
28
|
-
def build(
|
|
29
|
-
self,
|
|
30
|
-
kind: str,
|
|
31
|
-
project: str,
|
|
32
|
-
name: str,
|
|
33
|
-
uuid: str | None = None,
|
|
34
|
-
version: str | None = None,
|
|
35
|
-
description: str | None = None,
|
|
36
|
-
labels: list[str] | None = None,
|
|
37
|
-
embedded: bool = False,
|
|
38
|
-
**kwargs,
|
|
39
|
-
) -> FunctionPython:
|
|
40
|
-
kwargs = source_check(**kwargs)
|
|
41
|
-
obj = super().build(
|
|
42
|
-
kind=kind,
|
|
43
|
-
project=project,
|
|
44
|
-
name=name,
|
|
45
|
-
uuid=uuid,
|
|
46
|
-
version=version,
|
|
47
|
-
description=description,
|
|
48
|
-
labels=labels,
|
|
49
|
-
embedded=embedded,
|
|
50
|
-
**kwargs,
|
|
51
|
-
)
|
|
52
|
-
return source_post_check(obj)
|
|
53
|
-
|
|
54
|
-
def from_dict(self, obj: dict) -> FunctionPython:
|
|
55
|
-
"""
|
|
56
|
-
Create a new object from dictionary.
|
|
57
|
-
|
|
58
|
-
Parameters
|
|
59
|
-
----------
|
|
60
|
-
obj : dict
|
|
61
|
-
Dictionary to create object from.
|
|
62
|
-
|
|
63
|
-
Returns
|
|
64
|
-
-------
|
|
65
|
-
FunctionPython
|
|
66
|
-
Object instance.
|
|
67
|
-
"""
|
|
68
|
-
entity = super().from_dict(obj)
|
|
69
|
-
return source_post_check(entity)
|
|
70
|
-
|
|
71
|
-
def _parse_dict(self, obj: dict) -> dict:
|
|
72
|
-
"""
|
|
73
|
-
Get dictionary and parse it to a valid entity dictionary.
|
|
74
|
-
|
|
75
|
-
Parameters
|
|
76
|
-
----------
|
|
77
|
-
obj : dict
|
|
78
|
-
Dictionary to parse.
|
|
79
|
-
|
|
80
|
-
Returns
|
|
81
|
-
-------
|
|
82
|
-
dict
|
|
83
|
-
A dictionary containing the attributes of the entity instance.
|
|
84
|
-
"""
|
|
85
|
-
# Look for source in spec
|
|
86
|
-
if spec_dict := obj.get("spec", {}):
|
|
87
|
-
# Check source
|
|
88
|
-
source = spec_dict.get("source", {})
|
|
89
|
-
if source:
|
|
90
|
-
spec_dict["source"] = source_check(source=source)["source"]
|
|
91
|
-
|
|
92
|
-
return super()._parse_dict(obj)
|
|
@@ -6,19 +6,14 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
|
-
from
|
|
10
|
-
from digitalhub.utils.generic_utils import decode_base64_string
|
|
11
|
-
from digitalhub.utils.io_utils import write_text
|
|
12
|
-
from digitalhub.utils.uri_utils import has_local_scheme
|
|
13
|
-
|
|
14
|
-
from digitalhub_runtime_python.entities._commons.requirement_parser.parser import RequirementParser
|
|
9
|
+
from digitalhub_runtime_python.entities.function._base.entity import FunctionBaseFunction
|
|
15
10
|
|
|
16
11
|
if typing.TYPE_CHECKING:
|
|
17
12
|
from digitalhub_runtime_python.entities.function.python.spec import FunctionSpecPython
|
|
18
13
|
from digitalhub_runtime_python.entities.function.python.status import FunctionStatusPython
|
|
19
14
|
|
|
20
15
|
|
|
21
|
-
class FunctionPython(
|
|
16
|
+
class FunctionPython(FunctionBaseFunction):
|
|
22
17
|
"""
|
|
23
18
|
FunctionPython class.
|
|
24
19
|
"""
|
|
@@ -28,42 +23,3 @@ class FunctionPython(Function):
|
|
|
28
23
|
|
|
29
24
|
self.spec: FunctionSpecPython
|
|
30
25
|
self.status: FunctionStatusPython
|
|
31
|
-
|
|
32
|
-
def export(self) -> str:
|
|
33
|
-
"""
|
|
34
|
-
Export object as a YAML file in the context folder.
|
|
35
|
-
|
|
36
|
-
Returns
|
|
37
|
-
-------
|
|
38
|
-
str
|
|
39
|
-
Exported filepath.
|
|
40
|
-
"""
|
|
41
|
-
# Strip base64 from source at following conditions:
|
|
42
|
-
# - source is local path
|
|
43
|
-
# - base64 is not None
|
|
44
|
-
|
|
45
|
-
# Check source
|
|
46
|
-
source = self.spec.source.get("source")
|
|
47
|
-
if source is not None and has_local_scheme(source):
|
|
48
|
-
# Check base64. If it is set, decode it in a local file
|
|
49
|
-
# save in variable to restore on object after export
|
|
50
|
-
base64 = self.spec.source.pop("base64", None)
|
|
51
|
-
if base64 is not None:
|
|
52
|
-
# Write local file
|
|
53
|
-
src_pth = self._context().root / source
|
|
54
|
-
write_text(src_pth, decode_base64_string(base64))
|
|
55
|
-
|
|
56
|
-
# Export and restore base64, then return
|
|
57
|
-
pth = super().export()
|
|
58
|
-
self.spec.source["base64"] = base64
|
|
59
|
-
return pth
|
|
60
|
-
|
|
61
|
-
return super().export()
|
|
62
|
-
|
|
63
|
-
def _post_create_hook_before_save(self) -> None:
|
|
64
|
-
"""
|
|
65
|
-
Hook method called after the creation of the entity but before saving
|
|
66
|
-
in Core.
|
|
67
|
-
Can be overridden in subclasses to implement custom behavior.
|
|
68
|
-
"""
|
|
69
|
-
self.spec.requirements = RequirementParser().parse(self.spec.requirements)
|
|
@@ -18,7 +18,7 @@ from digitalhub_runtime_python.entities._commons.enums import Actions
|
|
|
18
18
|
from digitalhub_runtime_python.entities.run._base.utils import get_getters
|
|
19
19
|
|
|
20
20
|
if typing.TYPE_CHECKING:
|
|
21
|
-
from digitalhub.entities.
|
|
21
|
+
from digitalhub.entities._mixin.material.mixin import MaterialEntity
|
|
22
22
|
|
|
23
23
|
from digitalhub_runtime_python.entities.run._base.spec import RunSpecBaseRun
|
|
24
24
|
from digitalhub_runtime_python.entities.run._base.status import RunStatusBaseRun
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: digitalhub-runtime-python
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.0b3
|
|
4
4
|
Summary: Python runtime for DHCore
|
|
5
5
|
Project-URL: Homepage, https://github.com/scc-digitalhub/digitalhub-sdk-runtime-python
|
|
6
6
|
Author-email: Fondazione Bruno Kessler <digitalhub@fbk.eu>, Matteo Martini <mmartini@fbk.eu>
|
{digitalhub_runtime_python-0.16.0b2.dist-info → digitalhub_runtime_python-0.16.0b3.dist-info}/RECORD
RENAMED
|
@@ -2,48 +2,51 @@ digitalhub_runtime_python/__init__.py,sha256=TsiuxnaUlDDpwXUfcjDh0AIZyWsn_vIqh8U
|
|
|
2
2
|
digitalhub_runtime_python/entities/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
3
3
|
digitalhub_runtime_python/entities/_base/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
4
4
|
digitalhub_runtime_python/entities/_base/runtime_entity/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
5
|
-
digitalhub_runtime_python/entities/_base/runtime_entity/builder.py,sha256=
|
|
5
|
+
digitalhub_runtime_python/entities/_base/runtime_entity/builder.py,sha256=THkwWt_iul8fler4KJrHUMKhHtuqYyuk-pRoADqHH0U,3688
|
|
6
6
|
digitalhub_runtime_python/entities/_commons/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
7
7
|
digitalhub_runtime_python/entities/_commons/enums.py,sha256=G24c6GRO5wkZ4hEvk5tq4AG0Q6Mg-vQq6tk0VsMa5T4,1381
|
|
8
|
+
digitalhub_runtime_python/entities/_commons/utils.py,sha256=nmwB-4KoruimUK0NhGvzMeo2P4ulFnr13zfuxgE9ZMs,5714
|
|
8
9
|
digitalhub_runtime_python/entities/_commons/requirement_parser/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
9
10
|
digitalhub_runtime_python/entities/_commons/requirement_parser/enums.py,sha256=plZQOcr83YVYxfStdIFFw8U3BG9u8716H0B8KZUYzBc,540
|
|
10
11
|
digitalhub_runtime_python/entities/_commons/requirement_parser/factory.py,sha256=gh4LxQKrIWbPdvCk-OOXc1igcMfk8UqXYolkCBrznDk,2797
|
|
11
|
-
digitalhub_runtime_python/entities/_commons/requirement_parser/parser.py,sha256=
|
|
12
|
+
digitalhub_runtime_python/entities/_commons/requirement_parser/parser.py,sha256=kcdlFfK0ZDbfuwHVmmMJz4cmzDKAtkeCJLRRl5X4Yiw,4005
|
|
12
13
|
digitalhub_runtime_python/entities/_commons/requirement_parser/modules/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
13
14
|
digitalhub_runtime_python/entities/_commons/requirement_parser/modules/_base.py,sha256=NxzupYHQsEsGZcd8j7Z_XzPcxRGGTUyk5w2DQHOnlbo,348
|
|
14
15
|
digitalhub_runtime_python/entities/_commons/requirement_parser/modules/_conda.py,sha256=usJWlgQt37vypMPFLxDCApmMC5O4yi0kYjSQGjbhy9I,947
|
|
15
16
|
digitalhub_runtime_python/entities/_commons/requirement_parser/modules/_pip.py,sha256=IUQrkhfUpisSKz2IF3ZhxU52Nh_AYzzx_yty9ziABUU,1326
|
|
16
17
|
digitalhub_runtime_python/entities/_commons/requirement_parser/modules/_pyproject.py,sha256=8J7xRGrtMm9JeBj5-_1fY8l-xYfjP3k3ZkUtRSU9Ta8,988
|
|
17
18
|
digitalhub_runtime_python/entities/function/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
19
|
+
digitalhub_runtime_python/entities/function/_base/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
20
|
+
digitalhub_runtime_python/entities/function/_base/builder.py,sha256=JRwF-Q7SqQDCPKIhhg9Clz6efUvJY31MWV3kk1J0EAc,1280
|
|
21
|
+
digitalhub_runtime_python/entities/function/_base/entity.py,sha256=TMSCo8n1xBhGZ3iC3ggs2siBwEkl4FkTu5ETa6A_33g,3981
|
|
18
22
|
digitalhub_runtime_python/entities/function/guardrail/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
19
|
-
digitalhub_runtime_python/entities/function/guardrail/builder.py,sha256=
|
|
20
|
-
digitalhub_runtime_python/entities/function/guardrail/entity.py,sha256=
|
|
23
|
+
digitalhub_runtime_python/entities/function/guardrail/builder.py,sha256=qCymqxCGWC5T0jcR6kZIcOpeRV58TvAKRrdwLT4B5Lw,1113
|
|
24
|
+
digitalhub_runtime_python/entities/function/guardrail/entity.py,sha256=WY3yE2cs4XP1riAj4P3O1krmEhgI-cGWQ3yWVGdwPgs,746
|
|
21
25
|
digitalhub_runtime_python/entities/function/guardrail/models.py,sha256=ZZUb9RWVFO41Hr4ns1ITL02eODfB_TKyAoq3cGJrZMQ,340
|
|
22
26
|
digitalhub_runtime_python/entities/function/guardrail/spec.py,sha256=974KDiSH1UNmSVcNCj_qfWvWLQAeYRc8UcYWpOqIHJg,1676
|
|
23
27
|
digitalhub_runtime_python/entities/function/guardrail/status.py,sha256=tVBsETnnbVBaR1yvJ1nXizkbTTQ9flRg29TVrucwgYA,314
|
|
24
28
|
digitalhub_runtime_python/entities/function/hydra/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
25
|
-
digitalhub_runtime_python/entities/function/hydra/builder.py,sha256=
|
|
26
|
-
digitalhub_runtime_python/entities/function/hydra/entity.py,sha256=
|
|
29
|
+
digitalhub_runtime_python/entities/function/hydra/builder.py,sha256=JGgLWe-2Yi908AFhL_Q3pWcNoa2v1Dax_e7VgjuNWB8,1346
|
|
30
|
+
digitalhub_runtime_python/entities/function/hydra/entity.py,sha256=U1h2H8UVDPskpsttXcuzdo3IwSkeFOC1G8qh72g97hY,714
|
|
27
31
|
digitalhub_runtime_python/entities/function/hydra/models.py,sha256=DXQa9DTnHw_YAos2lfcNPFL2LpeWy0VAqa5s7joWflI,1155
|
|
28
32
|
digitalhub_runtime_python/entities/function/hydra/spec.py,sha256=n0meR5mUz6dIzpoa76Zfm6ezKxUHeOKezOXjpd0qlLU,1630
|
|
29
33
|
digitalhub_runtime_python/entities/function/hydra/status.py,sha256=O26R7uqJLRZ_UHrnTgiS7hsmdfHOho1szNrK9lITSEI,306
|
|
30
|
-
digitalhub_runtime_python/entities/function/hydra/utils.py,sha256=
|
|
34
|
+
digitalhub_runtime_python/entities/function/hydra/utils.py,sha256=wd8Hx_rQzoYjMXuSyJKbX3D5JqXci1OUcTafu030g7I,5570
|
|
31
35
|
digitalhub_runtime_python/entities/function/openinference/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
32
|
-
digitalhub_runtime_python/entities/function/openinference/builder.py,sha256
|
|
33
|
-
digitalhub_runtime_python/entities/function/openinference/entity.py,sha256=
|
|
36
|
+
digitalhub_runtime_python/entities/function/openinference/builder.py,sha256=jYGi-Qol5Vreyubd_MGB3hG83Hfv75sVJt2evHTtKeo,1177
|
|
37
|
+
digitalhub_runtime_python/entities/function/openinference/entity.py,sha256=43KLWGd-x9Vq7oTeiqXISmelWcBXoLGA_a8TYgwUu7Q,778
|
|
34
38
|
digitalhub_runtime_python/entities/function/openinference/models.py,sha256=qMsjy37P8XVepwx5WHRcmGPuJQ-rsrqYw2x_czoa6G4,887
|
|
35
39
|
digitalhub_runtime_python/entities/function/openinference/spec.py,sha256=bqORpqG6Uun_LcZUo0iFG-cu1aQzLkB2WUdHPy9yYc8,2047
|
|
36
40
|
digitalhub_runtime_python/entities/function/openinference/status.py,sha256=mfvAdnKcr3TUbM42AELirQd6Wr-06TPflkYFWVZEv80,322
|
|
37
41
|
digitalhub_runtime_python/entities/function/python/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
38
|
-
digitalhub_runtime_python/entities/function/python/builder.py,sha256=
|
|
39
|
-
digitalhub_runtime_python/entities/function/python/entity.py,sha256=
|
|
42
|
+
digitalhub_runtime_python/entities/function/python/builder.py,sha256=4ezReSC-91QD8UGPwL96NR39JuqucPPjrUaiZ7Ix-4g,1052
|
|
43
|
+
digitalhub_runtime_python/entities/function/python/entity.py,sha256=P62w_UKVfFzCGlKD4d-yneWiTN_P9CQTj8PQ3kjb7Ks,722
|
|
40
44
|
digitalhub_runtime_python/entities/function/python/models.py,sha256=pCqGJ1TSZ8-C4jhzzLL4DzZwi7jynxNUvsdX3mYV09M,1001
|
|
41
45
|
digitalhub_runtime_python/entities/function/python/spec.py,sha256=6TkwV0kGVryvZmvMY12RzfsTzw4D2Pm43dRNi3IvGy0,1428
|
|
42
46
|
digitalhub_runtime_python/entities/function/python/status.py,sha256=XK3KPKovCRiMfEFzFeCzaVkoQyuwfci9nI2JzYxCIec,308
|
|
43
|
-
digitalhub_runtime_python/entities/function/python/utils.py,sha256=mtSvxugeq45ylFR44P79AuErWsAVAYCRSM5sF8X3d6g,4382
|
|
44
47
|
digitalhub_runtime_python/entities/run/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
45
48
|
digitalhub_runtime_python/entities/run/_base/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
|
|
46
|
-
digitalhub_runtime_python/entities/run/_base/entity.py,sha256=
|
|
49
|
+
digitalhub_runtime_python/entities/run/_base/entity.py,sha256=BusdxsgFU6pTwxawOodRGqAr_26h0RFBl6_8A2UmVDQ,6130
|
|
47
50
|
digitalhub_runtime_python/entities/run/_base/spec.py,sha256=UevGoyMV_IbriCIOQ4IxRG-HWBW-Ul0l9Ftgm8tWFcs,2532
|
|
48
51
|
digitalhub_runtime_python/entities/run/_base/status.py,sha256=G_Dw5j590Ejk75YwS5eDKqaU6AqhpHKiHbS_IlMts8Y,817
|
|
49
52
|
digitalhub_runtime_python/entities/run/_base/utils.py,sha256=GWHtWUFJwMa7LNnYM6v8MCpLoEmUl9msO5coUqfz7Ig,1117
|
|
@@ -156,8 +159,8 @@ digitalhub_runtime_python/utils/configuration.py,sha256=BhrHFsvlCcAHA1hfmx7b5lUR
|
|
|
156
159
|
digitalhub_runtime_python/utils/inputs.py,sha256=c-dU61jHXrTd-5XJt4LacjfDzi_vWZFKwuJCbqAGdJQ,5806
|
|
157
160
|
digitalhub_runtime_python/utils/outputs.py,sha256=irGUqy43F26NC1_ruH831NDyDTIVQHwIf15oXpR-q2M,9571
|
|
158
161
|
digitalhub_runtime_python/utils/utils.py,sha256=qO-wh-9qJFvoJnWIWNeajtFQuBSYw3xhCI3JqV9gVHE,1936
|
|
159
|
-
digitalhub_runtime_python-0.16.
|
|
160
|
-
digitalhub_runtime_python-0.16.
|
|
161
|
-
digitalhub_runtime_python-0.16.
|
|
162
|
-
digitalhub_runtime_python-0.16.
|
|
163
|
-
digitalhub_runtime_python-0.16.
|
|
162
|
+
digitalhub_runtime_python-0.16.0b3.dist-info/METADATA,sha256=pCj_2StpGdYhl_MaU50S2a3AksLkzpHKTt9CTddiCfQ,17080
|
|
163
|
+
digitalhub_runtime_python-0.16.0b3.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
164
|
+
digitalhub_runtime_python-0.16.0b3.dist-info/licenses/AUTHORS,sha256=iDleK_2EAMmh0o8Te_E9mdXQCP4rBfFr9dW9d0-pCno,301
|
|
165
|
+
digitalhub_runtime_python-0.16.0b3.dist-info/licenses/LICENSE,sha256=z3xQCHfGmTnigfoUe3uidW_GUSVeFBdos30w9VNTRec,11361
|
|
166
|
+
digitalhub_runtime_python-0.16.0b3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|