From bc20e3a8bade0a3108419244a4043190e9426fbd Mon Sep 17 00:00:00 2001 From: Providex AI Date: Tue, 18 Aug 2026 13:47:16 -0700 Subject: [PATCH] fix(cli): single import style for importlib in the operator CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit github-code-quality flagged `importlib` imported both ways in rootsign/cli.py: `from importlib import resources` at module level (pre-existing) and `import importlib` inside `_require()`, which came in with the no-extras console-script fix (#28). Accurate, and mine. Rather than renaming the local import, hoisted `import_module` into the existing module-level `from importlib import ...` and dropped the function-local import entirely — `importlib` is stdlib, so there is nothing to defer, and `_require` is now three lines shorter. Note this does NOT undo #28: what had to be lazy there was psycopg2/alembic (the optional postgres extra), never importlib itself. Re-verified on a real bare install — the behaviour #28 fixed is unchanged: rootsign-admin --help -> exit 0 rootsign-admin status -> install hint, exit 1 (missing module: psycopg2) rootsign-admin init -> install hint, exit 1 (missing module: alembic) Full suite: 500 passed, 6 skipped. Co-Authored-By: Claude Opus 5 --- rootsign/cli.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rootsign/cli.py b/rootsign/cli.py index 3ca2e04..221a295 100644 --- a/rootsign/cli.py +++ b/rootsign/cli.py @@ -18,7 +18,7 @@ import shutil import subprocess import time -from importlib import resources +from importlib import import_module, resources from pathlib import Path from typing import TYPE_CHECKING, Any @@ -50,10 +50,8 @@ def _require(module: str) -> Any: Mirrors `rootsign.sdk.cli._session_factory`: a missing `postgres` extra becomes a one-line actionable error and exit 1, never a raw traceback. """ - import importlib - try: - return importlib.import_module(module) + return import_module(module) except ModuleNotFoundError as exc: from rootsign.errors import RootSignPostgresExtraRequired