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,151 @@
1
+ import importlib.util
2
+ import inspect
3
+ import pathlib
4
+ import sys
5
+ from dataclasses import dataclass
6
+ from typing import Tuple
7
+
8
+ import rich.repr
9
+
10
+ import flyte.app
11
+ from flyte.models import SerializationContext
12
+
13
+ try:
14
+ import fastapi
15
+ except ModuleNotFoundError:
16
+ raise ModuleNotFoundError("fastapi is not installed. Please install the 'fastapi', to use FastAPI apps.")
17
+
18
+
19
+ def _extract_fastapi_app_module_and_var(
20
+ app: fastapi.FastAPI, caller_frame: inspect.FrameInfo | None, serialization_context: SerializationContext
21
+ ) -> Tuple[str, str]:
22
+ """
23
+ Extract the module name and variable name for a FastAPI app instance.
24
+
25
+ This function solves the challenge that `inspect.getmodule(app)` returns the
26
+ `fastapi.applications` module (where the FastAPI class is defined) rather than
27
+ the user's module (where the `app` variable is defined). Since FastAPI apps are
28
+ instances rather than classes or functions, we need special handling to locate
29
+ the correct module and variable name.
30
+
31
+ The function uses the caller frame (captured when FastAPIAppEnvironment was
32
+ instantiated) to determine which file contains the app definition, then inspects
33
+ that module's globals to find FastAPI instances.
34
+
35
+ Args:
36
+ app: The FastAPI application instance to locate.
37
+ caller_frame: Frame information from where FastAPIAppEnvironment was instantiated.
38
+ If None, falls back to extract_obj_module (which may not work correctly).
39
+ serialization_context: Context containing the root directory for calculating
40
+ relative module paths.
41
+
42
+ Returns:
43
+ A tuple of (module_name, variable_name) where:
44
+ - module_name: Dotted module path (e.g., "examples.apps.single_script_fastapi")
45
+ - variable_name: The name of the variable holding the FastAPI app (e.g., "app")
46
+
47
+ Raises:
48
+ RuntimeError: If the module cannot be loaded or the app variable cannot be found.
49
+
50
+ Example:
51
+ >>> frame = inspect.getframeinfo(inspect.currentframe().f_back)
52
+ >>> module_name, var_name = _extract_fastapi_app_module_and_var(
53
+ ... app, frame, serialization_context
54
+ ... )
55
+ >>> # Returns: ("examples.apps.my_app", "app")
56
+ >>> # Can be used as: uvicorn examples.apps.my_app:app
57
+ """
58
+ if caller_frame is None:
59
+ raise RuntimeError("Caller frame cannot be None")
60
+
61
+ # Get the file path where the app was defined
62
+ file_path = pathlib.Path(caller_frame.filename)
63
+
64
+ # Calculate module name relative to source_dir
65
+ try:
66
+ relative_path = file_path.relative_to(serialization_context.root_dir or pathlib.Path("."))
67
+ module_name = pathlib.Path(relative_path).with_suffix("").as_posix().replace("/", ".")
68
+ except ValueError:
69
+ # File is not relative to source_dir, use the stem
70
+ module_name = file_path.stem
71
+
72
+ # Instead of reloading the module, inspect the caller frame's local variables
73
+ # The app variable should be in the frame's globals
74
+ caller_globals = None
75
+
76
+ # Try to get globals from the main module if it matches our file
77
+ if hasattr(sys.modules.get("__main__"), "__file__"):
78
+ main_file = pathlib.Path(sys.modules["__main__"].__file__ or ".").resolve()
79
+ if main_file == file_path.resolve():
80
+ caller_globals = sys.modules["__main__"].__dict__
81
+
82
+ if caller_globals is None:
83
+ # Load the module to inspect it
84
+ spec = importlib.util.spec_from_file_location(file_path.stem, file_path)
85
+ if spec is None or spec.loader is None:
86
+ raise RuntimeError(f"Could not load module from {file_path}")
87
+ module = importlib.util.module_from_spec(spec)
88
+ spec.loader.exec_module(module)
89
+ caller_globals = module.__dict__
90
+
91
+ # Extract variable name from module - look for FastAPI instances
92
+ app_var_name = None
93
+ for var_name, obj in caller_globals.items():
94
+ if isinstance(obj, fastapi.FastAPI):
95
+ # Found a FastAPI app - this is likely the one we want
96
+ # Store the first one we find
97
+ if app_var_name is None:
98
+ app_var_name = var_name
99
+ # If the objects match by identity, use this one
100
+ if obj is app:
101
+ app_var_name = var_name
102
+ break
103
+
104
+ if app_var_name is None:
105
+ raise RuntimeError("Could not find variable name for FastAPI app in module")
106
+
107
+ return module_name, app_var_name
108
+
109
+
110
+ @rich.repr.auto
111
+ @dataclass(kw_only=True, repr=True)
112
+ class FastAPIAppEnvironment(flyte.app.AppEnvironment):
113
+ app: fastapi.FastAPI
114
+ type: str = "FastAPI"
115
+ _caller_frame: inspect.FrameInfo | None = None
116
+
117
+ def __post_init__(self):
118
+ super().__post_init__()
119
+ if self.app is None:
120
+ raise ValueError("app cannot be None for FastAPIAppEnvironment")
121
+ if not isinstance(self.app, fastapi.FastAPI):
122
+ raise TypeError(f"app must be of type fastapi.FastAPI, got {type(self.app)}")
123
+
124
+ # Capture the frame where this environment was instantiated
125
+ # This helps us find the module where the app variable is defined
126
+ frame = inspect.currentframe()
127
+ if frame and frame.f_back:
128
+ # Go up the call stack to find the user's module
129
+ # Skip the dataclass __init__ frame
130
+ caller_frame = frame.f_back
131
+ if caller_frame and caller_frame.f_back:
132
+ self._caller_frame = inspect.getframeinfo(caller_frame.f_back)
133
+
134
+ def container_args(self, serialization_context: SerializationContext) -> list[str]:
135
+ """
136
+ Generate the container arguments for running the FastAPI app with uvicorn.
137
+
138
+ Returns:
139
+ A list of command arguments in the format:
140
+ ["uvicorn", "<module_name>:<app_var_name>", "--port", "<port>"]
141
+ """
142
+ module_name, app_var_name = _extract_fastapi_app_module_and_var(
143
+ self.app, self._caller_frame, serialization_context
144
+ )
145
+
146
+ p = self.port
147
+ assert isinstance(p, flyte.app.Port)
148
+ return ["uvicorn", f"{module_name}:{app_var_name}", "--port", str(p.port)]
149
+
150
+ def container_command(self, serialization_context: SerializationContext) -> list[str]:
151
+ return []
flyte/cli/__init__.py ADDED
@@ -0,0 +1,12 @@
1
+ import os
2
+
3
+ from flyte.cli.main import main
4
+
5
+ __all__ = ["main"]
6
+
7
+
8
+ # Set GRPC_VERBOSITY to NONE if not already set to silence unwanted output
9
+ # This addresses the issue with grpcio >=1.68.0 causing unwanted output
10
+ # https://github.com/flyteorg/flyte/issues/6082
11
+ if "GRPC_VERBOSITY" not in os.environ:
12
+ os.environ["GRPC_VERBOSITY"] = "NONE"
flyte/cli/_abort.py ADDED
@@ -0,0 +1,28 @@
1
+ import rich_click as click
2
+
3
+ from flyte.cli import _common as common
4
+
5
+
6
+ @click.group(name="abort")
7
+ def abort():
8
+ """
9
+ Abort an ongoing process.
10
+ """
11
+
12
+
13
+ @abort.command(cls=common.CommandBase)
14
+ @click.argument("run-name", type=str, required=True)
15
+ @click.pass_obj
16
+ def run(cfg: common.CLIConfig, run_name: str, project: str | None = None, domain: str | None = None):
17
+ """
18
+ Abort a run.
19
+ """
20
+ from flyte.remote import Run
21
+
22
+ cfg.init(project=project, domain=domain)
23
+ r = Run.get(name=run_name)
24
+ if r:
25
+ console = common.get_console()
26
+ with console.status(f"Aborting run '{run_name}'...", spinner="dots"):
27
+ r.abort()
28
+ console.print(f"Run '{run_name}' has been aborted.")
flyte/cli/_build.py ADDED
@@ -0,0 +1,114 @@
1
+ from dataclasses import dataclass, field, fields
2
+ from pathlib import Path
3
+ from types import ModuleType
4
+ from typing import Any, Dict, List, cast
5
+
6
+ import rich_click as click
7
+
8
+ import flyte
9
+
10
+ from . import _common as common
11
+ from ._common import CLIConfig
12
+
13
+
14
+ @dataclass
15
+ class BuildArguments:
16
+ noop: bool = field(
17
+ default=False,
18
+ metadata={
19
+ "click.option": click.Option(
20
+ ["--noop"],
21
+ type=bool,
22
+ help="Dummy parameter, placeholder for future use. Does not affect the build process.",
23
+ )
24
+ },
25
+ )
26
+
27
+ @classmethod
28
+ def from_dict(cls, d: Dict[str, Any]) -> "BuildArguments":
29
+ return cls(**d)
30
+
31
+ @classmethod
32
+ def options(cls) -> List[click.Option]:
33
+ """
34
+ Return the set of base parameters added to every flyte run workflow subcommand.
35
+ """
36
+ return [common.get_option_from_metadata(f.metadata) for f in fields(cls) if f.metadata]
37
+
38
+
39
+ class BuildEnvCommand(click.Command):
40
+ def __init__(self, obj_name: str, obj: Any, build_args: BuildArguments, *args, **kwargs):
41
+ self.obj_name = obj_name
42
+ self.obj = obj
43
+ self.build_args = build_args
44
+ super().__init__(*args, **kwargs)
45
+
46
+ def invoke(self, ctx: click.Context):
47
+ console = common.get_console()
48
+ console.print(f"Building Environment: {self.obj_name}")
49
+ obj: CLIConfig = ctx.obj
50
+ obj.init()
51
+ with console.status("Building...", spinner="dots"):
52
+ image_cache = flyte.build_images(self.obj)
53
+
54
+ console.print(common.format("Images", image_cache.repr(), obj.output_format))
55
+
56
+
57
+ class EnvPerFileGroup(common.ObjectsPerFileGroup):
58
+ """
59
+ Group that creates a command for each task in the current directory that is not `__init__.py`.
60
+ """
61
+
62
+ def __init__(self, filename: Path, build_args: BuildArguments, *args, **kwargs):
63
+ args = (filename, *args)
64
+ super().__init__(*args, **kwargs)
65
+ self.build_args = build_args
66
+
67
+ def _filter_objects(self, module: ModuleType) -> Dict[str, Any]:
68
+ return {k: v for k, v in module.__dict__.items() if isinstance(v, flyte.Environment)}
69
+
70
+ def _get_command_for_obj(self, ctx: click.Context, obj_name: str, obj: Any) -> click.Command:
71
+ obj = cast(flyte.Environment, obj)
72
+ return BuildEnvCommand(
73
+ name=obj_name,
74
+ obj_name=obj_name,
75
+ obj=obj,
76
+ help=f"{obj.name}" + (f": {obj.description}" if obj.description else ""),
77
+ build_args=self.build_args,
78
+ )
79
+
80
+
81
+ class EnvFiles(common.FileGroup):
82
+ """
83
+ Group that creates a command for each file in the current directory that is not `__init__.py`.
84
+ """
85
+
86
+ common_options_enabled = False
87
+
88
+ def __init__(
89
+ self,
90
+ *args,
91
+ **kwargs,
92
+ ):
93
+ if "params" not in kwargs:
94
+ kwargs["params"] = []
95
+ kwargs["params"].extend(BuildArguments.options())
96
+ super().__init__(*args, **kwargs)
97
+
98
+ def get_command(self, ctx, filename):
99
+ build_args = BuildArguments.from_dict(ctx.params)
100
+ return EnvPerFileGroup(
101
+ filename=Path(filename),
102
+ build_args=build_args,
103
+ name=filename,
104
+ help=f"Run, functions decorated `env.task` or instances of Tasks in {filename}",
105
+ )
106
+
107
+
108
+ build = EnvFiles(
109
+ name="build",
110
+ help="""
111
+ Build the environments defined in a python file or directory. This will build the images associated with the
112
+ environments.
113
+ """,
114
+ )