digitalhub-runtime-python 0.8.1__tar.gz → 0.9.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.
Files changed (66) hide show
  1. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/LICENSE.txt +1 -1
  2. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/PKG-INFO +3 -3
  3. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/__init__.py +7 -8
  4. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/_base/runtime_entity/builder.py +27 -0
  5. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/_commons/enums.py +25 -0
  6. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/function/python/builder.py +90 -0
  7. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/function/python/entity.py +67 -0
  8. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/function/python/models.py +49 -0
  9. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/function/python/spec.py +48 -0
  10. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/function/python/utils.py +152 -0
  11. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/run/python_run/builder.py +4 -3
  12. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/run/python_run/entity.py +18 -9
  13. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/run/python_run/spec.py +14 -8
  14. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/run/python_run/utils.py +1 -1
  15. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_build/builder.py +4 -3
  16. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_build/spec.py +12 -8
  17. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_job/builder.py +4 -3
  18. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_job/spec.py +14 -9
  19. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_serve/builder.py +4 -3
  20. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/task/python_serve/spec.py +55 -0
  21. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/runtimes/__init__.py +0 -0
  22. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/runtimes/runtime.py +9 -25
  23. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/utils/configuration.py +181 -0
  24. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/utils/inputs.py +1 -4
  25. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/utils/outputs.py +42 -17
  26. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/utils/utils.py +4 -3
  27. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python.egg-info/PKG-INFO +3 -3
  28. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python.egg-info/SOURCES.txt +3 -1
  29. digitalhub_runtime_python-0.9.0/digitalhub_runtime_python.egg-info/requires.txt +1 -0
  30. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/pyproject.toml +3 -3
  31. digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/_base/runtime_entity/builder.py +0 -22
  32. digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/function/python/builder.py +0 -20
  33. digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/function/python/entity.py +0 -33
  34. digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/function/python/models.py +0 -101
  35. digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/function/python/spec.py +0 -109
  36. digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/task/python_serve/spec.py +0 -48
  37. digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/utils/configuration.py +0 -246
  38. digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/utils/nuclio_configuration.py +0 -99
  39. digitalhub_runtime_python-0.8.1/digitalhub_runtime_python.egg-info/requires.txt +0 -1
  40. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/README.md +0 -0
  41. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/__init__.py +0 -0
  42. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/_base/__init__.py +0 -0
  43. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/_base/runtime_entity/__init__.py +0 -0
  44. {digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/function → digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/_commons}/__init__.py +0 -0
  45. {digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/function/python → digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/function}/__init__.py +0 -0
  46. {digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/run → digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/function/python}/__init__.py +0 -0
  47. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/function/python/status.py +0 -0
  48. {digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/run/python_run → digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/run}/__init__.py +0 -0
  49. {digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/task → digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/run/python_run}/__init__.py +0 -0
  50. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/run/python_run/status.py +0 -0
  51. {digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/task/python_build → digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/task}/__init__.py +0 -0
  52. {digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/task/python_job → digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/task/python_build}/__init__.py +0 -0
  53. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_build/entity.py +2 -2
  54. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_build/status.py +0 -0
  55. {digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/entities/task/python_serve → digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/task/python_job}/__init__.py +0 -0
  56. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_job/entity.py +2 -2
  57. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_job/models.py +0 -0
  58. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_job/status.py +0 -0
  59. {digitalhub_runtime_python-0.8.1/digitalhub_runtime_python/runtimes → digitalhub_runtime_python-0.9.0/digitalhub_runtime_python/entities/task/python_serve}/__init__.py +0 -0
  60. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_serve/entity.py +2 -2
  61. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/entities/task/python_serve/status.py +0 -0
  62. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/runtimes/builder.py +2 -2
  63. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python/utils/env.py +0 -0
  64. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python.egg-info/dependency_links.txt +0 -0
  65. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/digitalhub_runtime_python.egg-info/top_level.txt +0 -0
  66. {digitalhub_runtime_python-0.8.1 → digitalhub_runtime_python-0.9.0}/setup.cfg +0 -0
@@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright [yyyy] [name of copyright owner]
189
+ Copyright 2024 DSLab, Fondazione Bruno Kessler
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: digitalhub-runtime-python
3
- Version: 0.8.1
3
+ Version: 0.9.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
@@ -191,7 +191,7 @@ License: Apache License
191
191
  same "printed page" as the copyright notice for easier
192
192
  identification within third-party archives.
193
193
 
194
- Copyright [yyyy] [name of copyright owner]
194
+ Copyright 2024 DSLab, Fondazione Bruno Kessler
195
195
 
196
196
  Licensed under the Apache License, Version 2.0 (the "License");
197
197
  you may not use this file except in compliance with the License.
@@ -229,6 +229,6 @@ Classifier: Programming Language :: Python :: 3.11
229
229
  Requires-Python: >=3.9
230
230
  Description-Content-Type: text/markdown
231
231
  License-File: LICENSE.txt
232
- Requires-Dist: digitalhub[full]<0.9,>=0.8.0
232
+ Requires-Dist: digitalhub[full]<0.10,>=0.9.0b
233
233
 
234
234
  # SDK for DHCore
@@ -1,5 +1,4 @@
1
- from __future__ import annotations
2
-
1
+ from digitalhub_runtime_python.entities._commons.enums import EntityKinds
3
2
  from digitalhub_runtime_python.entities.function.python.builder import FunctionPythonBuilder
4
3
  from digitalhub_runtime_python.entities.run.python_run.builder import RunPythonRunBuilder
5
4
  from digitalhub_runtime_python.entities.task.python_build.builder import TaskPythonBuildBuilder
@@ -8,16 +7,16 @@ from digitalhub_runtime_python.entities.task.python_serve.builder import TaskPyt
8
7
  from digitalhub_runtime_python.utils.utils import handler
9
8
 
10
9
  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),
10
+ (EntityKinds.FUNCTION_PYTHON.value, FunctionPythonBuilder),
11
+ (EntityKinds.TASK_PYTHON_BUILD.value, TaskPythonBuildBuilder),
12
+ (EntityKinds.TASK_PYTHON_JOB.value, TaskPythonJobBuilder),
13
+ (EntityKinds.TASK_PYTHON_SERVE.value, TaskPythonServeBuilder),
14
+ (EntityKinds.RUN_PYTHON.value, RunPythonRunBuilder),
16
15
  )
17
16
 
18
17
  try:
19
18
  from digitalhub_runtime_python.runtimes.builder import RuntimePythonBuilder
20
19
 
21
- runtime_builders = ((kind, RuntimePythonBuilder) for kind in FunctionPythonBuilder().get_all_kinds())
20
+ runtime_builders = ((kind, RuntimePythonBuilder) for kind in [e.value for e in EntityKinds])
22
21
  except ImportError:
23
22
  runtime_builders = tuple()
@@ -0,0 +1,27 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.runtime_entity.builder import RuntimeEntityBuilder
4
+ from digitalhub.entities.task._base.utils import build_task_actions
5
+
6
+ from digitalhub_runtime_python.entities._commons.enums import EntityKinds, TaskActions
7
+
8
+
9
+ class RuntimeEntityBuilderPython(RuntimeEntityBuilder):
10
+ EXECUTABLE_KIND = EntityKinds.FUNCTION_PYTHON.value
11
+ TASKS_KINDS = build_task_actions(
12
+ [
13
+ (
14
+ EntityKinds.TASK_PYTHON_JOB.value,
15
+ TaskActions.JOB.value,
16
+ ),
17
+ (
18
+ EntityKinds.TASK_PYTHON_BUILD.value,
19
+ TaskActions.BUILD.value,
20
+ ),
21
+ (
22
+ EntityKinds.TASK_PYTHON_SERVE.value,
23
+ TaskActions.SERVE.value,
24
+ ),
25
+ ]
26
+ )
27
+ RUN_KIND = EntityKinds.RUN_PYTHON.value
@@ -0,0 +1,25 @@
1
+ from __future__ import annotations
2
+
3
+ from enum import Enum
4
+
5
+
6
+ class EntityKinds(Enum):
7
+ """
8
+ Entity kinds.
9
+ """
10
+
11
+ FUNCTION_PYTHON = "python"
12
+ TASK_PYTHON_BUILD = "python+build"
13
+ TASK_PYTHON_JOB = "python+job"
14
+ TASK_PYTHON_SERVE = "python+serve"
15
+ RUN_PYTHON = "python+run"
16
+
17
+
18
+ class TaskActions(Enum):
19
+ """
20
+ Task actions.
21
+ """
22
+
23
+ BUILD = "build"
24
+ JOB = "job"
25
+ SERVE = "serve"
@@ -0,0 +1,90 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities.function._base.builder import FunctionBuilder
4
+
5
+ from digitalhub_runtime_python.entities._base.runtime_entity.builder import RuntimeEntityBuilderPython
6
+ from digitalhub_runtime_python.entities._commons.enums import EntityKinds
7
+ from digitalhub_runtime_python.entities.function.python.entity import FunctionPython
8
+ from digitalhub_runtime_python.entities.function.python.spec import FunctionSpecPython, FunctionValidatorPython
9
+ from digitalhub_runtime_python.entities.function.python.status import FunctionStatusPython
10
+ from digitalhub_runtime_python.entities.function.python.utils import source_check, source_post_check
11
+
12
+
13
+ class FunctionPythonBuilder(FunctionBuilder, RuntimeEntityBuilderPython):
14
+ """
15
+ FunctionPython builder.
16
+ """
17
+
18
+ ENTITY_CLASS = FunctionPython
19
+ ENTITY_SPEC_CLASS = FunctionSpecPython
20
+ ENTITY_SPEC_VALIDATOR = FunctionValidatorPython
21
+ ENTITY_STATUS_CLASS = FunctionStatusPython
22
+ ENTITY_KIND = EntityKinds.FUNCTION_PYTHON.value
23
+
24
+ def build(
25
+ self,
26
+ kind: str,
27
+ project: str,
28
+ name: str,
29
+ uuid: str | None = None,
30
+ description: str | None = None,
31
+ labels: list[str] | None = None,
32
+ embedded: bool = False,
33
+ **kwargs,
34
+ ) -> FunctionPython:
35
+ kwargs = source_check(**kwargs)
36
+ obj = super().build(
37
+ kind,
38
+ project,
39
+ name,
40
+ uuid,
41
+ description,
42
+ labels,
43
+ embedded,
44
+ **kwargs,
45
+ )
46
+ return source_post_check(obj)
47
+
48
+ def from_dict(self, obj: dict, validate: bool = True) -> FunctionPython:
49
+ """
50
+ Create a new object from dictionary.
51
+
52
+ Parameters
53
+ ----------
54
+ obj : dict
55
+ Dictionary to create object from.
56
+ validate : bool
57
+ Flag to indicate if arguments must be validated.
58
+
59
+ Returns
60
+ -------
61
+ FunctionPython
62
+ Object instance.
63
+ """
64
+ entity = super().from_dict(obj, validate=validate)
65
+ return source_post_check(entity)
66
+
67
+ def _parse_dict(self, obj: dict, validate: bool = True) -> dict:
68
+ """
69
+ Get dictionary and parse it to a valid entity dictionary.
70
+
71
+ Parameters
72
+ ----------
73
+ entity : str
74
+ Entity type.
75
+ obj : dict
76
+ Dictionary to parse.
77
+
78
+ Returns
79
+ -------
80
+ dict
81
+ A dictionary containing the attributes of the entity instance.
82
+ """
83
+ # Look for source in spec
84
+ if spec_dict := obj.get("spec", {}):
85
+ # Check source
86
+ source = spec_dict.get("source", {})
87
+ if source:
88
+ spec_dict["source"] = source_check(source=source)["source"]
89
+
90
+ return super()._parse_dict(obj, validate=validate)
@@ -0,0 +1,67 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities.function._base.entity import Function
6
+ from digitalhub.utils.generic_utils import decode_base64_string
7
+ from digitalhub.utils.io_utils import write_text
8
+ from digitalhub.utils.uri_utils import has_local_scheme
9
+
10
+ if typing.TYPE_CHECKING:
11
+ from digitalhub.entities._base.entity.metadata import Metadata
12
+
13
+ from digitalhub_runtime_python.entities.function.python.spec import FunctionSpecPython
14
+ from digitalhub_runtime_python.entities.function.python.status import FunctionStatusPython
15
+
16
+
17
+ class FunctionPython(Function):
18
+ """
19
+ FunctionPython class.
20
+ """
21
+
22
+ def __init__(
23
+ self,
24
+ project: str,
25
+ name: str,
26
+ uuid: str,
27
+ kind: str,
28
+ metadata: Metadata,
29
+ spec: FunctionSpecPython,
30
+ status: FunctionStatusPython,
31
+ user: str | None = None,
32
+ ) -> None:
33
+ super().__init__(project, name, uuid, kind, metadata, spec, status, user)
34
+
35
+ self.spec: FunctionSpecPython
36
+ self.status: FunctionStatusPython
37
+
38
+ def export(self) -> str:
39
+ """
40
+ Export object as a YAML file in the context folder.
41
+
42
+ Returns
43
+ -------
44
+ str
45
+ Exported filepath.
46
+ """
47
+ # Strip base64 from source at following conditions:
48
+ # - source is local path
49
+ # - base64 is not None
50
+
51
+ # Check source
52
+ source = self.spec.source.get("source")
53
+ if source is not None and has_local_scheme(source):
54
+ # Check base64. If it is set, decode it in a local file
55
+ # save in variable to restore on object after export
56
+ base64 = self.spec.source.pop("base64", None)
57
+ if base64 is not None:
58
+ # Write local file
59
+ src_pth = self._context().root / source
60
+ write_text(src_pth, decode_base64_string(base64))
61
+
62
+ # Export and restore base64, then return
63
+ pth = super().export()
64
+ self.spec.source["base64"] = base64
65
+ return pth
66
+
67
+ return super().export()
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+
3
+ from enum import Enum
4
+
5
+ from pydantic import BaseModel, ConfigDict, Field
6
+
7
+
8
+ class PythonVersion(Enum):
9
+ """
10
+ Python version supported.
11
+ """
12
+
13
+ PYTHON3_9 = "PYTHON3_9"
14
+ PYTHON3_10 = "PYTHON3_10"
15
+ PYTHON3_11 = "PYTHON3_11"
16
+
17
+
18
+ class Lang(Enum):
19
+ """
20
+ Source code language.
21
+ """
22
+
23
+ PYTHON = "python"
24
+
25
+
26
+ class SourceValidator(BaseModel):
27
+ """
28
+ Source code params.
29
+ """
30
+
31
+ model_config = ConfigDict(use_enum_values=True)
32
+
33
+ source: str = None
34
+ "Pointer to source code."
35
+
36
+ handler: str = None
37
+ "Function entrypoint."
38
+
39
+ init_function: str = None
40
+ """Handler for init function."""
41
+
42
+ code: str = None
43
+ "Source code (plain text)."
44
+
45
+ base64: str = None
46
+ "Source code (base64 encoded)."
47
+
48
+ lang: Lang = Field(default=Lang.PYTHON.value)
49
+ "Source code language (hint)."
@@ -0,0 +1,48 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities.function._base.spec import FunctionSpec, FunctionValidator
4
+
5
+ from digitalhub_runtime_python.entities.function.python.models import PythonVersion, SourceValidator
6
+
7
+
8
+ class FunctionSpecPython(FunctionSpec):
9
+ """
10
+ FunctionSpecPython specifications.
11
+ """
12
+
13
+ def __init__(
14
+ self,
15
+ source: dict | None = None,
16
+ image: str | None = None,
17
+ base_image: str | None = None,
18
+ python_version: str | None = None,
19
+ requirements: list | None = None,
20
+ ) -> None:
21
+ super().__init__()
22
+
23
+ self.image = image
24
+ self.base_image = base_image
25
+ self.python_version = python_version
26
+ self.requirements = requirements
27
+ self.source = source
28
+
29
+
30
+ class FunctionValidatorPython(FunctionValidator):
31
+ """
32
+ FunctionValidatorPython validator.
33
+ """
34
+
35
+ source: SourceValidator
36
+ """Source code validator"""
37
+
38
+ python_version: PythonVersion
39
+ "Python version"
40
+
41
+ image: str = None
42
+ "Image where the function will be executed"
43
+
44
+ base_image: str = None
45
+ "Base image used to build the image where the function will be executed"
46
+
47
+ requirements: list[str] = None
48
+ "Requirements list to be installed in the image where the function will be executed"
@@ -0,0 +1,152 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+ from pathlib import Path
5
+
6
+ from digitalhub.stores.api import get_store
7
+ from digitalhub.utils.exceptions import EntityError
8
+ from digitalhub.utils.file_utils import eval_py_type, eval_zip_type
9
+ from digitalhub.utils.generic_utils import encode_source, encode_string
10
+ from digitalhub.utils.s3_utils import get_s3_bucket
11
+ from digitalhub.utils.uri_utils import has_local_scheme
12
+
13
+ from digitalhub_runtime_python.entities.function.python.models import Lang
14
+
15
+ if typing.TYPE_CHECKING:
16
+ from digitalhub_runtime_python.entities.function.python.entity import FunctionPython
17
+
18
+
19
+ def source_check(**kwargs) -> dict:
20
+ """
21
+ Check source code.
22
+
23
+ Parameters
24
+ ----------
25
+ **kwargs
26
+ Keyword arguments.
27
+
28
+ Returns
29
+ -------
30
+ dict
31
+ Checked source.
32
+ """
33
+ source: dict = kwargs.pop("source", None)
34
+ code_src = kwargs.pop("code_src", None)
35
+ code = kwargs.pop("code", None)
36
+ base64 = kwargs.pop("base64", None)
37
+ handler = kwargs.pop("handler", None)
38
+ init_function = kwargs.pop("init_function", None)
39
+ lang = kwargs.pop("lang", None)
40
+
41
+ if source is not None:
42
+ code_src = source.pop("source", None)
43
+ code = source.pop("code", None)
44
+ base64 = source.pop("base64", None)
45
+ handler = source.pop("handler", None)
46
+ init_function = source.pop("init_function", None)
47
+ lang = source.pop("lang", None)
48
+
49
+ kwargs["source"] = _check_params(
50
+ code_src=code_src,
51
+ code=code,
52
+ base64=base64,
53
+ handler=handler,
54
+ init_function=init_function,
55
+ lang=lang,
56
+ )
57
+ return kwargs
58
+
59
+
60
+ def _check_params(
61
+ code_src: str | None = None,
62
+ code: str | None = None,
63
+ base64: str | None = None,
64
+ handler: str | None = None,
65
+ init_function: str | None = None,
66
+ lang: str | None = None,
67
+ ) -> dict:
68
+ """
69
+ Check source.
70
+
71
+ Parameters
72
+ ----------
73
+ code_src : str
74
+ Source code source.
75
+ code : str
76
+ Source code.
77
+ base64 : str
78
+ Source code base64.
79
+ handler : str
80
+ Function handler.
81
+ init_function : str
82
+ Init function.
83
+ lang : str
84
+ Source code language.
85
+
86
+ Returns
87
+ -------
88
+ dict
89
+ Checked source.
90
+ """
91
+ source = {}
92
+
93
+ if handler is None:
94
+ raise EntityError("Handler must be provided.")
95
+ source["handler"] = handler
96
+
97
+ if init_function is not None:
98
+ source["init_function"] = init_function
99
+
100
+ if lang is None:
101
+ source["lang"] = Lang.PYTHON.value
102
+
103
+ if code_src is None and code is None and base64 is None:
104
+ raise EntityError("Source must be provided.")
105
+
106
+ if code_src is not None:
107
+ source["source"] = code_src
108
+
109
+ if base64 is not None:
110
+ source["base64"] = base64
111
+
112
+ if code is not None:
113
+ source["base64"] = encode_string(code)
114
+
115
+ return source
116
+
117
+
118
+ def source_post_check(exec: FunctionPython) -> FunctionPython:
119
+ """
120
+ Post check source.
121
+
122
+ Parameters
123
+ ----------
124
+ exec : FunctionPython
125
+ Executable.
126
+
127
+ Returns
128
+ -------
129
+ FunctionPython
130
+ Updated executable.
131
+ """
132
+ code_src = exec.spec.source.get("source", None)
133
+ base64 = exec.spec.source.get("base64", None)
134
+ if code_src is None or base64 is not None:
135
+ return exec
136
+
137
+ # Check local source
138
+ if has_local_scheme(code_src) and Path(code_src).is_file():
139
+ # Check py
140
+ if eval_py_type(code_src):
141
+ exec.spec.source["base64"] = encode_source(code_src)
142
+
143
+ # Check zip
144
+ elif eval_zip_type(code_src):
145
+ filename = Path(code_src).name
146
+ dst = f"zip+s3://{get_s3_bucket()}/{exec.project}/{exec.ENTITY_TYPE}/{exec.name}/{exec.id}/{filename}"
147
+ get_store(dst).upload(code_src, dst)
148
+ exec.spec.source["source"] = dst
149
+ if ":" not in exec.spec.source["handler"]:
150
+ exec.spec.source["handler"] = f"{Path(code_src).stem}:{exec.spec.source['handler']}"
151
+
152
+ return exec
@@ -1,12 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from digitalhub.entities.run._base.builder import RunBuilder
4
+
3
5
  from digitalhub_runtime_python.entities._base.runtime_entity.builder import RuntimeEntityBuilderPython
6
+ from digitalhub_runtime_python.entities._commons.enums import EntityKinds
4
7
  from digitalhub_runtime_python.entities.run.python_run.entity import RunPythonRun
5
8
  from digitalhub_runtime_python.entities.run.python_run.spec import RunSpecPythonRun, RunValidatorPythonRun
6
9
  from digitalhub_runtime_python.entities.run.python_run.status import RunStatusPythonRun
7
10
 
8
- from digitalhub.entities.run._base.builder import RunBuilder
9
-
10
11
 
11
12
  class RunPythonRunBuilder(RunBuilder, RuntimeEntityBuilderPython):
12
13
  """
@@ -17,4 +18,4 @@ class RunPythonRunBuilder(RunBuilder, RuntimeEntityBuilderPython):
17
18
  ENTITY_SPEC_CLASS = RunSpecPythonRun
18
19
  ENTITY_SPEC_VALIDATOR = RunValidatorPythonRun
19
20
  ENTITY_STATUS_CLASS = RunStatusPythonRun
20
- ENTITY_KIND = "python+run"
21
+ ENTITY_KIND = EntityKinds.RUN_PYTHON.value
@@ -5,22 +5,23 @@ import typing
5
5
  from typing import Any
6
6
 
7
7
  import requests
8
- from digitalhub_runtime_python.entities.run.python_run.utils import get_getter_for_material
9
-
8
+ from digitalhub.entities._commons.enums import Relationship, State
9
+ from digitalhub.entities._commons.utils import get_entity_type_from_key
10
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
11
  from digitalhub.factory.api import get_action_from_task_kind
14
12
  from digitalhub.utils.exceptions import EntityError
15
13
  from digitalhub.utils.logger import LOGGER
16
14
 
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
15
+ from digitalhub_runtime_python.entities._commons.enums import TaskActions
16
+ from digitalhub_runtime_python.entities.run.python_run.utils import get_getter_for_material
20
17
 
18
+ if typing.TYPE_CHECKING:
21
19
  from digitalhub.entities._base.entity.metadata import Metadata
22
20
  from digitalhub.entities._base.material.entity import MaterialEntity
23
21
 
22
+ from digitalhub_runtime_python.entities.run.python_run.spec import RunSpecPythonRun
23
+ from digitalhub_runtime_python.entities.run.python_run.status import RunStatusPythonRun
24
+
24
25
 
25
26
  class RunPythonRun(Run):
26
27
  """
@@ -51,7 +52,15 @@ class RunPythonRun(Run):
51
52
  None
52
53
  """
53
54
  self.refresh()
54
- self.spec.inputs = self.inputs(as_dict=True)
55
+ inputs = self.inputs(as_dict=True)
56
+ if self.spec.local_execution:
57
+ for _, v in inputs.items():
58
+ self.add_relationship(
59
+ relation=Relationship.CONSUMES.value,
60
+ dest=v.get("key"),
61
+ )
62
+ self.save(update=True)
63
+ self.spec.inputs = inputs
55
64
 
56
65
  def wait(self, log_info: bool = True) -> Run:
57
66
  """
@@ -70,7 +79,7 @@ class RunPythonRun(Run):
70
79
  task_kind = self.spec.task.split("://")[0]
71
80
  action = get_action_from_task_kind(self.kind, task_kind)
72
81
 
73
- if action == "serve":
82
+ if action == TaskActions.SERVE.value:
74
83
  serve_timeout = 300
75
84
  start = time.time()
76
85
 
@@ -11,14 +11,17 @@ class RunSpecPythonRun(RunSpec):
11
11
  task: str,
12
12
  local_execution: bool = False,
13
13
  function: str | None = None,
14
- node_selector: dict | None = None,
15
- volumes: list | None = None,
14
+ workflow: str | None = None,
15
+ node_selector: list[dict] | None = None,
16
+ volumes: list[dict] | None = None,
16
17
  resources: dict | None = None,
17
18
  affinity: dict | None = None,
18
- tolerations: list | None = None,
19
- envs: list | None = None,
20
- secrets: list | None = None,
19
+ tolerations: list[dict] | None = None,
20
+ envs: list[dict] | None = None,
21
+ secrets: list[str] | None = None,
21
22
  profile: str | None = None,
23
+ runtime_class: str | None = None,
24
+ priority_class: str | None = None,
22
25
  source: dict | None = None,
23
26
  image: str | None = None,
24
27
  base_image: str | None = None,
@@ -30,7 +33,6 @@ class RunSpecPythonRun(RunSpec):
30
33
  replicas: int | None = None,
31
34
  instructions: dict | None = None,
32
35
  inputs: dict | None = None,
33
- outputs: dict | None = None,
34
36
  parameters: dict | None = None,
35
37
  **kwargs,
36
38
  ) -> None:
@@ -38,6 +40,7 @@ class RunSpecPythonRun(RunSpec):
38
40
  task,
39
41
  local_execution,
40
42
  function,
43
+ workflow,
41
44
  node_selector,
42
45
  volumes,
43
46
  resources,
@@ -46,6 +49,8 @@ class RunSpecPythonRun(RunSpec):
46
49
  envs,
47
50
  secrets,
48
51
  profile,
52
+ runtime_class,
53
+ priority_class,
49
54
  **kwargs,
50
55
  )
51
56
  self.source = source
@@ -59,7 +64,6 @@ class RunSpecPythonRun(RunSpec):
59
64
  self.replicas = replicas
60
65
  self.instructions = instructions
61
66
  self.inputs = inputs
62
- self.outputs = outputs
63
67
  self.parameters = parameters
64
68
 
65
69
 
@@ -86,5 +90,7 @@ class RunValidatorPythonRun(RunValidator):
86
90
 
87
91
  # Run parameters
88
92
  inputs: dict = None
89
- outputs: dict = None
93
+ """Run inputs."""
94
+
90
95
  parameters: dict = None
96
+ """Run parameters."""
@@ -2,10 +2,10 @@ from __future__ import annotations
2
2
 
3
3
  from typing import Callable
4
4
 
5
+ from digitalhub.entities._commons.enums import EntityTypes
5
6
  from digitalhub.entities.artifact.crud import get_artifact
6
7
  from digitalhub.entities.dataitem.crud import get_dataitem
7
8
  from digitalhub.entities.model.crud import get_model
8
- from digitalhub.entities.utils.entity_types import EntityTypes
9
9
 
10
10
 
11
11
  def get_getter_for_material(entity_type: str) -> Callable: