digitalhub-runtime-python 0.7.0b5__tar.gz → 0.8.0__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.7.0b5 → digitalhub_runtime_python-0.8.0}/PKG-INFO +3 -2
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/__init__.py +23 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/_base/runtime_entity/builder.py +22 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/function/python/builder.py +20 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/function/python/entity.py +33 -0
- {digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/function → digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/function/python}/models.py +6 -6
- {digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/function → digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/function/python}/spec.py +6 -5
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/function/python/status.py +9 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/run/__init__.py +0 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/run/python_run/__init__.py +0 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/run/python_run/builder.py +20 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/run/python_run/entity.py +251 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/run/python_run/spec.py +90 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/run/python_run/status.py +25 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/run/python_run/utils.py +34 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/__init__.py +0 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_build/__init__.py +0 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_build/builder.py +20 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_build/entity.py +32 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_build/spec.py +44 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_build/status.py +9 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_job/__init__.py +0 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_job/builder.py +20 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_job/entity.py +32 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_job/spec.py +49 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_job/status.py +9 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_serve/__init__.py +0 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_serve/builder.py +20 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_serve/entity.py +32 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_serve/spec.py +48 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_serve/status.py +9 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/runtimes/__init__.py +0 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/runtimes/builder.py +11 -0
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python/runtimes/runtime.py +5 -8
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python/utils/configuration.py +5 -10
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python/utils/inputs.py +8 -18
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python/utils/nuclio_configuration.py +2 -1
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python/utils/outputs.py +17 -9
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python.egg-info/PKG-INFO +3 -2
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python.egg-info/SOURCES.txt +53 -0
- digitalhub_runtime_python-0.8.0/digitalhub_runtime_python.egg-info/requires.txt +1 -0
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/pyproject.toml +5 -4
- digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/__init__.py +0 -44
- digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/function/status.py +0 -9
- digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/run/spec.py +0 -80
- digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/run/status.py +0 -39
- digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/task/spec.py +0 -75
- digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/task/status.py +0 -21
- digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/runtimes/kind_registry.py +0 -15
- digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python.egg-info/SOURCES.txt +0 -30
- digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python.egg-info/requires.txt +0 -1
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/LICENSE.txt +0 -0
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/README.md +0 -0
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python/entities/__init__.py +0 -0
- {digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/function → digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/_base}/__init__.py +0 -0
- {digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/run → digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/_base/runtime_entity}/__init__.py +0 -0
- {digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/task → digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/function}/__init__.py +0 -0
- {digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/runtimes → digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/function/python}/__init__.py +0 -0
- {digitalhub_runtime_python-0.7.0b5/digitalhub_runtime_python/entities/task → digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_job}/models.py +0 -0
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python/utils/env.py +0 -0
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python/utils/utils.py +0 -0
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python.egg-info/dependency_links.txt +0 -0
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/digitalhub_runtime_python.egg-info/top_level.txt +0 -0
- {digitalhub_runtime_python-0.7.0b5 → digitalhub_runtime_python-0.8.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: digitalhub-runtime-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
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
|
|
@@ -225,9 +225,10 @@ Keywords: data,dataops,kubernetes
|
|
|
225
225
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
226
226
|
Classifier: Programming Language :: Python :: 3.9
|
|
227
227
|
Classifier: Programming Language :: Python :: 3.10
|
|
228
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
228
229
|
Requires-Python: >=3.9
|
|
229
230
|
Description-Content-Type: text/markdown
|
|
230
231
|
License-File: LICENSE.txt
|
|
231
|
-
Requires-Dist: digitalhub[
|
|
232
|
+
Requires-Dist: digitalhub[full]<0.9,>=0.8.0
|
|
232
233
|
|
|
233
234
|
# SDK for DHCore
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub_runtime_python.entities.function.python.builder import FunctionPythonBuilder
|
|
4
|
+
from digitalhub_runtime_python.entities.run.python_run.builder import RunPythonRunBuilder
|
|
5
|
+
from digitalhub_runtime_python.entities.task.python_build.builder import TaskPythonBuildBuilder
|
|
6
|
+
from digitalhub_runtime_python.entities.task.python_job.builder import TaskPythonJobBuilder
|
|
7
|
+
from digitalhub_runtime_python.entities.task.python_serve.builder import TaskPythonServeBuilder
|
|
8
|
+
from digitalhub_runtime_python.utils.utils import handler
|
|
9
|
+
|
|
10
|
+
entity_builders = (
|
|
11
|
+
(FunctionPythonBuilder.ENTITY_KIND, FunctionPythonBuilder),
|
|
12
|
+
(TaskPythonBuildBuilder.ENTITY_KIND, TaskPythonBuildBuilder),
|
|
13
|
+
(TaskPythonJobBuilder.ENTITY_KIND, TaskPythonJobBuilder),
|
|
14
|
+
(TaskPythonServeBuilder.ENTITY_KIND, TaskPythonServeBuilder),
|
|
15
|
+
(RunPythonRunBuilder.ENTITY_KIND, RunPythonRunBuilder),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
from digitalhub_runtime_python.runtimes.builder import RuntimePythonBuilder
|
|
20
|
+
|
|
21
|
+
runtime_builders = ((kind, RuntimePythonBuilder) for kind in FunctionPythonBuilder().get_all_kinds())
|
|
22
|
+
except ImportError:
|
|
23
|
+
runtime_builders = tuple()
|
digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/_base/runtime_entity/builder.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities._base.runtime_entity.builder import RuntimeEntityBuilder
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class RuntimeEntityBuilderPython(RuntimeEntityBuilder):
|
|
7
|
+
EXECUTABLE_KIND = "python"
|
|
8
|
+
TASKS_KINDS = [
|
|
9
|
+
{
|
|
10
|
+
"kind": "python+job",
|
|
11
|
+
"action": "job",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"kind": "python+build",
|
|
15
|
+
"action": "build",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"kind": "python+serve",
|
|
19
|
+
"action": "serve",
|
|
20
|
+
},
|
|
21
|
+
]
|
|
22
|
+
RUN_KIND = "python+run"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub_runtime_python.entities._base.runtime_entity.builder import RuntimeEntityBuilderPython
|
|
4
|
+
from digitalhub_runtime_python.entities.function.python.entity import FunctionPython
|
|
5
|
+
from digitalhub_runtime_python.entities.function.python.spec import FunctionSpecPython, FunctionValidatorPython
|
|
6
|
+
from digitalhub_runtime_python.entities.function.python.status import FunctionStatusPython
|
|
7
|
+
|
|
8
|
+
from digitalhub.entities.function._base.builder import FunctionBuilder
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FunctionPythonBuilder(FunctionBuilder, RuntimeEntityBuilderPython):
|
|
12
|
+
"""
|
|
13
|
+
FunctionPython builder.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
ENTITY_CLASS = FunctionPython
|
|
17
|
+
ENTITY_SPEC_CLASS = FunctionSpecPython
|
|
18
|
+
ENTITY_SPEC_VALIDATOR = FunctionValidatorPython
|
|
19
|
+
ENTITY_STATUS_CLASS = FunctionStatusPython
|
|
20
|
+
ENTITY_KIND = "python"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities.function._base.entity import Function
|
|
6
|
+
|
|
7
|
+
if typing.TYPE_CHECKING:
|
|
8
|
+
from digitalhub_runtime_python.entities.function.python.spec import FunctionSpecPython
|
|
9
|
+
from digitalhub_runtime_python.entities.function.python.status import FunctionStatusPython
|
|
10
|
+
|
|
11
|
+
from digitalhub.entities._base.entity.metadata import Metadata
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class FunctionPython(Function):
|
|
15
|
+
"""
|
|
16
|
+
FunctionPython class.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
project: str,
|
|
22
|
+
name: str,
|
|
23
|
+
uuid: str,
|
|
24
|
+
kind: str,
|
|
25
|
+
metadata: Metadata,
|
|
26
|
+
spec: FunctionSpecPython,
|
|
27
|
+
status: FunctionStatusPython,
|
|
28
|
+
user: str | None = None,
|
|
29
|
+
) -> None:
|
|
30
|
+
super().__init__(project, name, uuid, kind, metadata, spec, status, user)
|
|
31
|
+
|
|
32
|
+
self.spec: FunctionSpecPython
|
|
33
|
+
self.status: FunctionStatusPython
|
|
@@ -2,10 +2,10 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
|
-
from
|
|
6
|
-
from
|
|
7
|
-
from
|
|
8
|
-
from
|
|
5
|
+
from digitalhub.entities.function._base.models import SourceCodeStruct, SourceCodeValidator
|
|
6
|
+
from digitalhub.utils.exceptions import EntityError
|
|
7
|
+
from digitalhub.utils.generic_utils import encode_source, encode_string
|
|
8
|
+
from digitalhub.utils.uri_utils import map_uri_scheme
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class SourceCodeStructPython(SourceCodeStruct):
|
|
@@ -92,9 +92,9 @@ class SourceCodeStructPython(SourceCodeStruct):
|
|
|
92
92
|
return dict_
|
|
93
93
|
|
|
94
94
|
|
|
95
|
-
class
|
|
95
|
+
class SourceCodeValidatorPython(SourceCodeValidator):
|
|
96
96
|
"""
|
|
97
|
-
|
|
97
|
+
SourceCodeValidatorPython validator.
|
|
98
98
|
"""
|
|
99
99
|
|
|
100
100
|
init_function: str = None
|
|
@@ -2,13 +2,14 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import Literal
|
|
4
4
|
|
|
5
|
-
from
|
|
6
|
-
|
|
5
|
+
from digitalhub_runtime_python.entities.function.python.models import SourceCodeStructPython, SourceCodeValidatorPython
|
|
6
|
+
|
|
7
|
+
from digitalhub.entities.function._base.spec import FunctionSpec, FunctionValidator
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
class FunctionSpecPython(FunctionSpec):
|
|
10
11
|
"""
|
|
11
|
-
|
|
12
|
+
FunctionSpecPython specifications.
|
|
12
13
|
"""
|
|
13
14
|
|
|
14
15
|
def __init__(
|
|
@@ -90,9 +91,9 @@ class FunctionSpecPython(FunctionSpec):
|
|
|
90
91
|
return dict_
|
|
91
92
|
|
|
92
93
|
|
|
93
|
-
class
|
|
94
|
+
class FunctionValidatorPython(FunctionValidator, SourceCodeValidatorPython):
|
|
94
95
|
"""
|
|
95
|
-
|
|
96
|
+
FunctionValidatorPython validator.
|
|
96
97
|
"""
|
|
97
98
|
|
|
98
99
|
python_version: Literal["PYTHON3_9", "PYTHON3_10", "PYTHON3_11"]
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub_runtime_python.entities._base.runtime_entity.builder import RuntimeEntityBuilderPython
|
|
4
|
+
from digitalhub_runtime_python.entities.run.python_run.entity import RunPythonRun
|
|
5
|
+
from digitalhub_runtime_python.entities.run.python_run.spec import RunSpecPythonRun, RunValidatorPythonRun
|
|
6
|
+
from digitalhub_runtime_python.entities.run.python_run.status import RunStatusPythonRun
|
|
7
|
+
|
|
8
|
+
from digitalhub.entities.run._base.builder import RunBuilder
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class RunPythonRunBuilder(RunBuilder, RuntimeEntityBuilderPython):
|
|
12
|
+
"""
|
|
13
|
+
RunPythonRunBuilder runer.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
ENTITY_CLASS = RunPythonRun
|
|
17
|
+
ENTITY_SPEC_CLASS = RunSpecPythonRun
|
|
18
|
+
ENTITY_SPEC_VALIDATOR = RunValidatorPythonRun
|
|
19
|
+
ENTITY_STATUS_CLASS = RunStatusPythonRun
|
|
20
|
+
ENTITY_KIND = "python+run"
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
import typing
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import requests
|
|
8
|
+
from digitalhub_runtime_python.entities.run.python_run.utils import get_getter_for_material
|
|
9
|
+
|
|
10
|
+
from digitalhub.entities.run._base.entity import Run
|
|
11
|
+
from digitalhub.entities.utils.state import State
|
|
12
|
+
from digitalhub.entities.utils.utils import get_entity_type_from_key
|
|
13
|
+
from digitalhub.factory.api import get_action_from_task_kind
|
|
14
|
+
from digitalhub.utils.exceptions import EntityError
|
|
15
|
+
from digitalhub.utils.logger import LOGGER
|
|
16
|
+
|
|
17
|
+
if typing.TYPE_CHECKING:
|
|
18
|
+
from digitalhub_runtime_python.entities.run.python_run.spec import RunSpecPythonRun
|
|
19
|
+
from digitalhub_runtime_python.entities.run.python_run.status import RunStatusPythonRun
|
|
20
|
+
|
|
21
|
+
from digitalhub.entities._base.entity.metadata import Metadata
|
|
22
|
+
from digitalhub.entities._base.material.entity import MaterialEntity
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class RunPythonRun(Run):
|
|
26
|
+
"""
|
|
27
|
+
RunPythonRun class.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
project: str,
|
|
33
|
+
uuid: str,
|
|
34
|
+
kind: str,
|
|
35
|
+
metadata: Metadata,
|
|
36
|
+
spec: RunSpecPythonRun,
|
|
37
|
+
status: RunStatusPythonRun,
|
|
38
|
+
user: str | None = None,
|
|
39
|
+
) -> None:
|
|
40
|
+
super().__init__(project, uuid, kind, metadata, spec, status, user)
|
|
41
|
+
|
|
42
|
+
self.spec: RunSpecPythonRun
|
|
43
|
+
self.status: RunStatusPythonRun
|
|
44
|
+
|
|
45
|
+
def _setup_execution(self) -> None:
|
|
46
|
+
"""
|
|
47
|
+
Setup run execution.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
None
|
|
52
|
+
"""
|
|
53
|
+
self.refresh()
|
|
54
|
+
self.spec.inputs = self.inputs(as_dict=True)
|
|
55
|
+
|
|
56
|
+
def wait(self, log_info: bool = True) -> Run:
|
|
57
|
+
"""
|
|
58
|
+
Wait for run to finish.
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
log_info : bool
|
|
63
|
+
If True, log information.
|
|
64
|
+
|
|
65
|
+
Returns
|
|
66
|
+
-------
|
|
67
|
+
Run
|
|
68
|
+
Run object.
|
|
69
|
+
"""
|
|
70
|
+
task_kind = self.spec.task.split("://")[0]
|
|
71
|
+
action = get_action_from_task_kind(self.kind, task_kind)
|
|
72
|
+
|
|
73
|
+
if action == "serve":
|
|
74
|
+
serve_timeout = 300
|
|
75
|
+
start = time.time()
|
|
76
|
+
|
|
77
|
+
while time.time() - start < serve_timeout:
|
|
78
|
+
if log_info:
|
|
79
|
+
LOGGER.info(f"Waiting for run {self.id} to deploy service.")
|
|
80
|
+
|
|
81
|
+
self.refresh()
|
|
82
|
+
if self.status.service is not None:
|
|
83
|
+
if log_info:
|
|
84
|
+
msg = f"Run {self.id} service deployed."
|
|
85
|
+
LOGGER.info(msg)
|
|
86
|
+
return self
|
|
87
|
+
|
|
88
|
+
elif self.status.state == State.ERROR.value:
|
|
89
|
+
if log_info:
|
|
90
|
+
msg = f"Run {self.id} serving failed."
|
|
91
|
+
LOGGER.info(msg)
|
|
92
|
+
return self
|
|
93
|
+
|
|
94
|
+
time.sleep(5)
|
|
95
|
+
|
|
96
|
+
if log_info:
|
|
97
|
+
msg = f"Waiting for run {self.id} service timed out. Check logs for more information."
|
|
98
|
+
LOGGER.info(msg)
|
|
99
|
+
|
|
100
|
+
return self
|
|
101
|
+
|
|
102
|
+
return super().wait(log_info=log_info)
|
|
103
|
+
|
|
104
|
+
def inputs(self, as_dict: bool = False) -> dict:
|
|
105
|
+
"""
|
|
106
|
+
Get inputs passed in spec as objects or as dictionaries.
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
as_dict : bool
|
|
111
|
+
If True, return inputs as dictionaries.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
dict
|
|
116
|
+
Inputs.
|
|
117
|
+
"""
|
|
118
|
+
inputs = {}
|
|
119
|
+
if self.inputs is None:
|
|
120
|
+
return inputs
|
|
121
|
+
|
|
122
|
+
for parameter, key in self.spec.inputs.items():
|
|
123
|
+
entity_type = get_entity_type_from_key(key)
|
|
124
|
+
entity = get_getter_for_material(entity_type)(key)
|
|
125
|
+
if as_dict:
|
|
126
|
+
entity = entity.to_dict()
|
|
127
|
+
inputs[parameter] = entity
|
|
128
|
+
|
|
129
|
+
return inputs
|
|
130
|
+
|
|
131
|
+
def output(
|
|
132
|
+
self,
|
|
133
|
+
output_name: str,
|
|
134
|
+
as_key: bool = False,
|
|
135
|
+
as_dict: bool = False,
|
|
136
|
+
) -> MaterialEntity | dict | str | None:
|
|
137
|
+
"""
|
|
138
|
+
Get run's output by name.
|
|
139
|
+
|
|
140
|
+
Parameters
|
|
141
|
+
----------
|
|
142
|
+
output_name : str
|
|
143
|
+
Key of the result.
|
|
144
|
+
as_key : bool
|
|
145
|
+
If True, return result as key.
|
|
146
|
+
as_dict : bool
|
|
147
|
+
If True, return result as dictionary.
|
|
148
|
+
|
|
149
|
+
Returns
|
|
150
|
+
-------
|
|
151
|
+
Entity | dict | str | None
|
|
152
|
+
Result.
|
|
153
|
+
"""
|
|
154
|
+
return self.outputs(as_key=as_key, as_dict=as_dict).get(output_name)
|
|
155
|
+
|
|
156
|
+
def outputs(
|
|
157
|
+
self,
|
|
158
|
+
as_key: bool = False,
|
|
159
|
+
as_dict: bool = False,
|
|
160
|
+
) -> MaterialEntity | dict | str | None:
|
|
161
|
+
"""
|
|
162
|
+
Get run's outputs.
|
|
163
|
+
|
|
164
|
+
Parameters
|
|
165
|
+
----------
|
|
166
|
+
as_key : bool
|
|
167
|
+
If True, return results as keys.
|
|
168
|
+
as_dict : bool
|
|
169
|
+
If True, return results as dictionaries.
|
|
170
|
+
|
|
171
|
+
Returns
|
|
172
|
+
-------
|
|
173
|
+
dict
|
|
174
|
+
List of output objects.
|
|
175
|
+
"""
|
|
176
|
+
outputs = {}
|
|
177
|
+
if self.status.outputs is None:
|
|
178
|
+
return outputs
|
|
179
|
+
|
|
180
|
+
for parameter, key in self.status.outputs.items():
|
|
181
|
+
entity_type = get_entity_type_from_key(key)
|
|
182
|
+
entity = get_getter_for_material(entity_type)(key)
|
|
183
|
+
if as_key:
|
|
184
|
+
entity = entity.key
|
|
185
|
+
if as_dict:
|
|
186
|
+
entity = entity.to_dict()
|
|
187
|
+
outputs[parameter] = entity
|
|
188
|
+
|
|
189
|
+
return outputs
|
|
190
|
+
|
|
191
|
+
def result(self, result_name: str) -> Any:
|
|
192
|
+
"""
|
|
193
|
+
Get result by name.
|
|
194
|
+
|
|
195
|
+
Parameters
|
|
196
|
+
----------
|
|
197
|
+
result_name : str
|
|
198
|
+
Name of the result.
|
|
199
|
+
|
|
200
|
+
Returns
|
|
201
|
+
-------
|
|
202
|
+
Any
|
|
203
|
+
The result.
|
|
204
|
+
"""
|
|
205
|
+
return self.results().get(result_name)
|
|
206
|
+
|
|
207
|
+
def results(self) -> dict:
|
|
208
|
+
"""
|
|
209
|
+
Get results.
|
|
210
|
+
|
|
211
|
+
Returns
|
|
212
|
+
-------
|
|
213
|
+
dict
|
|
214
|
+
The results.
|
|
215
|
+
"""
|
|
216
|
+
if self.status.results is None:
|
|
217
|
+
return {}
|
|
218
|
+
return self.status.results
|
|
219
|
+
|
|
220
|
+
def invoke(
|
|
221
|
+
self,
|
|
222
|
+
method: str = "POST",
|
|
223
|
+
url: str | None = None,
|
|
224
|
+
**kwargs,
|
|
225
|
+
) -> requests.Response:
|
|
226
|
+
"""
|
|
227
|
+
Invoke run.
|
|
228
|
+
|
|
229
|
+
Parameters
|
|
230
|
+
----------
|
|
231
|
+
method : str
|
|
232
|
+
Method of the request.
|
|
233
|
+
url : str
|
|
234
|
+
URL of the request.
|
|
235
|
+
**kwargs : dict
|
|
236
|
+
Keyword arguments to pass to the request.
|
|
237
|
+
|
|
238
|
+
Returns
|
|
239
|
+
-------
|
|
240
|
+
requests.Response
|
|
241
|
+
Response from service.
|
|
242
|
+
"""
|
|
243
|
+
if self._context().local:
|
|
244
|
+
raise EntityError("Invoke not supported locally.")
|
|
245
|
+
if url is None:
|
|
246
|
+
try:
|
|
247
|
+
url = f"http://{self.status.service.get('url')}"
|
|
248
|
+
except AttributeError:
|
|
249
|
+
msg = "Url not specified and service not found on run status. If a service is deploying, use run.wait() or try again later."
|
|
250
|
+
raise EntityError(msg)
|
|
251
|
+
return requests.request(method=method, url=url, **kwargs)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities.run._base.spec import RunSpec, RunValidator
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class RunSpecPythonRun(RunSpec):
|
|
7
|
+
"""RunSpecPythonRun specifications."""
|
|
8
|
+
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
task: str,
|
|
12
|
+
local_execution: bool = False,
|
|
13
|
+
function: str | None = None,
|
|
14
|
+
node_selector: dict | None = None,
|
|
15
|
+
volumes: list | None = None,
|
|
16
|
+
resources: dict | None = None,
|
|
17
|
+
affinity: dict | None = None,
|
|
18
|
+
tolerations: list | None = None,
|
|
19
|
+
envs: list | None = None,
|
|
20
|
+
secrets: list | None = None,
|
|
21
|
+
profile: str | None = None,
|
|
22
|
+
source: dict | None = None,
|
|
23
|
+
image: str | None = None,
|
|
24
|
+
base_image: str | None = None,
|
|
25
|
+
python_version: str | None = None,
|
|
26
|
+
requirements: list | None = None,
|
|
27
|
+
backoff_limit: int | None = None,
|
|
28
|
+
schedule: str | None = None,
|
|
29
|
+
service_type: str | None = None,
|
|
30
|
+
replicas: int | None = None,
|
|
31
|
+
instructions: dict | None = None,
|
|
32
|
+
inputs: dict | None = None,
|
|
33
|
+
outputs: dict | None = None,
|
|
34
|
+
parameters: dict | None = None,
|
|
35
|
+
**kwargs,
|
|
36
|
+
) -> None:
|
|
37
|
+
super().__init__(
|
|
38
|
+
task,
|
|
39
|
+
local_execution,
|
|
40
|
+
function,
|
|
41
|
+
node_selector,
|
|
42
|
+
volumes,
|
|
43
|
+
resources,
|
|
44
|
+
affinity,
|
|
45
|
+
tolerations,
|
|
46
|
+
envs,
|
|
47
|
+
secrets,
|
|
48
|
+
profile,
|
|
49
|
+
**kwargs,
|
|
50
|
+
)
|
|
51
|
+
self.source = source
|
|
52
|
+
self.image = image
|
|
53
|
+
self.base_image = base_image
|
|
54
|
+
self.python_version = python_version
|
|
55
|
+
self.requirements = requirements
|
|
56
|
+
self.backoff_limit = backoff_limit
|
|
57
|
+
self.schedule = schedule
|
|
58
|
+
self.service_type = service_type
|
|
59
|
+
self.replicas = replicas
|
|
60
|
+
self.instructions = instructions
|
|
61
|
+
self.inputs = inputs
|
|
62
|
+
self.outputs = outputs
|
|
63
|
+
self.parameters = parameters
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class RunValidatorPythonRun(RunValidator):
|
|
67
|
+
"""RunValidatorPythonRun validator."""
|
|
68
|
+
|
|
69
|
+
# Function parameters
|
|
70
|
+
source: dict = None
|
|
71
|
+
image: str = None
|
|
72
|
+
base_image: str = None
|
|
73
|
+
python_version: str = None
|
|
74
|
+
requirements: list = None
|
|
75
|
+
|
|
76
|
+
# Task job
|
|
77
|
+
backoff_limit: int = None
|
|
78
|
+
schedule: str = None
|
|
79
|
+
|
|
80
|
+
# Task serve
|
|
81
|
+
service_type: str = None
|
|
82
|
+
replicas: int = None
|
|
83
|
+
|
|
84
|
+
# Task build
|
|
85
|
+
instructions: list[str] = None
|
|
86
|
+
|
|
87
|
+
# Run parameters
|
|
88
|
+
inputs: dict = None
|
|
89
|
+
outputs: dict = None
|
|
90
|
+
parameters: dict = None
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities.run._base.status import RunStatus
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class RunStatusPythonRun(RunStatus):
|
|
7
|
+
"""
|
|
8
|
+
RunStatusPythonRun status.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
state: str,
|
|
14
|
+
message: str | None = None,
|
|
15
|
+
transitions: list[dict] | None = None,
|
|
16
|
+
k8s: dict | None = None,
|
|
17
|
+
outputs: dict | None = None,
|
|
18
|
+
results: dict | None = None,
|
|
19
|
+
service: dict | None = None,
|
|
20
|
+
**kwargs,
|
|
21
|
+
) -> None:
|
|
22
|
+
super().__init__(state, message, transitions, k8s, **kwargs)
|
|
23
|
+
self.outputs = outputs
|
|
24
|
+
self.results = results
|
|
25
|
+
self.service = service
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Callable
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities.artifact.crud import get_artifact
|
|
6
|
+
from digitalhub.entities.dataitem.crud import get_dataitem
|
|
7
|
+
from digitalhub.entities.model.crud import get_model
|
|
8
|
+
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_getter_for_material(entity_type: str) -> Callable:
|
|
12
|
+
"""
|
|
13
|
+
Return appropriate getter function.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
entity_type : str
|
|
18
|
+
The entity type.
|
|
19
|
+
|
|
20
|
+
Returns
|
|
21
|
+
-------
|
|
22
|
+
Callable
|
|
23
|
+
The getter function.
|
|
24
|
+
"""
|
|
25
|
+
if entity_type == EntityTypes.ARTIFACT.value:
|
|
26
|
+
return get_artifact
|
|
27
|
+
|
|
28
|
+
if entity_type == EntityTypes.DATAITEM.value:
|
|
29
|
+
return get_dataitem
|
|
30
|
+
|
|
31
|
+
if entity_type == EntityTypes.MODEL.value:
|
|
32
|
+
return get_model
|
|
33
|
+
|
|
34
|
+
raise ValueError(f"Unhandled entity type: {entity_type}")
|
|
File without changes
|
digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_build/__init__.py
ADDED
|
File without changes
|
digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_build/builder.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub_runtime_python.entities._base.runtime_entity.builder import RuntimeEntityBuilderPython
|
|
4
|
+
from digitalhub_runtime_python.entities.task.python_build.entity import TaskPythonBuild
|
|
5
|
+
from digitalhub_runtime_python.entities.task.python_build.spec import TaskSpecPythonBuild, TaskValidatorPythonBuild
|
|
6
|
+
from digitalhub_runtime_python.entities.task.python_build.status import TaskStatusPythonBuild
|
|
7
|
+
|
|
8
|
+
from digitalhub.entities.task._base.builder import TaskBuilder
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TaskPythonBuildBuilder(TaskBuilder, RuntimeEntityBuilderPython):
|
|
12
|
+
"""
|
|
13
|
+
TaskPythonBuild builder.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
ENTITY_CLASS = TaskPythonBuild
|
|
17
|
+
ENTITY_SPEC_CLASS = TaskSpecPythonBuild
|
|
18
|
+
ENTITY_SPEC_VALIDATOR = TaskValidatorPythonBuild
|
|
19
|
+
ENTITY_STATUS_CLASS = TaskStatusPythonBuild
|
|
20
|
+
ENTITY_KIND = "python+build"
|
digitalhub_runtime_python-0.8.0/digitalhub_runtime_python/entities/task/python_build/entity.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities.task._base.entity import Task
|
|
6
|
+
|
|
7
|
+
if typing.TYPE_CHECKING:
|
|
8
|
+
from digitalhub_runtime_python.entities.task.python_build.spec import TaskSpecPythonBuild
|
|
9
|
+
from digitalhub_runtime_python.entities.task.python_build.status import TaskStatusPythonBuild
|
|
10
|
+
|
|
11
|
+
from digitalhub.entities._base.entity.metadata import Metadata
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TaskPythonBuild(Task):
|
|
15
|
+
"""
|
|
16
|
+
TaskPythonBuild class.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
project: str,
|
|
22
|
+
uuid: str,
|
|
23
|
+
kind: str,
|
|
24
|
+
metadata: Metadata,
|
|
25
|
+
spec: TaskSpecPythonBuild,
|
|
26
|
+
status: TaskStatusPythonBuild,
|
|
27
|
+
user: str | None = None,
|
|
28
|
+
) -> None:
|
|
29
|
+
super().__init__(project, uuid, kind, metadata, spec, status, user)
|
|
30
|
+
|
|
31
|
+
self.spec: TaskSpecPythonBuild
|
|
32
|
+
self.status: TaskStatusPythonBuild
|