diff --git a/gradient/cli/common.py b/gradient/cli/common.py index 8630af59..3cdf9f24 100644 --- a/gradient/cli/common.py +++ b/gradient/cli/common.py @@ -1,13 +1,17 @@ import functools import json +import re import click +import colorama +import termcolor import yaml from click.exceptions import Exit from click_didyoumean import DYMMixin from click_help_colors import HelpColorsGroup from gradient.cli import cli_types +from gradient.config import config OPTIONS_FILE_OPTION_NAME = "optionsFile" OPTIONS_FILE_PARAMETER_NAME = "options_file" @@ -78,11 +82,38 @@ def handle_parse_result(self, ctx, opts, args): ctx, opts, args) -class ArgumentReadValueFromConfigFile(ReadValueFromConfigFile, click.Argument): +class ColorExtrasInCommandHelpMixin(object): + def get_help_record(self, *args, **kwargs): + rv = super(ColorExtrasInCommandHelpMixin, self).get_help_record(*args, **kwargs) + if not config.USE_CONSOLE_COLORS: + return rv + + help_str = rv[1] + if help_str: + help_str = self._color_extras(help_str) + rv = rv[0], help_str + return rv + + def _color_extras(self, s): + pattern = re.compile(r"^.*(\[.*\])$") + found = re.findall(pattern, s) + if found: + extras_str = found[-1] + coloured_extras_str = self._color_str(extras_str) + s = s.replace(extras_str, coloured_extras_str) + + return s + + def _color_str(self, s): + s = termcolor.colored(s, config.HELP_HEADERS_COLOR) + return s + + +class GradientArgument(ColorExtrasInCommandHelpMixin, ReadValueFromConfigFile, click.Argument): pass -class OptionReadValueFromConfigFile(ReadValueFromConfigFile, click.Option): +class GradientOption(ColorExtrasInCommandHelpMixin, ReadValueFromConfigFile, click.Option): pass @@ -90,7 +121,7 @@ class OptionReadValueFromConfigFile(ReadValueFromConfigFile, click.Option): "--apiKey", "api_key", help="API key to use this time only", - cls=OptionReadValueFromConfigFile, + cls=GradientOption, ) diff --git a/gradient/cli/deployments.py b/gradient/cli/deployments.py index bb1587d2..17f791cb 100644 --- a/gradient/cli/deployments.py +++ b/gradient/cli/deployments.py @@ -44,35 +44,35 @@ def get_deployment_client(api_key): type=ChoiceType(DEPLOYMENT_TYPES_MAP, case_sensitive=False), required=True, help="Model deployment type. Only TensorFlow models can currently be deployed", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--modelId", "model_id", required=True, help="ID of a trained model", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--name", "name", required=True, help="Human-friendly name for new model deployment", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--machineType", "machine_type", required=True, help="Type of machine for new deployment", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--imageUrl", "image_url", required=True, help="Docker image for model serving", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--instanceCount", @@ -80,20 +80,20 @@ def get_deployment_client(api_key): type=int, required=True, help="Number of machine instances", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--clusterId", "cluster_id", help="Cluster ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--vpc", "use_vpc", type=bool, is_flag=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -123,19 +123,19 @@ def create_deployment(api_key, use_vpc, options_file, **kwargs): "state", type=ChoiceType(DEPLOYMENT_STATES_MAP, case_sensitive=False), help="Filter by deployment state", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--projectId", "project_id", help="Use to filter by project ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--modelId", "model_id", help="Use to filter by model ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -155,14 +155,14 @@ def get_deployments_list(api_key, options_file, **filters): "id_", required=True, help="Deployment ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--vpc", "use_vpc", type=bool, is_flag=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -178,14 +178,14 @@ def start_deployment(id_, use_vpc, options_file, api_key=None): "id_", required=True, help="Deployment ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--vpc", "use_vpc", type=bool, is_flag=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file diff --git a/gradient/cli/experiments.py b/gradient/cli/experiments.py index 088d11b9..8732557c 100644 --- a/gradient/cli/experiments.py +++ b/gradient/cli/experiments.py @@ -48,80 +48,80 @@ def common_experiments_create_options(f): "--name", required=True, help="Name of new experiment", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--ports", help="Port to use in new experiment", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workspace", "workspace", help="Path to workspace directory, archive, S3 or git repository", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workspaceArchive", "workspace_archive", help="Path to workspace .zip archive", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workspaceUrl", "workspace_url", help="Project git repository url", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--ignoreFiles", "ignore_files", help="Ignore certain files from uploading", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workingDirectory", "working_directory", help="Working directory for the experiment", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--artifactDirectory", "artifact_directory", help="Artifacts directory", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--clusterId", "cluster_id", help="Cluster ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--experimentEnv", "experiment_env", type=json_string, help="Environment variables in a JSON", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--projectId", "project_id", required=True, help="Project ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--modelType", "model_type", help="Model type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--modelPath", "model_path", help="Model path", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--isPreemptible", @@ -129,7 +129,7 @@ def common_experiments_create_options(f): type=bool, is_flag=True, help="Flag: is preemptible", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), ] return functools.reduce(lambda x, opt: opt(x), reversed(options), f) @@ -143,28 +143,28 @@ def common_experiment_create_multi_node_options(f): type=ChoiceType(MULTI_NODE_EXPERIMENT_TYPES_MAP, case_sensitive=False), required=True, help="Experiment Type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerContainer", "worker_container", required=True, help="Worker container", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerMachineType", "worker_machine_type", required=True, help="Worker machine type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerCommand", "worker_command", required=True, help="Worker command", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerCount", @@ -172,28 +172,28 @@ def common_experiment_create_multi_node_options(f): type=int, required=True, help="Worker count", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--parameterServerContainer", "parameter_server_container", required=True, help="Parameter server container", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--parameterServerMachineType", "parameter_server_machine_type", required=True, help="Parameter server machine type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--parameterServerCommand", "parameter_server_command", required=True, help="Parameter server command", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--parameterServerCount", @@ -201,62 +201,62 @@ def common_experiment_create_multi_node_options(f): type=int, required=True, help="Parameter server count", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerContainerUser", "worker_container_user", help="Worker container user", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerRegistryUsername", "worker_registry_username", help="Worker container registry username", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerRegistryPassword", "worker_registry_password", help="Worker registry password", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerRegistryUrl", "worker_registry_url", help="Worker registry URL", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--parameterServerContainerUser", "parameter_server_container_user", help="Parameter server container user", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--parameterServerRegistryUsername", "parameter_server_registry_username", help="Parameter server registry username", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--parameterServerRegistryPassword", "parameter_server_registry_password", help="Parameter server registry password", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--parameterServerRegistryUrl", "parameter_server_registry_url", help="Parameter server registry URL", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--vpc", "use_vpc", type=bool, is_flag=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), ] return functools.reduce(lambda x, opt: opt(x), reversed(options), f) @@ -268,51 +268,51 @@ def common_experiments_create_single_node_options(f): "--container", required=True, help="Container", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--machineType", "machine_type", required=True, help="Machine type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--command", required=True, help="Container entrypoint command", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--containerUser", "container_user", help="Container user", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--registryUsername", "registry_username", help="Registry username", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--registryPassword", "registry_password", help="Registry password", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--registryUrl", "registry_url", help="Registry URL", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--vpc", "use_vpc", type=bool, is_flag=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), ] return functools.reduce(lambda x, opt: opt(x), reversed(options), f) @@ -425,7 +425,7 @@ def create_and_start_single_node(ctx, api_key, show_logs, use_vpc, options_file, @experiments.command("start", help="Start experiment") -@click.argument("id", cls=common.ArgumentReadValueFromConfigFile) +@click.argument("id", cls=common.GradientArgument) @click.option( "--logs", "show_logs", @@ -437,7 +437,7 @@ def create_and_start_single_node(ctx, api_key, show_logs, use_vpc, options_file, "use_vpc", type=bool, is_flag=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -451,14 +451,14 @@ def start_experiment(ctx, id, show_logs, api_key, options_file, use_vpc): @experiments.command("stop", help="Stop experiment") -@click.argument("id", cls=common.ArgumentReadValueFromConfigFile) +@click.argument("id", cls=common.GradientArgument) @api_key_option @click.option( "--vpc", "use_vpc", type=bool, is_flag=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @common.options_file def stop_experiment(id, api_key, options_file, use_vpc): @@ -467,7 +467,7 @@ def stop_experiment(id, api_key, options_file, use_vpc): @experiments.command("list", help="List experiments") -@click.option("--projectId", "-p", "project_ids", multiple=True, cls=common.OptionReadValueFromConfigFile) +@click.option("--projectId", "-p", "project_ids", multiple=True, cls=common.GradientOption) @api_key_option @common.options_file def list_experiments(project_ids, api_key, options_file): @@ -476,7 +476,7 @@ def list_experiments(project_ids, api_key, options_file): @experiments.command("details", help="Show detail of an experiment") -@click.argument("id", cls=common.ArgumentReadValueFromConfigFile) +@click.argument("id", cls=common.GradientArgument) @api_key_option @common.options_file def get_experiment_details(id, options_file, api_key): @@ -489,28 +489,28 @@ def get_experiment_details(id, options_file, api_key): "--experimentId", "experiment_id", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--line", "line", required=False, default=0, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--limit", "limit", required=False, default=10000, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--follow", "follow", required=False, default=False, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file diff --git a/gradient/cli/hyperparameters.py b/gradient/cli/hyperparameters.py index f7aab8da..c8720327 100644 --- a/gradient/cli/hyperparameters.py +++ b/gradient/cli/hyperparameters.py @@ -22,42 +22,42 @@ def common_hyperparameter_create_options(f): "tuning_command", required=True, help="Tuning command", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerContainer", "worker_container", required=True, help="Worker container", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerContainerUser", "worker_container_user", required=False, help="Worker container user", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerMachineType", "worker_machine_type", required=True, help="Worker machine type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--hyperparameterServerMachineType", "hyperparameter_server_machine_type", required=False, help="Hyperparameter Server machine type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerCommand", "worker_command", required=True, help="Worker command", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerCount", @@ -65,7 +65,7 @@ def common_hyperparameter_create_options(f): required=True, type=int, help="Worker count", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerUseDockerfile", @@ -74,49 +74,49 @@ def common_hyperparameter_create_options(f): is_flag=True, default=False, help="Flag: use dockerfile", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerDockerfilePath", "dockerfile_path", help="Path to ", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerRegistryUsername", "worker_registry_username", help="Worker registry username", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workerRegistryPassword", "worker_registry_password", help="Worker registry password", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--hyperparameterServerRegistryUsername", "hyperparameter_server_registry_username", help="Hyperparameter server registry username", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--hyperparameterServerRegistryPassword", "hyperparameter_server_registry_password", help="Hyperparameter server registry password", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--hyperparameterServerContainer", "hyperparameter_server_container", help="Hyperparameter server container", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--hyperparameterServerContainerUser", "hyperparameter_server_container_user", help="Hyperparameter server container user", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), ] return functools.reduce(lambda x, opt: opt(x), reversed(options), f) @@ -167,7 +167,7 @@ def list_hyperparameters(api_key, options_file): "--id", "id_", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @common.api_key_option @common.options_file @@ -181,7 +181,7 @@ def get_hyperparameter_details(api_key, id_, options_file): "--id", "id_", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @common.api_key_option @common.options_file diff --git a/gradient/cli/jobs.py b/gradient/cli/jobs.py index 53ec5fda..216c1fa4 100644 --- a/gradient/cli/jobs.py +++ b/gradient/cli/jobs.py @@ -53,19 +53,19 @@ def stop_job(job_id, api_key=None): "--project", "project", help="Use to filter jobs by project name", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--projectId", "project_id", help="Use to filter jobs by project ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--experimentId", "experiment_id", help="Use to filter jobs by experiment ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -82,14 +82,14 @@ def common_jobs_create_options(f): "--name", "name", help="Job name", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--machineType", "machine_type", help="Virtual machine type", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--container", @@ -97,138 +97,138 @@ def common_jobs_create_options(f): default="paperspace/tensorflow-python", help="Docker container", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--command", "command", help="Job command/entrypoint", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--ports", "ports", help="Mapped ports", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), # TODO: make it a flag click.option( "--isPublic", "is_public", help="Flag: is job public", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workspace", "workspace", help="Path to workspace directory", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workspaceArchive", "workspace_archive", help="Path to workspace archive", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workspaceUrl", "workspace_url", help="Project git repository url", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--workingDirectory", "working_directory", help="Working directory for the experiment", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--ignoreFiles", "ignore_files", help="Ignore certain files from uploading", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--experimentId", "experiment_id", help="Experiment Id", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--jobEnv", "job_env", type=json_string, help="Environmental variables ", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--useDockerfile", "use_dockerfile", help="Flag: using Dockerfile", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), # TODO: make it a flag click.option( "--isPreemptible", "is_preemptible", help="Flag: isPreemptible", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--project", "project", help="Project name", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--projectId", "project_id", help="Project ID", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--startedByUserId", "started_by_user_id", help="User ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--relDockerfilePath", "rel_dockerfile_path", help="Relative path to Dockerfile", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--registryUsername", "registry_username", help="Docker registry username", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--registryPassword", "registry_password", help="Docker registry password", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--cluster", "cluster", help="Cluster name", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--clusterId", "cluster_id", help="Cluster id", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), click.option( "--nodeAttrs", "node_attrs", type=json_string, help="Cluster node details", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ), ] return reduce(lambda x, opt: opt(x), reversed(options), f) @@ -257,28 +257,28 @@ def create_job(ctx, api_key, options_file, **kwargs): "--jobId", "job_id", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--line", "line", required=False, default=0, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--limit", "limit", required=False, default=10000, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--follow", "follow", required=False, default=False, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -293,11 +293,11 @@ def artifacts(): @artifacts.command("destroy", help="Destroy job's artifacts") -@click.argument("job_id", cls=common.ArgumentReadValueFromConfigFile) +@click.argument("job_id", cls=common.GradientArgument) @click.option( "--files", "files", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -307,7 +307,7 @@ def destroy_artifacts(job_id, options_file, api_key=None, files=None): @artifacts.command("get", help="Get job's artifacts") -@click.argument("job_id", cls=common.ArgumentReadValueFromConfigFile) +@click.argument("job_id", cls=common.GradientArgument) @api_key_option @common.options_file def get_artifacts(job_id, options_file, api_key=None): @@ -316,14 +316,14 @@ def get_artifacts(job_id, options_file, api_key=None): @artifacts.command("list", help="List job's artifacts") -@click.argument("job_id", cls=common.ArgumentReadValueFromConfigFile) +@click.argument("job_id", cls=common.GradientArgument) @click.option( "--size", "-s", "size", help="Show file size", is_flag=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--links", @@ -332,13 +332,13 @@ def get_artifacts(job_id, options_file, api_key=None): help="Show file URL", is_flag=True, default=False, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--files", "files", help="Get only given file (use at the end * as a wildcard)", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file diff --git a/gradient/cli/machines.py b/gradient/cli/machines.py index d0ccd587..e04e6f21 100644 --- a/gradient/cli/machines.py +++ b/gradient/cli/machines.py @@ -36,14 +36,14 @@ def machines_group(): type=ChoiceType(REGIONS_MAP, case_sensitive=False), required=True, help="Name of the region", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--machineType", "machine_type", required=True, help="Machine type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -66,14 +66,14 @@ def check_machine_availability(region, machine_type, api_key, options_file): type=ChoiceType(REGIONS_MAP, case_sensitive=False), required=True, help="Name of the region", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--machineType", "machine_type", required=True, help="Machine type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--size", @@ -81,7 +81,7 @@ def check_machine_availability(region, machine_type, api_key, options_file): type=int, required=True, help="Storage size for the machine in GB", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--billingType", @@ -89,21 +89,21 @@ def check_machine_availability(region, machine_type, api_key, options_file): type=click.Choice(constants.BILLING_TYPES), required=True, help="Either 'monthly' or 'hourly' billing", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--machineName", "name", required=True, help="A memorable name for this machine", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--templateId", "template_id", required=True, help="Template id of the template to use for creating this machine", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--assignPublicIp", @@ -111,7 +111,7 @@ def check_machine_availability(region, machine_type, api_key, options_file): is_flag=True, default=None, # None is used so it can be filtered with `del_if_value_is_none` when flag was not set help="Assign a new public ip address on machine creation. Cannot be used with dynamicPublicIp", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--dynamicPublicIp", @@ -120,64 +120,64 @@ def check_machine_availability(region, machine_type, api_key, options_file): default=None, # None is used so it can be filtered with `del_if_value_is_none` when flag was not set help="Assigns a new public ip address on machine start and releases it from the account on machine stop. " "Cannot be used with assignPublicIp", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--networkId", "network_id", help="If creating on a specific network, specify its id", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--teamId", "team_id", help="If creating the machine for a team, specify the team id", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--userId", "user_id", help="If assigning to an existing user other than yourself, specify the user id (mutually exclusive with email, " "password, firstName, lastName)", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--email", "email", help="If creating a new user for this machine, specify their email address (mutually exclusive with userId)", callback=validate_email, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--password", "password", help="If creating a new user, specify their password (mutually exclusive with userId)", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--firstName", "first_name", help="If creating a new user, specify their first name (mutually exclusive with userId)", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--lastName", "last_name", help="If creating a new user, specify their last name (mutually exclusive with userId)", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--notificationEmail", "notification_email", help="Send a notification to this email address when complete", callback=validate_email, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--scriptId", "script_id", help="The script id of a script to be run on startup. See the Script Guide for more info on using scripts", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -215,14 +215,14 @@ def create_machine(api_key, options_file, **kwargs): "machine_id", required=True, help="The id of the machine to destroy", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--releasePublicIp", "release_public_ip", is_flag=True, help="releases any assigned public ip address for the machine; defaults to false", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -242,158 +242,158 @@ def destroy_machine(machine_id, release_public_ip, api_key, options_file): "params", type=json_string, help="JSON used to filter machines. Use either this or a combination of following options", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--machineId", "id", help="Optional machine id to match on", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--name", "name", help="Filter by machine name", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--os", "os", help="Filter by os used", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--ram", "ram", type=int, help="Filter by machine RAM (in bytes)", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--cpus", "cpus", type=int, help="Filter by CPU count", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--gpu", "gpu", help="Filter by GPU type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--storageTotal", "storage_total", help="Filter by total storage", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--storageUsed", "storage_used", help="Filter by storage used", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--usageRate", "usage_rate", help="Filter by usage rate", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--shutdownTimeoutInHours", "shutdown_timeout_in_hours", type=int, help="Filter by shutdown timeout", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--performAutoSnapshot", "perform_auto_snapshot", type=bool, help="Filter by performAutoSnapshot flag", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--autoSnapshotFrequency", "auto_snapshot_frequency", type=click.Choice(["hour", "day", "week"], case_sensitive=False), help="Filter by autoSnapshotFrequency flag", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--autoSnapshotSaveCount", "auto_snapshot_save_count", type=int, help="Filter by auto shapshots count", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--agentType", "agent_type", help="Filter by agent type", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--dtCreated", "created_timestamp", help="Filter by date created", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--state", "state", help="Filter by state", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--updatesPending", "updates_pending", help="Filter by updatesPending", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--networkId", "network_id", help="Filter by network ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--privateIpAddress", "private_ip_address", help="Filter by private IP address", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--publicIpAddress", "public_ip_address", help="Filter by public IP address", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--region", "region", type=ChoiceType(REGIONS_MAP, case_sensitive=False), help="Filter by region", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--userId", "user_id", help="Filter by user ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--teamId", "team_id", help="Filter by team ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--dtLastRun", "last_run_timestamp", help="Filter by last run date", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -420,7 +420,7 @@ def list_machines(api_key, params, options_file, **kwargs): "machine_id", help="Id of the machine to restart", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -438,7 +438,7 @@ def restart_machine(machine_id, api_key, options_file): "machine_id", help="Id of the machine to show", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -456,55 +456,55 @@ def show_machine_details(machine_id, api_key, options_file): "machine_id", help="Id of the machine to update", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--machineName", "name", help="New name for the machine", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--shutdownTimeoutInHours", "shutdown_timeout_in_hours", help="Number of hours before machine is shutdown if no one is logged in via the Paperspace client", type=int, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--shutdownTimeoutForces", "shutdown_timeout_forces", help="Force shutdown at shutdown timeout, even if there is a Paperspace client connection", type=bool, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--performAutoSnapshot", "perform_auto_snapshot", help="Perform auto snapshots", type=bool, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--autoSnapshotFrequency", "auto_snapshot_frequency", help="One of 'hour', 'day', 'week', or null", type=click.Choice(["hour", "day", "week"], case_sensitive=False), - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--autoSnapshotSaveCount", "auto_snapshot_save_count", help="Number of snapshots to save", type=int, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--dynamicPublicIp", "dynamic_public_ip", help="If true, assigns a new public ip address on machine start and releases it from the account on machine stop", type=bool, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -525,7 +525,7 @@ def update_machine(machine_id, api_key, options_file, **kwargs): "machine_id", help="Id of the machine to start", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -545,7 +545,7 @@ def start_machine(machine_id, api_key, options_file): "machine_id", help="Id of the machine to start", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -564,14 +564,14 @@ def stop_machine(machine_id, api_key, options_file): "machine_id", help="Id of the machine to start", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--billingMonth", "billing_month", required=True, help="Month in YYYY-MM format", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file @@ -591,7 +591,7 @@ def show_machine_utilization(machine_id, billing_month, api_key, options_file): "machine_id", help="Id of the machine to start", required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--state", @@ -599,7 +599,7 @@ def show_machine_utilization(machine_id, billing_month, api_key, options_file): help="Name of the state to wait for", type=click.Choice(["off", "serviceready", "ready"], case_sensitive=False), required=True, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @api_key_option @common.options_file diff --git a/gradient/cli/models.py b/gradient/cli/models.py index 4822ef56..6aa8de12 100644 --- a/gradient/cli/models.py +++ b/gradient/cli/models.py @@ -15,13 +15,13 @@ def models_group(): "--experimentId", "experiment_id", help="Use to filter by experiment ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--projectId", "project_id", help="Use to filter by project ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @common.api_key_option @common.options_file diff --git a/gradient/cli/notebooks.py b/gradient/cli/notebooks.py index 1458df96..69d3e832 100644 --- a/gradient/cli/notebooks.py +++ b/gradient/cli/notebooks.py @@ -17,7 +17,7 @@ def notebooks_group(): type=int, required=True, help="Type of Virtual Machine", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--containerId", @@ -25,7 +25,7 @@ def notebooks_group(): type=int, required=True, help="Container ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--clusterId", @@ -33,50 +33,50 @@ def notebooks_group(): type=int, required=True, help="Cluster ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--containerName", "container_name", help="Container name", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--name", "name", help="Notebook name", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--registryUsername", "registry_username", help="Registry username", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--registryPassword", "registry_password", help="Registry password", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--defaultEntrypoint", "default_entrypoint", help="Default entrypoint", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--containerUser", "container_user", help="Container user", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--shutdownTimeout", "shutdown_timeout", help="Shutdown timeout in hours", type=float, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--isPreemptible", @@ -84,7 +84,7 @@ def notebooks_group(): help="Is preemptible", is_flag=True, type=bool, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @common.api_key_option @common.options_file @@ -98,7 +98,7 @@ def create_notebook(api_key, options_file, **notebook): "--id", "id_", help="Notebook ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @common.api_key_option @common.options_file @@ -120,7 +120,7 @@ def list_notebooks(api_key, options_file): "--id", "id", help="Notebook ID", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @common.api_key_option @common.options_file diff --git a/gradient/cli/projects.py b/gradient/cli/projects.py index b5476818..948d73c6 100644 --- a/gradient/cli/projects.py +++ b/gradient/cli/projects.py @@ -25,19 +25,19 @@ def list_projects(api_key, options_file): "name", required=True, help="Name of new project", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--repositoryName", "repository_name", help="Name of the repository", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "--repositoryUrl", "repository_url", help="URL to the repository", - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @common.api_key_option @common.options_file diff --git a/gradient/cli/run.py b/gradient/cli/run.py index f058410d..39b1c3b9 100644 --- a/gradient/cli/run.py +++ b/gradient/cli/run.py @@ -21,24 +21,24 @@ "--python-command", "mode", flag_value=RunMode.RUN_MODE_PYTHON_COMMAND, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "-m", "--module", "mode", flag_value=RunMode.RUN_MODE_PYTHON_MODULE, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @click.option( "-s", "--shell", "mode", flag_value=RunMode.RUN_MODE_SHELL_COMMAND, - cls=common.OptionReadValueFromConfigFile, + cls=common.GradientOption, ) @common_jobs_create_options -@click.argument("script", nargs=-1, required=True, cls=common.ArgumentReadValueFromConfigFile) +@click.argument("script", nargs=-1, required=True, cls=common.GradientArgument) @common.api_key_option @common.options_file def run(api_key, options_file, **kwargs):