flyte 0.0.1b0__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 flyte might be problematic. Click here for more details.
- flyte/__init__.py +62 -0
- flyte/_api_commons.py +3 -0
- flyte/_bin/__init__.py +0 -0
- flyte/_bin/runtime.py +126 -0
- flyte/_build.py +25 -0
- flyte/_cache/__init__.py +12 -0
- flyte/_cache/cache.py +146 -0
- flyte/_cache/defaults.py +9 -0
- flyte/_cache/policy_function_body.py +42 -0
- flyte/_cli/__init__.py +0 -0
- flyte/_cli/_common.py +287 -0
- flyte/_cli/_create.py +42 -0
- flyte/_cli/_delete.py +23 -0
- flyte/_cli/_deploy.py +140 -0
- flyte/_cli/_get.py +235 -0
- flyte/_cli/_run.py +152 -0
- flyte/_cli/main.py +72 -0
- flyte/_code_bundle/__init__.py +8 -0
- flyte/_code_bundle/_ignore.py +113 -0
- flyte/_code_bundle/_packaging.py +187 -0
- flyte/_code_bundle/_utils.py +339 -0
- flyte/_code_bundle/bundle.py +178 -0
- flyte/_context.py +146 -0
- flyte/_datastructures.py +342 -0
- flyte/_deploy.py +202 -0
- flyte/_doc.py +29 -0
- flyte/_docstring.py +32 -0
- flyte/_environment.py +43 -0
- flyte/_group.py +31 -0
- flyte/_hash.py +23 -0
- flyte/_image.py +760 -0
- flyte/_initialize.py +634 -0
- flyte/_interface.py +84 -0
- flyte/_internal/__init__.py +3 -0
- flyte/_internal/controllers/__init__.py +115 -0
- flyte/_internal/controllers/_local_controller.py +118 -0
- flyte/_internal/controllers/_trace.py +40 -0
- flyte/_internal/controllers/pbhash.py +39 -0
- flyte/_internal/controllers/remote/__init__.py +40 -0
- flyte/_internal/controllers/remote/_action.py +141 -0
- flyte/_internal/controllers/remote/_client.py +43 -0
- flyte/_internal/controllers/remote/_controller.py +361 -0
- flyte/_internal/controllers/remote/_core.py +402 -0
- flyte/_internal/controllers/remote/_informer.py +361 -0
- flyte/_internal/controllers/remote/_service_protocol.py +50 -0
- flyte/_internal/imagebuild/__init__.py +11 -0
- flyte/_internal/imagebuild/docker_builder.py +416 -0
- flyte/_internal/imagebuild/image_builder.py +241 -0
- flyte/_internal/imagebuild/remote_builder.py +0 -0
- flyte/_internal/resolvers/__init__.py +0 -0
- flyte/_internal/resolvers/_task_module.py +54 -0
- flyte/_internal/resolvers/common.py +31 -0
- flyte/_internal/resolvers/default.py +28 -0
- flyte/_internal/runtime/__init__.py +0 -0
- flyte/_internal/runtime/convert.py +199 -0
- flyte/_internal/runtime/entrypoints.py +135 -0
- flyte/_internal/runtime/io.py +136 -0
- flyte/_internal/runtime/resources_serde.py +138 -0
- flyte/_internal/runtime/task_serde.py +210 -0
- flyte/_internal/runtime/taskrunner.py +190 -0
- flyte/_internal/runtime/types_serde.py +54 -0
- flyte/_logging.py +124 -0
- flyte/_protos/__init__.py +0 -0
- flyte/_protos/common/authorization_pb2.py +66 -0
- flyte/_protos/common/authorization_pb2.pyi +108 -0
- flyte/_protos/common/authorization_pb2_grpc.py +4 -0
- flyte/_protos/common/identifier_pb2.py +71 -0
- flyte/_protos/common/identifier_pb2.pyi +82 -0
- flyte/_protos/common/identifier_pb2_grpc.py +4 -0
- flyte/_protos/common/identity_pb2.py +48 -0
- flyte/_protos/common/identity_pb2.pyi +72 -0
- flyte/_protos/common/identity_pb2_grpc.py +4 -0
- flyte/_protos/common/list_pb2.py +36 -0
- flyte/_protos/common/list_pb2.pyi +69 -0
- flyte/_protos/common/list_pb2_grpc.py +4 -0
- flyte/_protos/common/policy_pb2.py +37 -0
- flyte/_protos/common/policy_pb2.pyi +27 -0
- flyte/_protos/common/policy_pb2_grpc.py +4 -0
- flyte/_protos/common/role_pb2.py +37 -0
- flyte/_protos/common/role_pb2.pyi +53 -0
- flyte/_protos/common/role_pb2_grpc.py +4 -0
- flyte/_protos/common/runtime_version_pb2.py +28 -0
- flyte/_protos/common/runtime_version_pb2.pyi +24 -0
- flyte/_protos/common/runtime_version_pb2_grpc.py +4 -0
- flyte/_protos/logs/dataplane/payload_pb2.py +96 -0
- flyte/_protos/logs/dataplane/payload_pb2.pyi +168 -0
- flyte/_protos/logs/dataplane/payload_pb2_grpc.py +4 -0
- flyte/_protos/secret/definition_pb2.py +49 -0
- flyte/_protos/secret/definition_pb2.pyi +93 -0
- flyte/_protos/secret/definition_pb2_grpc.py +4 -0
- flyte/_protos/secret/payload_pb2.py +62 -0
- flyte/_protos/secret/payload_pb2.pyi +94 -0
- flyte/_protos/secret/payload_pb2_grpc.py +4 -0
- flyte/_protos/secret/secret_pb2.py +38 -0
- flyte/_protos/secret/secret_pb2.pyi +6 -0
- flyte/_protos/secret/secret_pb2_grpc.py +198 -0
- flyte/_protos/secret/secret_pb2_grpc_grpc.py +198 -0
- flyte/_protos/validate/validate/validate_pb2.py +76 -0
- flyte/_protos/workflow/node_execution_service_pb2.py +26 -0
- flyte/_protos/workflow/node_execution_service_pb2.pyi +4 -0
- flyte/_protos/workflow/node_execution_service_pb2_grpc.py +32 -0
- flyte/_protos/workflow/queue_service_pb2.py +106 -0
- flyte/_protos/workflow/queue_service_pb2.pyi +141 -0
- flyte/_protos/workflow/queue_service_pb2_grpc.py +172 -0
- flyte/_protos/workflow/run_definition_pb2.py +128 -0
- flyte/_protos/workflow/run_definition_pb2.pyi +310 -0
- flyte/_protos/workflow/run_definition_pb2_grpc.py +4 -0
- flyte/_protos/workflow/run_logs_service_pb2.py +41 -0
- flyte/_protos/workflow/run_logs_service_pb2.pyi +28 -0
- flyte/_protos/workflow/run_logs_service_pb2_grpc.py +69 -0
- flyte/_protos/workflow/run_service_pb2.py +133 -0
- flyte/_protos/workflow/run_service_pb2.pyi +175 -0
- flyte/_protos/workflow/run_service_pb2_grpc.py +412 -0
- flyte/_protos/workflow/state_service_pb2.py +58 -0
- flyte/_protos/workflow/state_service_pb2.pyi +71 -0
- flyte/_protos/workflow/state_service_pb2_grpc.py +138 -0
- flyte/_protos/workflow/task_definition_pb2.py +72 -0
- flyte/_protos/workflow/task_definition_pb2.pyi +65 -0
- flyte/_protos/workflow/task_definition_pb2_grpc.py +4 -0
- flyte/_protos/workflow/task_service_pb2.py +44 -0
- flyte/_protos/workflow/task_service_pb2.pyi +31 -0
- flyte/_protos/workflow/task_service_pb2_grpc.py +104 -0
- flyte/_resources.py +226 -0
- flyte/_retry.py +32 -0
- flyte/_reusable_environment.py +25 -0
- flyte/_run.py +411 -0
- flyte/_secret.py +61 -0
- flyte/_task.py +367 -0
- flyte/_task_environment.py +200 -0
- flyte/_timeout.py +47 -0
- flyte/_tools.py +27 -0
- flyte/_trace.py +128 -0
- flyte/_utils/__init__.py +20 -0
- flyte/_utils/asyn.py +119 -0
- flyte/_utils/coro_management.py +25 -0
- flyte/_utils/file_handling.py +72 -0
- flyte/_utils/helpers.py +108 -0
- flyte/_utils/lazy_module.py +54 -0
- flyte/_utils/uv_script_parser.py +49 -0
- flyte/_version.py +21 -0
- flyte/connectors/__init__.py +0 -0
- flyte/errors.py +143 -0
- flyte/extras/__init__.py +5 -0
- flyte/extras/_container.py +273 -0
- flyte/io/__init__.py +11 -0
- flyte/io/_dataframe.py +0 -0
- flyte/io/_dir.py +448 -0
- flyte/io/_file.py +468 -0
- flyte/io/pickle/__init__.py +0 -0
- flyte/io/pickle/transformer.py +117 -0
- flyte/io/structured_dataset/__init__.py +129 -0
- flyte/io/structured_dataset/basic_dfs.py +219 -0
- flyte/io/structured_dataset/structured_dataset.py +1061 -0
- flyte/py.typed +0 -0
- flyte/remote/__init__.py +25 -0
- flyte/remote/_client/__init__.py +0 -0
- flyte/remote/_client/_protocols.py +131 -0
- flyte/remote/_client/auth/__init__.py +12 -0
- flyte/remote/_client/auth/_authenticators/__init__.py +0 -0
- flyte/remote/_client/auth/_authenticators/base.py +397 -0
- flyte/remote/_client/auth/_authenticators/client_credentials.py +73 -0
- flyte/remote/_client/auth/_authenticators/device_code.py +118 -0
- flyte/remote/_client/auth/_authenticators/external_command.py +79 -0
- flyte/remote/_client/auth/_authenticators/factory.py +200 -0
- flyte/remote/_client/auth/_authenticators/pkce.py +516 -0
- flyte/remote/_client/auth/_channel.py +184 -0
- flyte/remote/_client/auth/_client_config.py +83 -0
- flyte/remote/_client/auth/_default_html.py +32 -0
- flyte/remote/_client/auth/_grpc_utils/__init__.py +0 -0
- flyte/remote/_client/auth/_grpc_utils/auth_interceptor.py +288 -0
- flyte/remote/_client/auth/_grpc_utils/default_metadata_interceptor.py +151 -0
- flyte/remote/_client/auth/_keyring.py +143 -0
- flyte/remote/_client/auth/_token_client.py +260 -0
- flyte/remote/_client/auth/errors.py +16 -0
- flyte/remote/_client/controlplane.py +95 -0
- flyte/remote/_console.py +18 -0
- flyte/remote/_data.py +155 -0
- flyte/remote/_logs.py +116 -0
- flyte/remote/_project.py +86 -0
- flyte/remote/_run.py +873 -0
- flyte/remote/_secret.py +132 -0
- flyte/remote/_task.py +227 -0
- flyte/report/__init__.py +3 -0
- flyte/report/_report.py +178 -0
- flyte/report/_template.html +124 -0
- flyte/storage/__init__.py +24 -0
- flyte/storage/_remote_fs.py +34 -0
- flyte/storage/_storage.py +251 -0
- flyte/storage/_utils.py +5 -0
- flyte/types/__init__.py +13 -0
- flyte/types/_interface.py +25 -0
- flyte/types/_renderer.py +162 -0
- flyte/types/_string_literals.py +120 -0
- flyte/types/_type_engine.py +2210 -0
- flyte/types/_utils.py +80 -0
- flyte-0.0.1b0.dist-info/METADATA +179 -0
- flyte-0.0.1b0.dist-info/RECORD +390 -0
- flyte-0.0.1b0.dist-info/WHEEL +5 -0
- flyte-0.0.1b0.dist-info/entry_points.txt +3 -0
- flyte-0.0.1b0.dist-info/top_level.txt +1 -0
- union/__init__.py +54 -0
- union/_api_commons.py +3 -0
- union/_bin/__init__.py +0 -0
- union/_bin/runtime.py +113 -0
- union/_build.py +25 -0
- union/_cache/__init__.py +12 -0
- union/_cache/cache.py +141 -0
- union/_cache/defaults.py +9 -0
- union/_cache/policy_function_body.py +42 -0
- union/_cli/__init__.py +0 -0
- union/_cli/_common.py +263 -0
- union/_cli/_create.py +40 -0
- union/_cli/_delete.py +23 -0
- union/_cli/_deploy.py +120 -0
- union/_cli/_get.py +162 -0
- union/_cli/_params.py +579 -0
- union/_cli/_run.py +150 -0
- union/_cli/main.py +72 -0
- union/_code_bundle/__init__.py +8 -0
- union/_code_bundle/_ignore.py +113 -0
- union/_code_bundle/_packaging.py +187 -0
- union/_code_bundle/_utils.py +342 -0
- union/_code_bundle/bundle.py +176 -0
- union/_context.py +146 -0
- union/_datastructures.py +295 -0
- union/_deploy.py +185 -0
- union/_doc.py +29 -0
- union/_docstring.py +26 -0
- union/_environment.py +43 -0
- union/_group.py +31 -0
- union/_hash.py +23 -0
- union/_image.py +760 -0
- union/_initialize.py +585 -0
- union/_interface.py +84 -0
- union/_internal/__init__.py +3 -0
- union/_internal/controllers/__init__.py +77 -0
- union/_internal/controllers/_local_controller.py +77 -0
- union/_internal/controllers/pbhash.py +39 -0
- union/_internal/controllers/remote/__init__.py +40 -0
- union/_internal/controllers/remote/_action.py +131 -0
- union/_internal/controllers/remote/_client.py +43 -0
- union/_internal/controllers/remote/_controller.py +169 -0
- union/_internal/controllers/remote/_core.py +341 -0
- union/_internal/controllers/remote/_informer.py +260 -0
- union/_internal/controllers/remote/_service_protocol.py +44 -0
- union/_internal/imagebuild/__init__.py +11 -0
- union/_internal/imagebuild/docker_builder.py +416 -0
- union/_internal/imagebuild/image_builder.py +243 -0
- union/_internal/imagebuild/remote_builder.py +0 -0
- union/_internal/resolvers/__init__.py +0 -0
- union/_internal/resolvers/_task_module.py +31 -0
- union/_internal/resolvers/common.py +24 -0
- union/_internal/resolvers/default.py +27 -0
- union/_internal/runtime/__init__.py +0 -0
- union/_internal/runtime/convert.py +163 -0
- union/_internal/runtime/entrypoints.py +121 -0
- union/_internal/runtime/io.py +136 -0
- union/_internal/runtime/resources_serde.py +134 -0
- union/_internal/runtime/task_serde.py +202 -0
- union/_internal/runtime/taskrunner.py +179 -0
- union/_internal/runtime/types_serde.py +53 -0
- union/_logging.py +124 -0
- union/_protos/__init__.py +0 -0
- union/_protos/common/authorization_pb2.py +66 -0
- union/_protos/common/authorization_pb2.pyi +106 -0
- union/_protos/common/authorization_pb2_grpc.py +4 -0
- union/_protos/common/identifier_pb2.py +71 -0
- union/_protos/common/identifier_pb2.pyi +82 -0
- union/_protos/common/identifier_pb2_grpc.py +4 -0
- union/_protos/common/identity_pb2.py +48 -0
- union/_protos/common/identity_pb2.pyi +72 -0
- union/_protos/common/identity_pb2_grpc.py +4 -0
- union/_protos/common/list_pb2.py +36 -0
- union/_protos/common/list_pb2.pyi +69 -0
- union/_protos/common/list_pb2_grpc.py +4 -0
- union/_protos/common/policy_pb2.py +37 -0
- union/_protos/common/policy_pb2.pyi +27 -0
- union/_protos/common/policy_pb2_grpc.py +4 -0
- union/_protos/common/role_pb2.py +37 -0
- union/_protos/common/role_pb2.pyi +51 -0
- union/_protos/common/role_pb2_grpc.py +4 -0
- union/_protos/common/runtime_version_pb2.py +28 -0
- union/_protos/common/runtime_version_pb2.pyi +24 -0
- union/_protos/common/runtime_version_pb2_grpc.py +4 -0
- union/_protos/logs/dataplane/payload_pb2.py +96 -0
- union/_protos/logs/dataplane/payload_pb2.pyi +168 -0
- union/_protos/logs/dataplane/payload_pb2_grpc.py +4 -0
- union/_protos/secret/definition_pb2.py +49 -0
- union/_protos/secret/definition_pb2.pyi +93 -0
- union/_protos/secret/definition_pb2_grpc.py +4 -0
- union/_protos/secret/payload_pb2.py +62 -0
- union/_protos/secret/payload_pb2.pyi +94 -0
- union/_protos/secret/payload_pb2_grpc.py +4 -0
- union/_protos/secret/secret_pb2.py +38 -0
- union/_protos/secret/secret_pb2.pyi +6 -0
- union/_protos/secret/secret_pb2_grpc.py +198 -0
- union/_protos/validate/validate/validate_pb2.py +76 -0
- union/_protos/workflow/node_execution_service_pb2.py +26 -0
- union/_protos/workflow/node_execution_service_pb2.pyi +4 -0
- union/_protos/workflow/node_execution_service_pb2_grpc.py +32 -0
- union/_protos/workflow/queue_service_pb2.py +75 -0
- union/_protos/workflow/queue_service_pb2.pyi +103 -0
- union/_protos/workflow/queue_service_pb2_grpc.py +172 -0
- union/_protos/workflow/run_definition_pb2.py +100 -0
- union/_protos/workflow/run_definition_pb2.pyi +256 -0
- union/_protos/workflow/run_definition_pb2_grpc.py +4 -0
- union/_protos/workflow/run_logs_service_pb2.py +41 -0
- union/_protos/workflow/run_logs_service_pb2.pyi +28 -0
- union/_protos/workflow/run_logs_service_pb2_grpc.py +69 -0
- union/_protos/workflow/run_service_pb2.py +133 -0
- union/_protos/workflow/run_service_pb2.pyi +173 -0
- union/_protos/workflow/run_service_pb2_grpc.py +412 -0
- union/_protos/workflow/state_service_pb2.py +58 -0
- union/_protos/workflow/state_service_pb2.pyi +69 -0
- union/_protos/workflow/state_service_pb2_grpc.py +138 -0
- union/_protos/workflow/task_definition_pb2.py +72 -0
- union/_protos/workflow/task_definition_pb2.pyi +65 -0
- union/_protos/workflow/task_definition_pb2_grpc.py +4 -0
- union/_protos/workflow/task_service_pb2.py +44 -0
- union/_protos/workflow/task_service_pb2.pyi +31 -0
- union/_protos/workflow/task_service_pb2_grpc.py +104 -0
- union/_resources.py +226 -0
- union/_retry.py +32 -0
- union/_reusable_environment.py +25 -0
- union/_run.py +374 -0
- union/_secret.py +61 -0
- union/_task.py +354 -0
- union/_task_environment.py +186 -0
- union/_timeout.py +47 -0
- union/_tools.py +27 -0
- union/_utils/__init__.py +11 -0
- union/_utils/asyn.py +119 -0
- union/_utils/file_handling.py +71 -0
- union/_utils/helpers.py +46 -0
- union/_utils/lazy_module.py +54 -0
- union/_utils/uv_script_parser.py +49 -0
- union/_version.py +21 -0
- union/connectors/__init__.py +0 -0
- union/errors.py +128 -0
- union/extras/__init__.py +5 -0
- union/extras/_container.py +263 -0
- union/io/__init__.py +11 -0
- union/io/_dataframe.py +0 -0
- union/io/_dir.py +425 -0
- union/io/_file.py +418 -0
- union/io/pickle/__init__.py +0 -0
- union/io/pickle/transformer.py +117 -0
- union/io/structured_dataset/__init__.py +122 -0
- union/io/structured_dataset/basic_dfs.py +219 -0
- union/io/structured_dataset/structured_dataset.py +1057 -0
- union/py.typed +0 -0
- union/remote/__init__.py +23 -0
- union/remote/_client/__init__.py +0 -0
- union/remote/_client/_protocols.py +129 -0
- union/remote/_client/auth/__init__.py +12 -0
- union/remote/_client/auth/_authenticators/__init__.py +0 -0
- union/remote/_client/auth/_authenticators/base.py +391 -0
- union/remote/_client/auth/_authenticators/client_credentials.py +73 -0
- union/remote/_client/auth/_authenticators/device_code.py +120 -0
- union/remote/_client/auth/_authenticators/external_command.py +77 -0
- union/remote/_client/auth/_authenticators/factory.py +200 -0
- union/remote/_client/auth/_authenticators/pkce.py +515 -0
- union/remote/_client/auth/_channel.py +184 -0
- union/remote/_client/auth/_client_config.py +83 -0
- union/remote/_client/auth/_default_html.py +32 -0
- union/remote/_client/auth/_grpc_utils/__init__.py +0 -0
- union/remote/_client/auth/_grpc_utils/auth_interceptor.py +204 -0
- union/remote/_client/auth/_grpc_utils/default_metadata_interceptor.py +144 -0
- union/remote/_client/auth/_keyring.py +154 -0
- union/remote/_client/auth/_token_client.py +258 -0
- union/remote/_client/auth/errors.py +16 -0
- union/remote/_client/controlplane.py +86 -0
- union/remote/_data.py +149 -0
- union/remote/_logs.py +74 -0
- union/remote/_project.py +86 -0
- union/remote/_run.py +820 -0
- union/remote/_secret.py +132 -0
- union/remote/_task.py +193 -0
- union/report/__init__.py +3 -0
- union/report/_report.py +178 -0
- union/report/_template.html +124 -0
- union/storage/__init__.py +24 -0
- union/storage/_remote_fs.py +34 -0
- union/storage/_storage.py +247 -0
- union/storage/_utils.py +5 -0
- union/types/__init__.py +11 -0
- union/types/_renderer.py +162 -0
- union/types/_string_literals.py +120 -0
- union/types/_type_engine.py +2131 -0
- union/types/_utils.py +80 -0
union/_cache/cache.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from typing import (
|
|
4
|
+
Callable,
|
|
5
|
+
Generic,
|
|
6
|
+
List,
|
|
7
|
+
Optional,
|
|
8
|
+
Protocol,
|
|
9
|
+
Tuple,
|
|
10
|
+
Union,
|
|
11
|
+
runtime_checkable,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from typing_extensions import Literal, ParamSpec, TypeVar
|
|
15
|
+
|
|
16
|
+
from union._datastructures import CodeBundle
|
|
17
|
+
|
|
18
|
+
# if TYPE_CHECKING:
|
|
19
|
+
from union._image import Image
|
|
20
|
+
|
|
21
|
+
P = ParamSpec("P")
|
|
22
|
+
FuncOut = TypeVar("FuncOut")
|
|
23
|
+
|
|
24
|
+
CacheBehavior = Literal["auto", "override", "disable"]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class VersionParameters(Generic[P, FuncOut]):
|
|
29
|
+
"""
|
|
30
|
+
Parameters used for cache version hash generation.
|
|
31
|
+
|
|
32
|
+
:param func: The function to generate a version for. This is a required parameter but can be any callable
|
|
33
|
+
:type func: Callable[P, FuncOut]
|
|
34
|
+
:param image: The container image to generate a version for. This can be a string representing the
|
|
35
|
+
image name or an Image object.
|
|
36
|
+
:type image: Optional[Union[str, Image]]
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
func: Callable[P, FuncOut]
|
|
40
|
+
image: Optional[Union[str, Image]] = None
|
|
41
|
+
code_bundle: Optional[CodeBundle] = None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@runtime_checkable
|
|
45
|
+
class CachePolicy(Protocol):
|
|
46
|
+
def get_version(self, salt: str, params: VersionParameters) -> str: ...
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass
|
|
50
|
+
class Cache:
|
|
51
|
+
"""
|
|
52
|
+
Cache configuration for a task.
|
|
53
|
+
:param behavior: The behavior of the cache. Can be "auto", "override" or "disable".
|
|
54
|
+
:param version_override: The version of the cache. If not provided, the version will be
|
|
55
|
+
generated based on the cache policies
|
|
56
|
+
:type version_override: Optional[str]
|
|
57
|
+
:param serialize: Boolean that indicates if identical (ie. same inputs) instances of this task should be executed in
|
|
58
|
+
serial when caching is enabled. This means that given multiple concurrent executions over identical inputs,
|
|
59
|
+
only a single instance executes and the rest wait to reuse the cached results.
|
|
60
|
+
:type serialize: bool
|
|
61
|
+
:param ignored_inputs: A tuple of input names to ignore when generating the version hash.
|
|
62
|
+
:type ignored_inputs: Union[Tuple[str, ...], str]
|
|
63
|
+
:param salt: A salt used in the hash generation.
|
|
64
|
+
:type salt: str
|
|
65
|
+
:param policies: A list of cache policies to generate the version hash.
|
|
66
|
+
:type policies: Optional[Union[List[CachePolicy], CachePolicy]]
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
behavior: CacheBehavior
|
|
70
|
+
version_override: Optional[str] = None
|
|
71
|
+
serialize: bool = False
|
|
72
|
+
ignored_inputs: Union[Tuple[str, ...], str] = field(default_factory=tuple)
|
|
73
|
+
salt: str = ""
|
|
74
|
+
policies: Optional[Union[List[CachePolicy], CachePolicy]] = None
|
|
75
|
+
|
|
76
|
+
def __post_init__(self):
|
|
77
|
+
if self.behavior not in ["auto", "override", "disable"]:
|
|
78
|
+
raise ValueError(f"Invalid cache behavior: {self.behavior}. Must be one of ['auto', 'override', 'disable']")
|
|
79
|
+
if self.behavior == "disable":
|
|
80
|
+
return
|
|
81
|
+
|
|
82
|
+
if isinstance(self.ignored_inputs, str):
|
|
83
|
+
self._ignored_inputs = (self.ignored_inputs,)
|
|
84
|
+
else:
|
|
85
|
+
self._ignored_inputs = self.ignored_inputs
|
|
86
|
+
|
|
87
|
+
# Normalize policies so that self._policies is always a list
|
|
88
|
+
if self.policies is None:
|
|
89
|
+
from union._cache.defaults import get_default_policies
|
|
90
|
+
|
|
91
|
+
self.policies = get_default_policies()
|
|
92
|
+
elif isinstance(self.policies, CachePolicy):
|
|
93
|
+
self.policies = [self.policies]
|
|
94
|
+
|
|
95
|
+
if self.version_override is None and not self.policies:
|
|
96
|
+
raise ValueError("If version is not defined then at least one cache policy needs to be set")
|
|
97
|
+
|
|
98
|
+
def is_enabled(self) -> bool:
|
|
99
|
+
"""
|
|
100
|
+
Check if the cache policy is enabled.
|
|
101
|
+
"""
|
|
102
|
+
return self.behavior in ["auto", "override"]
|
|
103
|
+
|
|
104
|
+
def get_ignored_inputs(self) -> Tuple[str, ...]:
|
|
105
|
+
return self._ignored_inputs
|
|
106
|
+
|
|
107
|
+
def get_version(self, params: Optional[VersionParameters] = None) -> str:
|
|
108
|
+
if not self.is_enabled():
|
|
109
|
+
return ""
|
|
110
|
+
|
|
111
|
+
if self.version_override is not None:
|
|
112
|
+
return self.version_override
|
|
113
|
+
|
|
114
|
+
if params is None:
|
|
115
|
+
raise ValueError("Version parameters must be provided when version_override is not set.")
|
|
116
|
+
|
|
117
|
+
if params.code_bundle is not None:
|
|
118
|
+
if params.code_bundle.pkl is not None:
|
|
119
|
+
return params.code_bundle.computed_version
|
|
120
|
+
|
|
121
|
+
task_hash = ""
|
|
122
|
+
for policy in self.policies:
|
|
123
|
+
try:
|
|
124
|
+
task_hash += policy.get_version(self.salt, params)
|
|
125
|
+
except Exception as e:
|
|
126
|
+
raise ValueError(f"Failed to generate version for cache policy {policy}.") from e
|
|
127
|
+
|
|
128
|
+
hash_obj = hashlib.sha256(task_hash.encode())
|
|
129
|
+
return hash_obj.hexdigest()
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
CacheRequest = CacheBehavior | Cache
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def cache_from_request(cache: CacheRequest) -> Cache:
|
|
136
|
+
"""
|
|
137
|
+
Coerce user input into a cache object.
|
|
138
|
+
"""
|
|
139
|
+
if isinstance(cache, Cache):
|
|
140
|
+
return cache
|
|
141
|
+
return Cache(behavior=cache)
|
union/_cache/defaults.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import ast
|
|
2
|
+
import hashlib
|
|
3
|
+
import inspect
|
|
4
|
+
import textwrap
|
|
5
|
+
|
|
6
|
+
from .cache import CachePolicy, VersionParameters
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FunctionBodyPolicy(CachePolicy):
|
|
10
|
+
"""
|
|
11
|
+
A class that implements a versioning mechanism for functions by generating
|
|
12
|
+
a SHA-256 hash of the function's source code combined with a salt.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def get_version(self, salt: str, params: VersionParameters) -> str:
|
|
16
|
+
"""
|
|
17
|
+
This method generates a version string for a function by hashing the function's source code
|
|
18
|
+
combined with a salt.
|
|
19
|
+
|
|
20
|
+
:param salt: A string that is used to salt the hash.
|
|
21
|
+
:param params: VersionParameters object that contains the parameters (e.g. function, ImageSpec, etc.) that are
|
|
22
|
+
used to generate the version.
|
|
23
|
+
|
|
24
|
+
:return: A string that represents the version of the function.
|
|
25
|
+
"""
|
|
26
|
+
if params.func is None:
|
|
27
|
+
return ""
|
|
28
|
+
|
|
29
|
+
source = inspect.getsource(params.func)
|
|
30
|
+
dedented_source = textwrap.dedent(source)
|
|
31
|
+
|
|
32
|
+
# Parse the source code into an Abstract Syntax Tree (AST)
|
|
33
|
+
parsed_ast = ast.parse(dedented_source)
|
|
34
|
+
|
|
35
|
+
# Convert the AST into a string representation
|
|
36
|
+
ast_bytes = ast.dump(parsed_ast, include_attributes=False).encode("utf-8")
|
|
37
|
+
|
|
38
|
+
# Combine the AST bytes with the salt (encoded into bytes)
|
|
39
|
+
combined_data = ast_bytes + salt.encode("utf-8")
|
|
40
|
+
|
|
41
|
+
# Return the SHA-256 hash of the combined data (AST + salt)
|
|
42
|
+
return hashlib.sha256(combined_data).hexdigest()
|
union/_cli/__init__.py
ADDED
|
File without changes
|
union/_cli/_common.py
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import importlib.util
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from abc import abstractmethod
|
|
8
|
+
from dataclasses import Field, dataclass, field, replace
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from types import MappingProxyType, ModuleType
|
|
11
|
+
from typing import Any, Dict, Iterable, List, Optional
|
|
12
|
+
|
|
13
|
+
import rich_click as click
|
|
14
|
+
from rich.table import Table
|
|
15
|
+
|
|
16
|
+
import union.errors
|
|
17
|
+
|
|
18
|
+
PROJECT_OPTION = click.Option(
|
|
19
|
+
param_decls=["-p", "--project"],
|
|
20
|
+
required=False,
|
|
21
|
+
type=str,
|
|
22
|
+
default="default",
|
|
23
|
+
help="Project to operate on",
|
|
24
|
+
show_default=True,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
DOMAIN_OPTION = click.Option(
|
|
28
|
+
param_decls=["-d", "--domain"],
|
|
29
|
+
required=False,
|
|
30
|
+
type=str,
|
|
31
|
+
default="development",
|
|
32
|
+
help="Domain to operate on",
|
|
33
|
+
show_default=True,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
DRY_RUN_OPTION = click.Option(
|
|
37
|
+
param_decls=["--dry-run", "--dryrun"],
|
|
38
|
+
required=False,
|
|
39
|
+
type=bool,
|
|
40
|
+
is_flag=True,
|
|
41
|
+
default=False,
|
|
42
|
+
help="Dry run, do not actually call the backend service.",
|
|
43
|
+
show_default=True,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _common_options() -> List[click.Option]:
|
|
48
|
+
"""
|
|
49
|
+
Common options for that will be added to all commands and groups that inherit from CommandBase or GroupBase.
|
|
50
|
+
"""
|
|
51
|
+
return [PROJECT_OPTION, DOMAIN_OPTION]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# This is global state for the CLI, it is manipulated by the main command
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class CLIConfig:
|
|
59
|
+
"""
|
|
60
|
+
This is the global state for the CLI. It is manipulated by the main command.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
log_level: int = logging.ERROR
|
|
64
|
+
endpoint: str = "dns:///dogfood.cloud-staging.union.ai"
|
|
65
|
+
insecure: bool = False
|
|
66
|
+
org_override: str | None = None
|
|
67
|
+
|
|
68
|
+
def replace(self, **kwargs) -> CLIConfig:
|
|
69
|
+
"""
|
|
70
|
+
Replace the global state with a new one.
|
|
71
|
+
"""
|
|
72
|
+
return replace(self, **kwargs)
|
|
73
|
+
|
|
74
|
+
def init(self, project: str | None = None, domain: str | None = None):
|
|
75
|
+
import union
|
|
76
|
+
|
|
77
|
+
union.init(
|
|
78
|
+
endpoint=self.endpoint,
|
|
79
|
+
project=project,
|
|
80
|
+
domain=domain,
|
|
81
|
+
log_level=self.log_level,
|
|
82
|
+
insecure=self.insecure,
|
|
83
|
+
org=self.org_override,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class InvokeBaseMixin:
|
|
88
|
+
"""
|
|
89
|
+
Mixin to catch grpc.RpcError, union.RpcError, other errors and other exceptions and raise them as
|
|
90
|
+
gclick.ClickException.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
def invoke(self, ctx):
|
|
94
|
+
import grpc
|
|
95
|
+
|
|
96
|
+
try:
|
|
97
|
+
return super().invoke(ctx) # type: ignore
|
|
98
|
+
except grpc.aio.AioRpcError as e:
|
|
99
|
+
if e.code() == grpc.StatusCode.UNAUTHENTICATED:
|
|
100
|
+
raise click.ClickException(f"Authentication failed. Please check your credentials. {e!s}")
|
|
101
|
+
if e.code() == grpc.StatusCode.NOT_FOUND:
|
|
102
|
+
raise click.ClickException(f"Requested object NOT FOUND. Please check your input. Error: {e!s}")
|
|
103
|
+
if e.code() == grpc.StatusCode.ALREADY_EXISTS:
|
|
104
|
+
raise click.ClickException("Resource already exists.")
|
|
105
|
+
raise click.ClickException(f"Error invoking command: {e!s}") from e
|
|
106
|
+
except union.errors.InitializationError:
|
|
107
|
+
raise click.ClickException("Initialize the CLI with a remote configuration. For example, pass --endpoint")
|
|
108
|
+
except Exception as e:
|
|
109
|
+
raise click.ClickException(f"Error invoking command: {e}") from e
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class CommandBase(InvokeBaseMixin, click.RichCommand):
|
|
113
|
+
"""
|
|
114
|
+
Base class for all commands, that adds common options to all commands if enabled.
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
common_options_enabled = True
|
|
118
|
+
|
|
119
|
+
def __init__(self, *args, **kwargs):
|
|
120
|
+
if "params" not in kwargs:
|
|
121
|
+
kwargs["params"] = []
|
|
122
|
+
if self.common_options_enabled:
|
|
123
|
+
kwargs["params"].extend(_common_options())
|
|
124
|
+
super().__init__(*args, **kwargs)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class GroupBase(InvokeBaseMixin, click.RichGroup):
|
|
128
|
+
"""
|
|
129
|
+
Base class for all commands, that adds common options to all commands if enabled.
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
common_options_enabled = True
|
|
133
|
+
|
|
134
|
+
def __init__(self, *args, **kwargs):
|
|
135
|
+
if "params" not in kwargs:
|
|
136
|
+
kwargs["params"] = []
|
|
137
|
+
if self.common_options_enabled:
|
|
138
|
+
kwargs["params"].extend(_common_options())
|
|
139
|
+
super().__init__(*args, **kwargs)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class GroupBaseNoOptions(GroupBase):
|
|
143
|
+
common_options_enabled = False
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def make_click_option_field(o: click.Option) -> Field:
|
|
147
|
+
if o.multiple:
|
|
148
|
+
o.help = click.style("Multiple values allowed.", bold=True) + f"{o.help}"
|
|
149
|
+
return field(default_factory=lambda: o.default, metadata={"click.option": o})
|
|
150
|
+
return field(default=o.default, metadata={"click.option": o})
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def get_option_from_metadata(metadata: MappingProxyType) -> click.Option:
|
|
154
|
+
return metadata["click.option"]
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def key_value_callback(_: Any, param: str, values: List[str]) -> Optional[Dict[str, str]]:
|
|
158
|
+
"""
|
|
159
|
+
Callback for click to parse key-value pairs.
|
|
160
|
+
"""
|
|
161
|
+
if not values:
|
|
162
|
+
return None
|
|
163
|
+
result = {}
|
|
164
|
+
for v in values:
|
|
165
|
+
if "=" not in v:
|
|
166
|
+
raise click.BadParameter(f"Expected key-value pair of the form key=value, got {v}")
|
|
167
|
+
k, v_ = v.split("=", 1)
|
|
168
|
+
result[k.strip()] = v_.strip()
|
|
169
|
+
return result
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class ObjectsPerFileGroup(GroupBase):
|
|
173
|
+
"""
|
|
174
|
+
Group that creates a command for each object in a python file.
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
def __init__(self, filename: Path, *args, **kwargs):
|
|
178
|
+
super().__init__(*args, **kwargs)
|
|
179
|
+
if not filename.exists():
|
|
180
|
+
raise click.ClickException(f"{filename} does not exists")
|
|
181
|
+
self.filename = filename
|
|
182
|
+
self._objs = None
|
|
183
|
+
|
|
184
|
+
@abstractmethod
|
|
185
|
+
def _filter_objects(self, module: ModuleType) -> Dict[str, Any]:
|
|
186
|
+
raise NotImplementedError
|
|
187
|
+
|
|
188
|
+
@property
|
|
189
|
+
def objs(self) -> Dict[str, Any]:
|
|
190
|
+
if self._objs is not None:
|
|
191
|
+
return self._objs
|
|
192
|
+
|
|
193
|
+
module_name = os.path.splitext(os.path.basename(self.filename))[0]
|
|
194
|
+
module_path = os.path.dirname(os.path.abspath(self.filename))
|
|
195
|
+
|
|
196
|
+
spec = importlib.util.spec_from_file_location(module_name, self.filename)
|
|
197
|
+
module = importlib.util.module_from_spec(spec)
|
|
198
|
+
sys.modules[module_name] = module
|
|
199
|
+
|
|
200
|
+
sys.path.append(module_path)
|
|
201
|
+
spec.loader.exec_module(module)
|
|
202
|
+
|
|
203
|
+
self._objs = self._filter_objects(module)
|
|
204
|
+
return self._objs
|
|
205
|
+
|
|
206
|
+
def list_commands(self, ctx):
|
|
207
|
+
m = list(self.objs.keys())
|
|
208
|
+
return sorted(m)
|
|
209
|
+
|
|
210
|
+
@abstractmethod
|
|
211
|
+
def _get_command_for_obj(self, ctx: click.Context, obj_name: str, obj: Any) -> click.Command: ...
|
|
212
|
+
|
|
213
|
+
def get_command(self, ctx, obj_name):
|
|
214
|
+
obj = self.objs[obj_name]
|
|
215
|
+
return self._get_command_for_obj(ctx, obj_name, obj)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class FileGroup(GroupBase):
|
|
219
|
+
"""
|
|
220
|
+
Group that creates a command for each file in the current directory that is not __init__.py.
|
|
221
|
+
"""
|
|
222
|
+
|
|
223
|
+
common_options_enabled = False
|
|
224
|
+
|
|
225
|
+
def __init__(
|
|
226
|
+
self,
|
|
227
|
+
*args,
|
|
228
|
+
directory: Path | None = None,
|
|
229
|
+
**kwargs,
|
|
230
|
+
):
|
|
231
|
+
if "params" not in kwargs:
|
|
232
|
+
kwargs["params"] = []
|
|
233
|
+
super().__init__(*args, **kwargs)
|
|
234
|
+
self._files = None
|
|
235
|
+
self._dir = directory
|
|
236
|
+
|
|
237
|
+
@property
|
|
238
|
+
def files(self):
|
|
239
|
+
if self._files is None:
|
|
240
|
+
directory = self._dir or Path(".").absolute()
|
|
241
|
+
self._files = [os.fspath(p) for p in directory.glob("*.py") if p.name != "__init__.py"]
|
|
242
|
+
return self._files
|
|
243
|
+
|
|
244
|
+
def list_commands(self, ctx):
|
|
245
|
+
return self.files
|
|
246
|
+
|
|
247
|
+
def get_command(self, ctx, filename):
|
|
248
|
+
raise NotImplementedError
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def get_table(title: str, vals: Iterable[Any]) -> Table:
|
|
252
|
+
"""
|
|
253
|
+
Get a table from a list of values.
|
|
254
|
+
"""
|
|
255
|
+
table = Table(title=title)
|
|
256
|
+
headers = None
|
|
257
|
+
for p in vals:
|
|
258
|
+
if headers is None:
|
|
259
|
+
headers = [k for k, _ in p.__rich_repr__()]
|
|
260
|
+
for h in headers:
|
|
261
|
+
table.add_column(h.capitalize())
|
|
262
|
+
table.add_row(*[str(v) for _, v in p.__rich_repr__()])
|
|
263
|
+
return table
|
union/_cli/_create.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from typing import get_args
|
|
2
|
+
|
|
3
|
+
import rich_click as click
|
|
4
|
+
|
|
5
|
+
import union._cli._common as common
|
|
6
|
+
from union.remote._secret import SecretTypes
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@click.group(name="create")
|
|
10
|
+
def create():
|
|
11
|
+
"""
|
|
12
|
+
Create a new task or environment.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@create.command(cls=common.CommandBase)
|
|
17
|
+
@click.argument("name", type=str, required=True)
|
|
18
|
+
@click.argument("value", type=str, required=False)
|
|
19
|
+
@click.option("--from-file", type=click.Path(exists=True), help="Path to the file with the binary secret.")
|
|
20
|
+
@click.option("--type", type=click.Choice(get_args(SecretTypes)), default="regular", help="Type of the secret.")
|
|
21
|
+
@click.pass_obj
|
|
22
|
+
def secret(
|
|
23
|
+
cfg: common.CLIConfig,
|
|
24
|
+
name: str,
|
|
25
|
+
value: str | None = None,
|
|
26
|
+
from_file: str | None = None,
|
|
27
|
+
type: SecretTypes = "regular",
|
|
28
|
+
project: str | None = None,
|
|
29
|
+
domain: str | None = None,
|
|
30
|
+
):
|
|
31
|
+
"""
|
|
32
|
+
Create a new secret.
|
|
33
|
+
"""
|
|
34
|
+
from union.remote import Secret
|
|
35
|
+
|
|
36
|
+
cfg.init(project, domain)
|
|
37
|
+
if from_file:
|
|
38
|
+
with open(from_file, "rb") as f:
|
|
39
|
+
value = f.read()
|
|
40
|
+
Secret.create(name=name, value=value, type=type)
|
union/_cli/_delete.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import rich_click as click
|
|
2
|
+
|
|
3
|
+
import union._cli._common as common
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@click.group(name="delete")
|
|
7
|
+
def delete():
|
|
8
|
+
"""
|
|
9
|
+
Delete a task or environment.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@click.command(cls=common.CommandBase)
|
|
14
|
+
@click.argument("name", type=str, required=True)
|
|
15
|
+
@click.pass_obj
|
|
16
|
+
def secret(cfg: common.CLIConfig, name: str, project: str | None = None, domain: str | None = None):
|
|
17
|
+
"""
|
|
18
|
+
Delete a secret.
|
|
19
|
+
"""
|
|
20
|
+
from union.remote import Secret
|
|
21
|
+
|
|
22
|
+
cfg.init(project, domain)
|
|
23
|
+
Secret.delete(name=name)
|
union/_cli/_deploy.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
from dataclasses import dataclass, fields
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from types import ModuleType
|
|
4
|
+
from typing import Any, Dict, List, cast
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
|
|
8
|
+
import union
|
|
9
|
+
|
|
10
|
+
from .._code_bundle._utils import CopyFiles
|
|
11
|
+
from . import _common as common
|
|
12
|
+
from ._common import CLIConfig
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class DeployArguments:
|
|
17
|
+
project: str = common.make_click_option_field(common.PROJECT_OPTION)
|
|
18
|
+
domain: str = common.make_click_option_field(common.DOMAIN_OPTION)
|
|
19
|
+
dry_run: bool = common.make_click_option_field(common.DRY_RUN_OPTION)
|
|
20
|
+
copy_style: CopyFiles = common.make_click_option_field(
|
|
21
|
+
click.Option(
|
|
22
|
+
["--copy-style"],
|
|
23
|
+
type=click.Choice(["loaded_modules", "all_files", "none"]),
|
|
24
|
+
default="loaded_modules",
|
|
25
|
+
help="Copy style to use when running the task",
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
version: CopyFiles = common.make_click_option_field(
|
|
29
|
+
click.Option(
|
|
30
|
+
["--version"],
|
|
31
|
+
type=str,
|
|
32
|
+
required=False,
|
|
33
|
+
help="If no files are copied, user must specify a version to register tasks with",
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
@classmethod
|
|
38
|
+
def from_dict(cls, d: Dict[str, Any]) -> "DeployArguments":
|
|
39
|
+
return cls(**d)
|
|
40
|
+
|
|
41
|
+
@classmethod
|
|
42
|
+
def options(cls) -> List[click.Option]:
|
|
43
|
+
"""
|
|
44
|
+
Return the set of base parameters added to every pyflyte run workflow subcommand.
|
|
45
|
+
"""
|
|
46
|
+
return [common.get_option_from_metadata(f.metadata) for f in fields(cls) if f.metadata]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class DeployEnvCommand(click.Command):
|
|
50
|
+
def __init__(self, obj_name: str, obj: Any, deploy_args: DeployArguments, *args, **kwargs):
|
|
51
|
+
self.obj_name = obj_name
|
|
52
|
+
self.obj = obj
|
|
53
|
+
self.deploy_args = deploy_args
|
|
54
|
+
super().__init__(name=obj_name, *args, **kwargs)
|
|
55
|
+
|
|
56
|
+
def invoke(self, ctx):
|
|
57
|
+
print(f"Deploying environment: {self.obj_name}")
|
|
58
|
+
obj: CLIConfig = ctx.obj
|
|
59
|
+
obj.remote_init(self.deploy_args.project, self.deploy_args.domain)
|
|
60
|
+
return union.deploy(
|
|
61
|
+
self.obj,
|
|
62
|
+
dryrun=self.deploy_args.dry_run,
|
|
63
|
+
copy_style=self.deploy_args.copy_style,
|
|
64
|
+
version=self.deploy_args.version,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class EnvPerFileGroup(common.ObjectsPerFileGroup):
|
|
69
|
+
"""
|
|
70
|
+
Group that creates a command for each task in the current directory that is not __init__.py.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
def __init__(self, filename: Path, deploy_args: DeployArguments, *args, **kwargs):
|
|
74
|
+
super().__init__(*args, filename=filename, **kwargs)
|
|
75
|
+
self.deploy_args = deploy_args
|
|
76
|
+
|
|
77
|
+
def _filter_objects(self, module: ModuleType) -> Dict[str, Any]:
|
|
78
|
+
return {k: v for k, v in module.__dict__.items() if isinstance(v, union.TaskEnvironment)}
|
|
79
|
+
|
|
80
|
+
def _get_command_for_obj(self, ctx: click.Context, obj_name: str, obj: Any) -> click.Command:
|
|
81
|
+
obj = cast(union.TaskEnvironment, obj)
|
|
82
|
+
return DeployEnvCommand(
|
|
83
|
+
obj_name=obj_name,
|
|
84
|
+
obj=obj,
|
|
85
|
+
help=obj.description,
|
|
86
|
+
deploy_args=self.deploy_args,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class EnvFiles(common.FileGroup):
|
|
91
|
+
"""
|
|
92
|
+
Group that creates a command for each file in the current directory that is not __init__.py.
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
common_options_enabled = False
|
|
96
|
+
|
|
97
|
+
def __init__(
|
|
98
|
+
self,
|
|
99
|
+
*args,
|
|
100
|
+
**kwargs,
|
|
101
|
+
):
|
|
102
|
+
if "params" not in kwargs:
|
|
103
|
+
kwargs["params"] = []
|
|
104
|
+
kwargs["params"].extend(DeployArguments.options())
|
|
105
|
+
super().__init__(*args, **kwargs)
|
|
106
|
+
|
|
107
|
+
def get_command(self, ctx, filename):
|
|
108
|
+
deploy_args = DeployArguments.from_dict(ctx.params)
|
|
109
|
+
return EnvPerFileGroup(
|
|
110
|
+
filename=Path(filename),
|
|
111
|
+
deploy_args=deploy_args,
|
|
112
|
+
name=filename,
|
|
113
|
+
help=f"Run, functions decorated `env.task` or instances of Tasks in {filename}",
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
deploy = EnvFiles(
|
|
118
|
+
name="deploy",
|
|
119
|
+
help="deploy one or more environments from a python file.",
|
|
120
|
+
)
|