-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli_factory.py
339 lines (326 loc) · 13.2 KB
/
cli_factory.py
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import click
from sky.cli import (
_DocumentedCodeCommand,
_get_shell_complete_args,
_complete_file_name,
_complete_cluster_name,
_CLUSTER_FLAG_HELP,
_TASK_OPTIONS_WITH_NAME,
_EXTRA_RESOURCES_OPTIONS,
usage_lib,
backends,
_add_click_options
)
def setup_status_factory(func):
options = [
click.command(),
click.option('--all',
'-a',
default=False,
is_flag=True,
required=False,
help='Show all information in full.'),
click.option(
'--refresh',
'-r',
default=False,
is_flag=True,
required=False,
help='Query the latest cluster statuses from the cloud provider(s).'),
click.option('--ip',
default=False,
is_flag=True,
required=False,
help=('Get the IP address of the head node of a cluster. This '
'option will override all other options. For Kubernetes '
'clusters, the returned IP address is the internal IP '
'of the head pod, and may not be accessible from outside '
'the cluster.')),
click.option('--endpoints',
default=False,
is_flag=True,
required=False,
help=('Get all exposed endpoints and corresponding URLs for a'
'cluster. This option will override all other options.')),
click.option('--endpoint',
required=False,
default=None,
type=int,
help=('Get the endpoint URL for the specified port number on the '
'cluster. This option will override all other options.')),
click.option('--show-managed-jobs/--no-show-managed-jobs',
default=True,
is_flag=True,
required=False,
help='Also show recent in-progress managed jobs, if any.'),
click.option('--show-services/--no-show-services',
default=True,
is_flag=True,
required=False,
help='Also show sky serve services, if any.'),
click.argument('clusters',
required=False,
type=str,
nargs=-1,
**_get_shell_complete_args(_complete_cluster_name)),
]
for option in reversed(options):
func = option(func)
return func
def setup_launch_factory(func):
options = [
click.command(cls=_DocumentedCodeCommand),
click.argument('entrypoint',
required=False,
type=str,
nargs=-1,
**_get_shell_complete_args(_complete_file_name)),
click.option('--module-name',
'-m',
#default='pymc-marketing',
required=False,
type=str,
help=('Define the PyMC module / project you need tu use. '
'pymc-marketing is default.')),
click.option('--base-config-folder',
'-b',
required=False,
type=str,
help=('define config base Folder')),
click.option('--cluster',
'-c',
default=None,
type=str,
**_get_shell_complete_args(_complete_cluster_name),
help=_CLUSTER_FLAG_HELP),
click.option('--dryrun',
default=False,
is_flag=True,
help='If True, do not actually run the job.'),
click.option(
'--detach-setup',
'-s',
default=False,
is_flag=True,
help=
('If True, run setup in non-interactive mode as part of the job itself. '
'You can safely ctrl-c to detach from logging, and it will not interrupt '
'the setup process. To see the logs again after detaching, use `sky logs`.'
' To cancel setup, cancel the job via `sky cancel`. Useful for long-'
'running setup commands.')),
click.option(
'--detach-run',
'-d',
default=False,
is_flag=True,
help=('If True, as soon as a job is submitted, return from this call '
'and do not stream execution logs.')),
click.option('--docker',
'backend_name',
flag_value=backends.LocalDockerBackend.NAME,
default=False,
help='If used, runs locally inside a docker container.'),
_add_click_options(_TASK_OPTIONS_WITH_NAME + _EXTRA_RESOURCES_OPTIONS),
click.option(
'--idle-minutes-to-autostop',
'-i',
default=None,
type=int,
required=False,
help=('Automatically stop the cluster after this many minutes '
'of idleness, i.e., no running or pending jobs in the cluster\'s job '
'queue. Idleness gets reset whenever setting-up/running/pending jobs '
'are found in the job queue. '
'Setting this flag is equivalent to '
'running ``sky launch -d ...`` and then ``sky autostop -i <minutes>``'
'. If not set, the cluster will not be autostopped.')),
click.option(
'--retry-until-up',
'-r',
default=False,
is_flag=True,
required=False,
help=('Whether to retry provisioning infinitely until the cluster is up, '
'if we fail to launch the cluster on any possible region/cloud due '
'to unavailability errors.'),
),
click.option(
'--yes',
'-y',
is_flag=True,
default=False,
required=False,
# Disabling quote check here, as there seems to be a bug in pylint,
# which incorrectly recognizes the help string as a docstring.
# pylint: disable=bad-docstring-quotes
help='Skip confirmation prompt.'),
click.option('--no-setup',
is_flag=True,
default=False,
required=False,
help='Skip setup phase when (re-)launching cluster.'),
click.option(
'--clone-disk-from',
'--clone',
default=None,
type=str,
**_get_shell_complete_args(_complete_cluster_name),
help=('[Experimental] Clone disk from an existing cluster to launch '
'a new one. This is useful when the new cluster needs to have '
'the same data on the boot disk as an existing cluster.')),
click.option(
'--down',
default=None,
is_flag=True,
required=False,
help=
('Autodown the cluster: tear down the cluster after all jobs finish '
'(successfully or abnormally). If --idle-minutes-to-autostop is also set, '
'the cluster will be torn down after the specified idle time. '
'Note that if errors occur during provisioning/data syncing/setting up, '
'the cluster will not be torn down for debugging purposes.'))
]
for option in reversed(options):
func = option(func)
return func
def setup_exec_factory(func):
options = [
#cli.command(cls=_DocumentedCodeCommand),
click.command(cls=_DocumentedCodeCommand),
click.argument('cluster',
required=False,
type=str,
**_get_shell_complete_args(_complete_cluster_name)),
click.option(
'--cluster',
'-c',
'cluster_option',
hidden=True,
type=str,
help='This is the same as the positional argument, just for consistency.',
**_get_shell_complete_args(_complete_cluster_name)),
click.argument('entrypoint',
required=False,
type=str,
nargs=-1,
**_get_shell_complete_args(_complete_file_name)),
click.option('--module-name',
'-m',
#default='pymc-marketing',
required=False,
type=str,
help=('Define the PyMC module / project you need tu use. '
'pymc-marketing is default.')),
click.option('--base-config-folder',
'-b',
required=False,
type=str,
help=('define config base Folder')),
click.option(
'--detach-run',
'-d',
default=False,
is_flag=True,
help=('If True, as soon as a job is submitted, return from this call '
'and do not stream execution logs.')),
_add_click_options(_TASK_OPTIONS_WITH_NAME + _EXTRA_RESOURCES_OPTIONS),
usage_lib.entrypoint
]
for option in reversed(options):
func = option(func)
return func
def setup_start_factory(func):
options = [
click.command(cls=_DocumentedCodeCommand),
click.argument('clusters',
nargs=-1,
required=False,
**_get_shell_complete_args(_complete_cluster_name)),
click.option('--entrypoint',
'-e',
default=None,
type=str,
required=False,
**_get_shell_complete_args(_complete_file_name)),
click.option('--all',
'-a',
default=False,
is_flag=True,
required=False,
help='Start all existing clusters.'),
click.option('--yes',
'-y',
is_flag=True,
default=False,
required=False,
help='Skip confirmation prompt.'),
click.option(
'--idle-minutes-to-autostop',
'-i',
default=None,
type=int,
required=False,
help=('Automatically stop the cluster after this many minutes '
'of idleness, i.e., no running or pending jobs in the cluster\'s job '
'queue. Idleness gets reset whenever setting-up/running/pending jobs '
'are found in the job queue. '
'Setting this flag is equivalent to '
'running ``sky launch -d ...`` and then ``sky autostop -i <minutes>``'
'. If not set, the cluster will not be autostopped.')),
click.option(
'--down',
default=None,
is_flag=True,
required=False,
help=
('Autodown the cluster: tear down the cluster after specified minutes of '
'idle time after all jobs finish (successfully or abnormally). Requires '
'--idle-minutes-to-autostop to be set.'),
),
click.option(
'--retry-until-up',
'-r',
default=False,
is_flag=True,
required=False,
# Disabling quote check here, as there seems to be a bug in pylint,
# which incorrectly recognizes the help string as a docstring.
# pylint: disable=bad-docstring-quotes
help=('Retry provisioning infinitely until the cluster is up, '
'if we fail to start the cluster due to unavailability errors.'),
),
click.option(
'--force',
'-f',
default=False,
is_flag=True,
required=False,
help=('Force start the cluster even if it is already UP. Useful for '
'upgrading the SkyPilot runtime on the cluster.')),
usage_lib.entrypoint
]
for option in reversed(options):
func = option(func)
return func
def setup_stop_factory(func):
options = [
click.command(cls=_DocumentedCodeCommand),
click.argument('clusters',
nargs=-1,
required=False,
**_get_shell_complete_args(_complete_cluster_name)),
click.option('--all',
'-a',
default=None,
is_flag=True,
help='Stop all existing clusters.'),
click.option('--yes',
'-y',
is_flag=True,
default=False,
required=False,
help='Skip confirmation prompt.')
]
for option in reversed(options):
func = option(func)
return func