toolforge-components-cli 0.0.17__tar.gz → 0.0.19__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toolforge-components-cli
3
- Version: 0.0.17
3
+ Version: 0.0.19
4
4
  Summary: Toolforge components client
5
5
  License: GPLv3
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "toolforge-components-cli"
3
- version = "0.0.17"
3
+ version = "0.0.19"
4
4
  description = "Toolforge components client"
5
5
  authors = ["Slavina Stefanova <sstefanova@wikimedia.org>"]
6
6
  license = "GPLv3"
@@ -42,6 +42,8 @@ TOKEN_EXISTS_MSG = """A valid deployment token already exists. You can:
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
45
+ # Keep freeform descriptions from making the deployment list excessively wide.
46
+ DESCRIPTION_WIDTH = 45
45
47
 
46
48
 
47
49
  def handle_error(e: Exception, debug: bool = False) -> None:
@@ -100,6 +102,10 @@ def _display_deployment(deployment_data: dict, as_json: bool, prefix: str = "")
100
102
  click.echo(
101
103
  click.style("Created: ", bold=True) + deployment_data["creation_time"]
102
104
  )
105
+ if deployment_data.get("description"):
106
+ click.echo(
107
+ click.style("Description: ", bold=True) + deployment_data["description"]
108
+ )
103
109
  click.echo(
104
110
  click.style("Status: ", bold=True)
105
111
  + _format_status(deployment_data.get("status", "unknown"))
@@ -182,13 +188,15 @@ def config_create(ctx, config: TextIO | None, as_json: bool) -> None:
182
188
  components_client = ctx.obj["components_client"]
183
189
  display_messages = not as_json
184
190
 
185
- if config is None:
186
- if _should_prompt():
187
- click.echo(MISSING_CONFIG_MSG, err=True)
188
- sys.exit(1)
189
- config_data = yaml.safe_load(sys.stdin)
190
- else:
191
- config_data = yaml.safe_load(config)
191
+ if config is None and _should_prompt():
192
+ click.echo(MISSING_CONFIG_MSG, err=True)
193
+ sys.exit(1)
194
+
195
+ config_source = config if config is not None else sys.stdin
196
+ try:
197
+ config_data = yaml.safe_load(config_source)
198
+ except yaml.YAMLError as e:
199
+ raise ToolforgeUserError(f"Invalid YAML configuration: {e}") from e
192
200
 
193
201
  response = components_client.post(
194
202
  "/config", json=config_data, display_messages=display_messages
@@ -394,6 +402,11 @@ def deployment():
394
402
  "(ex. delete + create the continuous job)"
395
403
  ),
396
404
  )
405
+ @click.option(
406
+ "--description",
407
+ type=str,
408
+ help="Human-readable context describing what is being deployed and why.",
409
+ )
397
410
  @click.option(
398
411
  "--json",
399
412
  "as_json",
@@ -401,7 +414,13 @@ def deployment():
401
414
  help="If set, will output in JSON format",
402
415
  )
403
416
  @click.pass_context
404
- def deployment_create(ctx, force_build: bool, force_run: bool, as_json: bool) -> None:
417
+ def deployment_create(
418
+ ctx,
419
+ force_build: bool,
420
+ force_run: bool,
421
+ description: str | None,
422
+ as_json: bool,
423
+ ) -> None:
405
424
  components_client = ctx.obj["components_client"]
406
425
  display_messages = not as_json
407
426
 
@@ -411,9 +430,14 @@ def deployment_create(ctx, force_build: bool, force_run: bool, as_json: bool) ->
411
430
  if force_run:
412
431
  query_params["force-run"] = "true"
413
432
 
414
- response = components_client.post(
415
- "/deployment", params=query_params, display_messages=display_messages
416
- )
433
+ request_kwargs: dict[str, Any] = {
434
+ "params": query_params,
435
+ "display_messages": display_messages,
436
+ }
437
+ if description is not None:
438
+ request_kwargs["json"] = {"description": description}
439
+
440
+ response = components_client.post("/deployment", **request_kwargs)
417
441
 
418
442
  if as_json:
419
443
  click.echo(json.dumps(response, indent=4))
@@ -421,6 +445,8 @@ def deployment_create(ctx, force_build: bool, force_run: bool, as_json: bool) ->
421
445
  deployment_data = response.get("data", {})
422
446
  click.echo(f"Deployment ID: {deployment_data.get('deploy_id')}")
423
447
  click.echo(f"Created: {deployment_data.get('creation_time')}")
448
+ if deployment_data.get("description"):
449
+ click.echo(f"Description: {deployment_data['description']}")
424
450
  if deployment_data.get("builds"):
425
451
  click.echo("\nBuilds:")
426
452
  for component, build in deployment_data["builds"].items():
@@ -499,6 +525,9 @@ def deployment_list(ctx, as_json: bool) -> None:
499
525
  [
500
526
  deployment["deploy_id"],
501
527
  deployment["creation_time"],
528
+ textwrap.shorten(
529
+ deployment.get("description", ""), width=DESCRIPTION_WIDTH
530
+ ),
502
531
  _format_status(deployment.get("status", "unknown")),
503
532
  _format_builds(deployment.get("builds", {})),
504
533
  _format_runs(deployment.get("runs", {})),
@@ -509,7 +538,7 @@ def deployment_list(ctx, as_json: bool) -> None:
509
538
  tabulate(
510
539
  formatted_deployments,
511
540
  headers=_format_headers(
512
- ["ID", "Creation time", "Status", "Builds", "Runs"]
541
+ ["ID", "Creation time", "Description", "Status", "Builds", "Runs"]
513
542
  ),
514
543
  )
515
544
  )