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
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pathlib
|
|
3
|
+
import random
|
|
4
|
+
import tempfile
|
|
5
|
+
import typing
|
|
6
|
+
from typing import AsyncIterator, Optional
|
|
7
|
+
from uuid import UUID
|
|
8
|
+
|
|
9
|
+
import fsspec
|
|
10
|
+
from fsspec.asyn import AsyncFileSystem
|
|
11
|
+
from fsspec.utils import get_protocol
|
|
12
|
+
from obstore.exceptions import GenericError
|
|
13
|
+
from obstore.fsspec import register
|
|
14
|
+
|
|
15
|
+
from union._initialize import get_storage
|
|
16
|
+
from union._logging import logger
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def is_remote(path: typing.Union[pathlib.Path | str]) -> bool:
|
|
20
|
+
"""
|
|
21
|
+
Let's find a replacement
|
|
22
|
+
"""
|
|
23
|
+
protocol = get_protocol(str(path))
|
|
24
|
+
if protocol is None:
|
|
25
|
+
return False
|
|
26
|
+
return protocol != "file"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def strip_file_header(path: str) -> str:
|
|
30
|
+
"""
|
|
31
|
+
Drops file:// if it exists from the file
|
|
32
|
+
"""
|
|
33
|
+
if path.startswith("file://"):
|
|
34
|
+
return path.replace("file://", "", 1)
|
|
35
|
+
return path
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def get_random_local_path(file_path_or_file_name: pathlib.Path | str | None = None) -> pathlib.Path:
|
|
39
|
+
"""
|
|
40
|
+
Use file_path_or_file_name, when you want a random directory, but want to preserve the leaf file name
|
|
41
|
+
"""
|
|
42
|
+
local_tmp = pathlib.Path(tempfile.mkdtemp(prefix="union-tmp-"))
|
|
43
|
+
key = UUID(int=random.getrandbits(128)).hex
|
|
44
|
+
tmp_folder = local_tmp / key
|
|
45
|
+
tail = ""
|
|
46
|
+
if file_path_or_file_name:
|
|
47
|
+
_, tail = os.path.split(file_path_or_file_name)
|
|
48
|
+
if tail:
|
|
49
|
+
tmp_folder.mkdir(parents=True, exist_ok=True)
|
|
50
|
+
return tmp_folder / tail
|
|
51
|
+
local_tmp.mkdir(parents=True, exist_ok=True)
|
|
52
|
+
return tmp_folder
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_random_local_directory() -> pathlib.Path:
|
|
56
|
+
"""
|
|
57
|
+
:return: a random directory
|
|
58
|
+
:rtype: pathlib.Path
|
|
59
|
+
"""
|
|
60
|
+
_dir = get_random_local_path(None)
|
|
61
|
+
pathlib.Path(_dir).mkdir(parents=True, exist_ok=True)
|
|
62
|
+
return _dir
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def get_underlying_filesystem(
|
|
66
|
+
protocol: typing.Optional[str] = None,
|
|
67
|
+
anonymous: bool = False,
|
|
68
|
+
path: typing.Optional[str] = None,
|
|
69
|
+
**kwargs,
|
|
70
|
+
) -> fsspec.AbstractFileSystem:
|
|
71
|
+
if protocol is None:
|
|
72
|
+
# If protocol is None, get it from the path
|
|
73
|
+
protocol = get_protocol(path)
|
|
74
|
+
|
|
75
|
+
if get_storage():
|
|
76
|
+
storage_config = get_storage()
|
|
77
|
+
kwargs.update(storage_config.get_fsspec_kwargs(anonymous, **kwargs))
|
|
78
|
+
return fsspec.filesystem(protocol, **kwargs)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _get_anonymous_filesystem(from_path):
|
|
82
|
+
"""Get the anonymous file system if needed."""
|
|
83
|
+
return get_underlying_filesystem(get_protocol(from_path), anonymous=True, asynchronous=True)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
async def get(from_path: str, to_path: Optional[str] = None, recursive: bool = False, **kwargs) -> str:
|
|
87
|
+
if not to_path:
|
|
88
|
+
name = pathlib.Path(from_path).name
|
|
89
|
+
to_path = get_random_local_path(file_path_or_file_name=name)
|
|
90
|
+
logger.debug(f"Storing file from {from_path} to {to_path}")
|
|
91
|
+
file_system = get_underlying_filesystem(path=from_path)
|
|
92
|
+
try:
|
|
93
|
+
return await _get_from_filesystem(file_system, from_path, to_path, recursive=recursive, **kwargs)
|
|
94
|
+
except (OSError, GenericError) as oe:
|
|
95
|
+
logger.debug(f"Error in getting {from_path} to {to_path} rec {recursive} {oe}")
|
|
96
|
+
if isinstance(file_system, AsyncFileSystem):
|
|
97
|
+
try:
|
|
98
|
+
exists = await file_system._exists(from_path) # pylint: disable=W0212
|
|
99
|
+
except GenericError:
|
|
100
|
+
# for obstore, as it does not raise FileNotFoundError in fsspec but GenericError
|
|
101
|
+
# force it to try get_filesystem(anonymous=True)
|
|
102
|
+
exists = True
|
|
103
|
+
else:
|
|
104
|
+
exists = file_system.exists(from_path)
|
|
105
|
+
if not exists:
|
|
106
|
+
# TODO: update exception to be more specific
|
|
107
|
+
raise AssertionError(f"Unable to load data from {from_path}")
|
|
108
|
+
file_system = _get_anonymous_filesystem(from_path)
|
|
109
|
+
logger.debug(f"Attempting anonymous get with {file_system}")
|
|
110
|
+
return await _get_from_filesystem(file_system, from_path, to_path, recursive=recursive, **kwargs)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
async def _get_from_filesystem(
|
|
114
|
+
file_system: fsspec.AbstractFileSystem, from_path: str, to_path: pathlib.Path, recursive: bool, **kwargs
|
|
115
|
+
):
|
|
116
|
+
if isinstance(file_system, AsyncFileSystem):
|
|
117
|
+
dst = await file_system._get(from_path, to_path, recursive=recursive, **kwargs) # pylint: disable=W0212
|
|
118
|
+
else:
|
|
119
|
+
dst = file_system.get(from_path, to_path, recursive=recursive, **kwargs)
|
|
120
|
+
|
|
121
|
+
if isinstance(dst, (str, pathlib.Path)):
|
|
122
|
+
return dst
|
|
123
|
+
return to_path
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
async def put(from_path: str, to_path: Optional[str] = None, recursive: bool = False, **kwargs):
|
|
127
|
+
if not to_path:
|
|
128
|
+
from union._context import internal_ctx
|
|
129
|
+
|
|
130
|
+
ctx = internal_ctx()
|
|
131
|
+
name = pathlib.Path(from_path).name if not recursive else None # don't pass a name for folders
|
|
132
|
+
to_path = ctx.raw_data.get_random_remote_path(file_name=name)
|
|
133
|
+
|
|
134
|
+
file_system = get_underlying_filesystem(path=to_path)
|
|
135
|
+
from_path = strip_file_header(from_path)
|
|
136
|
+
if isinstance(file_system, AsyncFileSystem):
|
|
137
|
+
dst = await file_system._put(from_path, to_path, recursive=recursive, **kwargs) # pylint: disable=W0212
|
|
138
|
+
else:
|
|
139
|
+
dst = file_system.put(from_path, to_path, recursive=recursive, **kwargs)
|
|
140
|
+
if isinstance(dst, (str, pathlib.Path)):
|
|
141
|
+
return dst
|
|
142
|
+
else:
|
|
143
|
+
return to_path
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
async def put_stream(
|
|
147
|
+
data_iterable: typing.AsyncIterable[bytes] | bytes, *, name: str | None = None, to_path: str | None = None, **kwargs
|
|
148
|
+
) -> str:
|
|
149
|
+
"""
|
|
150
|
+
Put a stream of data to a remote location. This is useful for streaming data to a remote location.
|
|
151
|
+
Example usage:
|
|
152
|
+
```python
|
|
153
|
+
import union.storage as storage
|
|
154
|
+
storage.put_stream(iter([b'hello']), name="my_file.txt")
|
|
155
|
+
OR
|
|
156
|
+
storage.put_stream(iter([b'hello']), to_path="s3://my_bucket/my_file.txt")
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
:param data_iterable: Iterable of bytes to be streamed.
|
|
160
|
+
:param name: Name of the file to be created. If not provided, a random name will be generated.
|
|
161
|
+
:param to_path: Path to the remote location where the data will be stored.
|
|
162
|
+
:param kwargs: Additional arguments to be passed to the underlying filesystem.
|
|
163
|
+
:rtype: str
|
|
164
|
+
:return: The path to the remote location where the data was stored.
|
|
165
|
+
"""
|
|
166
|
+
if not to_path:
|
|
167
|
+
from union._context import internal_ctx
|
|
168
|
+
|
|
169
|
+
ctx = internal_ctx()
|
|
170
|
+
to_path = ctx.raw_data.get_random_remote_path(file_name=name)
|
|
171
|
+
fs = get_underlying_filesystem(path=to_path)
|
|
172
|
+
file_handle = None
|
|
173
|
+
if isinstance(fs, AsyncFileSystem):
|
|
174
|
+
try:
|
|
175
|
+
file_handle = await fs.open_async(to_path, "wb", **kwargs)
|
|
176
|
+
if isinstance(data_iterable, bytes):
|
|
177
|
+
await file_handle.write(data_iterable)
|
|
178
|
+
else:
|
|
179
|
+
async for data in data_iterable:
|
|
180
|
+
await file_handle.write(data)
|
|
181
|
+
return
|
|
182
|
+
except NotImplementedError:
|
|
183
|
+
logger.debug(f"{fs} doesn't implement 'open_async', falling back to sync")
|
|
184
|
+
finally:
|
|
185
|
+
if file_handle is not None:
|
|
186
|
+
await file_handle.close()
|
|
187
|
+
|
|
188
|
+
with fs.open(to_path, "wb", **kwargs) as f:
|
|
189
|
+
if isinstance(data_iterable, bytes):
|
|
190
|
+
f.write(data_iterable)
|
|
191
|
+
else:
|
|
192
|
+
# If data_iterable is async iterable, iterate over it and write each chunk to the file
|
|
193
|
+
async for data in data_iterable:
|
|
194
|
+
f.write(data)
|
|
195
|
+
return str(to_path)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
async def get_stream(path: pathlib.Path, chunk_size=10 * 2**20, **kwargs) -> AsyncIterator[bytes]:
|
|
199
|
+
"""
|
|
200
|
+
Get a stream of data from a remote location.
|
|
201
|
+
This is useful for downloading streaming data from a remote location.
|
|
202
|
+
Example usage:
|
|
203
|
+
```python
|
|
204
|
+
import union.storage as storage
|
|
205
|
+
obj = storage.get_stream(path="s3://my_bucket/my_file.txt")
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
:param path: Path to the remote location where the data will be downloaded.
|
|
209
|
+
:param kwargs: Additional arguments to be passed to the underlying filesystem.
|
|
210
|
+
:param chunk_size: Size of each chunk to be read from the file.
|
|
211
|
+
:return: An async iterator that yields chunks of data.
|
|
212
|
+
"""
|
|
213
|
+
fs = get_underlying_filesystem(path=path, **kwargs)
|
|
214
|
+
file_size = fs.info(path)["size"]
|
|
215
|
+
total_read = 0
|
|
216
|
+
file_handle = None
|
|
217
|
+
try:
|
|
218
|
+
if isinstance(fs, AsyncFileSystem):
|
|
219
|
+
file_handle = await fs.open_async(path, "rb")
|
|
220
|
+
while chunk := await file_handle.read(min(chunk_size, file_size - total_read)):
|
|
221
|
+
total_read += len(chunk)
|
|
222
|
+
yield chunk
|
|
223
|
+
return
|
|
224
|
+
except NotImplementedError:
|
|
225
|
+
logger.debug(f"{fs} doesn't implement 'open_async', falling back to sync")
|
|
226
|
+
finally:
|
|
227
|
+
if file_handle is not None:
|
|
228
|
+
file_handle.close()
|
|
229
|
+
|
|
230
|
+
# Sync fallback
|
|
231
|
+
with fs.open(path, "rb") as file_handle:
|
|
232
|
+
while chunk := file_handle.read(min(chunk_size, file_size - total_read)):
|
|
233
|
+
total_read += len(chunk)
|
|
234
|
+
yield chunk
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def join(*paths: str) -> str:
|
|
238
|
+
"""
|
|
239
|
+
Join multiple paths together. This is a wrapper around os.path.join.
|
|
240
|
+
# TODO replace with proper join with fsspec root etc
|
|
241
|
+
|
|
242
|
+
:param paths: Paths to be joined.
|
|
243
|
+
"""
|
|
244
|
+
return str(os.path.join(*paths))
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
register(["s3", "gs", "abfs", "abfss"], asynchronous=True)
|
union/storage/_utils.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
# This is the default chunk size union will use for writing to S3 and GCS. This is set to 25MB by default and is
|
|
4
|
+
# configurable by the user if needed. This is used when put() is called on filesystems.
|
|
5
|
+
_WRITE_SIZE_CHUNK_BYTES = int(os.environ.get("_F_P_WRITE_CHUNK_SIZE", "26214400")) # 25 * 2**20
|
union/types/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from ._renderer import Renderable
|
|
2
|
+
from ._string_literals import literal_string_repr
|
|
3
|
+
from ._type_engine import TypeEngine, TypeTransformer, TypeTransformerFailedError
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"Renderable",
|
|
7
|
+
"TypeEngine",
|
|
8
|
+
"TypeTransformer",
|
|
9
|
+
"TypeTransformerFailedError",
|
|
10
|
+
"literal_string_repr",
|
|
11
|
+
]
|
union/types/_renderer.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, Any
|
|
2
|
+
|
|
3
|
+
from markdown_it import MarkdownIt
|
|
4
|
+
from typing_extensions import Protocol, runtime_checkable
|
|
5
|
+
|
|
6
|
+
from union._utils import lazy_module
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
# Always import these modules in type-checking mode or when running pytest
|
|
10
|
+
import pandas
|
|
11
|
+
import pyarrow
|
|
12
|
+
else:
|
|
13
|
+
pandas = lazy_module("pandas")
|
|
14
|
+
pyarrow = lazy_module("pyarrow")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@runtime_checkable
|
|
18
|
+
class Renderable(Protocol):
|
|
19
|
+
def to_html(self, python_value: Any) -> str:
|
|
20
|
+
"""Convert an object(markdown, pandas.dataframe) to HTML and return HTML as a unicode string.
|
|
21
|
+
Returns: An HTML document as a string.
|
|
22
|
+
"""
|
|
23
|
+
raise NotImplementedError
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
DEFAULT_MAX_ROWS = 10
|
|
27
|
+
DEFAULT_MAX_COLS = 100
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class TopFrameRenderer:
|
|
31
|
+
"""
|
|
32
|
+
Render a DataFrame as an HTML table.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def __init__(self, max_rows: int = DEFAULT_MAX_ROWS, max_cols: int = DEFAULT_MAX_COLS):
|
|
36
|
+
self._max_rows = max_rows
|
|
37
|
+
self._max_cols = max_cols
|
|
38
|
+
|
|
39
|
+
def to_html(self, df: "pandas.DataFrame") -> str:
|
|
40
|
+
assert isinstance(df, pandas.DataFrame)
|
|
41
|
+
return df.to_html(max_rows=self._max_rows, max_cols=self._max_cols)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ArrowRenderer:
|
|
45
|
+
"""
|
|
46
|
+
Render an Arrow dataframe as an HTML table.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
def to_html(self, df: "pyarrow.Table") -> str:
|
|
50
|
+
assert isinstance(df, pyarrow.Table)
|
|
51
|
+
return df.to_string()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class MarkdownRenderer:
|
|
55
|
+
"""Convert a markdown string to HTML and return HTML as a unicode string."""
|
|
56
|
+
|
|
57
|
+
def to_html(self, text: str) -> str:
|
|
58
|
+
return MarkdownIt().render(text)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class SourceCodeRenderer:
|
|
62
|
+
"""
|
|
63
|
+
Convert Python source code to HTML, and return HTML as a unicode string.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
def __init__(self, title: str = "Source Code"):
|
|
67
|
+
self._title = title
|
|
68
|
+
|
|
69
|
+
def to_html(self, source_code: str) -> str:
|
|
70
|
+
"""
|
|
71
|
+
Convert the provided Python source code into HTML format using Pygments library.
|
|
72
|
+
|
|
73
|
+
This method applies a colorful style and replaces the color "#fff0f0" with "#ffffff" in CSS.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
source_code (str): The Python source code to be converted.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
str: The resulting HTML as a string, including CSS and highlighted source code.
|
|
80
|
+
"""
|
|
81
|
+
from pygments import highlight
|
|
82
|
+
from pygments.formatters.html import HtmlFormatter
|
|
83
|
+
from pygments.lexers.python import PythonLexer
|
|
84
|
+
|
|
85
|
+
formatter = HtmlFormatter(style="colorful")
|
|
86
|
+
css = formatter.get_style_defs(".highlight").replace("#fff0f0", "#ffffff")
|
|
87
|
+
html = highlight(source_code, PythonLexer(), formatter)
|
|
88
|
+
return f"<style>{css}</style>{html}"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class PythonDependencyRenderer:
|
|
92
|
+
"""
|
|
93
|
+
PythonDependencyDeck is a deck that contains information about packages installed via pip.
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
def __init__(self, title: str = "Dependencies"):
|
|
97
|
+
self._title = title
|
|
98
|
+
|
|
99
|
+
def to_html(self) -> str:
|
|
100
|
+
import json
|
|
101
|
+
import subprocess
|
|
102
|
+
import sys
|
|
103
|
+
|
|
104
|
+
from flytekit.loggers import logger
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
installed_packages = json.loads(
|
|
108
|
+
subprocess.check_output([sys.executable, "-m", "pip", "list", "--format", "json"])
|
|
109
|
+
)
|
|
110
|
+
requirements_txt = (
|
|
111
|
+
subprocess.check_output([sys.executable, "-m", "pip", "freeze"])
|
|
112
|
+
.decode("utf-8")
|
|
113
|
+
.replace("\\n", "\n")
|
|
114
|
+
.rstrip()
|
|
115
|
+
)
|
|
116
|
+
except Exception as e:
|
|
117
|
+
logger.error(f"Error occurred while fetching installed packages: {e}")
|
|
118
|
+
return "Error occurred while fetching installed packages."
|
|
119
|
+
|
|
120
|
+
table = (
|
|
121
|
+
"<table>\n<tr>\n<th style='text-align:left;'>Name</th>\n<th style='text-align:left;'>Version</th>\n</tr>\n"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
for entry in installed_packages:
|
|
125
|
+
table += f"<tr>\n<td>{entry['name']}</td>\n<td>{entry['version']}</td>\n</tr>\n"
|
|
126
|
+
|
|
127
|
+
table += "</table>"
|
|
128
|
+
|
|
129
|
+
html = f"""
|
|
130
|
+
<!DOCTYPE html>
|
|
131
|
+
<html lang="en">
|
|
132
|
+
<head>
|
|
133
|
+
<meta charset="UTF-8">
|
|
134
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
135
|
+
<title>Flyte Dependencies</title>
|
|
136
|
+
<script>
|
|
137
|
+
async function copyTable() {{
|
|
138
|
+
var requirements_txt = document.getElementById('requirements_txt');
|
|
139
|
+
|
|
140
|
+
try {{
|
|
141
|
+
await navigator.clipboard.writeText(requirements_txt.innerText);
|
|
142
|
+
}} catch (err) {{
|
|
143
|
+
console.log('Error accessing the clipboard: ' + err);
|
|
144
|
+
}}
|
|
145
|
+
}}
|
|
146
|
+
</script>
|
|
147
|
+
</head>
|
|
148
|
+
<body>
|
|
149
|
+
|
|
150
|
+
<button onclick="copyTable()">
|
|
151
|
+
<span>Copy table as requirements.txt</span>
|
|
152
|
+
</button>
|
|
153
|
+
<h3>Python Dependencies</h3>
|
|
154
|
+
|
|
155
|
+
{table}
|
|
156
|
+
|
|
157
|
+
<div id="requirements_txt" style="display:none">{requirements_txt}</div>
|
|
158
|
+
|
|
159
|
+
</body>
|
|
160
|
+
</html>
|
|
161
|
+
"""
|
|
162
|
+
return html
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import json
|
|
3
|
+
from typing import Any, Dict, Union
|
|
4
|
+
|
|
5
|
+
import msgpack
|
|
6
|
+
from flyteidl.core import literals_pb2
|
|
7
|
+
from google.protobuf.json_format import MessageToDict
|
|
8
|
+
|
|
9
|
+
from union._protos.workflow import run_definition_pb2
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _primitive_to_string(primitive: literals_pb2.Primitive) -> Any:
|
|
13
|
+
"""
|
|
14
|
+
This method is used to convert a primitive to a string representation.
|
|
15
|
+
"""
|
|
16
|
+
match primitive.WhichOneof("value"):
|
|
17
|
+
case "integer":
|
|
18
|
+
return primitive.integer
|
|
19
|
+
case "float_value":
|
|
20
|
+
return primitive.float_value
|
|
21
|
+
case "boolean":
|
|
22
|
+
return primitive.boolean
|
|
23
|
+
case "string_value":
|
|
24
|
+
return primitive.string_value
|
|
25
|
+
case "datetime":
|
|
26
|
+
return primitive.datetime.ToDatetime().isoformat()
|
|
27
|
+
case "duration":
|
|
28
|
+
return primitive.duration.ToSeconds()
|
|
29
|
+
case _:
|
|
30
|
+
raise ValueError(f"Unknown primitive type {primitive}")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _scalar_to_string(scalar: literals_pb2.Scalar) -> Any:
|
|
34
|
+
"""
|
|
35
|
+
This method is used to convert a scalar to a string representation.
|
|
36
|
+
"""
|
|
37
|
+
match scalar.WhichOneof("value"):
|
|
38
|
+
case "primitive":
|
|
39
|
+
return _primitive_to_string(scalar.primitive)
|
|
40
|
+
case "none_type":
|
|
41
|
+
return None
|
|
42
|
+
case "error":
|
|
43
|
+
return scalar.error.message
|
|
44
|
+
case "structured_dataset":
|
|
45
|
+
return scalar.structured_dataset.uri
|
|
46
|
+
case "schema":
|
|
47
|
+
return scalar.schema.uri
|
|
48
|
+
case "blob":
|
|
49
|
+
return scalar.blob.uri
|
|
50
|
+
case "binary":
|
|
51
|
+
if scalar.binary.tag == "msgpack":
|
|
52
|
+
return json.dumps(msgpack.unpackb(scalar.binary.value))
|
|
53
|
+
return base64.b64encode(scalar.binary.value)
|
|
54
|
+
case "generic":
|
|
55
|
+
return MessageToDict(scalar.generic)
|
|
56
|
+
case "union":
|
|
57
|
+
return _literal_string_repr(scalar.union.value)
|
|
58
|
+
case _:
|
|
59
|
+
raise ValueError(f"Unknown scalar type {scalar}")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _literal_string_repr(lit: literals_pb2.Literal) -> Any:
|
|
63
|
+
"""
|
|
64
|
+
This method is used to convert a literal to a string representation. This is useful in places, where we need to
|
|
65
|
+
use a shortened string representation of a literal, especially a FlyteFile, FlyteDirectory, or StructuredDataset.
|
|
66
|
+
"""
|
|
67
|
+
match lit.WhichOneof("value"):
|
|
68
|
+
case "scalar":
|
|
69
|
+
return _scalar_to_string(lit.scalar)
|
|
70
|
+
case "collection":
|
|
71
|
+
return [literal_string_repr(i) for i in lit.collection.literals]
|
|
72
|
+
case "map":
|
|
73
|
+
return {k: literal_string_repr(v) for k, v in lit.map.literals.items()}
|
|
74
|
+
case "offloaded_metadata":
|
|
75
|
+
# TODO: load literal from offloaded literal?
|
|
76
|
+
return f"Offloaded literal metadata: {lit.offloaded_metadata}"
|
|
77
|
+
case _:
|
|
78
|
+
raise ValueError(f"Unknown literal type {lit}")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _dict_literal_repr(lmd: Dict[str, literals_pb2.Literal]) -> Dict[str, Any]:
|
|
82
|
+
"""
|
|
83
|
+
This method is used to convert a literal map to a string representation.
|
|
84
|
+
"""
|
|
85
|
+
return {k: _literal_string_repr(v) for k, v in lmd.items()}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def literal_string_repr(
|
|
89
|
+
lm: Union[
|
|
90
|
+
literals_pb2.Literal,
|
|
91
|
+
run_definition_pb2.NamedLiteral,
|
|
92
|
+
run_definition_pb2.Inputs,
|
|
93
|
+
run_definition_pb2.Outputs,
|
|
94
|
+
literals_pb2.LiteralMap,
|
|
95
|
+
Dict[str, literals_pb2.Literal],
|
|
96
|
+
],
|
|
97
|
+
) -> Dict[str, Any]:
|
|
98
|
+
"""
|
|
99
|
+
This method is used to convert a literal map to a string representation.
|
|
100
|
+
"""
|
|
101
|
+
if lm is None:
|
|
102
|
+
return {}
|
|
103
|
+
match lm:
|
|
104
|
+
case literals_pb2.Literal():
|
|
105
|
+
return _literal_string_repr(lm)
|
|
106
|
+
case literals_pb2.LiteralMap():
|
|
107
|
+
return _dict_literal_repr(lm.literals)
|
|
108
|
+
case run_definition_pb2.NamedLiteral():
|
|
109
|
+
lmd = {lm.name: lm.value}
|
|
110
|
+
return _dict_literal_repr(lmd)
|
|
111
|
+
case run_definition_pb2.Inputs():
|
|
112
|
+
lmd = {n.name: n.value for n in lm.literals}
|
|
113
|
+
return _dict_literal_repr(lmd)
|
|
114
|
+
case run_definition_pb2.Outputs():
|
|
115
|
+
lmd = {n.name: n.value for n in lm.literals}
|
|
116
|
+
return _dict_literal_repr(lmd)
|
|
117
|
+
case dict():
|
|
118
|
+
return _dict_literal_repr(lm)
|
|
119
|
+
case _:
|
|
120
|
+
raise ValueError(f"Unknown literal type {lm}, type{type(lm)}")
|