toolforge-components-cli 0.0.20__tar.gz → 0.0.22__tar.gz
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.
- {toolforge_components_cli-0.0.20 → toolforge_components_cli-0.0.22}/PKG-INFO +2 -1
- {toolforge_components_cli-0.0.20 → toolforge_components_cli-0.0.22}/pyproject.toml +7 -1
- {toolforge_components_cli-0.0.20 → toolforge_components_cli-0.0.22}/toolforge_components_cli/cli.py +76 -31
- {toolforge_components_cli-0.0.20 → toolforge_components_cli-0.0.22}/LICENSE +0 -0
- {toolforge_components_cli-0.0.20 → toolforge_components_cli-0.0.22}/README.md +0 -0
- {toolforge_components_cli-0.0.20 → toolforge_components_cli-0.0.22}/toolforge_components_cli/__init__.py +0 -0
- {toolforge_components_cli-0.0.20 → toolforge_components_cli-0.0.22}/toolforge_components_cli/components.py +0 -0
- {toolforge_components_cli-0.0.20 → toolforge_components_cli-0.0.22}/toolforge_components_cli/config.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: toolforge-components-cli
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.22
|
|
4
4
|
Summary: Toolforge components client
|
|
5
5
|
License: GPLv3
|
|
6
6
|
License-File: LICENSE
|
|
@@ -11,6 +11,7 @@ Classifier: License :: Other/Proprietary License
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.13
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
14
15
|
Requires-Dist: PyYAML (>=6.0,<7.0)
|
|
15
16
|
Requires-Dist: click (>=8.0.3,<9.0.0)
|
|
16
17
|
Requires-Dist: cryptography (>=36.0.1,<37.0.0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "toolforge-components-cli"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.22"
|
|
4
4
|
description = "Toolforge components client"
|
|
5
5
|
authors = ["Slavina Stefanova <sstefanova@wikimedia.org>"]
|
|
6
6
|
license = "GPLv3"
|
|
@@ -20,6 +20,12 @@ toolforge-weld = ">=1.4,<2.0"
|
|
|
20
20
|
[tool.poetry.plugins."console_scripts"]
|
|
21
21
|
"toolforge-components" = "toolforge_components_cli.cli:main"
|
|
22
22
|
|
|
23
|
+
|
|
24
|
+
[tool.poetry.plugins."toolforge_cli.subcommands"]
|
|
25
|
+
components = "toolforge_components_cli.cli:toolforge_components"
|
|
26
|
+
deploy = "toolforge_components_cli.cli:deployment"
|
|
27
|
+
config = "toolforge_components_cli.cli:config"
|
|
28
|
+
|
|
23
29
|
[tool.poetry.group.dev.dependencies]
|
|
24
30
|
coverage = "^7.13.5"
|
|
25
31
|
pytest = "^9.0.3"
|
{toolforge_components_cli-0.0.20 → toolforge_components_cli-0.0.22}/toolforge_components_cli/cli.py
RENAMED
|
@@ -36,9 +36,9 @@ DELETE_TOKEN_CONFIRM_MSG = (
|
|
|
36
36
|
)
|
|
37
37
|
ABORT_MSG = "Aborting at user's request."
|
|
38
38
|
TOKEN_EXISTS_MSG = """A valid deployment token already exists. You can:
|
|
39
|
-
- Use 'deploy
|
|
40
|
-
- Use 'deploy
|
|
41
|
-
- Use 'deploy
|
|
39
|
+
- Use 'deploy token show' to see the current token
|
|
40
|
+
- Use 'deploy token refresh' to create a new token (this will invalidate the current one)
|
|
41
|
+
- Use 'deploy token delete' to remove the current token"""
|
|
42
42
|
# this seems to be enough to show the 'job <> is already up to date' message for most jobs and not too long to be
|
|
43
43
|
# too annoying
|
|
44
44
|
LONG_STATUS_WIDTH = 45
|
|
@@ -59,6 +59,45 @@ def handle_error(e: Exception, debug: bool = False) -> None:
|
|
|
59
59
|
click.echo(click.style(ERROR_REPORT_MSG, fg="red"), err=True)
|
|
60
60
|
|
|
61
61
|
|
|
62
|
+
class ComponentsGroup(click.Group):
|
|
63
|
+
"""This allows us to resue from toolforge-cli through entry-points.
|
|
64
|
+
|
|
65
|
+
We need to handle the errors here, as main() is not called through entry-points.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def invoke(self, ctx: click.Context) -> Any:
|
|
69
|
+
if not _is_embedded(ctx):
|
|
70
|
+
return super().invoke(ctx)
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
return super().invoke(ctx)
|
|
74
|
+
except (
|
|
75
|
+
click.exceptions.ClickException,
|
|
76
|
+
click.exceptions.Abort,
|
|
77
|
+
click.exceptions.Exit,
|
|
78
|
+
subprocess.CalledProcessError,
|
|
79
|
+
):
|
|
80
|
+
raise
|
|
81
|
+
except Exception as e:
|
|
82
|
+
handle_error(e, debug=(ctx.obj or {}).get("debug", False))
|
|
83
|
+
raise click.exceptions.Exit(1) from e
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _is_embedded(ctx: click.Context) -> bool:
|
|
87
|
+
return ctx.parent is not None and not isinstance(
|
|
88
|
+
ctx.parent.command, ComponentsGroup
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _get_components_client(ctx: click.Context) -> ComponentsClient:
|
|
93
|
+
ctx.ensure_object(dict)
|
|
94
|
+
if "components_client" not in ctx.obj:
|
|
95
|
+
ctx.obj["components_client"] = ComponentsClient.from_config(
|
|
96
|
+
config=get_loaded_config()
|
|
97
|
+
)
|
|
98
|
+
return ctx.obj["components_client"]
|
|
99
|
+
|
|
100
|
+
|
|
62
101
|
def _should_prompt() -> bool:
|
|
63
102
|
return sys.stdin.isatty()
|
|
64
103
|
|
|
@@ -137,7 +176,9 @@ def _display_deployment(deployment_data: dict, as_json: bool, prefix: str = "")
|
|
|
137
176
|
|
|
138
177
|
@click.version_option(prog_name="Toolforge Components CLI")
|
|
139
178
|
@click.group(
|
|
140
|
-
name="toolforge-components",
|
|
179
|
+
name="toolforge-components",
|
|
180
|
+
help="Toolforge Components command line interface",
|
|
181
|
+
cls=ComponentsGroup,
|
|
141
182
|
)
|
|
142
183
|
@click.option(
|
|
143
184
|
"-v",
|
|
@@ -158,19 +199,15 @@ def _display_deployment(deployment_data: dict, as_json: bool, prefix: str = "")
|
|
|
158
199
|
@click.pass_context
|
|
159
200
|
def toolforge_components(ctx, verbose: bool, debug: bool) -> None:
|
|
160
201
|
ctx.ensure_object(dict)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
"config": get_loaded_config(),
|
|
166
|
-
"components_client": ComponentsClient.from_config(
|
|
167
|
-
config=get_loaded_config()
|
|
168
|
-
),
|
|
169
|
-
}
|
|
170
|
-
)
|
|
202
|
+
# when loaded by toolforge-cli, the parent `toolforge` group might have set them already
|
|
203
|
+
ctx.obj["verbose"] = verbose or ctx.obj.get("verbose", False)
|
|
204
|
+
ctx.obj["debug"] = debug or ctx.obj.get("debug", False)
|
|
205
|
+
_get_components_client(ctx)
|
|
171
206
|
|
|
172
207
|
|
|
173
|
-
@toolforge_components.group(
|
|
208
|
+
@toolforge_components.group(
|
|
209
|
+
name="config", help="Manage component configurations", cls=ComponentsGroup
|
|
210
|
+
)
|
|
174
211
|
def config():
|
|
175
212
|
"""Manage component configurations."""
|
|
176
213
|
|
|
@@ -185,7 +222,7 @@ def config():
|
|
|
185
222
|
)
|
|
186
223
|
@click.pass_context
|
|
187
224
|
def config_create(ctx, config: TextIO | None, as_json: bool) -> None:
|
|
188
|
-
components_client = ctx
|
|
225
|
+
components_client = _get_components_client(ctx)
|
|
189
226
|
display_messages = not as_json
|
|
190
227
|
|
|
191
228
|
if config is None and _should_prompt():
|
|
@@ -215,7 +252,7 @@ def config_create(ctx, config: TextIO | None, as_json: bool) -> None:
|
|
|
215
252
|
)
|
|
216
253
|
@click.pass_context
|
|
217
254
|
def config_show(ctx, as_json: bool) -> None:
|
|
218
|
-
components_client = ctx
|
|
255
|
+
components_client = _get_components_client(ctx)
|
|
219
256
|
response = components_client.get("/config", display_messages=(not as_json))
|
|
220
257
|
_display_config(response.get("data", {}), as_json)
|
|
221
258
|
|
|
@@ -232,7 +269,7 @@ def config_show(ctx, as_json: bool) -> None:
|
|
|
232
269
|
)
|
|
233
270
|
@click.pass_context
|
|
234
271
|
def config_generate(ctx, as_json: bool) -> None:
|
|
235
|
-
components_client = ctx
|
|
272
|
+
components_client = _get_components_client(ctx)
|
|
236
273
|
response = components_client.get("/config/generate", display_messages=(not as_json))
|
|
237
274
|
_display_config(response.get("data", {}), as_json)
|
|
238
275
|
|
|
@@ -251,7 +288,7 @@ def config_generate(ctx, as_json: bool) -> None:
|
|
|
251
288
|
)
|
|
252
289
|
@click.pass_context
|
|
253
290
|
def config_delete(ctx, as_json: bool, yes_im_sure: bool) -> None:
|
|
254
|
-
components_client = ctx
|
|
291
|
+
components_client = _get_components_client(ctx)
|
|
255
292
|
display_messages = not as_json
|
|
256
293
|
|
|
257
294
|
check_response = components_client.get("/config", display_messages=False)
|
|
@@ -267,7 +304,9 @@ def config_delete(ctx, as_json: bool, yes_im_sure: bool) -> None:
|
|
|
267
304
|
_display_config(response.get("data", {}), as_json)
|
|
268
305
|
|
|
269
306
|
|
|
270
|
-
@toolforge_components.group(
|
|
307
|
+
@toolforge_components.group(
|
|
308
|
+
name="deploy-token", help="Manage deployment tokens", cls=ComponentsGroup
|
|
309
|
+
)
|
|
271
310
|
def deploy_token():
|
|
272
311
|
"""Manage deployment tokens."""
|
|
273
312
|
|
|
@@ -284,7 +323,7 @@ def deploy_token():
|
|
|
284
323
|
)
|
|
285
324
|
@click.pass_context
|
|
286
325
|
def deploy_token_create(ctx, as_json: bool) -> None:
|
|
287
|
-
components_client = ctx
|
|
326
|
+
components_client = _get_components_client(ctx)
|
|
288
327
|
|
|
289
328
|
try:
|
|
290
329
|
response = components_client.post("/deployment/token", display_messages=False)
|
|
@@ -313,7 +352,7 @@ def deploy_token_create(ctx, as_json: bool) -> None:
|
|
|
313
352
|
)
|
|
314
353
|
@click.pass_context
|
|
315
354
|
def deploy_token_refresh(ctx, as_json: bool, yes_im_sure: bool) -> None:
|
|
316
|
-
components_client = ctx
|
|
355
|
+
components_client = _get_components_client(ctx)
|
|
317
356
|
display_messages = not as_json
|
|
318
357
|
|
|
319
358
|
if not yes_im_sure and not click.confirm(
|
|
@@ -337,7 +376,7 @@ def deploy_token_refresh(ctx, as_json: bool, yes_im_sure: bool) -> None:
|
|
|
337
376
|
)
|
|
338
377
|
@click.pass_context
|
|
339
378
|
def deploy_token_show(ctx, as_json: bool) -> None:
|
|
340
|
-
components_client = ctx
|
|
379
|
+
components_client = _get_components_client(ctx)
|
|
341
380
|
response = components_client.get(
|
|
342
381
|
"/deployment/token", display_messages=(not as_json)
|
|
343
382
|
)
|
|
@@ -358,7 +397,7 @@ def deploy_token_show(ctx, as_json: bool) -> None:
|
|
|
358
397
|
)
|
|
359
398
|
@click.pass_context
|
|
360
399
|
def deploy_token_delete(ctx, as_json: bool, yes_im_sure: bool) -> None:
|
|
361
|
-
components_client = ctx
|
|
400
|
+
components_client = _get_components_client(ctx)
|
|
362
401
|
display_messages = not as_json
|
|
363
402
|
|
|
364
403
|
check_response = components_client.get("/deployment/token", display_messages=False)
|
|
@@ -378,11 +417,17 @@ def deploy_token_delete(ctx, as_json: bool, yes_im_sure: bool) -> None:
|
|
|
378
417
|
)
|
|
379
418
|
|
|
380
419
|
|
|
381
|
-
@toolforge_components.group(
|
|
420
|
+
@toolforge_components.group(
|
|
421
|
+
name="deployment", help="Manage deployments", cls=ComponentsGroup
|
|
422
|
+
)
|
|
382
423
|
def deployment():
|
|
383
424
|
"""Manage deployments."""
|
|
384
425
|
|
|
385
426
|
|
|
427
|
+
# so `deployment token <...>` is the same as `deploy-token <...>`
|
|
428
|
+
deployment.add_command(deploy_token, name="token")
|
|
429
|
+
|
|
430
|
+
|
|
386
431
|
@deployment.command(name="create", help="Create a new deployment.")
|
|
387
432
|
@click.option(
|
|
388
433
|
"--force-build",
|
|
@@ -421,7 +466,7 @@ def deployment_create(
|
|
|
421
466
|
description: str | None,
|
|
422
467
|
as_json: bool,
|
|
423
468
|
) -> None:
|
|
424
|
-
components_client = ctx
|
|
469
|
+
components_client = _get_components_client(ctx)
|
|
425
470
|
display_messages = not as_json
|
|
426
471
|
|
|
427
472
|
query_params: dict[str, str] = {}
|
|
@@ -511,7 +556,7 @@ def _format_status(status: str) -> str:
|
|
|
511
556
|
)
|
|
512
557
|
@click.pass_context
|
|
513
558
|
def deployment_list(ctx, as_json: bool) -> None:
|
|
514
|
-
components_client = ctx
|
|
559
|
+
components_client = _get_components_client(ctx)
|
|
515
560
|
display_messages = not as_json
|
|
516
561
|
|
|
517
562
|
response = components_client.get("/deployment", display_messages=display_messages)
|
|
@@ -525,7 +570,7 @@ def deployment_list(ctx, as_json: bool) -> None:
|
|
|
525
570
|
click.echo(
|
|
526
571
|
click.style(
|
|
527
572
|
(
|
|
528
|
-
"No deployments found, you can create one using `toolforge components deployment create`,"
|
|
573
|
+
"No deployments found, you can create one using `toolforge components deployment create`, "
|
|
529
574
|
+ "run `toolforge components deployment create --help` for more details"
|
|
530
575
|
),
|
|
531
576
|
fg="yellow",
|
|
@@ -570,7 +615,7 @@ def deployment_list(ctx, as_json: bool) -> None:
|
|
|
570
615
|
)
|
|
571
616
|
@click.pass_context
|
|
572
617
|
def deployment_show(ctx, deployment_id: str, as_json: bool) -> None:
|
|
573
|
-
components_client = ctx
|
|
618
|
+
components_client = _get_components_client(ctx)
|
|
574
619
|
response = components_client.get(
|
|
575
620
|
f"/deployment/{deployment_id}", display_messages=(not as_json)
|
|
576
621
|
)
|
|
@@ -594,7 +639,7 @@ def deployment_show(ctx, deployment_id: str, as_json: bool) -> None:
|
|
|
594
639
|
def deployment_delete(
|
|
595
640
|
ctx, deployment_id: str, as_json: bool, yes_im_sure: bool
|
|
596
641
|
) -> None:
|
|
597
|
-
components_client = ctx
|
|
642
|
+
components_client = _get_components_client(ctx)
|
|
598
643
|
display_messages = not as_json
|
|
599
644
|
|
|
600
645
|
if not yes_im_sure and not click.confirm(
|
|
@@ -619,7 +664,7 @@ def deployment_delete(
|
|
|
619
664
|
@click.argument("deployment_id", required=False, default="latest")
|
|
620
665
|
@click.pass_context
|
|
621
666
|
def deployment_cancel(ctx, deployment_id: str, as_json: bool) -> None:
|
|
622
|
-
components_client = ctx
|
|
667
|
+
components_client = _get_components_client(ctx)
|
|
623
668
|
display_messages = not as_json
|
|
624
669
|
|
|
625
670
|
response = components_client.put(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|