clarifai 11.2.2__py3-none-any.whl → 11.2.3rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. clarifai/__init__.py +1 -1
  2. clarifai/__pycache__/__init__.cpython-312.pyc +0 -0
  3. clarifai/__pycache__/errors.cpython-312.pyc +0 -0
  4. clarifai/__pycache__/versions.cpython-312.pyc +0 -0
  5. clarifai/cli/__pycache__/__init__.cpython-312.pyc +0 -0
  6. clarifai/cli/__pycache__/base.cpython-312.pyc +0 -0
  7. clarifai/cli/__pycache__/compute_cluster.cpython-312.pyc +0 -0
  8. clarifai/cli/__pycache__/deployment.cpython-312.pyc +0 -0
  9. clarifai/cli/__pycache__/model.cpython-312.pyc +0 -0
  10. clarifai/cli/__pycache__/nodepool.cpython-312.pyc +0 -0
  11. clarifai/cli/base.py +225 -89
  12. clarifai/cli/compute_cluster.py +21 -20
  13. clarifai/cli/deployment.py +63 -41
  14. clarifai/cli/model.py +1 -1
  15. clarifai/cli/nodepool.py +56 -40
  16. clarifai/client/__pycache__/__init__.cpython-312.pyc +0 -0
  17. clarifai/client/__pycache__/app.cpython-312.pyc +0 -0
  18. clarifai/client/__pycache__/base.cpython-312.pyc +0 -0
  19. clarifai/client/__pycache__/compute_cluster.cpython-312.pyc +0 -0
  20. clarifai/client/__pycache__/dataset.cpython-312.pyc +0 -0
  21. clarifai/client/__pycache__/deployment.cpython-312.pyc +0 -0
  22. clarifai/client/__pycache__/input.cpython-312.pyc +0 -0
  23. clarifai/client/__pycache__/lister.cpython-312.pyc +0 -0
  24. clarifai/client/__pycache__/model.cpython-312.pyc +0 -0
  25. clarifai/client/__pycache__/model_client.cpython-312.pyc +0 -0
  26. clarifai/client/__pycache__/module.cpython-312.pyc +0 -0
  27. clarifai/client/__pycache__/nodepool.cpython-312.pyc +0 -0
  28. clarifai/client/__pycache__/search.cpython-312.pyc +0 -0
  29. clarifai/client/__pycache__/user.cpython-312.pyc +0 -0
  30. clarifai/client/__pycache__/workflow.cpython-312.pyc +0 -0
  31. clarifai/client/auth/__pycache__/__init__.cpython-312.pyc +0 -0
  32. clarifai/client/auth/__pycache__/helper.cpython-312.pyc +0 -0
  33. clarifai/client/auth/__pycache__/register.cpython-312.pyc +0 -0
  34. clarifai/client/auth/__pycache__/stub.cpython-312.pyc +0 -0
  35. clarifai/constants/__pycache__/base.cpython-312.pyc +0 -0
  36. clarifai/constants/__pycache__/dataset.cpython-312.pyc +0 -0
  37. clarifai/constants/__pycache__/input.cpython-312.pyc +0 -0
  38. clarifai/constants/__pycache__/model.cpython-312.pyc +0 -0
  39. clarifai/constants/__pycache__/search.cpython-312.pyc +0 -0
  40. clarifai/constants/__pycache__/workflow.cpython-312.pyc +0 -0
  41. clarifai/datasets/__pycache__/__init__.cpython-312.pyc +0 -0
  42. clarifai/datasets/export/__pycache__/__init__.cpython-312.pyc +0 -0
  43. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-312.pyc +0 -0
  44. clarifai/datasets/upload/__pycache__/__init__.cpython-312.pyc +0 -0
  45. clarifai/datasets/upload/__pycache__/base.cpython-312.pyc +0 -0
  46. clarifai/datasets/upload/__pycache__/features.cpython-312.pyc +0 -0
  47. clarifai/datasets/upload/__pycache__/image.cpython-312.pyc +0 -0
  48. clarifai/datasets/upload/__pycache__/multimodal.cpython-312.pyc +0 -0
  49. clarifai/datasets/upload/__pycache__/text.cpython-312.pyc +0 -0
  50. clarifai/datasets/upload/__pycache__/utils.cpython-312.pyc +0 -0
  51. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-312.pyc +0 -0
  52. clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-312.pyc +0 -0
  53. clarifai/modules/__pycache__/__init__.cpython-312.pyc +0 -0
  54. clarifai/modules/__pycache__/css.cpython-312.pyc +0 -0
  55. clarifai/runners/__pycache__/__init__.cpython-312.pyc +0 -0
  56. clarifai/runners/__pycache__/server.cpython-312.pyc +0 -0
  57. clarifai/runners/models/__pycache__/__init__.cpython-312.pyc +0 -0
  58. clarifai/runners/models/__pycache__/base_typed_model.cpython-312.pyc +0 -0
  59. clarifai/runners/models/__pycache__/model_builder.cpython-312.pyc +0 -0
  60. clarifai/runners/models/__pycache__/model_class.cpython-312.pyc +0 -0
  61. clarifai/runners/models/__pycache__/model_run_locally.cpython-312.pyc +0 -0
  62. clarifai/runners/models/__pycache__/model_runner.cpython-312.pyc +0 -0
  63. clarifai/runners/models/__pycache__/model_servicer.cpython-312.pyc +0 -0
  64. clarifai/runners/models/model_builder.py +17 -7
  65. clarifai/runners/models/model_run_locally.py +1 -0
  66. clarifai/runners/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  67. clarifai/runners/utils/__pycache__/const.cpython-312.pyc +0 -0
  68. clarifai/runners/utils/__pycache__/data_handler.cpython-312.pyc +0 -0
  69. clarifai/runners/utils/__pycache__/data_types.cpython-312.pyc +0 -0
  70. clarifai/runners/utils/__pycache__/data_utils.cpython-312.pyc +0 -0
  71. clarifai/runners/utils/__pycache__/loader.cpython-312.pyc +0 -0
  72. clarifai/runners/utils/__pycache__/method_signatures.cpython-312.pyc +0 -0
  73. clarifai/runners/utils/__pycache__/serializers.cpython-312.pyc +0 -0
  74. clarifai/runners/utils/__pycache__/url_fetcher.cpython-312.pyc +0 -0
  75. clarifai/runners/utils/const.py +9 -8
  76. clarifai/schema/__pycache__/search.cpython-312.pyc +0 -0
  77. clarifai/urls/__pycache__/helper.cpython-312.pyc +0 -0
  78. clarifai/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  79. clarifai/utils/__pycache__/cli.cpython-312.pyc +0 -0
  80. clarifai/utils/__pycache__/config.cpython-312.pyc +0 -0
  81. clarifai/utils/__pycache__/constants.cpython-312.pyc +0 -0
  82. clarifai/utils/__pycache__/logging.cpython-312.pyc +0 -0
  83. clarifai/utils/__pycache__/misc.cpython-312.pyc +0 -0
  84. clarifai/utils/__pycache__/model_train.cpython-312.pyc +0 -0
  85. clarifai/utils/cli.py +124 -34
  86. clarifai/utils/config.py +105 -0
  87. clarifai/utils/config.py~ +145 -0
  88. clarifai/utils/constants.py +4 -0
  89. clarifai/utils/evaluation/__pycache__/__init__.cpython-312.pyc +0 -0
  90. clarifai/utils/evaluation/__pycache__/helpers.cpython-312.pyc +0 -0
  91. clarifai/utils/evaluation/__pycache__/main.cpython-312.pyc +0 -0
  92. clarifai/utils/misc.py +2 -0
  93. clarifai/workflows/__pycache__/__init__.cpython-312.pyc +0 -0
  94. clarifai/workflows/__pycache__/export.cpython-312.pyc +0 -0
  95. clarifai/workflows/__pycache__/utils.cpython-312.pyc +0 -0
  96. clarifai/workflows/__pycache__/validate.cpython-312.pyc +0 -0
  97. {clarifai-11.2.2.dist-info → clarifai-11.2.3rc1.dist-info}/METADATA +3 -15
  98. clarifai-11.2.3rc1.dist-info/RECORD +185 -0
  99. {clarifai-11.2.2.dist-info → clarifai-11.2.3rc1.dist-info}/WHEEL +1 -1
  100. clarifai-11.2.2.dist-info/RECORD +0 -101
  101. {clarifai-11.2.2.dist-info/licenses → clarifai-11.2.3rc1.dist-info}/LICENSE +0 -0
  102. {clarifai-11.2.2.dist-info → clarifai-11.2.3rc1.dist-info}/entry_points.txt +0 -0
  103. {clarifai-11.2.2.dist-info → clarifai-11.2.3rc1.dist-info}/top_level.txt +0 -0
clarifai/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "11.2.2"
1
+ __version__ = "11.2.3rc1"
clarifai/cli/base.py CHANGED
@@ -1,119 +1,255 @@
1
+ import json
1
2
  import os
3
+ import sys
2
4
 
3
5
  import click
6
+ import yaml
4
7
 
5
- from clarifai.utils.cli import dump_yaml, from_yaml, load_command_modules, set_base_url
8
+ from clarifai.utils.cli import AliasedGroup, TableFormatter, load_command_modules
9
+ from clarifai.utils.config import Config, Context
10
+ from clarifai.utils.constants import DEFAULT_CONFIG
6
11
  from clarifai.utils.logging import logger
7
12
 
8
13
 
9
- class CustomMultiGroup(click.Group):
14
+ #@click.group(cls=CustomMultiGroup)
15
+ @click.group(cls=AliasedGroup)
16
+ @click.option('--config', default=DEFAULT_CONFIG)
17
+ @click.pass_context
18
+ def cli(ctx, config):
19
+ """Clarifai CLI"""
20
+ ctx.ensure_object(dict)
21
+ if os.path.exists(config):
22
+ cfg = Config.from_yaml(filename=config)
23
+ ctx.obj = cfg
24
+ else:
25
+ cfg = Config(
26
+ filename=config,
27
+ current_context='default',
28
+ contexts={
29
+ 'default':
30
+ Context(
31
+ 'default',
32
+ CLARIFAI_PAT=os.environ.get('CLARIFAI_PAT', ''),
33
+ CLARIFAI_USER_ID=os.environ.get('CLARIFAI_USER_ID', ''),
34
+ CLARIFAI_API_BASE=os.environ.get('CLARIFAI_API_BASE', 'api.clarifai.com'),
35
+ )
36
+ })
37
+ try:
38
+ cfg.to_yaml(config)
39
+ except Exception:
40
+ logger.warning("Could not write configuration to disk. Could be a read only file system.")
41
+ ctx.obj = cfg # still have the default config even if couldn't write.
10
42
 
11
- def group(self, *args, **kwargs):
12
- """Behaves the same as `click.Group.group()` except if passed
13
- a list of names, all after the first will be aliases for the first.
14
- """
15
43
 
16
- def decorator(f):
17
- aliased_group = []
18
- if isinstance(args[0], list):
19
- # we have a list so create group aliases
20
- _args = [args[0][0]] + list(args[1:])
21
- for alias in args[0][1:]:
22
- grp = super(CustomMultiGroup, self).group(alias, *args[1:], **kwargs)(f)
23
- grp.short_help = "Alias for '{}'".format(_args[0])
24
- aliased_group.append(grp)
25
- else:
26
- _args = args
44
+ @cli.command()
45
+ @click.argument('shell', type=click.Choice(['bash', 'zsh']))
46
+ def shell_completion(shell):
47
+ """Shell completion script"""
48
+ os.system(f"_CLARIFAI_COMPLETE={shell}_source clarifai")
27
49
 
28
- # create the main group
29
- grp = super(CustomMultiGroup, self).group(*_args, **kwargs)(f)
30
50
 
31
- # for all of the aliased groups, share the main group commands
32
- for aliased in aliased_group:
33
- aliased.commands = grp.commands
51
+ @cli.group(['cfg'], cls=AliasedGroup)
52
+ def config():
53
+ """Manage CLI configuration"""
34
54
 
35
- return grp
36
55
 
37
- return decorator
56
+ @config.command(['e'])
57
+ @click.pass_context
58
+ def edit(ctx):
59
+ """Edit the configuration file"""
60
+ os.system(f'{os.environ.get("EDITOR", "vi")} {ctx.obj.filename}')
38
61
 
39
62
 
40
- @click.group(cls=CustomMultiGroup)
63
+ @config.command(['current'])
64
+ @click.option('-o', '--output-format', default='name', type=click.Choice(['name', 'json', 'yaml']))
41
65
  @click.pass_context
42
- def cli(ctx):
43
- """Clarifai CLI"""
44
- ctx.ensure_object(dict)
45
- config_path = f"{os.getenv('HOME')}/.clarifai/config.yaml"
46
- if os.path.exists(config_path):
47
- ctx.obj = from_yaml(config_path)
66
+ def current_context(ctx, output_format):
67
+ """Get the current context"""
68
+ if output_format == 'name':
69
+ print(ctx.obj.current_context)
48
70
  else:
49
- ctx.obj = {}
71
+ if output_format == 'json':
72
+ print(json.dumps(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
73
+ else:
74
+ print(yaml.safe_dump(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
50
75
 
51
76
 
52
- @cli.command()
53
- @click.option('--config', type=click.Path(), required=False, help='Path to the config file')
77
+ @config.command(['list', 'ls'])
54
78
  @click.option(
55
- '-e',
56
- '--env',
57
- required=False,
58
- help='Environment to use, choose from prod, staging and dev',
59
- type=click.Choice(['prod', 'staging', 'dev']))
79
+ '-o', '--output-format', default='wide', type=click.Choice(['wide', 'name', 'json', 'yaml']))
80
+ @click.pass_context
81
+ def get_contexts(ctx, output_format):
82
+ """Get all contexts"""
83
+ if output_format == 'wide':
84
+ formatter = TableFormatter(custom_columns={
85
+ '': lambda c: '*' if c.name == ctx.obj.current_context else '',
86
+ 'NAME': lambda c: c.name,
87
+ 'USER_ID': lambda c: c.user_id,
88
+ 'API_BASE': lambda c: c.api_base,
89
+ 'PAT': lambda c: pat_display(c.pat),
90
+ })
91
+ print(formatter.format(ctx.obj.contexts.values(), fmt="plain"))
92
+ elif output_format == 'name':
93
+ print('\n'.join(ctx.obj.contexts))
94
+ elif output_format in ('json', 'yaml'):
95
+ dicts = [v.__dict__ for c, v in ctx.obj.contexts.items()]
96
+ for d in dicts:
97
+ d.pop('pat')
98
+ if output_format == 'json':
99
+ print(json.dumps(dicts))
100
+ elif output_format == 'yaml':
101
+ print(yaml.safe_dump(dicts))
102
+
103
+
104
+ @config.command(['use'])
105
+ @click.argument('context-name', type=str)
106
+ @click.pass_context
107
+ def use_context(ctx, context_name):
108
+ """Set the current context"""
109
+ if context_name not in ctx.obj.contexts:
110
+ raise click.UsageError('Context not found')
111
+ ctx.obj.current_context = context_name
112
+ ctx.obj.to_yaml()
113
+ print(f'Set {context_name} as the current context')
114
+
115
+
116
+ @config.command(['cat'])
117
+ @click.option('-o', '--output-format', default='yaml', type=click.Choice(['yaml', 'json']))
118
+ @click.pass_obj
119
+ def dump(ctx_obj, output_format):
120
+ """Dump the configuration to stdout"""
121
+ if output_format == 'yaml':
122
+ yaml.safe_dump(ctx_obj.to_dict(), sys.stdout)
123
+ else:
124
+ json.dump(ctx_obj.to_dict(), sys.stdout, indent=2)
125
+
126
+
127
+ @cli.command()
128
+ @click.argument('api_url', default="https://api.clarifai.com")
60
129
  @click.option('--user_id', required=False, help='User ID')
61
130
  @click.pass_context
62
- def login(ctx, config, env, user_id):
131
+ def login(ctx, api_url, user_id):
63
132
  """Login command to set PAT and other configurations."""
64
133
 
65
- if config and os.path.exists(config):
66
- ctx.obj = from_yaml(config)
134
+ name = input('context name (default: "default"): ')
135
+ user_id = user_id if user_id is not None else input('user id: ')
136
+ pat = input_or_default(
137
+ 'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
138
+ 'ENVVAR')
67
139
 
68
- if 'pat' in ctx.obj:
69
- os.environ["CLARIFAI_PAT"] = ctx.obj['pat']
70
- logger.info("Loaded PAT from config file.")
71
- elif 'CLARIFAI_PAT' in os.environ:
72
- ctx.obj['pat'] = os.environ["CLARIFAI_PAT"]
73
- logger.info("Loaded PAT from environment variable.")
74
- else:
75
- _pat = click.prompt(
76
- "Get your PAT from https://clarifai.com/settings/security and pass it here", type=str)
77
- os.environ["CLARIFAI_PAT"] = _pat
78
- ctx.obj['pat'] = _pat
79
- logger.info("PAT saved successfully.")
80
-
81
- if user_id:
82
- ctx.obj['user_id'] = user_id
83
- os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
84
- elif 'user_id' in ctx.obj:
85
- ctx.obj['user_id'] = ctx.obj.get('user_id', "")
86
- os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
87
- elif 'CLARIFAI_USER_ID' in os.environ:
88
- ctx.obj['user_id'] = os.environ["CLARIFAI_USER_ID"]
89
- else:
90
- user_id = click.prompt("Pass the User ID here", type=str)
91
- os.environ["CLARIFAI_USER_ID"] = user_id
92
- ctx.obj['user_id'] = user_id
93
- logger.info("User ID saved successfully.")
94
-
95
- if env:
96
- ctx.obj['env'] = env
97
- ctx.obj['base_url'] = set_base_url(env)
98
- os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
99
- elif 'env' in ctx.obj:
100
- ctx.obj['env'] = ctx.obj.get('env', "prod")
101
- ctx.obj['base_url'] = set_base_url(ctx.obj['env'])
102
- os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
103
- elif 'CLARIFAI_API_BASE' in os.environ:
104
- ctx.obj['base_url'] = os.environ["CLARIFAI_API_BASE"]
105
- else:
106
- ctx.obj['env'] = 'prod'
107
- ctx.obj['base_url'] = set_base_url(ctx.obj['env'])
108
- os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
109
- logger.info("Base URL saved successfully.")
140
+ context = Context(
141
+ name,
142
+ CLARIFAI_API_BASE=api_url,
143
+ CLARIFAI_USER_ID=user_id,
144
+ CLARIFAI_PAT=pat,
145
+ )
146
+
147
+ if context.name == '':
148
+ context.name = 'default'
110
149
 
111
- config_path = f"{os.getenv('HOME')}/.clarifai/config.yaml"
112
- config_dir = os.path.dirname(config_path)
113
- if not os.path.exists(config_dir):
114
- os.makedirs(config_dir)
150
+ ctx.obj.contexts[context.name] = context
151
+ ctx.obj.current_context = context.name
115
152
 
116
- dump_yaml(ctx.obj, config_path)
153
+ ctx.obj.to_yaml()
154
+
155
+
156
+ @cli.group(cls=AliasedGroup)
157
+ def context():
158
+ """Manage contexts"""
159
+
160
+
161
+ def pat_display(pat):
162
+ return pat[:5] + "****"
163
+
164
+
165
+ @context.command(['ls'])
166
+ @click.pass_context
167
+ def list(ctx):
168
+ """List available contexts"""
169
+ formatter = TableFormatter(custom_columns={
170
+ '': lambda c: '*' if c.name == ctx.obj.current_context else '',
171
+ 'NAME': lambda c: c.name,
172
+ 'USER_ID': lambda c: c.user_id,
173
+ 'API_BASE': lambda c: c.api_base,
174
+ 'PAT': lambda c: pat_display(c.pat)
175
+ })
176
+ print(formatter.format(ctx.obj.contexts.values(), fmt="plain"))
177
+
178
+
179
+ def input_or_default(prompt, default):
180
+ value = input(prompt)
181
+ return value if value else default
182
+
183
+
184
+ @context.command()
185
+ @click.argument('name')
186
+ @click.option('--user-id', required=False, help='User ID')
187
+ @click.option('--base-url', required=False, help='Base URL')
188
+ @click.option('--pat', required=False, help='Personal access token')
189
+ @click.pass_context
190
+ def create(
191
+ ctx,
192
+ name,
193
+ user_id=None,
194
+ base_url=None,
195
+ pat=None,
196
+ ):
197
+ """Create a new context"""
198
+ if name in ctx.obj.contexts:
199
+ print(f'{name} already exists')
200
+ exit(1)
201
+ if not user_id:
202
+ user_id = input('user id: ')
203
+ if not base_url:
204
+ base_url = input_or_default('base url (default: https://api.clarifai.com): ',
205
+ 'https://api.clarifai.com')
206
+ if not pat:
207
+ pat = input_or_default(
208
+ 'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
209
+ 'ENVVAR')
210
+
211
+ context = Context(name, CLARIFAI_USER_ID=user_id, CLARIFAI_API_BASE=base_url, CLARIFAI_PAT=pat)
212
+ ctx.obj.contexts[context.name] = context
213
+ ctx.obj.to_yaml()
214
+
215
+
216
+ # write a click command to delete a context
217
+ @context.command(['rm'])
218
+ @click.argument('name')
219
+ @click.pass_context
220
+ def delete(ctx, name):
221
+ """Delete a context"""
222
+ if name not in ctx.obj.contexts:
223
+ print(f'{name} is not a valid context')
224
+ exit(1)
225
+ ctx.obj.contexts.pop(name)
226
+ ctx.obj.to_yaml()
227
+ print(f'{name} deleted')
228
+
229
+
230
+ @context.command()
231
+ @click.argument('name', type=str)
232
+ @click.pass_context
233
+ def use(ctx, name):
234
+ """Set the current context"""
235
+ if name not in ctx.obj.contexts:
236
+ raise click.UsageError('Context not found')
237
+ ctx.obj.current_context = name
238
+ ctx.obj.to_yaml()
239
+ print(f'Set {name} as the current context')
240
+
241
+
242
+ @cli.command()
243
+ @click.argument('script', type=str)
244
+ @click.option('--context', type=str, help='Context to use')
245
+ @click.pass_context
246
+ def run(ctx, script, context=None):
247
+ """Execute a script with the current context's environment"""
248
+ context = ctx.obj.current if not context else context
249
+ cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={context.base_url} CLARIFAI_PAT={context.pat} '
250
+ cmd += ' '.join([f'{k}={v}' for k, v in context.env.items()])
251
+ cmd += f' {script}'
252
+ os.system(cmd)
117
253
 
118
254
 
119
255
  # Import the CLI commands to register them
@@ -2,57 +2,58 @@ import click
2
2
 
3
3
  from clarifai.cli.base import cli
4
4
  from clarifai.client.user import User
5
- from clarifai.utils.cli import display_co_resources, validate_context
5
+ from clarifai.utils.cli import AliasedGroup, display_co_resources, validate_context
6
6
 
7
7
 
8
- @cli.group(['computecluster', 'cc'])
8
+ @cli.group(['computecluster', 'cc'], cls=AliasedGroup)
9
9
  def computecluster():
10
10
  """Manage Compute Clusters: create, delete, list"""
11
- pass
12
11
 
13
12
 
14
- @computecluster.command()
13
+ @computecluster.command(['c'])
14
+ @click.argument('compute_cluster_id')
15
15
  @click.option(
16
16
  '--config',
17
17
  type=click.Path(exists=True),
18
18
  required=True,
19
19
  help='Path to the compute cluster config file.')
20
- @click.option(
21
- '-cc_id',
22
- '--compute_cluster_id',
23
- required=False,
24
- help='New Compute Cluster ID for the compute cluster to create.')
25
20
  @click.pass_context
26
- def create(ctx, config, compute_cluster_id):
21
+ def create(ctx, compute_cluster_id, config):
27
22
  """Create a new Compute Cluster with the given config file."""
28
-
29
23
  validate_context(ctx)
30
- user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
24
+ user = User(
25
+ user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
31
26
  if compute_cluster_id:
32
27
  user.create_compute_cluster(config, compute_cluster_id=compute_cluster_id)
33
28
  else:
34
29
  user.create_compute_cluster(config)
35
30
 
36
31
 
37
- @computecluster.command()
32
+ @computecluster.command(['ls'])
38
33
  @click.option('--page_no', required=False, help='Page number to list.', default=1)
39
34
  @click.option('--per_page', required=False, help='Number of items per page.', default=16)
40
35
  @click.pass_context
41
36
  def list(ctx, page_no, per_page):
42
37
  """List all compute clusters for the user."""
43
-
44
38
  validate_context(ctx)
45
- user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
39
+ user = User(
40
+ user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
46
41
  response = user.list_compute_clusters(page_no, per_page)
47
- display_co_resources(response, "Compute Cluster")
42
+ display_co_resources(
43
+ response,
44
+ custom_columns={
45
+ 'ID': lambda c: c.id,
46
+ 'USER_ID': lambda c: c.user_id,
47
+ 'DESCRIPTION': lambda c: c.description,
48
+ })
48
49
 
49
50
 
50
- @computecluster.command()
51
- @click.option('-cc_id', '--compute_cluster_id', help='Compute Cluster ID of the user to delete.')
51
+ @computecluster.command(['rm'])
52
+ @click.argument('compute_cluster_id')
52
53
  @click.pass_context
53
54
  def delete(ctx, compute_cluster_id):
54
55
  """Deletes a compute cluster for the user."""
55
-
56
56
  validate_context(ctx)
57
- user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
57
+ user = User(
58
+ user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
58
59
  user.delete_compute_clusters([compute_cluster_id])
@@ -1,33 +1,27 @@
1
1
  import click
2
+
2
3
  from clarifai.cli.base import cli
4
+ from clarifai.client.compute_cluster import ComputeCluster
3
5
  from clarifai.client.nodepool import Nodepool
4
- from clarifai.utils.cli import display_co_resources, from_yaml, validate_context
6
+ from clarifai.client.user import User
7
+ from clarifai.utils.cli import AliasedGroup, display_co_resources, from_yaml, validate_context
5
8
 
6
9
 
7
- @cli.group(['deployment', 'dpl'])
10
+ @cli.group(['deployment', 'dp'], cls=AliasedGroup)
8
11
  def deployment():
9
12
  """Manage Deployments: create, delete, list"""
10
- pass
11
13
 
12
14
 
13
- @deployment.command()
14
- @click.option(
15
- '-np_id',
16
- '--nodepool_id',
17
- required=False,
18
- help='Nodepool ID for the Nodepool to interact with.')
15
+ @deployment.command(['c'])
16
+ @click.argument('nodepool_id')
17
+ @click.argument('deployment_id')
19
18
  @click.option(
20
19
  '--config',
21
20
  type=click.Path(exists=True),
22
21
  required=True,
23
22
  help='Path to the deployment config file.')
24
- @click.option(
25
- '-dpl_id',
26
- '--deployment_id',
27
- required=False,
28
- help='New deployment ID for the deployment to create.')
29
23
  @click.pass_context
30
- def create(ctx, nodepool_id, config, deployment_id):
24
+ def create(ctx, nodepool_id, deployment_id, config):
31
25
  """Create a new Deployment with the given config file."""
32
26
 
33
27
  validate_context(ctx)
@@ -37,21 +31,17 @@ def create(ctx, nodepool_id, config, deployment_id):
37
31
 
38
32
  nodepool = Nodepool(
39
33
  nodepool_id=nodepool_id,
40
- user_id=ctx.obj['user_id'],
41
- pat=ctx.obj['pat'],
42
- base_url=ctx.obj['base_url'])
34
+ user_id=ctx.obj.current.user_id,
35
+ pat=ctx.obj.current.pat,
36
+ base_url=ctx.obj.current.api_base)
43
37
  if deployment_id:
44
38
  nodepool.create_deployment(config, deployment_id=deployment_id)
45
39
  else:
46
40
  nodepool.create_deployment(config)
47
41
 
48
42
 
49
- @deployment.command()
50
- @click.option(
51
- '-np_id',
52
- '--nodepool_id',
53
- required=True,
54
- help='Nodepool ID for the Nodepool to interact with.')
43
+ @deployment.command(['ls'])
44
+ @click.argument('nodepool_id', default="")
55
45
  @click.option('--page_no', required=False, help='Page number to list.', default=1)
56
46
  @click.option('--per_page', required=False, help='Number of items per page.', default=16)
57
47
  @click.pass_context
@@ -59,22 +49,54 @@ def list(ctx, nodepool_id, page_no, per_page):
59
49
  """List all deployments for the nodepool."""
60
50
 
61
51
  validate_context(ctx)
62
- nodepool = Nodepool(
63
- nodepool_id=nodepool_id,
64
- user_id=ctx.obj['user_id'],
65
- pat=ctx.obj['pat'],
66
- base_url=ctx.obj['base_url'])
67
- response = nodepool.list_deployments(page_no=page_no, per_page=per_page)
68
- display_co_resources(response, "Deployment")
52
+ if nodepool_id:
53
+ nodepool = Nodepool(
54
+ nodepool_id=nodepool_id,
55
+ user_id=ctx.obj.current.user_id,
56
+ pat=ctx.obj.current.pat,
57
+ base_url=ctx.obj.current.api_base)
58
+ response = nodepool.list_deployments(page_no=page_no, per_page=per_page)
59
+ else:
60
+ user = User(
61
+ user_id=ctx.obj.current.user_id,
62
+ pat=ctx.obj.current.pat,
63
+ base_url=ctx.obj.current.api_base)
64
+ ccs = user.list_compute_clusters(page_no, per_page)
65
+ nps = []
66
+ for cc in ccs:
67
+ compute_cluster = ComputeCluster(
68
+ compute_cluster_id=cc.id,
69
+ user_id=ctx.obj.current.user_id,
70
+ pat=ctx.obj.current.pat,
71
+ base_url=ctx.obj.current.api_base)
72
+ nps.extend([i for i in compute_cluster.list_nodepools(page_no, per_page)])
73
+ response = []
74
+ for np in nps:
75
+ nodepool = Nodepool(
76
+ nodepool_id=np.id,
77
+ user_id=ctx.obj.current.user_id,
78
+ pat=ctx.obj.current.pat,
79
+ base_url=ctx.obj.current.api_base)
80
+ response.extend([i for i in nodepool.list_deployments(page_no=page_no, per_page=per_page)])
69
81
 
82
+ display_co_resources(
83
+ response,
84
+ custom_columns={
85
+ 'ID': lambda c: c.id,
86
+ 'USER_ID': lambda c: c.user_id,
87
+ 'COMPUTE_CLUSTER_ID': lambda c: c.nodepools[0].compute_cluster.id,
88
+ 'NODEPOOL_ID': lambda c: c.nodepools[0].id,
89
+ 'MODEL_USER_ID': lambda c: c.worker.model.user_id,
90
+ 'MODEL_APP_ID': lambda c: c.worker.model.app_id,
91
+ 'MODEL_ID': lambda c: c.worker.model.id,
92
+ 'MODEL_VERSION_ID': lambda c: c.worker.model.model_version.id,
93
+ 'DESCRIPTION': lambda c: c.description,
94
+ })
70
95
 
71
- @deployment.command()
72
- @click.option(
73
- '-np_id',
74
- '--nodepool_id',
75
- required=True,
76
- help='Nodepool ID for the Nodepool to interact with.')
77
- @click.option('-dpl_id', '--deployment_id', help='Deployment ID of the nodepool to delete.')
96
+
97
+ @deployment.command(['rm'])
98
+ @click.argument('nodepool_id')
99
+ @click.argument('deployment_id')
78
100
  @click.pass_context
79
101
  def delete(ctx, nodepool_id, deployment_id):
80
102
  """Deletes a deployment for the nodepool."""
@@ -82,7 +104,7 @@ def delete(ctx, nodepool_id, deployment_id):
82
104
  validate_context(ctx)
83
105
  nodepool = Nodepool(
84
106
  nodepool_id=nodepool_id,
85
- user_id=ctx.obj['user_id'],
86
- pat=ctx.obj['pat'],
87
- base_url=ctx.obj['base_url'])
107
+ user_id=ctx.obj.current.user_id,
108
+ pat=ctx.obj.current.pat,
109
+ base_url=ctx.obj.current.api_base)
88
110
  nodepool.delete_deployments([deployment_id])
clarifai/cli/model.py CHANGED
@@ -5,7 +5,7 @@ from clarifai.cli.base import cli
5
5
 
6
6
  @cli.group(['model'])
7
7
  def model():
8
- """Manage models: upload, test locally, run locally, predict, and more"""
8
+ """Manage models: upload, test, local dev, predict, etc"""
9
9
 
10
10
 
11
11
  @model.command()