Skip to content

Commit 5835597

Browse files
authored
Merge pull request #234 from Paperspace/PS-12850-Improve_consistency_of_options_and_commands_names
Ps 12850 improve consistency of options and commands names
2 parents 2ec1468 + 00f2383 commit 5835597

29 files changed

+264
-120
lines changed

gradient/cli/clusters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def get_clusters_client(api_key):
1616
def clusters():
1717
pass
1818

19+
1920
@clusters.command("list", help="List your team clusters")
2021
@click.option(
2122
"--limit",

gradient/cli/common.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ def __init__(self, param_decls, **kwargs):
244244
super(GradientDatasetOption, self).__init__("dataset", param_decls, **kwargs)
245245

246246

247-
def validate_comma_split_option(comma_option_value, option_value):
247+
def validate_comma_split_option(comma_option_value, option_value, raise_if_no_tags=False):
248+
if raise_if_no_tags and not any((comma_option_value, option_value)):
249+
raise click.UsageError("No tags provided")
250+
248251
if comma_option_value or option_value:
249252
if option_value:
250253
option_value = list(option_value)
@@ -253,4 +256,6 @@ def validate_comma_split_option(comma_option_value, option_value):
253256
if comma_option_value:
254257
comma_option_value = [s.strip() for s in comma_option_value.split(",")]
255258
option_value.extend(comma_option_value)
256-
return sorted(list(set(option_value)))
259+
260+
tags = sorted(set(option_value))
261+
return tags

gradient/cli/deployments.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,13 @@ def get_deployment(deployment_id, api_key, options_file):
448448

449449

450450
@deployments_tags.command("add", help="Add tags to deployment")
451-
@click.argument("id", cls=common.GradientArgument)
451+
@click.option(
452+
"--id",
453+
"id",
454+
required=True,
455+
cls=common.GradientOption,
456+
help="ID of the deployment",
457+
)
452458
@click.option(
453459
"--tag",
454460
"tags",
@@ -465,7 +471,7 @@ def get_deployment(deployment_id, api_key, options_file):
465471
@api_key_option
466472
@common.options_file
467473
def deployment_add_tag(id, options_file, api_key, **kwargs):
468-
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"))
474+
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"), raise_if_no_tags=True)
469475

470476
deployment_client = get_deployment_client(api_key)
471477

@@ -474,7 +480,13 @@ def deployment_add_tag(id, options_file, api_key, **kwargs):
474480

475481

476482
@deployments_tags.command("remove", help="Remove tags from deployment")
477-
@click.argument("id", cls=common.GradientArgument)
483+
@click.option(
484+
"--id",
485+
"id",
486+
required=True,
487+
cls=common.GradientOption,
488+
help="ID of the deployment",
489+
)
478490
@click.option(
479491
"--tag",
480492
"tags",
@@ -491,7 +503,7 @@ def deployment_add_tag(id, options_file, api_key, **kwargs):
491503
@api_key_option
492504
@common.options_file
493505
def deployment_remove_tags(id, options_file, api_key, **kwargs):
494-
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"))
506+
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"), raise_if_no_tags=True)
495507

496508
deployment_client = get_deployment_client(api_key)
497509

gradient/cli/experiments.py

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,13 @@ def create_and_start_single_node(ctx, api_key, show_logs, tensorboard, tensorboa
600600

601601

602602
@experiments_group.command("start", help="Start experiment")
603-
@click.argument("id", cls=common.GradientArgument)
603+
@click.option(
604+
"--id",
605+
"id",
606+
required=True,
607+
cls=common.GradientOption,
608+
help="ID of the experiment",
609+
)
604610
@click.option(
605611
"--logs",
606612
"show_logs",
@@ -619,7 +625,13 @@ def start_experiment(ctx, id, show_logs, api_key, options_file):
619625

620626

621627
@experiments_group.command("stop", help="Stop experiment")
622-
@click.argument("id", cls=common.GradientArgument)
628+
@click.option(
629+
"--id",
630+
"id",
631+
required=True,
632+
cls=common.GradientOption,
633+
help="ID of the experiment",
634+
)
623635
@api_key_option
624636
@common.options_file
625637
def stop_experiment(id, api_key, options_file):
@@ -672,7 +684,13 @@ def list_experiments(project_ids, api_key, exp_limit, exp_offset, tags, options_
672684

673685

674686
@experiments_group.command("details", help="Show detail of an experiment")
675-
@click.argument("id", cls=common.GradientArgument)
687+
@click.option(
688+
"--id",
689+
"id",
690+
required=True,
691+
cls=common.GradientOption,
692+
help="ID of the experiment",
693+
)
676694
@api_key_option
677695
@common.options_file
678696
def get_experiment_details(id, options_file, api_key):
@@ -682,7 +700,7 @@ def get_experiment_details(id, options_file, api_key):
682700

683701
@experiments_group.command("logs", help="List experiment logs")
684702
@click.option(
685-
"--experimentId",
703+
"--id",
686704
"experiment_id",
687705
required=True,
688706
cls=common.GradientOption,
@@ -716,7 +734,13 @@ def list_logs(experiment_id, line, limit, follow, options_file, api_key=None):
716734

717735

718736
@experiments_group.command("delete", help="Delete an experiment")
719-
@click.argument("id", cls=common.GradientArgument)
737+
@click.option(
738+
"--id",
739+
"id",
740+
required=True,
741+
cls=common.GradientOption,
742+
help="ID of the experiment",
743+
)
720744
@api_key_option
721745
@common.options_file
722746
def delete_experiment(id, options_file, api_key):
@@ -725,7 +749,13 @@ def delete_experiment(id, options_file, api_key):
725749

726750

727751
@experiments_tags.command("add", help="Add tags to experiment")
728-
@click.argument("id", cls=common.GradientArgument)
752+
@click.option(
753+
"--id",
754+
"id",
755+
required=True,
756+
cls=common.GradientOption,
757+
help="ID of the experiment",
758+
)
729759
@click.option(
730760
"--tag",
731761
"tags",
@@ -742,14 +772,20 @@ def delete_experiment(id, options_file, api_key):
742772
@api_key_option
743773
@common.options_file
744774
def experiment_add_tags(id, options_file, api_key, **kwargs):
745-
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"))
775+
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"), raise_if_no_tags=True)
746776

747777
command = ExperimentAddTagsCommand(api_key=api_key)
748778
command.execute(id, **kwargs)
749779

750780

751781
@experiments_tags.command("remove", help="Remove tags from experiment")
752-
@click.argument("id", cls=common.GradientArgument)
782+
@click.option(
783+
"--id",
784+
"id",
785+
required=True,
786+
cls=common.GradientOption,
787+
help="ID of the experiment",
788+
)
753789
@click.option(
754790
"--tag",
755791
"tags",
@@ -766,7 +802,7 @@ def experiment_add_tags(id, options_file, api_key, **kwargs):
766802
@api_key_option
767803
@common.options_file
768804
def experiment_remove_tags(id, options_file, api_key, **kwargs):
769-
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"))
805+
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"), raise_if_no_tags=True)
770806

771807
command = ExperimentRemoveTagsCommand(api_key=api_key)
772808
command.execute(id, **kwargs)

gradient/cli/hyperparameters.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,13 @@ def start_hyperparameter_tuning(api_key, options_file, id_):
195195

196196

197197
@hyperparameters_tags.command("add", help="Add tags to hyperparameter")
198-
@click.argument("id", cls=common.GradientArgument)
198+
@click.option(
199+
"--id",
200+
"id",
201+
required=True,
202+
cls=common.GradientOption,
203+
help="ID of the hyperparameter",
204+
)
199205
@click.option(
200206
"--tag",
201207
"tags",
@@ -212,14 +218,20 @@ def start_hyperparameter_tuning(api_key, options_file, id_):
212218
@common.api_key_option
213219
@common.options_file
214220
def hyperparameter_add_tag(id, options_file, api_key, **kwargs):
215-
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"))
221+
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"), raise_if_no_tags=True)
216222

217223
command = HyperparameterAddTagsCommand(api_key=api_key)
218224
command.execute(id, **kwargs)
219225

220226

221227
@hyperparameters_tags.command("remove", help="Remove tags from hyperparameter")
222-
@click.argument("id", cls=common.GradientArgument)
228+
@click.option(
229+
"--id",
230+
"id",
231+
required=True,
232+
cls=common.GradientOption,
233+
help="ID of the hyperparameter",
234+
)
223235
@click.option(
224236
"--tag",
225237
"tags",
@@ -236,7 +248,7 @@ def hyperparameter_add_tag(id, options_file, api_key, **kwargs):
236248
@common.api_key_option
237249
@common.options_file
238250
def hyperparameter_remove_tags(id, options_file, api_key, **kwargs):
239-
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"))
251+
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"), raise_if_no_tags=True)
240252

241253
command = HyperparameterRemoveTagsCommand(api_key=api_key)
242254
command.execute(id, **kwargs)

gradient/cli/jobs.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def jobs_tags():
3333

3434
@jobs_group.command("delete", help="Delete job")
3535
@click.option(
36-
"--jobId",
36+
"--id",
3737
"job_id",
3838
required=True,
3939
help="Delete job with given ID",
@@ -46,7 +46,7 @@ def delete_job(job_id, api_key):
4646

4747
@jobs_group.command("stop", help="Stop running job")
4848
@click.option(
49-
"--jobId",
49+
"--id",
5050
"job_id",
5151
required=True,
5252
help="Stop job with given ID",
@@ -296,7 +296,7 @@ def create_job(ctx, api_key, options_file, **kwargs):
296296

297297
@jobs_group.command("logs", help="List job logs")
298298
@click.option(
299-
"--jobId",
299+
"--id",
300300
"job_id",
301301
required=True,
302302
cls=common.GradientOption,
@@ -335,7 +335,12 @@ def artifacts():
335335

336336

337337
@artifacts.command("destroy", help="Destroy job's artifacts")
338-
@click.argument("job_id", cls=common.GradientArgument)
338+
@click.option(
339+
"--id",
340+
"job_id",
341+
cls=common.GradientOption,
342+
help="ID of the job",
343+
)
339344
@click.option(
340345
"--files",
341346
"files",
@@ -349,7 +354,12 @@ def destroy_artifacts(job_id, options_file, api_key=None, files=None):
349354

350355

351356
@artifacts.command("get", help="Get job's artifacts")
352-
@click.argument("job_id", cls=common.GradientArgument)
357+
@click.option(
358+
"--id",
359+
"job_id",
360+
cls=common.GradientOption,
361+
help="ID of the job",
362+
)
353363
@api_key_option
354364
@common.options_file
355365
def get_artifacts(job_id, options_file, api_key=None):
@@ -358,7 +368,12 @@ def get_artifacts(job_id, options_file, api_key=None):
358368

359369

360370
@artifacts.command("list", help="List job's artifacts")
361-
@click.argument("job_id", cls=common.GradientArgument)
371+
@click.option(
372+
"--id",
373+
"job_id",
374+
cls=common.GradientOption,
375+
help="ID of the job",
376+
)
362377
@click.option(
363378
"--size",
364379
"-s",
@@ -391,7 +406,7 @@ def list_artifacts(job_id, size, links, files, options_file, api_key=None):
391406

392407
@artifacts.command("download", help="List job's artifacts")
393408
@click.option(
394-
"--jobId",
409+
"--id",
395410
"job_id",
396411
cls=common.GradientOption,
397412
)
@@ -408,7 +423,13 @@ def download_artifacts(job_id, destination_directory, options_file, api_key=None
408423

409424

410425
@jobs_tags.command("add", help="Add tags to job")
411-
@click.argument("id", cls=common.GradientArgument)
426+
@click.option(
427+
"--id",
428+
"id",
429+
required=True,
430+
cls=common.GradientOption,
431+
help="ID of the job",
432+
)
412433
@click.option(
413434
"--tag",
414435
"tags",
@@ -425,14 +446,20 @@ def download_artifacts(job_id, destination_directory, options_file, api_key=None
425446
@api_key_option
426447
@common.options_file
427448
def job_add_tag(id, options_file, api_key, **kwargs):
428-
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"))
449+
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"), raise_if_no_tags=True)
429450

430451
command = JobAddTagsCommand(api_key=api_key)
431452
command.execute(id, **kwargs)
432453

433454

434455
@jobs_tags.command("remove", help="Remove tags from job")
435-
@click.argument("id", cls=common.GradientArgument)
456+
@click.option(
457+
"--id",
458+
"id",
459+
required=True,
460+
cls=common.GradientOption,
461+
help="ID of the job",
462+
)
436463
@click.option(
437464
"--tag",
438465
"tags",
@@ -449,7 +476,7 @@ def job_add_tag(id, options_file, api_key, **kwargs):
449476
@api_key_option
450477
@common.options_file
451478
def job_remove_tags(id, options_file, api_key, **kwargs):
452-
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"))
479+
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"), raise_if_no_tags=True)
453480

454481
command = JobRemoveTagsCommand(api_key=api_key)
455482
command.execute(id, **kwargs)

0 commit comments

Comments
 (0)