11import collections
22import functools
3- import json
4- import re
53
64import click
75
86from paperspace import constants , client , config
9- from paperspace .cli .jobs .commands import jobs_group
7+ from paperspace .cli .common import api_key_option , del_if_value_is_none
8+ from paperspace .cli .jobs import jobs_group
9+ from paperspace .cli .models import models_group
10+ from paperspace .cli .projects import projects_group
11+ from paperspace .cli .types import ChoiceType , json_string
12+ from paperspace .cli .validators import validate_mutually_exclusive , validate_email
1013from paperspace .commands import experiments as experiments_commands , deployments as deployments_commands , \
1114 machines as machines_commands , login as login_commands
1215
13-
14- class ChoiceType (click .Choice ):
15- """Takes a string-keyed map and converts cli-provided parameter to corresponding value"""
16-
17- def __init__ (self , type_map , case_sensitive = True ):
18- super (ChoiceType , self ).__init__ (tuple (type_map .keys ()), case_sensitive = case_sensitive )
19- self .type_map = type_map
20-
21- def convert (self , value , param , ctx ):
22- value = super (ChoiceType , self ).convert (value , param , ctx ).upper ()
23- return self .type_map [value ]
24-
25-
2616MULTI_NODE_EXPERIMENT_TYPES_MAP = collections .OrderedDict (
2717 (
2818 ("GRPC" , constants .ExperimentType .GRPC_MULTI_NODE ),
@@ -31,55 +21,6 @@ def convert(self, value, param, ctx):
3121)
3222
3323
34- class Number (click .ParamType ):
35- name = "number"
36-
37- def convert (self , value , param , ctx ):
38- try :
39- number = int (value )
40- except ValueError :
41- try :
42- number = float (value )
43- except ValueError :
44- self .fail ('{} is not a valid number' .format (value ), param , ctx )
45-
46- return number
47-
48-
49- def json_string (val ):
50- """Wraps json.loads so the cli help shows proper option's type name instead of 'LOADS'"""
51- return json .loads (val )
52-
53-
54- def del_if_value_is_none (dict_ ):
55- """Remove all elements with value == None"""
56- for key , val in list (dict_ .items ()):
57- if val is None :
58- del dict_ [key ]
59-
60-
61- api_key_option = click .option (
62- "--apiKey" ,
63- "api_key" ,
64- help = "API key to use this time only" ,
65- )
66-
67-
68- def validate_mutually_exclusive (options_1 , options_2 , error_message ):
69- used_option_in_options_1 = any (option is not None for option in options_1 )
70- used_option_in_options_2 = any (option is not None for option in options_2 )
71- if used_option_in_options_1 and used_option_in_options_2 :
72- raise click .UsageError (error_message )
73-
74-
75- def validate_email (ctx , param , value ):
76- if value is not None \
77- and not re .match (r"[^@]+@[^@]+\.[^@]+" , value ):
78- raise click .BadParameter ("Bad email address format" )
79-
80- return value
81-
82-
8324@click .group ()
8425def cli ():
8526 pass
@@ -471,12 +412,22 @@ def create_deployment(api_key=None, **kwargs):
471412 type = ChoiceType (DEPLOYMENT_STATES_MAP , case_sensitive = False ),
472413 help = "Filter by deployment state" ,
473414)
415+ @click .option (
416+ "--projectId" ,
417+ "projectId" ,
418+ help = "Use to filter by project ID" ,
419+ )
420+ @click .option (
421+ "--modelId" ,
422+ "modelId" ,
423+ help = "Use to filter by project ID" ,
424+ )
474425@api_key_option
475- def get_deployments_list (api_key = None , ** kwargs ):
476- del_if_value_is_none (kwargs )
426+ def get_deployments_list (api_key = None , ** filters ):
427+ del_if_value_is_none (filters )
477428 deployments_api = client .API (config .CONFIG_HOST , api_key = api_key )
478429 command = deployments_commands .ListDeploymentsCommand (api = deployments_api )
479- command .execute (kwargs )
430+ command .execute (filters )
480431
481432
482433@deployments .command ("update" , help = "Update deployment properties" )
@@ -516,7 +467,7 @@ def get_deployments_list(api_key=None, **kwargs):
516467def update_deployment_model (id_ , api_key , ** kwargs ):
517468 del_if_value_is_none (kwargs )
518469 deployments_api = client .API (config .CONFIG_HOST , api_key = api_key )
519- command = deployments_commands .UpdateModelCommand (api = deployments_api )
470+ command = deployments_commands .UpdateDeploymentCommand (api = deployments_api )
520471 command .execute (id_ , kwargs )
521472
522473
@@ -1124,3 +1075,5 @@ def version():
11241075
11251076
11261077cli .add_command (jobs_group )
1078+ cli .add_command (projects_group )
1079+ cli .add_command (models_group )
0 commit comments