toolforge-components-cli 0.0.15__tar.gz → 0.0.18__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,20 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toolforge-components-cli
3
- Version: 0.0.15
3
+ Version: 0.0.18
4
4
  Summary: Toolforge components client
5
5
  License: GPLv3
6
6
  License-File: LICENSE
7
7
  Author: Slavina Stefanova
8
8
  Author-email: sstefanova@wikimedia.org
9
- Requires-Python: >=3.7,<4.0
9
+ Requires-Python: >=3.13,<4.0
10
10
  Classifier: License :: Other/Proprietary License
11
11
  Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.7
13
- Classifier: Programming Language :: Python :: 3.8
14
- Classifier: Programming Language :: Python :: 3.9
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Programming Language :: Python :: 3.11
17
- Classifier: Programming Language :: Python :: 3.12
18
12
  Classifier: Programming Language :: Python :: 3.13
19
13
  Classifier: Programming Language :: Python :: 3.14
20
14
  Requires-Dist: PyYAML (>=6.0,<7.0)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "toolforge-components-cli"
3
- version = "0.0.15"
3
+ version = "0.0.18"
4
4
  description = "Toolforge components client"
5
5
  authors = ["Slavina Stefanova <sstefanova@wikimedia.org>"]
6
6
  license = "GPLv3"
@@ -8,7 +8,7 @@ readme = "README.md"
8
8
  homepage = "https://gitlab.wikimedia.org/repos/cloud/toolforge/components-cli"
9
9
 
10
10
  [tool.poetry.dependencies]
11
- python = "^3.7"
11
+ python = "^3.13"
12
12
  click = "^8.0.3"
13
13
  PyYAML = "^6.0"
14
14
  requests = "^2.27.1"
@@ -21,9 +21,9 @@ toolforge-weld = ">=1.4,<2.0"
21
21
  "toolforge-components" = "toolforge_components_cli.cli:main"
22
22
 
23
23
  [tool.poetry.group.dev.dependencies]
24
- coverage = "^6.2"
25
- pytest = "^6.2.5"
26
- pytest-cov = "^3.0.0"
24
+ coverage = "^7.13.5"
25
+ pytest = "^9.0.3"
26
+ pytest-cov = "^7.1.0"
27
27
  bats-core-pkg = "^0.1.3"
28
28
  requests-mock = "^1.11.0"
29
29
 
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python3
2
1
  from __future__ import annotations
3
2
 
4
3
  import json
@@ -43,6 +42,8 @@ TOKEN_EXISTS_MSG = """A valid deployment token already exists. You can:
43
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
44
43
  # too annoying
45
44
  LONG_STATUS_WIDTH = 45
45
+ # Keep freeform descriptions from making the deployment list excessively wide.
46
+ DESCRIPTION_WIDTH = 45
46
47
 
47
48
 
48
49
  def handle_error(e: Exception, debug: bool = False) -> None:
@@ -101,6 +102,10 @@ def _display_deployment(deployment_data: dict, as_json: bool, prefix: str = "")
101
102
  click.echo(
102
103
  click.style("Created: ", bold=True) + deployment_data["creation_time"]
103
104
  )
105
+ if deployment_data.get("description"):
106
+ click.echo(
107
+ click.style("Description: ", bold=True) + deployment_data["description"]
108
+ )
104
109
  click.echo(
105
110
  click.style("Status: ", bold=True)
106
111
  + _format_status(deployment_data.get("status", "unknown"))
@@ -395,6 +400,11 @@ def deployment():
395
400
  "(ex. delete + create the continuous job)"
396
401
  ),
397
402
  )
403
+ @click.option(
404
+ "--description",
405
+ type=str,
406
+ help="Human-readable context describing what is being deployed and why.",
407
+ )
398
408
  @click.option(
399
409
  "--json",
400
410
  "as_json",
@@ -402,7 +412,13 @@ def deployment():
402
412
  help="If set, will output in JSON format",
403
413
  )
404
414
  @click.pass_context
405
- def deployment_create(ctx, force_build: bool, force_run: bool, as_json: bool) -> None:
415
+ def deployment_create(
416
+ ctx,
417
+ force_build: bool,
418
+ force_run: bool,
419
+ description: str | None,
420
+ as_json: bool,
421
+ ) -> None:
406
422
  components_client = ctx.obj["components_client"]
407
423
  display_messages = not as_json
408
424
 
@@ -412,9 +428,14 @@ def deployment_create(ctx, force_build: bool, force_run: bool, as_json: bool) ->
412
428
  if force_run:
413
429
  query_params["force-run"] = "true"
414
430
 
415
- response = components_client.post(
416
- "/deployment", params=query_params, display_messages=display_messages
417
- )
431
+ request_kwargs: dict[str, Any] = {
432
+ "params": query_params,
433
+ "display_messages": display_messages,
434
+ }
435
+ if description is not None:
436
+ request_kwargs["json"] = {"description": description}
437
+
438
+ response = components_client.post("/deployment", **request_kwargs)
418
439
 
419
440
  if as_json:
420
441
  click.echo(json.dumps(response, indent=4))
@@ -422,6 +443,8 @@ def deployment_create(ctx, force_build: bool, force_run: bool, as_json: bool) ->
422
443
  deployment_data = response.get("data", {})
423
444
  click.echo(f"Deployment ID: {deployment_data.get('deploy_id')}")
424
445
  click.echo(f"Created: {deployment_data.get('creation_time')}")
446
+ if deployment_data.get("description"):
447
+ click.echo(f"Description: {deployment_data['description']}")
425
448
  if deployment_data.get("builds"):
426
449
  click.echo("\nBuilds:")
427
450
  for component, build in deployment_data["builds"].items():
@@ -500,6 +523,9 @@ def deployment_list(ctx, as_json: bool) -> None:
500
523
  [
501
524
  deployment["deploy_id"],
502
525
  deployment["creation_time"],
526
+ textwrap.shorten(
527
+ deployment.get("description", ""), width=DESCRIPTION_WIDTH
528
+ ),
503
529
  _format_status(deployment.get("status", "unknown")),
504
530
  _format_builds(deployment.get("builds", {})),
505
531
  _format_runs(deployment.get("runs", {})),
@@ -510,7 +536,7 @@ def deployment_list(ctx, as_json: bool) -> None:
510
536
  tabulate(
511
537
  formatted_deployments,
512
538
  headers=_format_headers(
513
- ["ID", "Creation time", "Status", "Builds", "Runs"]
539
+ ["ID", "Creation time", "Description", "Status", "Builds", "Runs"]
514
540
  ),
515
541
  )
516
542
  )
@@ -602,7 +628,7 @@ def main() -> int:
602
628
  except subprocess.CalledProcessError as e:
603
629
  handle_error(e, debug=debug)
604
630
  return e.returncode
605
- except Exception as e:
631
+ except Exception as e: # noqa: BLE001
606
632
  handle_error(e, debug=debug)
607
633
  return 1
608
634
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import socket
4
- from typing import Any, Type, Union
4
+ from typing import Any
5
5
 
6
6
  import requests
7
7
  from toolforge_weld.api_client import ConnectionError, ToolforgeClient
@@ -30,7 +30,7 @@ def handle_http_exception(e: requests.exceptions.HTTPError) -> Exception:
30
30
  if e.response is None:
31
31
  return ComponentsClientError(message="Got no response", context={})
32
32
 
33
- error_class: Union[Type[ComponentsClientError], Type[ComponentsClientUserError]]
33
+ error_class: type[ComponentsClientError | ComponentsClientUserError]
34
34
  if 400 <= e.response.status_code <= 499:
35
35
  error_class = ComponentsClientUserError
36
36
  else:
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from dataclasses import dataclass, field
4
- from functools import lru_cache
4
+ from functools import cache
5
5
  from typing import Any
6
6
 
7
7
  from toolforge_weld.config import Config, Section, load_config
@@ -20,6 +20,6 @@ class ComponentsConfig(Section):
20
20
  return cls(**params)
21
21
 
22
22
 
23
- @lru_cache(maxsize=None)
23
+ @cache
24
24
  def get_loaded_config() -> Config:
25
25
  return load_config(client_name="components", extra_sections=[ComponentsConfig])