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
flyte/cli/_user.py ADDED
@@ -0,0 +1,17 @@
1
+ import rich_click as click
2
+
3
+ import flyte.remote as remote
4
+
5
+ from . import _common as common
6
+
7
+
8
+ @click.command()
9
+ @click.pass_obj
10
+ def whoami(
11
+ cfg: common.CLIConfig,
12
+ ):
13
+ """Display the current user information."""
14
+ cfg.init()
15
+ console = common.get_console()
16
+ user_info = remote.User.get()
17
+ console.print(user_info.to_json())
flyte/cli/main.py ADDED
@@ -0,0 +1,221 @@
1
+ import rich_click as click
2
+ from typing_extensions import get_args
3
+
4
+ from flyte._logging import LogFormat, initialize_logger, logger
5
+
6
+ from . import _common as common
7
+ from ._abort import abort
8
+ from ._build import build
9
+ from ._common import CLIConfig
10
+ from ._create import create
11
+ from ._delete import delete
12
+ from ._deploy import deploy
13
+ from ._gen import gen
14
+ from ._get import get
15
+ from ._plugins import discover_and_register_plugins
16
+ from ._run import run
17
+ from ._serve import serve
18
+ from ._update import update
19
+ from ._user import whoami
20
+
21
+ help_config = click.RichHelpConfiguration(
22
+ use_markdown=True,
23
+ use_markdown_emoji=True,
24
+ command_groups={
25
+ "flyte": [
26
+ {
27
+ "name": "Run and stop tasks",
28
+ "commands": ["run", "abort"],
29
+ },
30
+ {
31
+ "name": "Management of various objects.",
32
+ "commands": ["create", "get", "delete", "update"],
33
+ },
34
+ {
35
+ "name": "Build and deploy environments, tasks and images.",
36
+ "commands": ["build", "deploy"],
37
+ },
38
+ {
39
+ "name": "Documentation generation",
40
+ "commands": ["gen"],
41
+ },
42
+ {
43
+ "name": "User information",
44
+ "commands": ["whoami"],
45
+ },
46
+ ]
47
+ },
48
+ )
49
+
50
+
51
+ def _verbosity_to_loglevel(verbosity: int) -> int | None:
52
+ """
53
+ Converts a verbosity level from the CLI to a logging level.
54
+
55
+ :param verbosity: verbosity level from the CLI
56
+ :return: logging level
57
+ """
58
+ import logging
59
+
60
+ match verbosity:
61
+ case 0:
62
+ return None
63
+ case 1:
64
+ return logging.WARNING
65
+ case 2:
66
+ return logging.INFO
67
+ case _:
68
+ return logging.DEBUG
69
+
70
+
71
+ @click.group(cls=click.RichGroup)
72
+ @click.option(
73
+ "--endpoint",
74
+ type=str,
75
+ required=False,
76
+ help="The endpoint to connect to. This will override any configuration file and simply use `pkce` to connect.",
77
+ )
78
+ @click.option(
79
+ "--insecure",
80
+ is_flag=True,
81
+ required=False,
82
+ help="Use an insecure connection to the endpoint. If not specified, the CLI will use TLS.",
83
+ type=bool,
84
+ default=None,
85
+ show_default=True,
86
+ )
87
+ @click.option(
88
+ "--auth-type",
89
+ type=click.Choice(common.ALL_AUTH_OPTIONS, case_sensitive=False),
90
+ default=None,
91
+ help="Authentication type to use for the Flyte backend. Defaults to 'pkce'.",
92
+ show_default=True,
93
+ required=False,
94
+ )
95
+ @click.option(
96
+ "-v",
97
+ "--verbose",
98
+ required=False,
99
+ help="Show verbose messages and exception traces. Repeating multiple times increases the verbosity (e.g., -vvv).",
100
+ count=True,
101
+ default=0,
102
+ type=int,
103
+ )
104
+ @click.option(
105
+ "--org",
106
+ type=str,
107
+ required=False,
108
+ help="The organization to which the command applies.",
109
+ )
110
+ @click.option(
111
+ "-c",
112
+ "--config",
113
+ "config_file",
114
+ required=False,
115
+ type=click.Path(exists=True),
116
+ help="Path to the configuration file to use. If not specified, the default configuration file is used.",
117
+ )
118
+ @click.option(
119
+ "--output-format",
120
+ "-of",
121
+ type=click.Choice(get_args(common.OutputFormat), case_sensitive=False),
122
+ default="table",
123
+ help="Output format for commands that support it. Defaults to 'table'.",
124
+ show_default=True,
125
+ required=False,
126
+ )
127
+ @click.option(
128
+ "--log-format",
129
+ type=click.Choice(get_args(LogFormat), case_sensitive=False),
130
+ envvar="LOG_FORMAT",
131
+ default="console",
132
+ help="Formatting for logs, defaults to 'console' which is meant to be human readable."
133
+ " 'json' is meant for machine parsing.",
134
+ show_default=True,
135
+ required=False,
136
+ )
137
+ @click.rich_config(help_config=help_config)
138
+ @click.pass_context
139
+ def main(
140
+ ctx: click.Context,
141
+ endpoint: str | None,
142
+ insecure: bool,
143
+ verbose: int,
144
+ log_format: LogFormat,
145
+ org: str | None,
146
+ config_file: str | None,
147
+ auth_type: str | None = None,
148
+ output_format: common.OutputFormat = "table",
149
+ ):
150
+ """
151
+ The Flyte CLI is the command line interface for working with the Flyte SDK and backend.
152
+
153
+ It follows a simple verb/noun structure,
154
+ where the top-level commands are verbs that describe the action to be taken,
155
+ and the subcommands are nouns that describe the object of the action.
156
+
157
+ The root command can be used to configure the CLI for persistent settings,
158
+ such as the endpoint, organization, and verbosity level.
159
+
160
+ Set endpoint and organization:
161
+
162
+ ```bash
163
+ $ flyte --endpoint <endpoint> --org <org> get project <project_name>
164
+ ```
165
+
166
+ Increase verbosity level (This is useful for debugging,
167
+ this will show more logs and exception traces):
168
+
169
+ ```bash
170
+ $ flyte -vvv get logs <run-name>
171
+ ```
172
+
173
+ Override the default config file:
174
+
175
+ ```bash
176
+ $ flyte --config /path/to/config.yaml run ...
177
+ ```
178
+
179
+ * [Documentation](https://www.union.ai/docs/flyte/user-guide/)
180
+ * [GitHub](https://github.com/flyteorg/flyte): Please leave a star if you like Flyte!
181
+ * [Slack](https://slack.flyte.org): Join the community and ask questions.
182
+ * [Issues](https://github.com/flyteorg/flyte/issues)
183
+
184
+ """
185
+ import flyte.config as config
186
+
187
+ log_level = _verbosity_to_loglevel(verbose)
188
+ if log_level is not None or log_format != "console":
189
+ initialize_logger(log_level=log_level, log_format=log_format)
190
+
191
+ cfg = config.auto(config_file=config_file)
192
+ if cfg.source:
193
+ logger.debug(f"Using config file discovered at location `{cfg.source.absolute()}`")
194
+
195
+ ctx.obj = CLIConfig(
196
+ log_level=log_level,
197
+ log_format=log_format,
198
+ endpoint=endpoint,
199
+ insecure=insecure,
200
+ org=org,
201
+ config=cfg,
202
+ ctx=ctx,
203
+ auth_type=auth_type,
204
+ output_format=output_format,
205
+ )
206
+
207
+
208
+ main.add_command(run)
209
+ main.add_command(deploy)
210
+ main.add_command(get) # type: ignore
211
+ main.add_command(create) # type: ignore
212
+ main.add_command(abort) # type: ignore
213
+ main.add_command(gen) # type: ignore
214
+ main.add_command(delete) # type: ignore
215
+ main.add_command(build)
216
+ main.add_command(whoami) # type: ignore
217
+ main.add_command(update) # type: ignore
218
+ main.add_command(serve) # type: ignore
219
+
220
+ # Discover and register CLI plugins from installed packages
221
+ discover_and_register_plugins(main)
@@ -0,0 +1,3 @@
1
+ from flyte.config._config import Config, auto, get_config_file, set_if_exists
2
+
3
+ __all__ = ["Config", "auto", "get_config_file", "set_if_exists"]
@@ -0,0 +1,248 @@
1
+ from __future__ import annotations
2
+
3
+ import dataclasses
4
+ import os
5
+ import pathlib
6
+ import typing
7
+ from dataclasses import dataclass, field
8
+ from typing import TYPE_CHECKING
9
+
10
+ import rich.repr
11
+
12
+ from flyte._logging import logger
13
+ from flyte.config import _internal
14
+ from flyte.config._reader import ConfigFile, get_config_file, read_file_if_exists
15
+
16
+ _all__ = ["ConfigFile", "PlatformConfig", "TaskConfig", "ImageConfig"]
17
+
18
+ if TYPE_CHECKING:
19
+ from flyte.remote._client.auth import AuthType
20
+
21
+
22
+ @rich.repr.auto
23
+ @dataclass(init=True, repr=True, eq=True, frozen=True)
24
+ class PlatformConfig(object):
25
+ """
26
+ This object contains the settings to talk to a Flyte backend (the DNS location of your Admin server basically).
27
+
28
+ :param endpoint: DNS for Flyte backend
29
+ :param insecure: Whether or not to use SSL
30
+ :param insecure_skip_verify: Whether to skip SSL certificate verification
31
+ :param console_endpoint: endpoint for console if different from Flyte backend
32
+ :param command: This command is executed to return a token using an external process
33
+ :param proxy_command: This command is executed to return a token for proxy authorization using an external process
34
+ :param client_id: This is the public identifier for the app which handles authorization for a Flyte deployment.
35
+ More details here: https://www.oauth.com/oauth2-servers/client-registration/client-id-secret/.
36
+ :param client_credentials_secret: Used for service auth, which is automatically called during pyflyte. This will
37
+ allow the Flyte engine to read the password directly from the environment variable. Note that this is
38
+ less secure! Please only use this if mounting the secret as a file is impossible
39
+ :param scopes: List of scopes to request. This is only applicable to the client credentials flow
40
+ :param auth_mode: The OAuth mode to use. Defaults to pkce flow
41
+ :param ca_cert_file_path: [optional] str Root Cert to be loaded and used to verify admin
42
+ :param http_proxy_url: [optional] HTTP Proxy to be used for OAuth requests
43
+ """
44
+
45
+ endpoint: str | None = None
46
+ insecure: bool = False
47
+ insecure_skip_verify: bool = False
48
+ ca_cert_file_path: typing.Optional[str] = None
49
+ console_endpoint: typing.Optional[str] = None
50
+ command: typing.Optional[typing.List[str]] = None
51
+ proxy_command: typing.Optional[typing.List[str]] = None
52
+ client_id: typing.Optional[str] = None
53
+ client_credentials_secret: typing.Optional[str] = None
54
+ scopes: typing.List[str] = field(default_factory=list)
55
+ auth_mode: "AuthType" = "Pkce"
56
+ audience: typing.Optional[str] = None
57
+ rpc_retries: int = 3
58
+ http_proxy_url: typing.Optional[str] = None
59
+
60
+ @classmethod
61
+ def auto(cls, config_file: typing.Optional[typing.Union[str, ConfigFile]] = None) -> "PlatformConfig":
62
+ """
63
+ Reads from a config file, and overrides from Environment variables. Refer to ConfigEntry for details
64
+ :param config_file:
65
+ :return:
66
+ """
67
+
68
+ config_file = get_config_file(config_file)
69
+ kwargs: typing.Dict[str, typing.Any] = {}
70
+ kwargs = set_if_exists(kwargs, "insecure", _internal.Platform.INSECURE.read(config_file))
71
+ kwargs = set_if_exists(
72
+ kwargs, "insecure_skip_verify", _internal.Platform.INSECURE_SKIP_VERIFY.read(config_file)
73
+ )
74
+ kwargs = set_if_exists(kwargs, "ca_cert_file_path", _internal.Platform.CA_CERT_FILE_PATH.read(config_file))
75
+ kwargs = set_if_exists(kwargs, "command", _internal.Credentials.COMMAND.read(config_file))
76
+ kwargs = set_if_exists(kwargs, "proxy_command", _internal.Credentials.PROXY_COMMAND.read(config_file))
77
+ kwargs = set_if_exists(kwargs, "client_id", _internal.Credentials.CLIENT_ID.read(config_file))
78
+
79
+ is_client_secret = False
80
+ client_credentials_secret = read_file_if_exists(
81
+ _internal.Credentials.CLIENT_CREDENTIALS_SECRET_LOCATION.read(config_file)
82
+ )
83
+ if client_credentials_secret:
84
+ is_client_secret = True
85
+ if client_credentials_secret.endswith("\n"):
86
+ logger.info("Newline stripped from client secret")
87
+ client_credentials_secret = client_credentials_secret.strip()
88
+ kwargs = set_if_exists(
89
+ kwargs,
90
+ "client_credentials_secret",
91
+ client_credentials_secret,
92
+ )
93
+
94
+ client_credentials_secret_env_var = _internal.Credentials.CLIENT_CREDENTIALS_SECRET_ENV_VAR.read(config_file)
95
+ if client_credentials_secret_env_var:
96
+ client_credentials_secret = os.getenv(client_credentials_secret_env_var)
97
+ if client_credentials_secret:
98
+ is_client_secret = True
99
+ kwargs = set_if_exists(kwargs, "client_credentials_secret", client_credentials_secret)
100
+ kwargs = set_if_exists(kwargs, "scopes", _internal.Credentials.SCOPES.read(config_file))
101
+ kwargs = set_if_exists(kwargs, "auth_mode", _internal.Credentials.AUTH_MODE.read(config_file))
102
+ if is_client_secret:
103
+ kwargs = set_if_exists(kwargs, "auth_mode", "ClientSecret")
104
+ kwargs = set_if_exists(kwargs, "endpoint", _internal.Platform.URL.read(config_file))
105
+ kwargs = set_if_exists(kwargs, "console_endpoint", _internal.Platform.CONSOLE_ENDPOINT.read(config_file))
106
+
107
+ kwargs = set_if_exists(kwargs, "http_proxy_url", _internal.Platform.HTTP_PROXY_URL.read(config_file))
108
+ return PlatformConfig(**kwargs)
109
+
110
+ def replace(self, **kwargs: typing.Any) -> "PlatformConfig":
111
+ """
112
+ Returns a new PlatformConfig instance with the values from the kwargs overriding the current instance.
113
+ """
114
+ return dataclasses.replace(self, **kwargs)
115
+
116
+ @classmethod
117
+ def for_endpoint(cls, endpoint: str, insecure: bool = False) -> "PlatformConfig":
118
+ return PlatformConfig(endpoint=endpoint, insecure=insecure)
119
+
120
+
121
+ @rich.repr.auto
122
+ @dataclass(init=True, repr=True, eq=True, frozen=True)
123
+ class TaskConfig(object):
124
+ org: str | None = None
125
+ project: str | None = None
126
+ domain: str | None = None
127
+
128
+ @classmethod
129
+ def auto(cls, config_file: typing.Optional[typing.Union[str, ConfigFile]] = None) -> "TaskConfig":
130
+ """
131
+ Reads from a config file, and overrides from Environment variables. Refer to ConfigEntry for details
132
+ :param config_file:
133
+ :return:
134
+ """
135
+ config_file = get_config_file(config_file)
136
+ kwargs: typing.Dict[str, typing.Any] = {}
137
+ kwargs = set_if_exists(kwargs, "org", _internal.Task.ORG.read(config_file))
138
+ kwargs = set_if_exists(kwargs, "project", _internal.Task.PROJECT.read(config_file))
139
+ kwargs = set_if_exists(kwargs, "domain", _internal.Task.DOMAIN.read(config_file))
140
+ return TaskConfig(**kwargs)
141
+
142
+
143
+ @rich.repr.auto
144
+ @dataclass(init=True, repr=True, eq=True, frozen=True)
145
+ class ImageConfig(object):
146
+ """
147
+ Configuration for Docker image settings.
148
+ """
149
+
150
+ builder: str | None = None
151
+ image_refs: typing.Dict[str, str] = field(default_factory=dict)
152
+
153
+ @classmethod
154
+ def auto(cls, config_file: typing.Optional[typing.Union[str, ConfigFile]] = None) -> "ImageConfig":
155
+ """
156
+ Reads from a config file, and overrides from Environment variables. Refer to ConfigEntry for details
157
+ :param config_file:
158
+ :return:
159
+ """
160
+ config_file = get_config_file(config_file)
161
+ kwargs: typing.Dict[str, typing.Any] = {}
162
+ kwargs = set_if_exists(kwargs, "builder", _internal.Image.BUILDER.read(config_file))
163
+ kwargs = set_if_exists(kwargs, "image_refs", _internal.Image.IMAGE_REFS.read(config_file))
164
+ return ImageConfig(**kwargs)
165
+
166
+
167
+ @rich.repr.auto
168
+ @dataclass(init=True, repr=True, eq=True, frozen=True)
169
+ class Config(object):
170
+ """
171
+ This the parent configuration object and holds all the underlying configuration object types. An instance of
172
+ this object holds all the config necessary to
173
+
174
+ 1. Interactive session with Flyte backend
175
+ 2. Some parts are required for Serialization, for example Platform Config is not required
176
+ 3. Runtime of a task
177
+ """
178
+
179
+ platform: PlatformConfig = field(default=PlatformConfig())
180
+ task: TaskConfig = field(default=TaskConfig())
181
+ image: ImageConfig = field(default=ImageConfig())
182
+ source: pathlib.Path | None = None
183
+
184
+ def with_params(
185
+ self,
186
+ platform: PlatformConfig | None = None,
187
+ task: TaskConfig | None = None,
188
+ image: ImageConfig | None = None,
189
+ ) -> "Config":
190
+ return Config(
191
+ platform=platform or self.platform,
192
+ task=task or self.task,
193
+ image=image or self.image,
194
+ )
195
+
196
+ @classmethod
197
+ def auto(cls, config_file: typing.Union[str, pathlib.Path, ConfigFile, None] = None) -> "Config":
198
+ """
199
+ Automatically constructs the Config Object. The order of precedence is as follows
200
+ 1. first try to find any env vars that match the config vars specified in the FLYTE_CONFIG format.
201
+ 2. If not found in environment then values ar read from the config file
202
+ 3. If not found in the file, then the default values are used.
203
+
204
+ :param config_file: file path to read the config from, if not specified default locations are searched
205
+ :return: Config
206
+ """
207
+ config_file = get_config_file(config_file)
208
+ if config_file is None:
209
+ logger.debug("No config file found, using default values")
210
+ return Config()
211
+ return Config(
212
+ platform=PlatformConfig.auto(config_file),
213
+ task=TaskConfig.auto(config_file),
214
+ image=ImageConfig.auto(config_file),
215
+ source=config_file.path,
216
+ )
217
+
218
+
219
+ def set_if_exists(d: dict, k: str, val: typing.Any) -> dict:
220
+ """
221
+ Given a dict ``d`` sets the key ``k`` with value of config ``v``, if the config value ``v`` is set
222
+ and return the updated dictionary.
223
+ """
224
+ exists = isinstance(val, bool) or bool(val is not None and val)
225
+ if exists:
226
+ d[k] = val
227
+ return d
228
+
229
+
230
+ def auto(config_file: typing.Union[str, pathlib.Path, ConfigFile, None] = None) -> Config:
231
+ """
232
+ Automatically constructs the Config Object. The order of precedence is as follows
233
+ 1. If specified, read the config from the provided file path.
234
+ 2. If not specified, the config file is searched in the default locations.
235
+ a. ./config.yaml if it exists (current working directory)
236
+ b. ./.flyte/config.yaml if it exists (current working directory)
237
+ c. <git_root>/.flyte/config.yaml if it exists
238
+ d. `UCTL_CONFIG` environment variable
239
+ e. `FLYTECTL_CONFIG` environment variable
240
+ f. ~/.union/config.yaml if it exists
241
+ g. ~/.flyte/config.yaml if it exists
242
+ 3. If any value is not found in the config file, the default value is used.
243
+ 4. For any value there are environment variables that match the config variable names, those will override
244
+
245
+ :param config_file: file path to read the config from, if not specified default locations are searched
246
+ :return: Config
247
+ """
248
+ return Config.auto(config_file)
@@ -0,0 +1,73 @@
1
+ from flyte.config._reader import ConfigEntry, YamlConfigEntry
2
+
3
+
4
+ class Platform(object):
5
+ URL = ConfigEntry(YamlConfigEntry("admin.endpoint"))
6
+ INSECURE = ConfigEntry(YamlConfigEntry("admin.insecure", bool))
7
+ INSECURE_SKIP_VERIFY = ConfigEntry(YamlConfigEntry("admin.insecureSkipVerify", bool))
8
+ CONSOLE_ENDPOINT = ConfigEntry(YamlConfigEntry("console.endpoint"))
9
+ CA_CERT_FILE_PATH = ConfigEntry(YamlConfigEntry("admin.caCertFilePath"))
10
+ HTTP_PROXY_URL = ConfigEntry(YamlConfigEntry("admin.httpProxyURL"))
11
+
12
+
13
+ class Credentials(object):
14
+ SECTION = "credentials"
15
+ COMMAND = ConfigEntry(YamlConfigEntry("admin.command", list))
16
+ """
17
+ This command is executed to return a token using an external process.
18
+ """
19
+
20
+ PROXY_COMMAND = ConfigEntry(YamlConfigEntry("admin.proxyCommand", list))
21
+ """
22
+ This command is executed to return a token for authorization with a proxy
23
+ in front of Flyte using an external process.
24
+ """
25
+
26
+ CLIENT_ID = ConfigEntry(YamlConfigEntry("admin.clientId"))
27
+ """
28
+ This is the public identifier for the app which handles authorization for a Flyte deployment.
29
+ More details here: https://www.oauth.com/oauth2-servers/client-registration/client-id-secret/.
30
+ """
31
+
32
+ CLIENT_CREDENTIALS_SECRET_LOCATION = ConfigEntry(YamlConfigEntry("admin.clientSecretLocation"))
33
+ """
34
+ Used for basic auth, which is automatically called during pyflyte. This will allow the Flyte engine to read the
35
+ password from a mounted file.
36
+ """
37
+
38
+ CLIENT_CREDENTIALS_SECRET_ENV_VAR = ConfigEntry(YamlConfigEntry("admin.clientSecretEnvVar"))
39
+ """
40
+ Used for basic auth, which is automatically called during pyflyte. This will allow the Flyte engine to read the
41
+ password from a mounted environment variable.
42
+ """
43
+
44
+ SCOPES = ConfigEntry(YamlConfigEntry("admin.scopes", list))
45
+ """
46
+ This setting can be used to manually pass in scopes into authenticator flows - eg.) for Auth0 compatibility
47
+ """
48
+
49
+ AUTH_MODE = ConfigEntry(YamlConfigEntry("admin.authType"))
50
+ """
51
+ The auth mode defines the behavior used to request and refresh credentials. The currently supported modes include:
52
+ - 'standard' or 'Pkce': This uses the pkce-enhanced authorization code flow by opening a browser window to initiate
53
+ credentials access.
54
+ - "DeviceFlow": This uses the Device Authorization Flow
55
+ - 'basic', 'client_credentials' or 'clientSecret': This uses symmetric key auth in which the end user enters a
56
+ client id and a client secret and public key encryption is used to facilitate authentication.
57
+ - None: No auth will be attempted.
58
+ """
59
+
60
+
61
+ class Task(object):
62
+ ORG = ConfigEntry(YamlConfigEntry("task.org"))
63
+ PROJECT = ConfigEntry(YamlConfigEntry("task.project"))
64
+ DOMAIN = ConfigEntry(YamlConfigEntry("task.domain"))
65
+
66
+
67
+ class Image(object):
68
+ """
69
+ Defines the configuration for the image builder.
70
+ """
71
+
72
+ BUILDER = ConfigEntry(YamlConfigEntry("image.builder"))
73
+ IMAGE_REFS = ConfigEntry(YamlConfigEntry("image.image_refs"))