Skip to content

fix(cli): single import style for importlib in the operator CLI - #33

Merged
oabolade merged 1 commit into
mainfrom
fix/importlib-single-import-style
Aug 18, 2026
Merged

fix(cli): single import style for importlib in the operator CLI#33
oabolade merged 1 commit into
mainfrom
fix/importlib-single-import-style

Conversation

@oabolade

Copy link
Copy Markdown
Contributor

Clears the remaining code-quality finding on main.

The finding

github-code-quality flagged importlib imported both ways in rootsign/cli.py:

line
21 from importlib import resources — pre-existing
53 import importlib — came in with #28's _require()

Accurate, and mine.

The fix

Rather than renaming the local import, hoisted import_module into the existing module-level from importlib import ... and dropped the function-local import entirely:

from importlib import import_module, resources
...
def _require(module: str) -> Any:
    try:
        return import_module(module)

importlib is stdlib, so there was never anything to defer — _require is now three lines shorter and the file has one import style.

This does not undo #28. What had to be lazy there was psycopg2 / alembic (the optional postgres extra), never importlib itself.

Verification

Re-ran against a real bare install to confirm #28's behaviour is intact:

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
  • ruff check clean apart from the 2 pre-existing E402s

The other open finding

except BaseException at rootsign/sdk/decorator.py:344dismissed, not fixed. It's the ADR-002 failure-isolation pattern: the handler stores error = exc, runs _try_ingest, then re-raises unconditionally (raise error), so KeyboardInterrupt / SystemExit still propagate — just after the ACTION_RECORD is emitted, which is the whole point.

Worth noting why it reappeared: it was dismissed earlier in this audit at decorator.py:299. Dismissals are pinned to a location, so when _log_safe and the postgres_extra_required import shifted the line to 344, CodeQL opened it as a new finding. Same mechanism that reopened log-injection alerts #8/#9 as #10/#11. Expect this one to resurface on any future edit above it in that file.

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
@oabolade
oabolade merged commit 02afa70 into main Aug 18, 2026
24 checks passed
@oabolade
oabolade deleted the fix/importlib-single-import-style branch August 18, 2026 20:53
oabolade added a commit that referenced this pull request Aug 19, 2026
Patch release. Every change that ships in the wheel since v0.2.0 is a bug fix;
no new public API and nothing breaking.

  #25  fix(security)  log injection — `tool_name` off the MCP proxy wire
                      reached two logger calls unescaped
  #27  fix(security)  same guard reshaped so CodeQL can see it; output
                      byte-identical
  #28  fix(sdk)       BOTH console scripts were unusable on a bare install —
                      `rootsign version`, `rootsign --help`,
                      `rootsign verify --local` and every `rootsign-admin`
                      command died on ModuleNotFoundError
  #30  fix(sdk)       missing `postgres` extra now names the install command on
                      every DB-backed path, not just some
  #33  fix(cli)       single import style for importlib

#29/#31/#32 (test + CI) and #26 (actions bump) change nothing in the
distribution.

README's Status headline moves to v0.2.1; the phase table's "✅ v0.2.0" row
stays put — that records when 1.5 shipped, which is history, not the current
version.

`rootsign/_version.py` reads the version from installed distribution metadata,
so pyproject.toml is the only place it is written. Reinstalled and verified it
propagates to `rootsign.__version__`, `SDK_VERSION` (which lands in every
envelope's `sdk_version`), and `rootsign version`.

Built the artifacts and smoke-tested the wheel in a fresh no-extras venv —
the #28 fix holds in the thing that would actually go to PyPI:

    rootsign version        -> rootsign 0.2.1
    rootsign --help         -> exit 0
    rootsign-admin --help   -> exit 0
    rootsign verify <uuid>  -> install hint, exit 1
    DB packages resolved    -> none

Full suite: 500 passed, 6 skipped.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant