-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathmain.py
More file actions
310 lines (282 loc) · 8.7 KB
/
Copy pathmain.py
File metadata and controls
310 lines (282 loc) · 8.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import rich_click as click
from typing_extensions import get_args
import flyte
from flyte._logging import _LOG_LEVEL_MAP, LogFormat, initialize_logger, logger
from . import _common as common
from ._abort import abort
from ._build import build
from ._common import CLIConfig
from ._create import create
from ._delete import delete
from ._deploy import deploy
from ._edit import edit
from ._gen import gen
from ._get import get
from ._plugins import discover_and_register_plugins
from ._prefetch import prefetch
from ._proxy import proxy
from ._rerun import rerun
from ._run import run
from ._serve import serve
from ._signal import signal
from ._start import start
from ._stop import stop
from ._update import update
from ._user import whoami
help_config = click.RichHelpConfiguration(
use_markdown=True,
use_markdown_emoji=True,
command_groups={
"flyte": [
{
"name": "Run and stop tasks",
"commands": ["run", "rerun", "abort", "signal"],
},
{
"name": "Serve Apps",
"commands": ["serve"],
},
{
"name": "Management of various objects.",
"commands": ["create", "get", "delete", "update"],
},
{
"name": "Settings management.",
"commands": ["edit"],
},
{
"name": "Build and deploy environments, tasks and images.",
"commands": ["build", "deploy"],
},
{
"name": "Prefetch artifacts from remote registries.",
"commands": ["prefetch"],
},
{
"name": "Documentation generation",
"commands": ["gen"],
},
{
"name": "User information",
"commands": ["whoami"],
},
]
},
)
def _verbosity_to_loglevel(verbosity: int) -> int | None:
"""
Converts a verbosity level from the CLI to a logging level.
Args:
verbosity: verbosity level from the CLI
Returns:
logging level
"""
import logging
match verbosity:
case 0:
return None
case 1:
return logging.WARNING
case 2:
return logging.INFO
case _:
return logging.DEBUG
@click.group(cls=click.RichGroup)
@click.version_option(
message=f"Flyte SDK version: {flyte.version()}",
)
@click.option(
"--endpoint",
type=str,
required=False,
help="The endpoint to connect to. This will override any configuration file and simply use `pkce` to connect.",
)
@click.option(
"--insecure",
is_flag=True,
required=False,
help="Use an insecure connection to the endpoint. If not specified, the CLI will use TLS.",
type=bool,
default=None,
show_default=True,
)
@click.option(
"--image-builder",
"--builder",
type=click.Choice(["local", "remote"]),
default=None,
help="Image builder to use for building images. Overrides the config file setting."
" If not specified, the builder from the config file (image.builder) is used,"
" falling back to `local`.",
show_default=True,
required=False,
)
@click.option(
"--auth-type",
type=click.Choice(common.ALL_AUTH_OPTIONS, case_sensitive=False),
default=None,
help="Authentication type to use for the Flyte backend. Defaults to `pkce`.",
show_default=True,
required=False,
)
@click.option(
"-v",
"--verbose",
required=False,
help="Show verbose messages and exception traces. Repeating multiple times increases the verbosity (e.g., -vvv).",
count=True,
default=0,
type=int,
)
@click.option(
"--org",
type=str,
required=False,
help="The organization to which the command applies.",
)
@click.option(
"-c",
"--config",
"config_file",
required=False,
type=click.Path(exists=True, dir_okay=False),
help="Path to the configuration file to use. If not specified, the default configuration file is used.",
)
@click.option(
"--output-format",
"-of",
type=click.Choice(get_args(common.OutputFormat), case_sensitive=False),
default="table",
help="Output format for commands that support it. Defaults to `table`.",
show_default=True,
required=False,
)
@click.option(
"--log-format",
type=click.Choice(get_args(LogFormat), case_sensitive=False),
envvar="LOG_FORMAT",
default="console",
help="Formatting for logs, defaults to `console` which is meant to be human readable."
" `json` is meant for machine parsing.",
show_default=True,
required=False,
)
@click.option(
"--user-log-level",
type=click.Choice(["debug", "info", "warning", "error", "critical"], case_sensitive=False),
envvar="USER_LOG_LEVEL",
default="info",
show_default=True,
help="Log level for user task logs. Independent of the internal Flyte log level (-v).",
required=False,
)
@click.option(
"--reset-root-logger",
is_flag=True,
required=False,
help="If set, the root logger will be reset to use Flyte logging style",
type=bool,
default=False,
show_default=True,
)
@click.option(
"--no-progress",
is_flag=True,
required=False,
help="Disable the animated progress spinner — useful in CI / non-interactive logs.",
type=bool,
default=False,
show_default=True,
)
@click.rich_config(help_config=help_config)
@click.pass_context
def main(
ctx: click.Context,
endpoint: str | None,
insecure: bool,
image_builder: str | None,
verbose: int,
log_format: LogFormat,
reset_root_logger: bool,
org: str | None,
config_file: str | None,
auth_type: str | None = None,
output_format: common.OutputFormat = "table",
user_log_level: str = "info",
no_progress: bool = False,
):
"""
The Flyte CLI is the command line interface for working with the Flyte SDK and backend.
It follows a simple verb/noun structure,
where the top-level commands are verbs that describe the action to be taken,
and the subcommands are nouns that describe the object of the action.
The root command can be used to configure the CLI for persistent settings,
such as the endpoint, organization, and verbosity level.
Set endpoint and organization:
```bash
$ flyte --endpoint <endpoint> --org <org> get project <project_name>
```
Increase verbosity level (This is useful for debugging,
this will show more logs and exception traces):
```bash
$ flyte -vvv get logs <run-name>
```
Override the default config file:
```bash
$ flyte --config /path/to/config.yaml run ...
```
* [Documentation](https://www.union.ai/docs/flyte/user-guide/)
* [GitHub](https://github.com/flyteorg/flyte): Please leave a star if you like Flyte!
* [Slack](https://slack.flyte.org): Join the community and ask questions.
* [Issues](https://github.com/flyteorg/flyte/issues)
"""
import flyte.config as config
log_level = _verbosity_to_loglevel(verbose)
user_log_level_int = _LOG_LEVEL_MAP[user_log_level.lower()]
initialize_logger(
log_level=log_level,
log_format=log_format,
enable_rich=True,
reset_root_logger=reset_root_logger,
user_log_level=user_log_level_int,
)
cfg = config.auto(config_file=config_file)
if cfg.source:
logger.debug(f"Using config file discovered at location `{cfg.source.absolute()}`")
ctx.obj = CLIConfig(
log_level=log_level,
log_format=log_format,
reset_root_logger=reset_root_logger,
user_log_level=user_log_level_int,
endpoint=endpoint,
insecure=insecure,
image_builder=image_builder,
org=org,
config=cfg,
ctx=ctx,
auth_type=auth_type,
output_format=output_format,
no_progress=no_progress,
)
from flyte._status import set_output_mode
set_output_mode("rich" if output_format == "table" else "plain")
main.add_command(run)
main.add_command(rerun)
main.add_command(deploy)
main.add_command(get) # type: ignore
main.add_command(create) # type: ignore
main.add_command(abort) # type: ignore
main.add_command(signal) # type: ignore
main.add_command(gen) # type: ignore
main.add_command(delete) # type: ignore
main.add_command(build)
main.add_command(whoami) # type: ignore
main.add_command(update) # type: ignore
main.add_command(serve) # type: ignore
main.add_command(start) # type: ignore
main.add_command(stop) # type: ignore
main.add_command(prefetch) # type: ignore
main.add_command(edit) # type: ignore
main.add_command(proxy) # type: ignore
# Discover and register CLI plugins from installed packages
discover_and_register_plugins(main)