refactor: extract _console.py from __init__.py (PR-1/8)#2474
Conversation
7051a67 to
17111c5
Compare
There was a problem hiding this comment.
Pull request overview
This PR is part 1/8 of the specify_cli/__init__.py split refactor, extracting Rich/Typer console UI primitives into a new base-layer module while keeping backward-compatible imports via re-exports from specify_cli.
Changes:
- Added
src/specify_cli/_console.pycontaining the Rich console singleton, banner rendering, keyboard input helpers, andStepTracker. - Updated
src/specify_cli/__init__.pyto import/re-export the extracted console symbols and removed their inlined implementations. - Added a regression test ensuring the extracted symbols remain importable from
specify_cli.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/_console.py |
New module housing the extracted Rich UI primitives and Typer banner group. |
src/specify_cli/__init__.py |
Re-exports moved console symbols and removes the inlined implementations. |
tests/test_console_imports.py |
Regression test to guard import compatibility for the re-exported console symbols. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 3
7da5416 to
0fd5a0c
Compare
|
Please address Copilot feedback |
Don't worry. Don't rush. I will fix these problems. |
56356dd to
9d6df93
Compare
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (1)
src/specify_cli/init.py:80
get_keyis imported from._consolebut not used anywhere in this file; Ruff will flag this as an unused import (F401) duringruff check src/. If it’s meant to be re-exported, mark it as such (e.g., add to__all__or use a targetednoqa: F401).
console,
get_key,
select_with_arrows,
- Files reviewed: 3/3 changed files
- Comments generated: 1
Move Rich UI primitives (BANNER, TAGLINE, StepTracker, get_key, select_with_arrows, console, BannerGroup, show_banner) into a new src/specify_cli/_console.py module. Re-export all symbols from __init__.py to preserve the public API. Add regression guard tests.
…ptions - Add module-level docstring documenting the console layer's purpose and the dependency-layering rule (no imports from other specify_cli modules) - Tighten select_with_arrows() signature: options typed as dict[str, str] and default_key as str | None to align with repo typing style - Add early ValueError guard when options is empty, preventing downstream ZeroDivisionError / IndexError inside the Live loop
- Add Callable import from collections.abc for precise callback typing - Annotate StepTracker._refresh_cb as Callable[[], None] | None - Add parameter/return types to attach_refresh() - Use explicit keyword form typer.Exit(code=1) across all error exits - Add blank line between StepTracker class and get_key() (PEP 8) - Add regression test for select_with_arrows() raising ValueError on empty options dict
- Add explicit __all__ for intentional re-exports (BANNER, TAGLINE, get_key) - Prevent F401 unused import errors in CI lint checks - Maintain backward compatibility for external imports
9b942c9 to
f01fdfa
Compare
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback
The CLI package intentionally re-exports console helpers for compatibility, so __all__ must track that public surface instead of narrowing star imports to a partial set. Constraint: Existing tests import console helpers directly from specify_cli Rejected: Remove __all__ entirely | keeping an explicit export list documents the intended compatibility surface Confidence: high Scope-risk: narrow Directive: Keep __all__ synchronized when adding or removing specify_cli public re-exports Tested: uv run pytest tests/test_console_imports.py -q
|
Please address Copilot feedback |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Perhaps I need a testing method. The current approach is just too inefficient |
|
The reviews are not always that efficient, but they are necessary so we do not regress and also cover the corner cases. Unfortunately it does NOT show it all in one go so we have to go through these review cycles. Note we also go through the same cycles so we feel the same pain! |
|
Please address Test & Lint errors |
Use `X as X` form for BANNER, TAGLINE, and get_key imports to mark them as intentional public re-exports and silence ruff F401 lint errors.
|
Thank you! |
Summary
Part 1 of 8 in the
__init__.pymodule split refactor (design spec).Extracts all Rich UI primitives from the 5880-line
__init__.pyinto a focused_console.pybase-layer module.Moved symbols:
BANNER,TAGLINE— ASCII art constantsStepTracker— live progress tree rendererget_key,select_with_arrows— interactive keyboard inputBannerGroup,show_banner— Typer banner integrationconsole— Rich Console singletonBackward compatibility: All symbols remain importable from
specify_clivia re-exports in__init__.py.Dependency rule:
_console.pyhas zero internal imports (base layer).Test plan
tests/test_console_imports.pyguards all 8 re-exported symbolsfrom specify_cli import console, StepTracker, ...worksspecify --helprenders banner correctly