digitalhub 0.7.0b2__py3-none-any.whl → 0.8.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.
Potentially problematic release.
This version of digitalhub might be problematic. Click here for more details.
- digitalhub/__init__.py +63 -93
- digitalhub/client/__init__.py +0 -0
- digitalhub/client/_base/__init__.py +0 -0
- digitalhub/client/_base/client.py +56 -0
- digitalhub/client/api.py +63 -0
- digitalhub/client/builder.py +50 -0
- digitalhub/client/dhcore/__init__.py +0 -0
- digitalhub/client/dhcore/client.py +669 -0
- digitalhub/client/dhcore/env.py +21 -0
- digitalhub/client/dhcore/models.py +46 -0
- digitalhub/client/dhcore/utils.py +111 -0
- digitalhub/client/local/__init__.py +0 -0
- digitalhub/client/local/client.py +533 -0
- digitalhub/context/__init__.py +0 -0
- digitalhub/context/api.py +93 -0
- digitalhub/context/builder.py +94 -0
- digitalhub/context/context.py +136 -0
- digitalhub/datastores/__init__.py +0 -0
- digitalhub/datastores/_base/__init__.py +0 -0
- digitalhub/datastores/_base/datastore.py +85 -0
- digitalhub/datastores/api.py +37 -0
- digitalhub/datastores/builder.py +110 -0
- digitalhub/datastores/local/__init__.py +0 -0
- digitalhub/datastores/local/datastore.py +50 -0
- digitalhub/datastores/remote/__init__.py +0 -0
- digitalhub/datastores/remote/datastore.py +31 -0
- digitalhub/datastores/s3/__init__.py +0 -0
- digitalhub/datastores/s3/datastore.py +46 -0
- digitalhub/datastores/sql/__init__.py +0 -0
- digitalhub/datastores/sql/datastore.py +68 -0
- digitalhub/entities/__init__.py +0 -0
- digitalhub/entities/_base/__init__.py +0 -0
- digitalhub/entities/_base/_base/__init__.py +0 -0
- digitalhub/entities/_base/_base/entity.py +82 -0
- digitalhub/entities/_base/api_utils.py +620 -0
- digitalhub/entities/_base/context/__init__.py +0 -0
- digitalhub/entities/_base/context/entity.py +118 -0
- digitalhub/entities/_base/crud.py +468 -0
- digitalhub/entities/_base/entity/__init__.py +0 -0
- digitalhub/entities/_base/entity/_constructors/__init__.py +0 -0
- digitalhub/entities/_base/entity/_constructors/metadata.py +44 -0
- digitalhub/entities/_base/entity/_constructors/name.py +31 -0
- digitalhub/entities/_base/entity/_constructors/spec.py +33 -0
- digitalhub/entities/_base/entity/_constructors/status.py +52 -0
- digitalhub/entities/_base/entity/_constructors/uuid.py +26 -0
- digitalhub/entities/_base/entity/builder.py +175 -0
- digitalhub/entities/_base/entity/entity.py +106 -0
- digitalhub/entities/_base/entity/metadata.py +59 -0
- digitalhub/entities/_base/entity/spec.py +58 -0
- digitalhub/entities/_base/entity/status.py +43 -0
- digitalhub/entities/_base/executable/__init__.py +0 -0
- digitalhub/entities/_base/executable/entity.py +405 -0
- digitalhub/entities/_base/material/__init__.py +0 -0
- digitalhub/entities/_base/material/entity.py +214 -0
- digitalhub/entities/_base/material/spec.py +22 -0
- digitalhub/entities/_base/material/status.py +49 -0
- digitalhub/entities/_base/runtime_entity/__init__.py +0 -0
- digitalhub/entities/_base/runtime_entity/builder.py +106 -0
- digitalhub/entities/_base/unversioned/__init__.py +0 -0
- digitalhub/entities/_base/unversioned/builder.py +66 -0
- digitalhub/entities/_base/unversioned/entity.py +49 -0
- digitalhub/entities/_base/versioned/__init__.py +0 -0
- digitalhub/entities/_base/versioned/builder.py +68 -0
- digitalhub/entities/_base/versioned/entity.py +53 -0
- digitalhub/entities/artifact/__init__.py +0 -0
- digitalhub/entities/artifact/_base/__init__.py +0 -0
- digitalhub/entities/artifact/_base/builder.py +86 -0
- digitalhub/entities/artifact/_base/entity.py +39 -0
- digitalhub/entities/artifact/_base/spec.py +15 -0
- digitalhub/entities/artifact/_base/status.py +9 -0
- digitalhub/entities/artifact/artifact/__init__.py +0 -0
- digitalhub/entities/artifact/artifact/builder.py +18 -0
- digitalhub/entities/artifact/artifact/entity.py +32 -0
- digitalhub/entities/artifact/artifact/spec.py +27 -0
- digitalhub/entities/artifact/artifact/status.py +15 -0
- digitalhub/entities/artifact/crud.py +332 -0
- digitalhub/entities/builders.py +63 -0
- digitalhub/entities/dataitem/__init__.py +0 -0
- digitalhub/entities/dataitem/_base/__init__.py +0 -0
- digitalhub/entities/dataitem/_base/builder.py +86 -0
- digitalhub/entities/dataitem/_base/entity.py +75 -0
- digitalhub/entities/dataitem/_base/spec.py +15 -0
- digitalhub/entities/dataitem/_base/status.py +20 -0
- digitalhub/entities/dataitem/crud.py +372 -0
- digitalhub/entities/dataitem/dataitem/__init__.py +0 -0
- digitalhub/entities/dataitem/dataitem/builder.py +18 -0
- digitalhub/entities/dataitem/dataitem/entity.py +32 -0
- digitalhub/entities/dataitem/dataitem/spec.py +15 -0
- digitalhub/entities/dataitem/dataitem/status.py +9 -0
- digitalhub/entities/dataitem/iceberg/__init__.py +0 -0
- digitalhub/entities/dataitem/iceberg/builder.py +18 -0
- digitalhub/entities/dataitem/iceberg/entity.py +32 -0
- digitalhub/entities/dataitem/iceberg/spec.py +15 -0
- digitalhub/entities/dataitem/iceberg/status.py +9 -0
- digitalhub/entities/dataitem/table/__init__.py +0 -0
- digitalhub/entities/dataitem/table/builder.py +18 -0
- digitalhub/entities/dataitem/table/entity.py +146 -0
- digitalhub/entities/dataitem/table/models.py +62 -0
- digitalhub/entities/dataitem/table/spec.py +25 -0
- digitalhub/entities/dataitem/table/status.py +9 -0
- digitalhub/entities/function/__init__.py +0 -0
- digitalhub/entities/function/_base/__init__.py +0 -0
- digitalhub/entities/function/_base/builder.py +79 -0
- digitalhub/entities/function/_base/entity.py +98 -0
- digitalhub/entities/function/_base/models.py +118 -0
- digitalhub/entities/function/_base/spec.py +15 -0
- digitalhub/entities/function/_base/status.py +9 -0
- digitalhub/entities/function/crud.py +279 -0
- digitalhub/entities/model/__init__.py +0 -0
- digitalhub/entities/model/_base/__init__.py +0 -0
- digitalhub/entities/model/_base/builder.py +86 -0
- digitalhub/entities/model/_base/entity.py +34 -0
- digitalhub/entities/model/_base/spec.py +49 -0
- digitalhub/entities/model/_base/status.py +9 -0
- digitalhub/entities/model/crud.py +331 -0
- digitalhub/entities/model/huggingface/__init__.py +0 -0
- digitalhub/entities/model/huggingface/builder.py +18 -0
- digitalhub/entities/model/huggingface/entity.py +32 -0
- digitalhub/entities/model/huggingface/spec.py +36 -0
- digitalhub/entities/model/huggingface/status.py +9 -0
- digitalhub/entities/model/mlflow/__init__.py +0 -0
- digitalhub/entities/model/mlflow/builder.py +18 -0
- digitalhub/entities/model/mlflow/entity.py +32 -0
- digitalhub/entities/model/mlflow/models.py +26 -0
- digitalhub/entities/model/mlflow/spec.py +44 -0
- digitalhub/entities/model/mlflow/status.py +9 -0
- digitalhub/entities/model/mlflow/utils.py +81 -0
- digitalhub/entities/model/model/__init__.py +0 -0
- digitalhub/entities/model/model/builder.py +18 -0
- digitalhub/entities/model/model/entity.py +32 -0
- digitalhub/entities/model/model/spec.py +15 -0
- digitalhub/entities/model/model/status.py +9 -0
- digitalhub/entities/model/sklearn/__init__.py +0 -0
- digitalhub/entities/model/sklearn/builder.py +18 -0
- digitalhub/entities/model/sklearn/entity.py +32 -0
- digitalhub/entities/model/sklearn/spec.py +15 -0
- digitalhub/entities/model/sklearn/status.py +9 -0
- digitalhub/entities/project/__init__.py +0 -0
- digitalhub/entities/project/_base/__init__.py +0 -0
- digitalhub/entities/project/_base/builder.py +128 -0
- digitalhub/entities/project/_base/entity.py +2078 -0
- digitalhub/entities/project/_base/spec.py +50 -0
- digitalhub/entities/project/_base/status.py +9 -0
- digitalhub/entities/project/crud.py +357 -0
- digitalhub/entities/run/__init__.py +0 -0
- digitalhub/entities/run/_base/__init__.py +0 -0
- digitalhub/entities/run/_base/builder.py +94 -0
- digitalhub/entities/run/_base/entity.py +307 -0
- digitalhub/entities/run/_base/spec.py +50 -0
- digitalhub/entities/run/_base/status.py +9 -0
- digitalhub/entities/run/crud.py +219 -0
- digitalhub/entities/secret/__init__.py +0 -0
- digitalhub/entities/secret/_base/__init__.py +0 -0
- digitalhub/entities/secret/_base/builder.py +81 -0
- digitalhub/entities/secret/_base/entity.py +74 -0
- digitalhub/entities/secret/_base/spec.py +35 -0
- digitalhub/entities/secret/_base/status.py +9 -0
- digitalhub/entities/secret/crud.py +290 -0
- digitalhub/entities/task/__init__.py +0 -0
- digitalhub/entities/task/_base/__init__.py +0 -0
- digitalhub/entities/task/_base/builder.py +91 -0
- digitalhub/entities/task/_base/entity.py +136 -0
- digitalhub/entities/task/_base/models.py +208 -0
- digitalhub/entities/task/_base/spec.py +53 -0
- digitalhub/entities/task/_base/status.py +9 -0
- digitalhub/entities/task/crud.py +228 -0
- digitalhub/entities/utils/__init__.py +0 -0
- digitalhub/entities/utils/api.py +346 -0
- digitalhub/entities/utils/entity_types.py +19 -0
- digitalhub/entities/utils/state.py +31 -0
- digitalhub/entities/utils/utils.py +202 -0
- digitalhub/entities/workflow/__init__.py +0 -0
- digitalhub/entities/workflow/_base/__init__.py +0 -0
- digitalhub/entities/workflow/_base/builder.py +79 -0
- digitalhub/entities/workflow/_base/entity.py +74 -0
- digitalhub/entities/workflow/_base/spec.py +15 -0
- digitalhub/entities/workflow/_base/status.py +9 -0
- digitalhub/entities/workflow/crud.py +278 -0
- digitalhub/factory/__init__.py +0 -0
- digitalhub/factory/api.py +277 -0
- digitalhub/factory/factory.py +268 -0
- digitalhub/factory/utils.py +90 -0
- digitalhub/readers/__init__.py +0 -0
- digitalhub/readers/_base/__init__.py +0 -0
- digitalhub/readers/_base/builder.py +26 -0
- digitalhub/readers/_base/reader.py +70 -0
- digitalhub/readers/api.py +80 -0
- digitalhub/readers/factory.py +133 -0
- digitalhub/readers/pandas/__init__.py +0 -0
- digitalhub/readers/pandas/builder.py +29 -0
- digitalhub/readers/pandas/reader.py +207 -0
- digitalhub/runtimes/__init__.py +0 -0
- digitalhub/runtimes/_base.py +102 -0
- digitalhub/runtimes/builder.py +32 -0
- digitalhub/stores/__init__.py +0 -0
- digitalhub/stores/_base/__init__.py +0 -0
- digitalhub/stores/_base/store.py +189 -0
- digitalhub/stores/api.py +54 -0
- digitalhub/stores/builder.py +211 -0
- digitalhub/stores/local/__init__.py +0 -0
- digitalhub/stores/local/store.py +230 -0
- digitalhub/stores/remote/__init__.py +0 -0
- digitalhub/stores/remote/store.py +143 -0
- digitalhub/stores/s3/__init__.py +0 -0
- digitalhub/stores/s3/store.py +563 -0
- digitalhub/stores/sql/__init__.py +0 -0
- digitalhub/stores/sql/store.py +328 -0
- digitalhub/utils/__init__.py +0 -0
- digitalhub/utils/data_utils.py +127 -0
- digitalhub/utils/exceptions.py +67 -0
- digitalhub/utils/file_utils.py +204 -0
- digitalhub/utils/generic_utils.py +183 -0
- digitalhub/utils/git_utils.py +148 -0
- digitalhub/utils/io_utils.py +116 -0
- digitalhub/utils/logger.py +17 -0
- digitalhub/utils/s3_utils.py +58 -0
- digitalhub/utils/uri_utils.py +56 -0
- {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/METADATA +30 -13
- digitalhub-0.8.0.dist-info/RECORD +231 -0
- {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/WHEEL +1 -1
- test/local/CRUD/test_artifacts.py +96 -0
- test/local/CRUD/test_dataitems.py +96 -0
- test/local/CRUD/test_models.py +95 -0
- test/test_crud_functions.py +1 -1
- test/test_crud_runs.py +1 -1
- test/test_crud_tasks.py +1 -1
- digitalhub-0.7.0b2.dist-info/RECORD +0 -14
- test/test_crud_artifacts.py +0 -96
- test/test_crud_dataitems.py +0 -96
- {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/LICENSE.txt +0 -0
- {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/top_level.txt +0 -0
- /test/{test_imports.py → local/imports/test_imports.py} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities._base.entity.spec import Spec, SpecValidator
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ProjectSpec(Spec):
|
|
7
|
+
"""
|
|
8
|
+
ProjectSpec specifications.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
context: str | None = None,
|
|
14
|
+
functions: list | None = None,
|
|
15
|
+
artifacts: list | None = None,
|
|
16
|
+
workflows: list | None = None,
|
|
17
|
+
dataitems: list | None = None,
|
|
18
|
+
models: list | None = None,
|
|
19
|
+
**kwargs,
|
|
20
|
+
) -> None:
|
|
21
|
+
self.context = context if context is not None else "./"
|
|
22
|
+
self.functions = functions if functions is not None else []
|
|
23
|
+
self.artifacts = artifacts if artifacts is not None else []
|
|
24
|
+
self.workflows = workflows if workflows is not None else []
|
|
25
|
+
self.dataitems = dataitems if dataitems is not None else []
|
|
26
|
+
self.models = models if models is not None else []
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ProjectValidator(SpecValidator):
|
|
30
|
+
"""
|
|
31
|
+
ProjectValidator validator.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
context: str = None
|
|
35
|
+
"""The project's context."""
|
|
36
|
+
|
|
37
|
+
functions: list = None
|
|
38
|
+
"""List of project's functions."""
|
|
39
|
+
|
|
40
|
+
artifacts: list = None
|
|
41
|
+
"""List of project's artifacts."""
|
|
42
|
+
|
|
43
|
+
workflows: list = None
|
|
44
|
+
"""List of project's workflows."""
|
|
45
|
+
|
|
46
|
+
dataitems: list = None
|
|
47
|
+
"""List of project's dataitems."""
|
|
48
|
+
|
|
49
|
+
models: list = None
|
|
50
|
+
"""List of project's models."""
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import importlib.util as imputil
|
|
4
|
+
import typing
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from digitalhub.client.api import build_client, get_client
|
|
8
|
+
from digitalhub.context.api import delete_context
|
|
9
|
+
from digitalhub.entities._base.api_utils import delete_entity_api_base, read_entity_api_base, update_entity_api_base
|
|
10
|
+
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
11
|
+
from digitalhub.factory.api import build_entity_from_dict, build_entity_from_params
|
|
12
|
+
from digitalhub.utils.exceptions import BackendError, EntityAlreadyExistsError, EntityError
|
|
13
|
+
from digitalhub.utils.io_utils import read_yaml
|
|
14
|
+
|
|
15
|
+
if typing.TYPE_CHECKING:
|
|
16
|
+
from digitalhub.entities.project._base.entity import Project
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
ENTITY_TYPE = EntityTypes.PROJECT.value
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def new_project(
|
|
23
|
+
name: str,
|
|
24
|
+
description: str | None = None,
|
|
25
|
+
labels: list[str] | None = None,
|
|
26
|
+
local: bool = False,
|
|
27
|
+
config: dict | None = None,
|
|
28
|
+
context: str | None = None,
|
|
29
|
+
setup_kwargs: dict | None = None,
|
|
30
|
+
**kwargs,
|
|
31
|
+
) -> Project:
|
|
32
|
+
"""
|
|
33
|
+
Create a new object.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
name : str
|
|
38
|
+
Object name.
|
|
39
|
+
description : str
|
|
40
|
+
Description of the object (human readable).
|
|
41
|
+
labels : list[str]
|
|
42
|
+
List of labels.
|
|
43
|
+
local : bool
|
|
44
|
+
If True, use local backend, if False use DHCore backend. Default to False.
|
|
45
|
+
config : dict
|
|
46
|
+
DHCore environment configuration.
|
|
47
|
+
context : str
|
|
48
|
+
The context local folder of the project.
|
|
49
|
+
setup_kwargs : dict
|
|
50
|
+
Setup keyword arguments passed to setup_project() function.
|
|
51
|
+
**kwargs : dict
|
|
52
|
+
Keyword arguments.
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
Project
|
|
57
|
+
Object instance.
|
|
58
|
+
|
|
59
|
+
Examples
|
|
60
|
+
--------
|
|
61
|
+
>>> obj = new_project("my-project")
|
|
62
|
+
"""
|
|
63
|
+
build_client(local, config)
|
|
64
|
+
if context is None:
|
|
65
|
+
context = name
|
|
66
|
+
obj = build_entity_from_params(
|
|
67
|
+
name=name,
|
|
68
|
+
kind="project",
|
|
69
|
+
description=description,
|
|
70
|
+
labels=labels,
|
|
71
|
+
local=local,
|
|
72
|
+
context=context,
|
|
73
|
+
**kwargs,
|
|
74
|
+
)
|
|
75
|
+
obj.save()
|
|
76
|
+
return _setup_project(obj, setup_kwargs)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def get_project(
|
|
80
|
+
name: str,
|
|
81
|
+
local: bool = False,
|
|
82
|
+
config: dict | None = None,
|
|
83
|
+
setup_kwargs: dict | None = None,
|
|
84
|
+
**kwargs,
|
|
85
|
+
) -> Project:
|
|
86
|
+
"""
|
|
87
|
+
Retrieves project details from backend.
|
|
88
|
+
|
|
89
|
+
Parameters
|
|
90
|
+
----------
|
|
91
|
+
name : str
|
|
92
|
+
The Project name.
|
|
93
|
+
local : bool
|
|
94
|
+
Flag to determine if backend is local.
|
|
95
|
+
config : dict
|
|
96
|
+
DHCore environment configuration.
|
|
97
|
+
setup_kwargs : dict
|
|
98
|
+
Setup keyword arguments passed to setup_project() function.
|
|
99
|
+
**kwargs : dict
|
|
100
|
+
Parameters to pass to the API call.
|
|
101
|
+
|
|
102
|
+
Returns
|
|
103
|
+
-------
|
|
104
|
+
Project
|
|
105
|
+
Object instance.
|
|
106
|
+
|
|
107
|
+
Examples
|
|
108
|
+
--------
|
|
109
|
+
>>> obj = get_project("my-project")
|
|
110
|
+
"""
|
|
111
|
+
build_client(local, config)
|
|
112
|
+
client = get_client(local)
|
|
113
|
+
obj = read_entity_api_base(client, ENTITY_TYPE, name, **kwargs)
|
|
114
|
+
obj["local"] = local
|
|
115
|
+
project = build_entity_from_dict(obj)
|
|
116
|
+
return _setup_project(project, setup_kwargs)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def import_project(
|
|
120
|
+
file: str,
|
|
121
|
+
local: bool = False,
|
|
122
|
+
config: dict | None = None,
|
|
123
|
+
setup_kwargs: dict | None = None,
|
|
124
|
+
) -> Project:
|
|
125
|
+
"""
|
|
126
|
+
Import object from a YAML file.
|
|
127
|
+
|
|
128
|
+
Parameters
|
|
129
|
+
----------
|
|
130
|
+
file : str
|
|
131
|
+
Path to YAML file.
|
|
132
|
+
local : bool
|
|
133
|
+
Flag to determine if backend is local.
|
|
134
|
+
config : dict
|
|
135
|
+
DHCore environment configuration.
|
|
136
|
+
setup_kwargs : dict
|
|
137
|
+
Setup keyword arguments passed to setup_project() function.
|
|
138
|
+
|
|
139
|
+
Returns
|
|
140
|
+
-------
|
|
141
|
+
Project
|
|
142
|
+
Object instance.
|
|
143
|
+
|
|
144
|
+
Examples
|
|
145
|
+
--------
|
|
146
|
+
>>> obj = import_project("my-project.yaml")
|
|
147
|
+
"""
|
|
148
|
+
build_client(local, config)
|
|
149
|
+
dict_obj: dict = read_yaml(file)
|
|
150
|
+
dict_obj["local"] = local
|
|
151
|
+
obj = build_entity_from_dict(dict_obj)
|
|
152
|
+
obj = _setup_project(obj, setup_kwargs)
|
|
153
|
+
|
|
154
|
+
try:
|
|
155
|
+
obj.save()
|
|
156
|
+
except EntityAlreadyExistsError:
|
|
157
|
+
pass
|
|
158
|
+
|
|
159
|
+
# Import related entities
|
|
160
|
+
obj._import_entities(dict_obj)
|
|
161
|
+
|
|
162
|
+
obj.refresh()
|
|
163
|
+
|
|
164
|
+
return obj
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def load_project(
|
|
168
|
+
name: str | None = None,
|
|
169
|
+
filename: str | None = None,
|
|
170
|
+
local: bool = False,
|
|
171
|
+
config: dict | None = None,
|
|
172
|
+
setup_kwargs: dict | None = None,
|
|
173
|
+
**kwargs,
|
|
174
|
+
) -> Project:
|
|
175
|
+
"""
|
|
176
|
+
Load project and context from backend or file. Name or
|
|
177
|
+
filename must be provided. Name takes precedence over filename.
|
|
178
|
+
|
|
179
|
+
Parameters
|
|
180
|
+
----------
|
|
181
|
+
name : str
|
|
182
|
+
Project name.
|
|
183
|
+
filename : str
|
|
184
|
+
Path to YAML file.
|
|
185
|
+
local : bool
|
|
186
|
+
Flag to determine if backend is local.
|
|
187
|
+
config : dict
|
|
188
|
+
DHCore environment configuration.
|
|
189
|
+
setup_kwargs : dict
|
|
190
|
+
Setup keyword arguments passed to setup_project() function.
|
|
191
|
+
**kwargs : dict
|
|
192
|
+
Keyword arguments.
|
|
193
|
+
|
|
194
|
+
Returns
|
|
195
|
+
-------
|
|
196
|
+
Project
|
|
197
|
+
Object instance.
|
|
198
|
+
|
|
199
|
+
Examples
|
|
200
|
+
--------
|
|
201
|
+
If name is provided, load project from backend.
|
|
202
|
+
>>> obj = load_project(name="my-project")
|
|
203
|
+
|
|
204
|
+
If filename is provided, load project from file.
|
|
205
|
+
>>> obj = load_project(filename="my-project.yaml")
|
|
206
|
+
"""
|
|
207
|
+
if name is not None:
|
|
208
|
+
return get_project(name=name, local=local, config=config, setup_kwargs=setup_kwargs, **kwargs)
|
|
209
|
+
if filename is not None:
|
|
210
|
+
return import_project(filename, local=local, config=config, setup_kwargs=setup_kwargs)
|
|
211
|
+
raise EntityError("Either name or filename must be provided.")
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def get_or_create_project(
|
|
215
|
+
name: str,
|
|
216
|
+
local: bool = False,
|
|
217
|
+
config: dict | None = None,
|
|
218
|
+
context: str | None = None,
|
|
219
|
+
setup_kwargs: dict | None = None,
|
|
220
|
+
**kwargs,
|
|
221
|
+
) -> Project:
|
|
222
|
+
"""
|
|
223
|
+
Try to get project. If not exists, create it.
|
|
224
|
+
|
|
225
|
+
Parameters
|
|
226
|
+
----------
|
|
227
|
+
name : str
|
|
228
|
+
Project name.
|
|
229
|
+
local : bool
|
|
230
|
+
Flag to determine if backend is local.
|
|
231
|
+
config : dict
|
|
232
|
+
DHCore environment configuration.
|
|
233
|
+
context : str
|
|
234
|
+
Folder where the project will saves its context locally.
|
|
235
|
+
setup_kwargs : dict
|
|
236
|
+
Setup keyword arguments passed to setup_project() function.
|
|
237
|
+
**kwargs : dict
|
|
238
|
+
Keyword arguments.
|
|
239
|
+
|
|
240
|
+
Returns
|
|
241
|
+
-------
|
|
242
|
+
Project
|
|
243
|
+
Object instance.
|
|
244
|
+
"""
|
|
245
|
+
try:
|
|
246
|
+
return get_project(
|
|
247
|
+
name,
|
|
248
|
+
local=local,
|
|
249
|
+
config=config,
|
|
250
|
+
setup_kwargs=setup_kwargs,
|
|
251
|
+
**kwargs,
|
|
252
|
+
)
|
|
253
|
+
except BackendError:
|
|
254
|
+
return new_project(
|
|
255
|
+
name,
|
|
256
|
+
local=local,
|
|
257
|
+
config=config,
|
|
258
|
+
setup_kwargs=setup_kwargs,
|
|
259
|
+
context=context,
|
|
260
|
+
**kwargs,
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def update_project(entity: Project, local: bool = False, **kwargs) -> Project:
|
|
265
|
+
"""
|
|
266
|
+
Update object. Note that object spec are immutable.
|
|
267
|
+
|
|
268
|
+
Parameters
|
|
269
|
+
----------
|
|
270
|
+
entity : Project
|
|
271
|
+
Object to update.
|
|
272
|
+
local : bool
|
|
273
|
+
Flag to determine if backend is local.
|
|
274
|
+
**kwargs : dict
|
|
275
|
+
Parameters to pass to the API call.
|
|
276
|
+
|
|
277
|
+
Returns
|
|
278
|
+
-------
|
|
279
|
+
Project
|
|
280
|
+
The updated object.
|
|
281
|
+
|
|
282
|
+
Examples
|
|
283
|
+
--------
|
|
284
|
+
>>> obj = update_project(obj)
|
|
285
|
+
"""
|
|
286
|
+
client = get_client(local)
|
|
287
|
+
obj = update_entity_api_base(client, ENTITY_TYPE, entity.name, entity.to_dict(), **kwargs)
|
|
288
|
+
return build_entity_from_dict(obj)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def delete_project(
|
|
292
|
+
name: str,
|
|
293
|
+
cascade: bool = True,
|
|
294
|
+
clean_context: bool = True,
|
|
295
|
+
local: bool = False,
|
|
296
|
+
**kwargs,
|
|
297
|
+
) -> list[dict]:
|
|
298
|
+
"""
|
|
299
|
+
Delete a project.
|
|
300
|
+
|
|
301
|
+
Parameters
|
|
302
|
+
----------
|
|
303
|
+
name : str
|
|
304
|
+
Project name.
|
|
305
|
+
cascade : bool
|
|
306
|
+
Flag to determine if delete is cascading.
|
|
307
|
+
clean_context : bool
|
|
308
|
+
Flag to determine if context will be deleted. If a context is deleted,
|
|
309
|
+
all its objects are unreacheable.
|
|
310
|
+
local : bool
|
|
311
|
+
Flag to determine if backend is local.
|
|
312
|
+
**kwargs : dict
|
|
313
|
+
Parameters to pass to the API call.
|
|
314
|
+
|
|
315
|
+
Returns
|
|
316
|
+
-------
|
|
317
|
+
dict
|
|
318
|
+
Response from backend.
|
|
319
|
+
|
|
320
|
+
Examples
|
|
321
|
+
--------
|
|
322
|
+
>>> delete_project("my-project")
|
|
323
|
+
"""
|
|
324
|
+
client = get_client(local)
|
|
325
|
+
obj = delete_entity_api_base(client, ENTITY_TYPE, name, cascade=cascade, **kwargs)
|
|
326
|
+
if clean_context:
|
|
327
|
+
delete_context(name)
|
|
328
|
+
return obj
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def _setup_project(project: Project, setup_kwargs: dict | None = None) -> Project:
|
|
332
|
+
"""
|
|
333
|
+
Search for setup_project.py file and launch setup hanlder as project hook.
|
|
334
|
+
|
|
335
|
+
Parameters
|
|
336
|
+
----------
|
|
337
|
+
project : Project
|
|
338
|
+
The project to scafold.
|
|
339
|
+
setup_kwargs : dict
|
|
340
|
+
Arguments to pass to setup handler.
|
|
341
|
+
|
|
342
|
+
Returns
|
|
343
|
+
-------
|
|
344
|
+
Project
|
|
345
|
+
Set up project.
|
|
346
|
+
"""
|
|
347
|
+
setup_kwargs = setup_kwargs if setup_kwargs is not None else {}
|
|
348
|
+
check_pth = Path(project.spec.context, ".CHECK")
|
|
349
|
+
setup_pth = Path(project.spec.context, "setup_project.py")
|
|
350
|
+
if setup_pth.exists() and not check_pth.exists():
|
|
351
|
+
spec = imputil.spec_from_file_location("setup_project", setup_pth)
|
|
352
|
+
mod = imputil.module_from_spec(spec)
|
|
353
|
+
spec.loader.exec_module(mod)
|
|
354
|
+
handler = getattr(mod, "setup")
|
|
355
|
+
project = handler(project, **setup_kwargs)
|
|
356
|
+
check_pth.touch()
|
|
357
|
+
return project
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._base.runtime_entity.builder import EntityError, RuntimeEntityBuilder
|
|
6
|
+
from digitalhub.entities._base.unversioned.builder import UnversionedBuilder
|
|
7
|
+
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
8
|
+
|
|
9
|
+
if typing.TYPE_CHECKING:
|
|
10
|
+
from digitalhub.entities.run._base.entity import Run
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class RunBuilder(UnversionedBuilder, RuntimeEntityBuilder):
|
|
14
|
+
"""
|
|
15
|
+
Run builder.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
ENTITY_TYPE = EntityTypes.RUN.value
|
|
19
|
+
|
|
20
|
+
def build(
|
|
21
|
+
self,
|
|
22
|
+
project: str,
|
|
23
|
+
kind: str,
|
|
24
|
+
uuid: str | None = None,
|
|
25
|
+
labels: list[str] | None = None,
|
|
26
|
+
task: str | None = None,
|
|
27
|
+
local_execution: bool = False,
|
|
28
|
+
**kwargs,
|
|
29
|
+
) -> Run:
|
|
30
|
+
"""
|
|
31
|
+
Create a new object.
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
project : str
|
|
36
|
+
Project name.
|
|
37
|
+
kind : str
|
|
38
|
+
Kind the object.
|
|
39
|
+
uuid : str
|
|
40
|
+
ID of the object.
|
|
41
|
+
labels : list[str]
|
|
42
|
+
List of labels.
|
|
43
|
+
task : str
|
|
44
|
+
Name of the task associated with the run.
|
|
45
|
+
local_execution : bool
|
|
46
|
+
Flag to determine if object has local execution.
|
|
47
|
+
**kwargs : dict
|
|
48
|
+
Spec keyword arguments.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
Run
|
|
53
|
+
Object instance.
|
|
54
|
+
"""
|
|
55
|
+
if task is None:
|
|
56
|
+
raise EntityError("Missing task in run spec")
|
|
57
|
+
self._check_kind_validity(task)
|
|
58
|
+
uuid = self.build_uuid(uuid)
|
|
59
|
+
metadata = self.build_metadata(
|
|
60
|
+
project=project,
|
|
61
|
+
name=uuid,
|
|
62
|
+
labels=labels,
|
|
63
|
+
)
|
|
64
|
+
spec = self.build_spec(
|
|
65
|
+
task=task,
|
|
66
|
+
local_execution=local_execution,
|
|
67
|
+
**kwargs,
|
|
68
|
+
)
|
|
69
|
+
status = self.build_status()
|
|
70
|
+
return self.build_entity(
|
|
71
|
+
project=project,
|
|
72
|
+
uuid=uuid,
|
|
73
|
+
kind=kind,
|
|
74
|
+
metadata=metadata,
|
|
75
|
+
spec=spec,
|
|
76
|
+
status=status,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def _check_kind_validity(self, task: str) -> None:
|
|
80
|
+
"""
|
|
81
|
+
Check kind validity.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
task : str
|
|
86
|
+
Task string.
|
|
87
|
+
|
|
88
|
+
Returns
|
|
89
|
+
-------
|
|
90
|
+
None
|
|
91
|
+
"""
|
|
92
|
+
task_kind = task.split("://")[0]
|
|
93
|
+
if task_kind not in self.get_all_kinds():
|
|
94
|
+
raise EntityError(f"Invalid run '{self.ENTITY_KIND}' for task kind '{task_kind}'")
|