|
| 1 | +import click |
| 2 | +from sky.cli import ( |
| 3 | + _DocumentedCodeCommand, |
| 4 | + _get_shell_complete_args, |
| 5 | + _complete_file_name, |
| 6 | + _complete_cluster_name, |
| 7 | + _CLUSTER_FLAG_HELP, |
| 8 | + _TASK_OPTIONS_WITH_NAME, |
| 9 | + _EXTRA_RESOURCES_OPTIONS, |
| 10 | + usage_lib, |
| 11 | + backends, |
| 12 | + _add_click_options |
| 13 | + |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +def setup_status_factory(func): |
| 18 | + options = [ |
| 19 | + click.command(), |
| 20 | + click.option('--all', |
| 21 | + '-a', |
| 22 | + default=False, |
| 23 | + is_flag=True, |
| 24 | + required=False, |
| 25 | + help='Show all information in full.'), |
| 26 | + click.option( |
| 27 | + '--refresh', |
| 28 | + '-r', |
| 29 | + default=False, |
| 30 | + is_flag=True, |
| 31 | + required=False, |
| 32 | + help='Query the latest cluster statuses from the cloud provider(s).'), |
| 33 | + click.option('--ip', |
| 34 | + default=False, |
| 35 | + is_flag=True, |
| 36 | + required=False, |
| 37 | + help=('Get the IP address of the head node of a cluster. This ' |
| 38 | + 'option will override all other options. For Kubernetes ' |
| 39 | + 'clusters, the returned IP address is the internal IP ' |
| 40 | + 'of the head pod, and may not be accessible from outside ' |
| 41 | + 'the cluster.')), |
| 42 | + click.option('--endpoints', |
| 43 | + default=False, |
| 44 | + is_flag=True, |
| 45 | + required=False, |
| 46 | + help=('Get all exposed endpoints and corresponding URLs for a' |
| 47 | + 'cluster. This option will override all other options.')), |
| 48 | + click.option('--endpoint', |
| 49 | + required=False, |
| 50 | + default=None, |
| 51 | + type=int, |
| 52 | + help=('Get the endpoint URL for the specified port number on the ' |
| 53 | + 'cluster. This option will override all other options.')), |
| 54 | + click.option('--show-managed-jobs/--no-show-managed-jobs', |
| 55 | + default=True, |
| 56 | + is_flag=True, |
| 57 | + required=False, |
| 58 | + help='Also show recent in-progress managed jobs, if any.'), |
| 59 | + click.option('--show-services/--no-show-services', |
| 60 | + default=True, |
| 61 | + is_flag=True, |
| 62 | + required=False, |
| 63 | + help='Also show sky serve services, if any.'), |
| 64 | + click.argument('clusters', |
| 65 | + required=False, |
| 66 | + type=str, |
| 67 | + nargs=-1, |
| 68 | + **_get_shell_complete_args(_complete_cluster_name)), |
| 69 | + ] |
| 70 | + for option in reversed(options): |
| 71 | + func = option(func) |
| 72 | + return func |
| 73 | + |
| 74 | +def setup_launch_factory(func): |
| 75 | + options = [ |
| 76 | + click.command(cls=_DocumentedCodeCommand), |
| 77 | + click.argument('entrypoint', |
| 78 | + required=False, |
| 79 | + type=str, |
| 80 | + nargs=-1, |
| 81 | + **_get_shell_complete_args(_complete_file_name)), |
| 82 | + click.option('--pymc_module', |
| 83 | + '-m', |
| 84 | + required=False, |
| 85 | + type=str, |
| 86 | + help=('Define the PyMC module / project you need tu use')), |
| 87 | + click.option('--cluster', |
| 88 | + '-c', |
| 89 | + default=None, |
| 90 | + type=str, |
| 91 | + **_get_shell_complete_args(_complete_cluster_name), |
| 92 | + help=_CLUSTER_FLAG_HELP), |
| 93 | + click.option('--dryrun', |
| 94 | + default=False, |
| 95 | + is_flag=True, |
| 96 | + help='If True, do not actually run the job.'), |
| 97 | + click.option( |
| 98 | + '--detach-setup', |
| 99 | + '-s', |
| 100 | + default=False, |
| 101 | + is_flag=True, |
| 102 | + help= |
| 103 | + ('If True, run setup in non-interactive mode as part of the job itself. ' |
| 104 | + 'You can safely ctrl-c to detach from logging, and it will not interrupt ' |
| 105 | + 'the setup process. To see the logs again after detaching, use `sky logs`.' |
| 106 | + ' To cancel setup, cancel the job via `sky cancel`. Useful for long-' |
| 107 | + 'running setup commands.')), |
| 108 | + click.option( |
| 109 | + '--detach-run', |
| 110 | + '-d', |
| 111 | + default=False, |
| 112 | + is_flag=True, |
| 113 | + help=('If True, as soon as a job is submitted, return from this call ' |
| 114 | + 'and do not stream execution logs.')), |
| 115 | + click.option('--docker', |
| 116 | + 'backend_name', |
| 117 | + flag_value=backends.LocalDockerBackend.NAME, |
| 118 | + default=False, |
| 119 | + help='If used, runs locally inside a docker container.'), |
| 120 | + _add_click_options(_TASK_OPTIONS_WITH_NAME + _EXTRA_RESOURCES_OPTIONS), |
| 121 | + click.option( |
| 122 | + '--idle-minutes-to-autostop', |
| 123 | + '-i', |
| 124 | + default=None, |
| 125 | + type=int, |
| 126 | + required=False, |
| 127 | + help=('Automatically stop the cluster after this many minutes ' |
| 128 | + 'of idleness, i.e., no running or pending jobs in the cluster\'s job ' |
| 129 | + 'queue. Idleness gets reset whenever setting-up/running/pending jobs ' |
| 130 | + 'are found in the job queue. ' |
| 131 | + 'Setting this flag is equivalent to ' |
| 132 | + 'running ``sky launch -d ...`` and then ``sky autostop -i <minutes>``' |
| 133 | + '. If not set, the cluster will not be autostopped.')), |
| 134 | + click.option( |
| 135 | + '--retry-until-up', |
| 136 | + '-r', |
| 137 | + default=False, |
| 138 | + is_flag=True, |
| 139 | + required=False, |
| 140 | + help=('Whether to retry provisioning infinitely until the cluster is up, ' |
| 141 | + 'if we fail to launch the cluster on any possible region/cloud due ' |
| 142 | + 'to unavailability errors.'), |
| 143 | + ), |
| 144 | + click.option( |
| 145 | + '--yes', |
| 146 | + '-y', |
| 147 | + is_flag=True, |
| 148 | + default=False, |
| 149 | + required=False, |
| 150 | + # Disabling quote check here, as there seems to be a bug in pylint, |
| 151 | + # which incorrectly recognizes the help string as a docstring. |
| 152 | + # pylint: disable=bad-docstring-quotes |
| 153 | + help='Skip confirmation prompt.'), |
| 154 | + click.option('--no-setup', |
| 155 | + is_flag=True, |
| 156 | + default=False, |
| 157 | + required=False, |
| 158 | + help='Skip setup phase when (re-)launching cluster.'), |
| 159 | + click.option( |
| 160 | + '--clone-disk-from', |
| 161 | + '--clone', |
| 162 | + default=None, |
| 163 | + type=str, |
| 164 | + **_get_shell_complete_args(_complete_cluster_name), |
| 165 | + help=('[Experimental] Clone disk from an existing cluster to launch ' |
| 166 | + 'a new one. This is useful when the new cluster needs to have ' |
| 167 | + 'the same data on the boot disk as an existing cluster.')) |
| 168 | + ] |
| 169 | + |
| 170 | + for option in reversed(options): |
| 171 | + func = option(func) |
| 172 | + return func |
0 commit comments