refactor: extract _console.py from __init__.py (PR-1/8)#2474
Open
darion-yaphet wants to merge 5 commits into
Open
refactor: extract _console.py from __init__.py (PR-1/8)#2474darion-yaphet wants to merge 5 commits into
darion-yaphet wants to merge 5 commits into
Conversation
7051a67 to
17111c5
Compare
5 tasks
Contributor
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
Collaborator
|
Please address Copilot feedback |
Author
Don't worry. Don't rush. I will fix these problems. |
56356dd to
9d6df93
Compare
Contributor
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
requested changes
May 12, 2026
Collaborator
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
Comment on lines
+29
to
+40
| # Public API - intentional re-exports for backward compatibility. | ||
| __all__ = [ | ||
| "BANNER", | ||
| "BannerGroup", | ||
| "StepTracker", | ||
| "TAGLINE", | ||
| "console", | ||
| "get_key", | ||
| "select_with_arrows", | ||
| "show_banner", | ||
| ] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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