flyte 2.0.0b32__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.

Files changed (204) hide show
  1. flyte/__init__.py +108 -0
  2. flyte/_bin/__init__.py +0 -0
  3. flyte/_bin/debug.py +38 -0
  4. flyte/_bin/runtime.py +195 -0
  5. flyte/_bin/serve.py +178 -0
  6. flyte/_build.py +26 -0
  7. flyte/_cache/__init__.py +12 -0
  8. flyte/_cache/cache.py +147 -0
  9. flyte/_cache/defaults.py +9 -0
  10. flyte/_cache/local_cache.py +216 -0
  11. flyte/_cache/policy_function_body.py +42 -0
  12. flyte/_code_bundle/__init__.py +8 -0
  13. flyte/_code_bundle/_ignore.py +121 -0
  14. flyte/_code_bundle/_packaging.py +218 -0
  15. flyte/_code_bundle/_utils.py +347 -0
  16. flyte/_code_bundle/bundle.py +266 -0
  17. flyte/_constants.py +1 -0
  18. flyte/_context.py +155 -0
  19. flyte/_custom_context.py +73 -0
  20. flyte/_debug/__init__.py +0 -0
  21. flyte/_debug/constants.py +38 -0
  22. flyte/_debug/utils.py +17 -0
  23. flyte/_debug/vscode.py +307 -0
  24. flyte/_deploy.py +408 -0
  25. flyte/_deployer.py +109 -0
  26. flyte/_doc.py +29 -0
  27. flyte/_docstring.py +32 -0
  28. flyte/_environment.py +122 -0
  29. flyte/_excepthook.py +37 -0
  30. flyte/_group.py +32 -0
  31. flyte/_hash.py +8 -0
  32. flyte/_image.py +1055 -0
  33. flyte/_initialize.py +628 -0
  34. flyte/_interface.py +119 -0
  35. flyte/_internal/__init__.py +3 -0
  36. flyte/_internal/controllers/__init__.py +129 -0
  37. flyte/_internal/controllers/_local_controller.py +239 -0
  38. flyte/_internal/controllers/_trace.py +48 -0
  39. flyte/_internal/controllers/remote/__init__.py +58 -0
  40. flyte/_internal/controllers/remote/_action.py +211 -0
  41. flyte/_internal/controllers/remote/_client.py +47 -0
  42. flyte/_internal/controllers/remote/_controller.py +583 -0
  43. flyte/_internal/controllers/remote/_core.py +465 -0
  44. flyte/_internal/controllers/remote/_informer.py +381 -0
  45. flyte/_internal/controllers/remote/_service_protocol.py +50 -0
  46. flyte/_internal/imagebuild/__init__.py +3 -0
  47. flyte/_internal/imagebuild/docker_builder.py +706 -0
  48. flyte/_internal/imagebuild/image_builder.py +277 -0
  49. flyte/_internal/imagebuild/remote_builder.py +386 -0
  50. flyte/_internal/imagebuild/utils.py +78 -0
  51. flyte/_internal/resolvers/__init__.py +0 -0
  52. flyte/_internal/resolvers/_task_module.py +21 -0
  53. flyte/_internal/resolvers/common.py +31 -0
  54. flyte/_internal/resolvers/default.py +28 -0
  55. flyte/_internal/runtime/__init__.py +0 -0
  56. flyte/_internal/runtime/convert.py +486 -0
  57. flyte/_internal/runtime/entrypoints.py +204 -0
  58. flyte/_internal/runtime/io.py +188 -0
  59. flyte/_internal/runtime/resources_serde.py +152 -0
  60. flyte/_internal/runtime/reuse.py +125 -0
  61. flyte/_internal/runtime/rusty.py +193 -0
  62. flyte/_internal/runtime/task_serde.py +362 -0
  63. flyte/_internal/runtime/taskrunner.py +209 -0
  64. flyte/_internal/runtime/trigger_serde.py +160 -0
  65. flyte/_internal/runtime/types_serde.py +54 -0
  66. flyte/_keyring/__init__.py +0 -0
  67. flyte/_keyring/file.py +115 -0
  68. flyte/_logging.py +300 -0
  69. flyte/_map.py +312 -0
  70. flyte/_module.py +72 -0
  71. flyte/_pod.py +30 -0
  72. flyte/_resources.py +473 -0
  73. flyte/_retry.py +32 -0
  74. flyte/_reusable_environment.py +102 -0
  75. flyte/_run.py +724 -0
  76. flyte/_secret.py +96 -0
  77. flyte/_task.py +550 -0
  78. flyte/_task_environment.py +316 -0
  79. flyte/_task_plugins.py +47 -0
  80. flyte/_timeout.py +47 -0
  81. flyte/_tools.py +27 -0
  82. flyte/_trace.py +119 -0
  83. flyte/_trigger.py +1000 -0
  84. flyte/_utils/__init__.py +30 -0
  85. flyte/_utils/asyn.py +121 -0
  86. flyte/_utils/async_cache.py +139 -0
  87. flyte/_utils/coro_management.py +27 -0
  88. flyte/_utils/docker_credentials.py +173 -0
  89. flyte/_utils/file_handling.py +72 -0
  90. flyte/_utils/helpers.py +134 -0
  91. flyte/_utils/lazy_module.py +54 -0
  92. flyte/_utils/module_loader.py +104 -0
  93. flyte/_utils/org_discovery.py +57 -0
  94. flyte/_utils/uv_script_parser.py +49 -0
  95. flyte/_version.py +34 -0
  96. flyte/app/__init__.py +22 -0
  97. flyte/app/_app_environment.py +157 -0
  98. flyte/app/_deploy.py +125 -0
  99. flyte/app/_input.py +160 -0
  100. flyte/app/_runtime/__init__.py +3 -0
  101. flyte/app/_runtime/app_serde.py +347 -0
  102. flyte/app/_types.py +101 -0
  103. flyte/app/extras/__init__.py +3 -0
  104. flyte/app/extras/_fastapi.py +151 -0
  105. flyte/cli/__init__.py +12 -0
  106. flyte/cli/_abort.py +28 -0
  107. flyte/cli/_build.py +114 -0
  108. flyte/cli/_common.py +468 -0
  109. flyte/cli/_create.py +371 -0
  110. flyte/cli/_delete.py +45 -0
  111. flyte/cli/_deploy.py +293 -0
  112. flyte/cli/_gen.py +176 -0
  113. flyte/cli/_get.py +370 -0
  114. flyte/cli/_option.py +33 -0
  115. flyte/cli/_params.py +554 -0
  116. flyte/cli/_plugins.py +209 -0
  117. flyte/cli/_run.py +597 -0
  118. flyte/cli/_serve.py +64 -0
  119. flyte/cli/_update.py +37 -0
  120. flyte/cli/_user.py +17 -0
  121. flyte/cli/main.py +221 -0
  122. flyte/config/__init__.py +3 -0
  123. flyte/config/_config.py +248 -0
  124. flyte/config/_internal.py +73 -0
  125. flyte/config/_reader.py +225 -0
  126. flyte/connectors/__init__.py +11 -0
  127. flyte/connectors/_connector.py +270 -0
  128. flyte/connectors/_server.py +197 -0
  129. flyte/connectors/utils.py +135 -0
  130. flyte/errors.py +243 -0
  131. flyte/extend.py +19 -0
  132. flyte/extras/__init__.py +5 -0
  133. flyte/extras/_container.py +286 -0
  134. flyte/git/__init__.py +3 -0
  135. flyte/git/_config.py +21 -0
  136. flyte/io/__init__.py +29 -0
  137. flyte/io/_dataframe/__init__.py +131 -0
  138. flyte/io/_dataframe/basic_dfs.py +223 -0
  139. flyte/io/_dataframe/dataframe.py +1026 -0
  140. flyte/io/_dir.py +910 -0
  141. flyte/io/_file.py +914 -0
  142. flyte/io/_hashing_io.py +342 -0
  143. flyte/models.py +479 -0
  144. flyte/py.typed +0 -0
  145. flyte/remote/__init__.py +35 -0
  146. flyte/remote/_action.py +738 -0
  147. flyte/remote/_app.py +57 -0
  148. flyte/remote/_client/__init__.py +0 -0
  149. flyte/remote/_client/_protocols.py +189 -0
  150. flyte/remote/_client/auth/__init__.py +12 -0
  151. flyte/remote/_client/auth/_auth_utils.py +14 -0
  152. flyte/remote/_client/auth/_authenticators/__init__.py +0 -0
  153. flyte/remote/_client/auth/_authenticators/base.py +403 -0
  154. flyte/remote/_client/auth/_authenticators/client_credentials.py +73 -0
  155. flyte/remote/_client/auth/_authenticators/device_code.py +117 -0
  156. flyte/remote/_client/auth/_authenticators/external_command.py +79 -0
  157. flyte/remote/_client/auth/_authenticators/factory.py +200 -0
  158. flyte/remote/_client/auth/_authenticators/pkce.py +516 -0
  159. flyte/remote/_client/auth/_channel.py +213 -0
  160. flyte/remote/_client/auth/_client_config.py +85 -0
  161. flyte/remote/_client/auth/_default_html.py +32 -0
  162. flyte/remote/_client/auth/_grpc_utils/__init__.py +0 -0
  163. flyte/remote/_client/auth/_grpc_utils/auth_interceptor.py +288 -0
  164. flyte/remote/_client/auth/_grpc_utils/default_metadata_interceptor.py +151 -0
  165. flyte/remote/_client/auth/_keyring.py +152 -0
  166. flyte/remote/_client/auth/_token_client.py +260 -0
  167. flyte/remote/_client/auth/errors.py +16 -0
  168. flyte/remote/_client/controlplane.py +128 -0
  169. flyte/remote/_common.py +30 -0
  170. flyte/remote/_console.py +19 -0
  171. flyte/remote/_data.py +161 -0
  172. flyte/remote/_logs.py +185 -0
  173. flyte/remote/_project.py +88 -0
  174. flyte/remote/_run.py +386 -0
  175. flyte/remote/_secret.py +142 -0
  176. flyte/remote/_task.py +527 -0
  177. flyte/remote/_trigger.py +306 -0
  178. flyte/remote/_user.py +33 -0
  179. flyte/report/__init__.py +3 -0
  180. flyte/report/_report.py +182 -0
  181. flyte/report/_template.html +124 -0
  182. flyte/storage/__init__.py +36 -0
  183. flyte/storage/_config.py +237 -0
  184. flyte/storage/_parallel_reader.py +274 -0
  185. flyte/storage/_remote_fs.py +34 -0
  186. flyte/storage/_storage.py +456 -0
  187. flyte/storage/_utils.py +5 -0
  188. flyte/syncify/__init__.py +56 -0
  189. flyte/syncify/_api.py +375 -0
  190. flyte/types/__init__.py +52 -0
  191. flyte/types/_interface.py +40 -0
  192. flyte/types/_pickle.py +145 -0
  193. flyte/types/_renderer.py +162 -0
  194. flyte/types/_string_literals.py +119 -0
  195. flyte/types/_type_engine.py +2254 -0
  196. flyte/types/_utils.py +80 -0
  197. flyte-2.0.0b32.data/scripts/debug.py +38 -0
  198. flyte-2.0.0b32.data/scripts/runtime.py +195 -0
  199. flyte-2.0.0b32.dist-info/METADATA +351 -0
  200. flyte-2.0.0b32.dist-info/RECORD +204 -0
  201. flyte-2.0.0b32.dist-info/WHEEL +5 -0
  202. flyte-2.0.0b32.dist-info/entry_points.txt +7 -0
  203. flyte-2.0.0b32.dist-info/licenses/LICENSE +201 -0
  204. flyte-2.0.0b32.dist-info/top_level.txt +1 -0
@@ -0,0 +1,197 @@
1
+ import inspect
2
+ import os
3
+ import sys
4
+ from http import HTTPStatus
5
+ from typing import Callable, Dict, List, Tuple, Type, Union
6
+
7
+ import grpc
8
+ from flyteidl2.core.security_pb2 import Connection
9
+ from flyteidl2.plugins.connector_pb2 import (
10
+ CreateTaskRequest,
11
+ CreateTaskResponse,
12
+ DeleteTaskRequest,
13
+ DeleteTaskResponse,
14
+ GetConnectorRequest,
15
+ GetConnectorResponse,
16
+ GetTaskLogsRequest,
17
+ GetTaskLogsResponse,
18
+ GetTaskMetricsRequest,
19
+ GetTaskMetricsResponse,
20
+ GetTaskRequest,
21
+ GetTaskResponse,
22
+ ListConnectorsRequest,
23
+ ListConnectorsResponse,
24
+ )
25
+ from flyteidl2.service.connector_pb2_grpc import (
26
+ AsyncConnectorServiceServicer,
27
+ ConnectorMetadataServiceServicer,
28
+ )
29
+ from prometheus_client import Counter, Summary
30
+
31
+ from flyte._internal.runtime.convert import Inputs, convert_from_inputs_to_native
32
+ from flyte._logging import logger
33
+ from flyte.connectors._connector import ConnectorRegistry, FlyteConnectorNotFound, get_resource_proto
34
+ from flyte.connectors.utils import _start_grpc_server
35
+ from flyte.models import NativeInterface, _has_default
36
+ from flyte.syncify import syncify
37
+ from flyte.types import TypeEngine
38
+
39
+ metric_prefix = "flyte_connector_"
40
+ create_operation = "create"
41
+ get_operation = "get"
42
+ delete_operation = "delete"
43
+
44
+ # Follow the naming convention. https://prometheus.io/docs/practices/naming/
45
+ request_success_count = Counter(
46
+ f"{metric_prefix}requests_success_total",
47
+ "Total number of successful requests",
48
+ ["task_type", "operation"],
49
+ )
50
+ request_failure_count = Counter(
51
+ f"{metric_prefix}requests_failure_total",
52
+ "Total number of failed requests",
53
+ ["task_type", "operation", "error_code"],
54
+ )
55
+ request_latency = Summary(
56
+ f"{metric_prefix}request_latency_seconds",
57
+ "Time spent processing connector request",
58
+ ["task_type", "operation"],
59
+ )
60
+ input_literal_size = Summary(f"{metric_prefix}input_literal_bytes", "Size of input literal", ["task_type"])
61
+
62
+
63
+ def _handle_exception(e: Exception, context: grpc.ServicerContext, task_type: str, operation: str):
64
+ if isinstance(e, FlyteConnectorNotFound):
65
+ error_message = f"Cannot find connector for task type: {task_type}."
66
+ logger.error(error_message)
67
+ context.set_code(grpc.StatusCode.NOT_FOUND)
68
+ context.set_details(error_message)
69
+ request_failure_count.labels(task_type=task_type, operation=operation, error_code=HTTPStatus.NOT_FOUND).inc()
70
+ else:
71
+ error_message = f"failed to {operation} {task_type} task with error:\n {e}."
72
+ logger.error(error_message)
73
+ context.set_code(grpc.StatusCode.INTERNAL)
74
+ context.set_details(error_message)
75
+ request_failure_count.labels(
76
+ task_type=task_type, operation=operation, error_code=HTTPStatus.INTERNAL_SERVER_ERROR
77
+ ).inc()
78
+
79
+
80
+ class ConnectorService:
81
+ @syncify
82
+ @classmethod
83
+ async def run(cls, port: int, prometheus_port: int, worker: int, timeout: int | None, modules: List[str] | None):
84
+ working_dir = os.getcwd()
85
+ if all(os.path.realpath(path) != working_dir for path in sys.path):
86
+ sys.path.append(working_dir)
87
+ await _start_grpc_server(port, prometheus_port, worker, timeout, modules)
88
+
89
+
90
+ def record_connector_metrics(func: Callable):
91
+ async def wrapper(
92
+ self,
93
+ request: Union[CreateTaskRequest, GetTaskRequest, DeleteTaskRequest],
94
+ context: grpc.ServicerContext,
95
+ *args,
96
+ **kwargs,
97
+ ):
98
+ if isinstance(request, CreateTaskRequest):
99
+ task_type = request.template.type
100
+ operation = create_operation
101
+ if request.inputs:
102
+ input_literal_size.labels(task_type=task_type).observe(request.inputs.ByteSize())
103
+ elif isinstance(request, GetTaskRequest):
104
+ task_type = request.task_category.name
105
+ operation = get_operation
106
+ elif isinstance(request, DeleteTaskRequest):
107
+ task_type = request.task_category.name
108
+ operation = delete_operation
109
+ else:
110
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
111
+ context.set_details("Method not implemented!")
112
+ return None
113
+
114
+ try:
115
+ with request_latency.labels(task_type=task_type, operation=operation).time():
116
+ res = await func(self, request, context, *args, **kwargs)
117
+ request_success_count.labels(task_type=task_type, operation=operation).inc()
118
+ return res
119
+ except Exception as e:
120
+ _handle_exception(e, context, task_type, operation)
121
+
122
+ return wrapper
123
+
124
+
125
+ def _get_connection_kwargs(request: Connection) -> Dict[str, str]:
126
+ kwargs = {}
127
+
128
+ for k, v in request.secrets.items():
129
+ kwargs[k] = v
130
+ for k, v in request.configs.items():
131
+ kwargs[k] = v
132
+
133
+ return kwargs
134
+
135
+
136
+ class AsyncConnectorService(AsyncConnectorServiceServicer):
137
+ @record_connector_metrics
138
+ async def CreateTask(self, request: CreateTaskRequest, context: grpc.ServicerContext) -> CreateTaskResponse:
139
+ template = request.template
140
+ connector = ConnectorRegistry.get_connector(template.type, template.task_type_version)
141
+ logger.info(f"{connector.name} start creating the job")
142
+ python_interface_inputs: Dict[str, Tuple[Type, Type[_has_default] | Type[inspect._empty]]] = {
143
+ name: (TypeEngine.guess_python_type(lt.type), inspect.Parameter.empty)
144
+ for name, lt in template.interface.inputs.variables.items()
145
+ }
146
+ native_interface = NativeInterface.from_types(inputs=python_interface_inputs, outputs={})
147
+ native_inputs = await convert_from_inputs_to_native(native_interface, Inputs(proto_inputs=request.inputs))
148
+ resource_meta = await connector.create(
149
+ task_template=request.template,
150
+ inputs=native_inputs,
151
+ output_prefix=request.output_prefix,
152
+ task_execution_metadata=request.task_execution_metadata,
153
+ connection=_get_connection_kwargs(request.connection),
154
+ )
155
+ return CreateTaskResponse(resource_meta=resource_meta.encode())
156
+
157
+ @record_connector_metrics
158
+ async def GetTask(self, request: GetTaskRequest, context: grpc.ServicerContext) -> GetTaskResponse:
159
+ connector = ConnectorRegistry.get_connector(request.task_category.name, request.task_category.version)
160
+ logger.info(f"{connector.name} start checking the status of the job")
161
+ res = await connector.get(
162
+ resource_meta=connector.metadata_type.decode(request.resource_meta),
163
+ connection=_get_connection_kwargs(request.connection),
164
+ )
165
+ return GetTaskResponse(resource=await get_resource_proto(res))
166
+
167
+ @record_connector_metrics
168
+ async def DeleteTask(self, request: DeleteTaskRequest, context: grpc.ServicerContext) -> DeleteTaskResponse:
169
+ connector = ConnectorRegistry.get_connector(request.task_category.name, request.task_category.version)
170
+ logger.info(f"{connector.name} start deleting the job")
171
+ await connector.delete(
172
+ resource_meta=connector.metadata_type.decode(request.resource_meta),
173
+ connection=_get_connection_kwargs(request.connection),
174
+ )
175
+ return DeleteTaskResponse()
176
+
177
+ async def GetTaskMetrics(
178
+ self, request: GetTaskMetricsRequest, context: grpc.ServicerContext
179
+ ) -> GetTaskMetricsResponse:
180
+ connector = ConnectorRegistry.get_connector(request.task_category.name, request.task_category.version)
181
+ logger.info(f"{connector.name} start getting metrics of the job")
182
+ return await connector.get_metrics(resource_meta=connector.metadata_type.decode(request.resource_meta))
183
+
184
+ async def GetTaskLogs(self, request: GetTaskLogsRequest, context: grpc.ServicerContext) -> GetTaskLogsResponse:
185
+ connector = ConnectorRegistry.get_connector(request.task_category.name, request.task_category.version)
186
+ logger.info(f"{connector.name} start getting logs of the job")
187
+ return await connector.get_logs(resource_meta=connector.metadata_type.decode(request.resource_meta))
188
+
189
+
190
+ class ConnectorMetadataService(ConnectorMetadataServiceServicer):
191
+ async def GetConnector(self, request: GetConnectorRequest, context: grpc.ServicerContext) -> GetConnectorResponse:
192
+ return GetConnectorResponse(connector=ConnectorRegistry._get_connector_metadata(request.name))
193
+
194
+ async def ListConnectors(
195
+ self, request: ListConnectorsRequest, context: grpc.ServicerContext
196
+ ) -> ListConnectorsResponse:
197
+ return ListConnectorsResponse(connectors=ConnectorRegistry._list_connectors())
@@ -0,0 +1,135 @@
1
+ import importlib
2
+ from concurrent import futures
3
+ from importlib.metadata import entry_points
4
+ from typing import List
5
+
6
+ import click
7
+ import grpc
8
+ from flyteidl2.core.execution_pb2 import TaskExecution
9
+ from flyteidl2.service import connector_pb2
10
+ from flyteidl2.service.connector_pb2_grpc import (
11
+ add_AsyncConnectorServiceServicer_to_server,
12
+ add_ConnectorMetadataServiceServicer_to_server,
13
+ )
14
+ from rich.console import Console
15
+ from rich.table import Table
16
+
17
+ from flyte import logger
18
+
19
+
20
+ def is_terminal_phase(phase: TaskExecution.Phase) -> bool:
21
+ """
22
+ Return true if the phase is terminal.
23
+ """
24
+ return phase in [TaskExecution.SUCCEEDED, TaskExecution.ABORTED, TaskExecution.FAILED]
25
+
26
+
27
+ def convert_to_flyte_phase(state: str) -> TaskExecution.Phase:
28
+ """
29
+ Convert the state from the connector to the phase in flyte.
30
+ """
31
+ state = state.lower()
32
+ if state in ["failed", "timeout", "timedout", "canceled", "cancelled", "skipped"]:
33
+ return TaskExecution.FAILED
34
+ if state in ["internal_error"]:
35
+ return TaskExecution.RETRYABLE_FAILED
36
+ elif state in ["done", "succeeded", "success", "completed"]:
37
+ return TaskExecution.SUCCEEDED
38
+ elif state in ["running", "terminating"]:
39
+ return TaskExecution.RUNNING
40
+ elif state in ["pending"]:
41
+ return TaskExecution.INITIALIZING
42
+ raise ValueError(f"Unrecognized state: {state}")
43
+
44
+
45
+ async def _start_grpc_server(
46
+ port: int, prometheus_port: int, worker: int, timeout: int | None, modules: List[str] | None
47
+ ):
48
+ try:
49
+ from flyte.connectors._server import (
50
+ AsyncConnectorService,
51
+ ConnectorMetadataService,
52
+ )
53
+ except ImportError as e:
54
+ raise ImportError(
55
+ "Flyte connector dependencies are not installed."
56
+ " Please install it using `pip install flyteplugins-connector`"
57
+ ) from e
58
+
59
+ click.secho("🚀 Starting the connector service...")
60
+ _load_connectors(modules)
61
+ _start_http_server(prometheus_port)
62
+
63
+ print_metadata()
64
+
65
+ server = grpc.aio.server(futures.ThreadPoolExecutor(max_workers=worker))
66
+
67
+ add_AsyncConnectorServiceServicer_to_server(AsyncConnectorService(), server)
68
+ add_ConnectorMetadataServiceServicer_to_server(ConnectorMetadataService(), server)
69
+ _start_health_check_server(server, worker)
70
+
71
+ server.add_insecure_port(f"[::]:{port}")
72
+ await server.start()
73
+ await server.wait_for_termination(timeout)
74
+
75
+
76
+ def _start_http_server(prometheus_port: int):
77
+ try:
78
+ from prometheus_client import start_http_server
79
+
80
+ click.secho("Starting up the server to expose the prometheus metrics...")
81
+ start_http_server(prometheus_port)
82
+ except ImportError as e:
83
+ click.secho(f"Failed to start the prometheus server with error {e}", fg="red")
84
+
85
+
86
+ def _start_health_check_server(server: grpc.Server, worker: int):
87
+ try:
88
+ from grpc_health.v1 import health, health_pb2, health_pb2_grpc
89
+
90
+ health_servicer = health.HealthServicer(
91
+ experimental_non_blocking=True,
92
+ experimental_thread_pool=futures.ThreadPoolExecutor(max_workers=worker),
93
+ )
94
+
95
+ for service in connector_pb2.DESCRIPTOR.services_by_name.values():
96
+ health_servicer.set(service.full_name, health_pb2.HealthCheckResponse.SERVING)
97
+ health_servicer.set(health.SERVICE_NAME, health_pb2.HealthCheckResponse.SERVING)
98
+
99
+ health_pb2_grpc.add_HealthServicer_to_server(health_servicer, server)
100
+
101
+ except ImportError as e:
102
+ click.secho(f"Failed to start the health check servicer with error {e}", fg="red")
103
+
104
+
105
+ def print_metadata():
106
+ from flyte.connectors import ConnectorRegistry
107
+
108
+ connectors = ConnectorRegistry._list_connectors()
109
+
110
+ table = Table(title="Connector Metadata")
111
+ table.add_column("Connector Name", style="cyan", no_wrap=True)
112
+ table.add_column("Support Task Types", style="cyan")
113
+
114
+ for connector in connectors:
115
+ categories = ""
116
+ for category in connector.supported_task_categories:
117
+ categories += f"{category.name} ({category.version}) "
118
+ table.add_row(connector.name, categories)
119
+
120
+ console = Console()
121
+ console.print(table)
122
+
123
+
124
+ def _load_connectors(modules: List[str] | None):
125
+ plugins = entry_points(group="flyte.connectors")
126
+ for ep in plugins:
127
+ try:
128
+ logger.info(f"Loading connector: {ep.name}")
129
+ ep.load()
130
+ except Exception as e:
131
+ logger.warning(f"Failed to load type transformer {ep.name} with error: {e}")
132
+
133
+ if modules:
134
+ for m in modules:
135
+ importlib.import_module(m)
flyte/errors.py ADDED
@@ -0,0 +1,243 @@
1
+ """
2
+ Exceptions raised by Union.
3
+
4
+ These errors are raised when the underlying task execution fails, either because of a user error, system error or an
5
+ unknown error.
6
+ """
7
+
8
+ from typing import Literal
9
+
10
+ ErrorKind = Literal["system", "unknown", "user"]
11
+
12
+
13
+ def silence_grpc_polling_error(loop, context):
14
+ """
15
+ Suppress specific gRPC polling errors in the event loop.
16
+ """
17
+ exc = context.get("exception")
18
+ if isinstance(exc, BlockingIOError):
19
+ return # suppress
20
+ loop.default_exception_handler(context)
21
+
22
+
23
+ class BaseRuntimeError(RuntimeError):
24
+ """
25
+ Base class for all Union runtime errors. These errors are raised when the underlying task execution fails, either
26
+ because of a user error, system error or an unknown error.
27
+ """
28
+
29
+ def __init__(self, code: str, kind: ErrorKind, root_cause_message: str, worker: str | None = None):
30
+ super().__init__(root_cause_message)
31
+ self.code = code
32
+ self.kind = kind
33
+ self.worker = worker
34
+
35
+
36
+ class InitializationError(BaseRuntimeError):
37
+ """
38
+ This error is raised when the Union system is tried to access without being initialized.
39
+ """
40
+
41
+
42
+ class RuntimeSystemError(BaseRuntimeError):
43
+ """
44
+ This error is raised when the underlying task execution fails because of a system error. This could be a bug in the
45
+ Union system or a bug in the user's code.
46
+ """
47
+
48
+ def __init__(self, code: str, message: str, worker: str | None = None):
49
+ super().__init__(code, "system", message, worker)
50
+
51
+
52
+ class UnionRpcError(RuntimeSystemError):
53
+ """
54
+ This error is raised when communication with the Union server fails.
55
+ """
56
+
57
+
58
+ class RuntimeUserError(BaseRuntimeError):
59
+ """
60
+ This error is raised when the underlying task execution fails because of an error in the user's code.
61
+ """
62
+
63
+ def __init__(self, code: str, message: str, worker: str | None = None):
64
+ super().__init__(code, "user", message, worker)
65
+
66
+
67
+ class RuntimeUnknownError(BaseRuntimeError):
68
+ """
69
+ This error is raised when the underlying task execution fails because of an unknown error.
70
+ """
71
+
72
+ def __init__(self, code: str, message: str, worker: str | None = None):
73
+ super().__init__(code, "unknown", message, worker)
74
+
75
+
76
+ class OOMError(RuntimeUserError):
77
+ """
78
+ This error is raised when the underlying task execution fails because of an out-of-memory error.
79
+ """
80
+
81
+
82
+ class TaskInterruptedError(RuntimeUserError):
83
+ """
84
+ This error is raised when the underlying task execution is interrupted.
85
+ """
86
+
87
+
88
+ class PrimaryContainerNotFoundError(RuntimeUserError):
89
+ """
90
+ This error is raised when the primary container is not found.
91
+ """
92
+
93
+
94
+ class TaskTimeoutError(RuntimeUserError):
95
+ """
96
+ This error is raised when the underlying task execution runs for longer than the specified timeout.
97
+ """
98
+
99
+ def __init__(self, message: str):
100
+ super().__init__("TaskTimeoutError", message, "user")
101
+
102
+
103
+ class RetriesExhaustedError(RuntimeUserError):
104
+ """
105
+ This error is raised when the underlying task execution fails after all retries have been exhausted.
106
+ """
107
+
108
+
109
+ class InvalidImageNameError(RuntimeUserError):
110
+ """
111
+ This error is raised when the image name is invalid.
112
+ """
113
+
114
+
115
+ class ImagePullBackOffError(RuntimeUserError):
116
+ """
117
+ This error is raised when the image cannot be pulled.
118
+ """
119
+
120
+
121
+ class CustomError(RuntimeUserError):
122
+ """
123
+ This error is raised when the user raises a custom error.
124
+ """
125
+
126
+ def __init__(self, code: str, message: str):
127
+ super().__init__(code, message, "user")
128
+
129
+ @classmethod
130
+ def from_exception(cls, e: Exception):
131
+ """
132
+ Create a CustomError from an exception. The exception's class name is used as the error code and the exception
133
+ message is used as the error message.
134
+ """
135
+ new_exc = cls(e.__class__.__name__, str(e))
136
+ new_exc.__cause__ = e
137
+ return new_exc
138
+
139
+
140
+ class NotInTaskContextError(RuntimeUserError):
141
+ """
142
+ This error is raised when the user tries to access the task context outside of a task.
143
+ """
144
+
145
+
146
+ class ActionNotFoundError(RuntimeError):
147
+ """
148
+ This error is raised when the user tries to access an action that does not exist.
149
+ """
150
+
151
+
152
+ class ReferenceTaskError(RuntimeUserError):
153
+ """
154
+ This error is raised when the user tries to access a task that does not exist.
155
+ """
156
+
157
+ def __init__(self, message: str):
158
+ super().__init__("ReferenceTaskUsageError", message, "user")
159
+
160
+
161
+ class LogsNotYetAvailableError(BaseRuntimeError):
162
+ """
163
+ This error is raised when the logs are not yet available for a task.
164
+ """
165
+
166
+ def __init__(self, message: str):
167
+ super().__init__("LogsNotYetAvailable", "system", message, None)
168
+
169
+
170
+ class RuntimeDataValidationError(RuntimeUserError):
171
+ """
172
+ This error is raised when the user tries to access a resource that does not exist or is invalid.
173
+ """
174
+
175
+ def __init__(self, var: str, e: Exception | str, task_name: str = ""):
176
+ super().__init__(
177
+ "DataValidationError", f"In task {task_name} variable {var}, failed to serialize/deserialize because of {e}"
178
+ )
179
+
180
+
181
+ class DeploymentError(RuntimeUserError):
182
+ """
183
+ This error is raised when the deployment of a task fails, or some preconditions for deployment are not met.
184
+ """
185
+
186
+ def __init__(self, message: str):
187
+ super().__init__("DeploymentError", message, "user")
188
+
189
+
190
+ class ImageBuildError(RuntimeUserError):
191
+ """
192
+ This error is raised when the image build fails.
193
+ """
194
+
195
+ def __init__(self, message: str):
196
+ super().__init__("ImageBuildError", message, "user")
197
+
198
+
199
+ class ModuleLoadError(RuntimeUserError):
200
+ """
201
+ This error is raised when the module cannot be loaded, either because it does not exist or because of a
202
+ syntax error.
203
+ """
204
+
205
+ def __init__(self, message: str):
206
+ super().__init__("ModuleLoadError", message, "user")
207
+
208
+
209
+ class InlineIOMaxBytesBreached(RuntimeUserError):
210
+ """
211
+ This error is raised when the inline IO max bytes limit is breached.
212
+ This can be adjusted per task by setting max_inline_io_bytes in the task definition.
213
+ """
214
+
215
+ def __init__(self, message: str):
216
+ super().__init__("InlineIOMaxBytesBreached", message, "user")
217
+
218
+
219
+ class RunAbortedError(RuntimeUserError):
220
+ """
221
+ This error is raised when the run is aborted by the user.
222
+ """
223
+
224
+ def __init__(self, message: str):
225
+ super().__init__("RunAbortedError", message, "user")
226
+
227
+
228
+ class SlowDownError(RuntimeUserError):
229
+ """
230
+ This error is raised when the user tries to access a resource that does not exist or is invalid.
231
+ """
232
+
233
+ def __init__(self, message: str):
234
+ super().__init__("SlowDownError", message, "user")
235
+
236
+
237
+ class OnlyAsyncIOSupportedError(RuntimeUserError):
238
+ """
239
+ This error is raised when the user tries to use sync IO in an async task.
240
+ """
241
+
242
+ def __init__(self, message: str):
243
+ super().__init__("OnlyAsyncIOSupportedError", message, "user")
flyte/extend.py ADDED
@@ -0,0 +1,19 @@
1
+ from ._initialize import is_initialized
2
+ from ._internal.imagebuild.image_builder import ImageBuildEngine
3
+ from ._internal.runtime.entrypoints import download_code_bundle
4
+ from ._internal.runtime.resources_serde import get_proto_resources
5
+ from ._resources import PRIMARY_CONTAINER_DEFAULT_NAME, pod_spec_from_resources
6
+ from ._task import AsyncFunctionTaskTemplate, TaskTemplate
7
+ from ._task_plugins import TaskPluginRegistry
8
+
9
+ __all__ = [
10
+ "PRIMARY_CONTAINER_DEFAULT_NAME",
11
+ "AsyncFunctionTaskTemplate",
12
+ "ImageBuildEngine",
13
+ "TaskPluginRegistry",
14
+ "TaskTemplate",
15
+ "download_code_bundle",
16
+ "get_proto_resources",
17
+ "is_initialized",
18
+ "pod_spec_from_resources",
19
+ ]
@@ -0,0 +1,5 @@
1
+ from ._container import ContainerTask
2
+
3
+ __all__ = [
4
+ "ContainerTask",
5
+ ]