digitalhub-runtime-python 0.14.2__py3-none-any.whl → 0.15.0__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/__init__.py +59 -12
- digitalhub_runtime_python/entities/_base/runtime_entity/builder.py +56 -0
- digitalhub_runtime_python/entities/_commons/enums.py +12 -0
- digitalhub_runtime_python/entities/_commons/requirement_parser/enums.py +27 -0
- digitalhub_runtime_python/entities/_commons/requirement_parser/factory.py +75 -0
- digitalhub_runtime_python/entities/_commons/requirement_parser/modules/_base.py +14 -0
- digitalhub_runtime_python/entities/_commons/requirement_parser/modules/_conda.py +38 -0
- digitalhub_runtime_python/entities/_commons/requirement_parser/modules/_pip.py +43 -0
- digitalhub_runtime_python/entities/_commons/requirement_parser/modules/_pyproject.py +41 -0
- digitalhub_runtime_python/entities/_commons/requirement_parser/parser.py +96 -0
- digitalhub_runtime_python/entities/function/guardrail/builder.py +93 -0
- digitalhub_runtime_python/entities/function/guardrail/entity.py +69 -0
- digitalhub_runtime_python/entities/function/guardrail/models.py +15 -0
- digitalhub_runtime_python/entities/function/guardrail/spec.py +58 -0
- digitalhub_runtime_python/entities/function/guardrail/status.py +13 -0
- digitalhub_runtime_python/entities/function/openinference/builder.py +93 -0
- digitalhub_runtime_python/entities/function/openinference/entity.py +69 -0
- digitalhub_runtime_python/entities/function/openinference/models.py +46 -0
- digitalhub_runtime_python/entities/function/openinference/spec.py +69 -0
- digitalhub_runtime_python/entities/function/openinference/status.py +13 -0
- digitalhub_runtime_python/entities/function/python/builder.py +4 -8
- digitalhub_runtime_python/entities/function/python/entity.py +12 -14
- digitalhub_runtime_python/entities/function/python/models.py +1 -1
- digitalhub_runtime_python/entities/function/python/spec.py +3 -3
- digitalhub_runtime_python/entities/function/python/utils.py +20 -11
- digitalhub_runtime_python/entities/run/_base/entity.py +11 -63
- digitalhub_runtime_python/entities/run/_base/spec.py +20 -33
- digitalhub_runtime_python/entities/run/guardrail_build/builder.py +28 -0
- digitalhub_runtime_python/entities/run/guardrail_build/entity.py +25 -0
- digitalhub_runtime_python/entities/run/guardrail_build/spec.py +70 -0
- digitalhub_runtime_python/entities/run/guardrail_build/status.py +13 -0
- digitalhub_runtime_python/entities/run/guardrail_serve/builder.py +28 -0
- digitalhub_runtime_python/entities/run/guardrail_serve/entity.py +25 -0
- digitalhub_runtime_python/entities/run/guardrail_serve/spec.py +76 -0
- digitalhub_runtime_python/entities/run/guardrail_serve/status.py +13 -0
- digitalhub_runtime_python/entities/run/openinference_build/__init__.py +3 -0
- digitalhub_runtime_python/entities/run/openinference_build/builder.py +28 -0
- digitalhub_runtime_python/entities/run/openinference_build/entity.py +25 -0
- digitalhub_runtime_python/entities/run/openinference_build/spec.py +76 -0
- digitalhub_runtime_python/entities/run/openinference_build/status.py +13 -0
- digitalhub_runtime_python/entities/run/openinference_serve/__init__.py +3 -0
- digitalhub_runtime_python/entities/run/openinference_serve/builder.py +28 -0
- digitalhub_runtime_python/entities/run/openinference_serve/entity.py +25 -0
- digitalhub_runtime_python/entities/run/openinference_serve/spec.py +82 -0
- digitalhub_runtime_python/entities/run/openinference_serve/status.py +13 -0
- digitalhub_runtime_python/entities/run/python_build/__init__.py +3 -0
- digitalhub_runtime_python/entities/run/{build → python_build}/builder.py +3 -3
- digitalhub_runtime_python/entities/run/python_build/entity.py +25 -0
- digitalhub_runtime_python/entities/run/python_job/__init__.py +3 -0
- digitalhub_runtime_python/entities/run/{job → python_job}/builder.py +3 -3
- digitalhub_runtime_python/entities/run/python_job/entity.py +69 -0
- digitalhub_runtime_python/entities/run/python_job/spec.py +68 -0
- digitalhub_runtime_python/entities/run/python_serve/__init__.py +3 -0
- digitalhub_runtime_python/entities/run/{serve → python_serve}/builder.py +3 -3
- digitalhub_runtime_python/entities/run/python_serve/entity.py +75 -0
- digitalhub_runtime_python/entities/task/guardrail_build/__init__.py +3 -0
- digitalhub_runtime_python/entities/task/guardrail_build/builder.py +28 -0
- digitalhub_runtime_python/entities/task/guardrail_build/entity.py +25 -0
- digitalhub_runtime_python/entities/task/guardrail_build/spec.py +42 -0
- digitalhub_runtime_python/entities/task/{job/models.py → guardrail_build/status.py} +3 -6
- digitalhub_runtime_python/entities/task/guardrail_serve/__init__.py +3 -0
- digitalhub_runtime_python/entities/task/guardrail_serve/builder.py +28 -0
- digitalhub_runtime_python/entities/task/guardrail_serve/entity.py +25 -0
- digitalhub_runtime_python/entities/task/guardrail_serve/spec.py +54 -0
- digitalhub_runtime_python/entities/task/guardrail_serve/status.py +13 -0
- digitalhub_runtime_python/entities/task/openinference_build/__init__.py +3 -0
- digitalhub_runtime_python/entities/task/openinference_build/builder.py +28 -0
- digitalhub_runtime_python/entities/task/openinference_build/entity.py +25 -0
- digitalhub_runtime_python/entities/task/openinference_build/spec.py +42 -0
- digitalhub_runtime_python/entities/task/openinference_build/status.py +13 -0
- digitalhub_runtime_python/entities/task/openinference_serve/__init__.py +3 -0
- digitalhub_runtime_python/entities/task/openinference_serve/builder.py +28 -0
- digitalhub_runtime_python/entities/task/openinference_serve/entity.py +25 -0
- digitalhub_runtime_python/entities/task/openinference_serve/spec.py +54 -0
- digitalhub_runtime_python/entities/task/openinference_serve/status.py +13 -0
- digitalhub_runtime_python/entities/task/python_build/__init__.py +3 -0
- digitalhub_runtime_python/entities/task/{build → python_build}/builder.py +3 -3
- digitalhub_runtime_python/entities/task/python_build/entity.py +25 -0
- digitalhub_runtime_python/entities/task/{build → python_build}/spec.py +7 -17
- digitalhub_runtime_python/entities/task/python_job/__init__.py +3 -0
- digitalhub_runtime_python/entities/task/{job → python_job}/builder.py +3 -3
- digitalhub_runtime_python/entities/task/python_job/entity.py +25 -0
- digitalhub_runtime_python/entities/task/python_serve/__init__.py +3 -0
- digitalhub_runtime_python/entities/task/{serve → python_serve}/builder.py +3 -3
- digitalhub_runtime_python/entities/task/python_serve/entity.py +25 -0
- digitalhub_runtime_python/entities/task/{serve → python_serve}/spec.py +9 -19
- digitalhub_runtime_python/runtimes/builder.py +25 -2
- digitalhub_runtime_python/runtimes/runtime.py +31 -55
- digitalhub_runtime_python/utils/configuration.py +247 -109
- digitalhub_runtime_python/utils/inputs.py +21 -15
- digitalhub_runtime_python/utils/outputs.py +28 -32
- {digitalhub_runtime_python-0.14.2.dist-info → digitalhub_runtime_python-0.15.0.dist-info}/METADATA +10 -5
- digitalhub_runtime_python-0.15.0.dist-info/RECORD +125 -0
- {digitalhub_runtime_python-0.14.2.dist-info → digitalhub_runtime_python-0.15.0.dist-info}/WHEEL +1 -1
- digitalhub_runtime_python/entities/run/_base/builder.py +0 -25
- digitalhub_runtime_python/entities/run/build/entity.py +0 -36
- digitalhub_runtime_python/entities/run/job/entity.py +0 -36
- digitalhub_runtime_python/entities/run/job/spec.py +0 -15
- digitalhub_runtime_python/entities/run/serve/entity.py +0 -36
- digitalhub_runtime_python/entities/task/build/entity.py +0 -36
- digitalhub_runtime_python/entities/task/job/entity.py +0 -36
- digitalhub_runtime_python/entities/task/serve/entity.py +0 -36
- digitalhub_runtime_python-0.14.2.dist-info/RECORD +0 -66
- /digitalhub_runtime_python/entities/{run/build → _commons/requirement_parser}/__init__.py +0 -0
- /digitalhub_runtime_python/entities/{run/job → _commons/requirement_parser/modules}/__init__.py +0 -0
- /digitalhub_runtime_python/entities/{run/serve → function/guardrail}/__init__.py +0 -0
- /digitalhub_runtime_python/entities/{task/build → function/openinference}/__init__.py +0 -0
- /digitalhub_runtime_python/entities/{task/job → run/guardrail_build}/__init__.py +0 -0
- /digitalhub_runtime_python/entities/{task/serve → run/guardrail_serve}/__init__.py +0 -0
- /digitalhub_runtime_python/entities/run/{build → python_build}/spec.py +0 -0
- /digitalhub_runtime_python/entities/run/{build → python_build}/status.py +0 -0
- /digitalhub_runtime_python/entities/run/{job → python_job}/status.py +0 -0
- /digitalhub_runtime_python/entities/run/{serve → python_serve}/spec.py +0 -0
- /digitalhub_runtime_python/entities/run/{serve → python_serve}/status.py +0 -0
- /digitalhub_runtime_python/entities/task/{build → python_build}/status.py +0 -0
- /digitalhub_runtime_python/entities/task/{job → python_job}/spec.py +0 -0
- /digitalhub_runtime_python/entities/task/{job → python_job}/status.py +0 -0
- /digitalhub_runtime_python/entities/task/{serve → python_serve}/status.py +0 -0
- {digitalhub_runtime_python-0.14.2.dist-info → digitalhub_runtime_python-0.15.0.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub_runtime_python-0.14.2.dist-info → digitalhub_runtime_python-0.15.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,28 +2,75 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
from digitalhub_runtime_python.entities._commons.enums import EntityKinds
|
|
5
|
+
from digitalhub_runtime_python.entities.function.guardrail.builder import FunctionGuardrailBuilder
|
|
6
|
+
from digitalhub_runtime_python.entities.function.openinference.builder import FunctionOpeninferenceBuilder
|
|
5
7
|
from digitalhub_runtime_python.entities.function.python.builder import FunctionPythonBuilder
|
|
6
|
-
from digitalhub_runtime_python.entities.run.
|
|
7
|
-
from digitalhub_runtime_python.entities.run.
|
|
8
|
-
from digitalhub_runtime_python.entities.run.
|
|
9
|
-
from digitalhub_runtime_python.entities.
|
|
10
|
-
from digitalhub_runtime_python.entities.
|
|
11
|
-
from digitalhub_runtime_python.entities.
|
|
8
|
+
from digitalhub_runtime_python.entities.run.guardrail_build.builder import RunGuardrailRunBuildBuilder
|
|
9
|
+
from digitalhub_runtime_python.entities.run.guardrail_serve.builder import RunGuardrailRunServeBuilder
|
|
10
|
+
from digitalhub_runtime_python.entities.run.openinference_build.builder import RunOpeninferenceRunBuildBuilder
|
|
11
|
+
from digitalhub_runtime_python.entities.run.openinference_serve.builder import RunOpeninferenceRunServeBuilder
|
|
12
|
+
from digitalhub_runtime_python.entities.run.python_build.builder import RunPythonRunBuildBuilder
|
|
13
|
+
from digitalhub_runtime_python.entities.run.python_job.builder import RunPythonRunJobBuilder
|
|
14
|
+
from digitalhub_runtime_python.entities.run.python_serve.builder import RunPythonRunServeBuilder
|
|
15
|
+
from digitalhub_runtime_python.entities.task.guardrail_build.builder import TaskGuardrailBuildBuilder
|
|
16
|
+
from digitalhub_runtime_python.entities.task.guardrail_serve.builder import TaskGuardrailServeBuilder
|
|
17
|
+
from digitalhub_runtime_python.entities.task.openinference_build.builder import TaskOpeninferenceBuildBuilder
|
|
18
|
+
from digitalhub_runtime_python.entities.task.openinference_serve.builder import TaskOpeninferenceServeBuilder
|
|
19
|
+
from digitalhub_runtime_python.entities.task.python_build.builder import TaskPythonBuildBuilder
|
|
20
|
+
from digitalhub_runtime_python.entities.task.python_job.builder import TaskPythonJobBuilder
|
|
21
|
+
from digitalhub_runtime_python.entities.task.python_serve.builder import TaskPythonServeBuilder
|
|
12
22
|
from digitalhub_runtime_python.utils.utils import handler
|
|
13
23
|
|
|
14
24
|
entity_builders = (
|
|
25
|
+
(EntityKinds.FUNCTION_GUARDRAIL.value, FunctionGuardrailBuilder),
|
|
26
|
+
(EntityKinds.FUNCTION_OPENINFERENCE.value, FunctionOpeninferenceBuilder),
|
|
15
27
|
(EntityKinds.FUNCTION_PYTHON.value, FunctionPythonBuilder),
|
|
16
|
-
(EntityKinds.
|
|
17
|
-
(EntityKinds.
|
|
18
|
-
(EntityKinds.
|
|
28
|
+
(EntityKinds.RUN_GUARDRAIL_BUILD.value, RunGuardrailRunBuildBuilder),
|
|
29
|
+
(EntityKinds.RUN_GUARDRAIL_SERVE.value, RunGuardrailRunServeBuilder),
|
|
30
|
+
(EntityKinds.RUN_OPENINFERENCE_BUILD.value, RunOpeninferenceRunBuildBuilder),
|
|
31
|
+
(EntityKinds.RUN_OPENINFERENCE_SERVE.value, RunOpeninferenceRunServeBuilder),
|
|
19
32
|
(EntityKinds.RUN_PYTHON_BUILD.value, RunPythonRunBuildBuilder),
|
|
20
33
|
(EntityKinds.RUN_PYTHON_JOB.value, RunPythonRunJobBuilder),
|
|
21
34
|
(EntityKinds.RUN_PYTHON_SERVE.value, RunPythonRunServeBuilder),
|
|
35
|
+
(EntityKinds.TASK_GUARDRAIL_BUILD.value, TaskGuardrailBuildBuilder),
|
|
36
|
+
(EntityKinds.TASK_GUARDRAIL_SERVE.value, TaskGuardrailServeBuilder),
|
|
37
|
+
(EntityKinds.TASK_OPENINFERENCE_BUILD.value, TaskOpeninferenceBuildBuilder),
|
|
38
|
+
(EntityKinds.TASK_OPENINFERENCE_SERVE.value, TaskOpeninferenceServeBuilder),
|
|
39
|
+
(EntityKinds.TASK_PYTHON_BUILD.value, TaskPythonBuildBuilder),
|
|
40
|
+
(EntityKinds.TASK_PYTHON_JOB.value, TaskPythonJobBuilder),
|
|
41
|
+
(EntityKinds.TASK_PYTHON_SERVE.value, TaskPythonServeBuilder),
|
|
22
42
|
)
|
|
23
43
|
|
|
24
44
|
try:
|
|
25
|
-
from digitalhub_runtime_python.runtimes.builder import
|
|
45
|
+
from digitalhub_runtime_python.runtimes.builder import (
|
|
46
|
+
RuntimeGuardrailBuilder,
|
|
47
|
+
RuntimeOpeninferenceBuilder,
|
|
48
|
+
RuntimePythonBuilder,
|
|
49
|
+
RuntimePythonJobBuilder,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
runtime_builders = (
|
|
53
|
+
(EntityKinds.FUNCTION_GUARDRAIL.value, RuntimeGuardrailBuilder),
|
|
54
|
+
(EntityKinds.FUNCTION_OPENINFERENCE.value, RuntimeOpeninferenceBuilder),
|
|
55
|
+
(EntityKinds.FUNCTION_PYTHON.value, RuntimePythonBuilder),
|
|
56
|
+
(EntityKinds.RUN_GUARDRAIL_BUILD.value, RuntimeGuardrailBuilder),
|
|
57
|
+
(EntityKinds.RUN_GUARDRAIL_SERVE.value, RuntimeGuardrailBuilder),
|
|
58
|
+
(EntityKinds.RUN_OPENINFERENCE_BUILD.value, RuntimeOpeninferenceBuilder),
|
|
59
|
+
(EntityKinds.RUN_OPENINFERENCE_SERVE.value, RuntimeOpeninferenceBuilder),
|
|
60
|
+
(EntityKinds.RUN_PYTHON_BUILD.value, RuntimePythonBuilder),
|
|
61
|
+
(EntityKinds.RUN_PYTHON_JOB.value, RuntimePythonJobBuilder),
|
|
62
|
+
(EntityKinds.RUN_PYTHON_SERVE.value, RuntimePythonBuilder),
|
|
63
|
+
(EntityKinds.TASK_GUARDRAIL_BUILD.value, RuntimeGuardrailBuilder),
|
|
64
|
+
(EntityKinds.TASK_GUARDRAIL_SERVE.value, RuntimeGuardrailBuilder),
|
|
65
|
+
(EntityKinds.TASK_OPENINFERENCE_BUILD.value, RuntimeOpeninferenceBuilder),
|
|
66
|
+
(EntityKinds.TASK_OPENINFERENCE_SERVE.value, RuntimeOpeninferenceBuilder),
|
|
67
|
+
(EntityKinds.TASK_PYTHON_BUILD.value, RuntimePythonBuilder),
|
|
68
|
+
(EntityKinds.TASK_PYTHON_JOB.value, RuntimePythonJobBuilder),
|
|
69
|
+
(EntityKinds.TASK_PYTHON_SERVE.value, RuntimePythonBuilder),
|
|
70
|
+
)
|
|
71
|
+
except ImportError as e:
|
|
72
|
+
from digitalhub.utils.logger.logger import get_logger
|
|
26
73
|
|
|
27
|
-
|
|
28
|
-
|
|
74
|
+
logger = get_logger(__name__)
|
|
75
|
+
logger.debug(f"Error importing runtime builders: {e}")
|
|
29
76
|
runtime_builders = tuple()
|
|
@@ -44,3 +44,59 @@ class RuntimeEntityBuilderPython(RuntimeEntityBuilder):
|
|
|
44
44
|
),
|
|
45
45
|
]
|
|
46
46
|
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class RuntimeEntityBuilderOpeninference(RuntimeEntityBuilder):
|
|
50
|
+
EXECUTABLE_KIND = EntityKinds.FUNCTION_OPENINFERENCE.value
|
|
51
|
+
TASKS_KINDS = map_actions(
|
|
52
|
+
[
|
|
53
|
+
(
|
|
54
|
+
EntityKinds.TASK_OPENINFERENCE_BUILD.value,
|
|
55
|
+
Actions.BUILD.value,
|
|
56
|
+
),
|
|
57
|
+
(
|
|
58
|
+
EntityKinds.TASK_OPENINFERENCE_SERVE.value,
|
|
59
|
+
Actions.SERVE.value,
|
|
60
|
+
),
|
|
61
|
+
]
|
|
62
|
+
)
|
|
63
|
+
RUN_KINDS = map_actions(
|
|
64
|
+
[
|
|
65
|
+
(
|
|
66
|
+
EntityKinds.RUN_OPENINFERENCE_BUILD.value,
|
|
67
|
+
Actions.BUILD.value,
|
|
68
|
+
),
|
|
69
|
+
(
|
|
70
|
+
EntityKinds.RUN_OPENINFERENCE_SERVE.value,
|
|
71
|
+
Actions.SERVE.value,
|
|
72
|
+
),
|
|
73
|
+
]
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class RuntimeEntityBuilderGuardrail(RuntimeEntityBuilder):
|
|
78
|
+
EXECUTABLE_KIND = EntityKinds.FUNCTION_GUARDRAIL.value
|
|
79
|
+
TASKS_KINDS = map_actions(
|
|
80
|
+
[
|
|
81
|
+
(
|
|
82
|
+
EntityKinds.TASK_GUARDRAIL_BUILD.value,
|
|
83
|
+
Actions.BUILD.value,
|
|
84
|
+
),
|
|
85
|
+
(
|
|
86
|
+
EntityKinds.TASK_GUARDRAIL_SERVE.value,
|
|
87
|
+
Actions.SERVE.value,
|
|
88
|
+
),
|
|
89
|
+
]
|
|
90
|
+
)
|
|
91
|
+
RUN_KINDS = map_actions(
|
|
92
|
+
[
|
|
93
|
+
(
|
|
94
|
+
EntityKinds.RUN_GUARDRAIL_BUILD.value,
|
|
95
|
+
Actions.BUILD.value,
|
|
96
|
+
),
|
|
97
|
+
(
|
|
98
|
+
EntityKinds.RUN_GUARDRAIL_SERVE.value,
|
|
99
|
+
Actions.SERVE.value,
|
|
100
|
+
),
|
|
101
|
+
]
|
|
102
|
+
)
|
|
@@ -20,6 +20,18 @@ class EntityKinds(Enum):
|
|
|
20
20
|
RUN_PYTHON_JOB = "python+job:run"
|
|
21
21
|
RUN_PYTHON_SERVE = "python+serve:run"
|
|
22
22
|
|
|
23
|
+
FUNCTION_OPENINFERENCE = "openinference"
|
|
24
|
+
TASK_OPENINFERENCE_BUILD = "openinference+build"
|
|
25
|
+
TASK_OPENINFERENCE_SERVE = "openinference+serve"
|
|
26
|
+
RUN_OPENINFERENCE_BUILD = "openinference+build:run"
|
|
27
|
+
RUN_OPENINFERENCE_SERVE = "openinference+serve:run"
|
|
28
|
+
|
|
29
|
+
FUNCTION_GUARDRAIL = "guardrail"
|
|
30
|
+
TASK_GUARDRAIL_BUILD = "guardrail+build"
|
|
31
|
+
TASK_GUARDRAIL_SERVE = "guardrail+serve"
|
|
32
|
+
RUN_GUARDRAIL_BUILD = "guardrail+build:run"
|
|
33
|
+
RUN_GUARDRAIL_SERVE = "guardrail+serve:run"
|
|
34
|
+
|
|
23
35
|
|
|
24
36
|
class Actions(Enum):
|
|
25
37
|
"""
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from enum import Enum
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RequirementFormat(Enum):
|
|
9
|
+
"""
|
|
10
|
+
Enum for requirement file formats.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
PIP = "pip"
|
|
14
|
+
PYPROJECT = "pyproject"
|
|
15
|
+
CONDA = "conda"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class RequirementFile(Enum):
|
|
19
|
+
"""
|
|
20
|
+
Enum for requirement file names.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
REQUIREMENTS_TXT = "requirements.txt"
|
|
24
|
+
SETUP_PY = "setup.py"
|
|
25
|
+
PYPROJECT_TOML = "pyproject.toml"
|
|
26
|
+
CONDA_ENV_YAML = "conda.yaml"
|
|
27
|
+
CONDA_ENV_YML = "conda.yml"
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from digitalhub_runtime_python.entities._commons.requirement_parser.enums import RequirementFile, RequirementFormat
|
|
9
|
+
from digitalhub_runtime_python.entities._commons.requirement_parser.modules._base import BaseParser
|
|
10
|
+
from digitalhub_runtime_python.entities._commons.requirement_parser.modules._conda import CondaParser
|
|
11
|
+
from digitalhub_runtime_python.entities._commons.requirement_parser.modules._pip import PipParser
|
|
12
|
+
from digitalhub_runtime_python.entities._commons.requirement_parser.modules._pyproject import PyProjectParser
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class RequirementParserFactory:
|
|
16
|
+
"""
|
|
17
|
+
Factory for requirement parsers.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def get_parser(self, requirements_file: str) -> BaseParser:
|
|
21
|
+
"""
|
|
22
|
+
Get the requirement parser based on the format.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
requirements_file : str
|
|
27
|
+
The path to the requirements file.
|
|
28
|
+
|
|
29
|
+
Returns
|
|
30
|
+
-------
|
|
31
|
+
BaseParser
|
|
32
|
+
The requirement parser.
|
|
33
|
+
"""
|
|
34
|
+
req_type = self._requirements_format(requirements_file)
|
|
35
|
+
match req_type:
|
|
36
|
+
case RequirementFormat.PIP:
|
|
37
|
+
return PipParser()
|
|
38
|
+
case RequirementFormat.PYPROJECT:
|
|
39
|
+
return PyProjectParser()
|
|
40
|
+
case RequirementFormat.CONDA:
|
|
41
|
+
return CondaParser()
|
|
42
|
+
case _:
|
|
43
|
+
raise ValueError(f"No parser found for format: {requirements_file}")
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def _requirements_format(requirements_file: str) -> RequirementFormat:
|
|
47
|
+
"""
|
|
48
|
+
Understand requirements file format.
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
requirements_file : str
|
|
53
|
+
The path to the requirements file.
|
|
54
|
+
|
|
55
|
+
Returns
|
|
56
|
+
-------
|
|
57
|
+
RequirementFormat
|
|
58
|
+
The format of the requirements file (e.g., 'pip', 'pyproject', 'conda').
|
|
59
|
+
"""
|
|
60
|
+
match Path(requirements_file).name:
|
|
61
|
+
case RequirementFile.REQUIREMENTS_TXT.value:
|
|
62
|
+
return RequirementFormat.PIP
|
|
63
|
+
case RequirementFile.SETUP_PY.value:
|
|
64
|
+
return RequirementFormat.PIP
|
|
65
|
+
case RequirementFile.PYPROJECT_TOML.value:
|
|
66
|
+
return RequirementFormat.PYPROJECT
|
|
67
|
+
case RequirementFile.CONDA_ENV_YML.value:
|
|
68
|
+
return RequirementFormat.CONDA
|
|
69
|
+
case RequirementFile.CONDA_ENV_YAML.value:
|
|
70
|
+
return RequirementFormat.CONDA
|
|
71
|
+
case _:
|
|
72
|
+
raise ValueError(
|
|
73
|
+
f"Unsupported requirements file: {Path(requirements_file).name}."
|
|
74
|
+
f" Supported filenames are: {', '.join([f.value for f in RequirementFile])}."
|
|
75
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from abc import abstractmethod
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BaseParser:
|
|
9
|
+
@staticmethod
|
|
10
|
+
@abstractmethod
|
|
11
|
+
def parse_requirements(source: str) -> list[str]:
|
|
12
|
+
"""
|
|
13
|
+
Parses the requirements file and returns a list of dependencies.
|
|
14
|
+
"""
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import yaml
|
|
6
|
+
|
|
7
|
+
from digitalhub_runtime_python.entities._commons.requirement_parser.modules._base import BaseParser
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CondaParser(BaseParser):
|
|
11
|
+
@staticmethod
|
|
12
|
+
def parse_requirements(source: str) -> list[str]:
|
|
13
|
+
"""
|
|
14
|
+
Parse an environment.yml file.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
source : str
|
|
19
|
+
Path to an environment.yml file.
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
list[str]
|
|
24
|
+
A list of requirement strings.
|
|
25
|
+
"""
|
|
26
|
+
requirements = []
|
|
27
|
+
|
|
28
|
+
with open(source, "r") as f:
|
|
29
|
+
data = yaml.safe_load(f)
|
|
30
|
+
|
|
31
|
+
if not data or "dependencies" not in data:
|
|
32
|
+
return requirements
|
|
33
|
+
|
|
34
|
+
for dep in data["dependencies"]:
|
|
35
|
+
if isinstance(dep, dict) and "pip" in dep:
|
|
36
|
+
requirements.extend(dep["pip"])
|
|
37
|
+
|
|
38
|
+
return requirements
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from pip._internal.network.session import PipSession
|
|
6
|
+
from pip._internal.req import parse_requirements as pip_parse
|
|
7
|
+
|
|
8
|
+
from digitalhub_runtime_python.entities._commons.requirement_parser.modules._base import BaseParser
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PipParser(BaseParser):
|
|
12
|
+
@staticmethod
|
|
13
|
+
def parse_requirements(source: str) -> list[str]:
|
|
14
|
+
"""
|
|
15
|
+
Parse a requirements.txt file using pip's internal parser.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
source : str
|
|
20
|
+
Path to a requirements.txt file.
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
list[str]
|
|
25
|
+
A list of requirement strings as they would be understood by pip.
|
|
26
|
+
|
|
27
|
+
Examples
|
|
28
|
+
--------
|
|
29
|
+
>>> requirements = parse_requirements_with_pip("/path/to/requirements.txt")
|
|
30
|
+
>>> print(requirements)
|
|
31
|
+
['numpy>=1.0', 'pandas==2.0.0', 'git+https://github.com/user/repo.git@main']
|
|
32
|
+
"""
|
|
33
|
+
# Parse using pip's internal parser
|
|
34
|
+
session = PipSession()
|
|
35
|
+
parsed = pip_parse(source, session=session)
|
|
36
|
+
|
|
37
|
+
# Extract requirement strings
|
|
38
|
+
requirements = []
|
|
39
|
+
for req in parsed:
|
|
40
|
+
if req.requirement:
|
|
41
|
+
requirements.append(str(req.requirement))
|
|
42
|
+
|
|
43
|
+
return requirements
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
import tomllib
|
|
7
|
+
except ImportError:
|
|
8
|
+
import tomli as tomllib
|
|
9
|
+
|
|
10
|
+
from digitalhub_runtime_python.entities._commons.requirement_parser.modules._base import BaseParser
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PyProjectParser(BaseParser):
|
|
14
|
+
@staticmethod
|
|
15
|
+
def parse_requirements(source: str) -> list[str]:
|
|
16
|
+
"""
|
|
17
|
+
Parse a pyproject.toml file.
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
source : str
|
|
22
|
+
Path to a pyproject.toml file.
|
|
23
|
+
|
|
24
|
+
Returns
|
|
25
|
+
-------
|
|
26
|
+
list[str]
|
|
27
|
+
A list of requirement strings.
|
|
28
|
+
"""
|
|
29
|
+
requirements = []
|
|
30
|
+
|
|
31
|
+
with open(source, "rb") as f:
|
|
32
|
+
data = tomllib.load(f)
|
|
33
|
+
|
|
34
|
+
project = data.get("project", {})
|
|
35
|
+
|
|
36
|
+
# Dependencies
|
|
37
|
+
dependencies = project.get("dependencies", [])
|
|
38
|
+
if isinstance(dependencies, list):
|
|
39
|
+
requirements.extend(dependencies)
|
|
40
|
+
|
|
41
|
+
return requirements
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from pip._internal.operations import freeze
|
|
9
|
+
|
|
10
|
+
from digitalhub_runtime_python.entities._commons.requirement_parser.factory import RequirementParserFactory
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class RequirementParser:
|
|
14
|
+
"""
|
|
15
|
+
A utility class for parsing requirements files using pip's internal parser.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def parse(self, requirements: list[str] | str | None = None) -> list[str] | None:
|
|
19
|
+
"""
|
|
20
|
+
Parse the requirements file.
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
list[str] | None
|
|
25
|
+
A list of requirement strings or None if no requirements are provided.
|
|
26
|
+
"""
|
|
27
|
+
if requirements is None:
|
|
28
|
+
return
|
|
29
|
+
elif isinstance(requirements, str):
|
|
30
|
+
self._validate_path(requirements)
|
|
31
|
+
parser = RequirementParserFactory().get_parser(requirements)
|
|
32
|
+
parsed = parser.parse_requirements(requirements)
|
|
33
|
+
return self.read_installed_packages(parsed)
|
|
34
|
+
return self.read_installed_packages(requirements)
|
|
35
|
+
|
|
36
|
+
def _validate_path(self, path: str) -> None:
|
|
37
|
+
"""
|
|
38
|
+
Validate the provided path.
|
|
39
|
+
"""
|
|
40
|
+
if not Path(path).exists():
|
|
41
|
+
raise FileNotFoundError(f"Requirements file not found: {path}")
|
|
42
|
+
if not Path(path).is_file():
|
|
43
|
+
raise ValueError(f"Provided path is not a file: {path}")
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def read_installed_packages(requirements: list[str] | None = None) -> list[str] | None:
|
|
47
|
+
"""
|
|
48
|
+
Read installed packages in execution context.
|
|
49
|
+
|
|
50
|
+
If requirements is provided, returns only those packages with their
|
|
51
|
+
versions filled in from the environment. Package names without versions
|
|
52
|
+
in the requirements list will have their versions added if found.
|
|
53
|
+
|
|
54
|
+
Parameters
|
|
55
|
+
----------
|
|
56
|
+
requirements : list[str]
|
|
57
|
+
Optional list of package names (e.g., ['pandas', 'torch']) or
|
|
58
|
+
requirements with versions (e.g., ['pandas==2.0.0']).
|
|
59
|
+
|
|
60
|
+
Returns
|
|
61
|
+
-------
|
|
62
|
+
list[str]
|
|
63
|
+
List of installed packages in pip freeze format (e.g., ['numpy==1.24.0', 'pandas==2.0.0']).
|
|
64
|
+
"""
|
|
65
|
+
separators = ["==", ">=", "<=", ">", "<", "~=", "!="]
|
|
66
|
+
|
|
67
|
+
# Build a mapping of normalized package names to their installed versions
|
|
68
|
+
installed_map: dict[str, str] = {}
|
|
69
|
+
for pkg in freeze.freeze():
|
|
70
|
+
# Handle different separators
|
|
71
|
+
for sep in separators:
|
|
72
|
+
if sep in pkg:
|
|
73
|
+
name, version = pkg.split(sep, 1)
|
|
74
|
+
# Normalize package name (lowercase, replace _ with -)
|
|
75
|
+
installed_map[name.lower().replace("_", "-")] = f"{name}{sep}{version}"
|
|
76
|
+
break
|
|
77
|
+
|
|
78
|
+
result = []
|
|
79
|
+
for req in requirements:
|
|
80
|
+
# Check if requirement already has a version specifier
|
|
81
|
+
has_version = any(sep in req for sep in separators)
|
|
82
|
+
|
|
83
|
+
if has_version:
|
|
84
|
+
# Keep as-is if version is already specified
|
|
85
|
+
result.append(req)
|
|
86
|
+
else:
|
|
87
|
+
# Normalize the requirement name for lookup
|
|
88
|
+
normalized_name = req.lower().replace("_", "-")
|
|
89
|
+
if normalized_name in installed_map:
|
|
90
|
+
# Use the installed version
|
|
91
|
+
result.append(installed_map[normalized_name])
|
|
92
|
+
else:
|
|
93
|
+
# Package not found in environment, keep without version
|
|
94
|
+
result.append(req)
|
|
95
|
+
|
|
96
|
+
return result
|
|
@@ -0,0 +1,93 @@
|
|
|
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 RuntimeEntityBuilderGuardrail
|
|
10
|
+
from digitalhub_runtime_python.entities._commons.enums import EntityKinds
|
|
11
|
+
from digitalhub_runtime_python.entities.function.guardrail.entity import FunctionGuardrail
|
|
12
|
+
from digitalhub_runtime_python.entities.function.guardrail.spec import (
|
|
13
|
+
FunctionSpecGuardrail,
|
|
14
|
+
FunctionValidatorGuardrail,
|
|
15
|
+
)
|
|
16
|
+
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
|
+
|
|
19
|
+
|
|
20
|
+
class FunctionGuardrailBuilder(FunctionBuilder, RuntimeEntityBuilderGuardrail):
|
|
21
|
+
"""
|
|
22
|
+
FunctionGuardrail builder.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
ENTITY_CLASS = FunctionGuardrail
|
|
26
|
+
ENTITY_SPEC_CLASS = FunctionSpecGuardrail
|
|
27
|
+
ENTITY_SPEC_VALIDATOR = FunctionValidatorGuardrail
|
|
28
|
+
ENTITY_STATUS_CLASS = FunctionStatusGuardrail
|
|
29
|
+
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
|
+
description: str | None = None,
|
|
38
|
+
labels: list[str] | None = None,
|
|
39
|
+
embedded: bool = False,
|
|
40
|
+
**kwargs,
|
|
41
|
+
) -> FunctionGuardrail:
|
|
42
|
+
kwargs = source_check(**kwargs)
|
|
43
|
+
obj = super().build(
|
|
44
|
+
kind,
|
|
45
|
+
project,
|
|
46
|
+
name,
|
|
47
|
+
uuid,
|
|
48
|
+
description,
|
|
49
|
+
labels,
|
|
50
|
+
embedded,
|
|
51
|
+
**kwargs,
|
|
52
|
+
)
|
|
53
|
+
return source_post_check(obj)
|
|
54
|
+
|
|
55
|
+
def from_dict(self, obj: dict) -> FunctionGuardrail:
|
|
56
|
+
"""
|
|
57
|
+
Create a new object from dictionary.
|
|
58
|
+
|
|
59
|
+
Parameters
|
|
60
|
+
----------
|
|
61
|
+
obj : dict
|
|
62
|
+
Dictionary to create object from.
|
|
63
|
+
|
|
64
|
+
Returns
|
|
65
|
+
-------
|
|
66
|
+
FunctionGuardrail
|
|
67
|
+
Object instance.
|
|
68
|
+
"""
|
|
69
|
+
entity = super().from_dict(obj)
|
|
70
|
+
return source_post_check(entity)
|
|
71
|
+
|
|
72
|
+
def _parse_dict(self, obj: dict) -> dict:
|
|
73
|
+
"""
|
|
74
|
+
Get dictionary and parse it to a valid entity dictionary.
|
|
75
|
+
|
|
76
|
+
Parameters
|
|
77
|
+
----------
|
|
78
|
+
obj : dict
|
|
79
|
+
Dictionary to parse.
|
|
80
|
+
|
|
81
|
+
Returns
|
|
82
|
+
-------
|
|
83
|
+
dict
|
|
84
|
+
A dictionary containing the attributes of the entity instance.
|
|
85
|
+
"""
|
|
86
|
+
# Look for source in spec
|
|
87
|
+
if spec_dict := obj.get("spec", {}):
|
|
88
|
+
# Check source
|
|
89
|
+
source = spec_dict.get("source", {})
|
|
90
|
+
if source:
|
|
91
|
+
spec_dict["source"] = source_check(source=source)["source"]
|
|
92
|
+
|
|
93
|
+
return super()._parse_dict(obj)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import typing
|
|
8
|
+
|
|
9
|
+
from digitalhub.entities.function._base.entity import Function
|
|
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
|
|
15
|
+
|
|
16
|
+
if typing.TYPE_CHECKING:
|
|
17
|
+
from digitalhub_runtime_python.entities.function.guardrail.spec import FunctionSpecGuardrail
|
|
18
|
+
from digitalhub_runtime_python.entities.function.guardrail.status import FunctionStatusGuardrail
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class FunctionGuardrail(Function):
|
|
22
|
+
"""
|
|
23
|
+
FunctionGuardrail class.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
27
|
+
super().__init__(*args, **kwargs)
|
|
28
|
+
|
|
29
|
+
self.spec: FunctionSpecGuardrail
|
|
30
|
+
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)
|