From c97a7c6ee16fc643195bc59b87396b68e4e11d82 Mon Sep 17 00:00:00 2001 From: "russell@unturf.com" Date: Wed, 17 Jun 2026 07:30:28 -0400 Subject: [PATCH] =?UTF-8?q?wallet=5Fdist=5Fhealth:=20argparse=20instead=20?= =?UTF-8?q?of=20click=20=E2=80=94=20match=20repo=20convention?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every other CLI in the repo (crypto_watcher/__init__, digest_sender, offer_tick, fix_s3_acls, lib/un.py) uses stdlib argparse. The mps_wallet_dist_health module imported click out of habit, breaking that pattern and forcing a new install_requires entry that wasn't declared (516 ModuleNotFoundError test errors on master CI). Swap to argparse, drop the click dep. Same interface: mps_wallet_dist_health [config_path] [--timeout SECS] Same exit codes (0 OK, 2 config, 3 RPC failure). Defaults preserved. --- .../lib/crypto_watcher/wallet_dist_health.py | 95 ++++++++++--------- requirements.py3.txt | 6 -- 2 files changed, 49 insertions(+), 52 deletions(-) diff --git a/make_post_sell/lib/crypto_watcher/wallet_dist_health.py b/make_post_sell/lib/crypto_watcher/wallet_dist_health.py index 3978b34..e1fc221 100644 --- a/make_post_sell/lib/crypto_watcher/wallet_dist_health.py +++ b/make_post_sell/lib/crypto_watcher/wallet_dist_health.py @@ -20,48 +20,55 @@ Exit code: from __future__ import annotations +import argparse import sys import traceback -import click - from make_post_sell.lib.crypto_watcher.wallet_dist_config import ( WalletDistConfig, load_wallet_dist_config, ) -@click.command(name="mps-wallet-dist-health") -@click.argument( - "config_path", - type=click.Path(dir_okay=False, exists=True, readable=True), - default="/opt/make_post_sell/production.ini", -) -@click.option( - "--timeout", - type=float, - default=10.0, - show_default=True, - help="dist call timeout in seconds.", -) -def cli(config_path: str, timeout: float) -> None: - """Verify MPS can talk to wallet@cammy over Erlang dist.""" +def _parse_args(argv: list[str] | None = None) -> argparse.Namespace: + parser = argparse.ArgumentParser( + prog="mps_wallet_dist_health", + description="Verify MPS can talk to wallet@cammy over Erlang dist.", + ) + parser.add_argument( + "config_path", + nargs="?", + default="/opt/make_post_sell/production.ini", + help="path to production.ini (default: /opt/make_post_sell/production.ini)", + ) + parser.add_argument( + "--timeout", + type=float, + default=10.0, + help="dist call timeout in seconds (default: 10.0)", + ) + return parser.parse_args(argv) + + +def main(argv: list[str] | None = None) -> int: + args = _parse_args(argv) + try: - cfg = load_wallet_dist_config(config_path) + cfg = load_wallet_dist_config(args.config_path) except Exception as e: - click.echo(f"config error: {e}", err=True) - raise SystemExit(2) from None + print(f"config error: {e}", file=sys.stderr) + return 2 if not cfg.enabled: - click.echo("wallet_dist.enabled = false (nothing to test)", err=True) - raise SystemExit(2) + print("wallet_dist.enabled = false (nothing to test)", file=sys.stderr) + return 2 - click.echo("=== MPS wallet-dist health check ===") - click.echo(f"our_node_name : {cfg.our_node_name}") - click.echo(f"peer : {cfg.peer_name}@{cfg.peer_host}") - click.echo(f"registered_name : {cfg.registered_name}") - click.echo(f"tls : {'mTLS' if cfg.tls_cert else 'plain'}") - click.echo("") + print("=== MPS wallet-dist health check ===") + print(f"our_node_name : {cfg.our_node_name}") + print(f"peer : {cfg.peer_name}@{cfg.peer_host}") + print(f"registered_name : {cfg.registered_name}") + print(f"tls : {'mTLS' if cfg.tls_cert else 'plain'}") + print("") # Local import — erldistpy is a runtime-optional dep (only required # when wallet_dist is enabled). Importing at module top would force @@ -71,34 +78,30 @@ def cli(config_path: str, timeout: float) -> None: ErlangDistMoneroClient, ) except ImportError as e: - click.echo(f"erldistpy not installed: {e}", err=True) - click.echo("hint: pip install 'erldistpy>=0.1.6'", err=True) - raise SystemExit(3) from None + print(f"erldistpy not installed: {e}", file=sys.stderr) + print("hint: pip install 'erldistpy>=0.1.6'", file=sys.stderr) + return 3 try: with ErlangDistMoneroClient( **cfg.client_kwargs(), - call_timeout=timeout, + call_timeout=args.timeout, ) as client: - click.echo("connected ✓") + print("connected") height = client.get_height() - click.echo(f"monero height: {height}") + print(f"monero height: {height}") synced = client.is_synced() - click.echo(f"synced: {synced}") + print(f"synced: {synced}") except Exception as e: - click.echo(f"\nDIST RPC FAILED: {type(e).__name__}: {e}", err=True) - click.echo("traceback:", err=True) + print(f"\nDIST RPC FAILED: {type(e).__name__}: {e}", file=sys.stderr) + print("traceback:", file=sys.stderr) traceback.print_exc() - raise SystemExit(3) from None + return 3 - click.echo("") - click.echo("OK — MPS can reach Wallet.Service on the cluster ✓") - - -def main() -> None: - # The console_script entry point. Click handles arg parsing. - cli(standalone_mode=True) # standard click flow + print("") + print("OK - MPS can reach Wallet.Service on the cluster") + return 0 if __name__ == "__main__": # pragma: no cover - cli(standalone_mode=True) + sys.exit(main()) diff --git a/requirements.py3.txt b/requirements.py3.txt index 66802f5..a5693e2 100644 --- a/requirements.py3.txt +++ b/requirements.py3.txt @@ -68,9 +68,3 @@ html5lib # included here; see lib/crypto_watcher/erldist_clients.py for the # drop-in clients). erldistpy>=0.1.6 - -# Used by mps_wallet_dist_health CLI (lib/crypto_watcher/wallet_dist_health.py) -# for argument parsing + colored output. Already a transitive dep of pyramid -# in most cases, but pin it explicitly so test imports don't break in cleaner -# CI envs. -click