refactor: extract _console.py from __init__.py (PR-1/8)#2474
Open
darion-yaphet wants to merge 2 commits intogithub:mainfrom
Open
refactor: extract _console.py from __init__.py (PR-1/8)#2474darion-yaphet wants to merge 2 commits intogithub:mainfrom
darion-yaphet wants to merge 2 commits intogithub:mainfrom
Conversation
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.
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
…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
7da5416 to
0fd5a0c
Compare
| from other ``specify_cli`` sub-modules; all dependencies must flow *into* this | ||
| layer, not out of it, to avoid circular imports. | ||
| """ | ||
| from __future__ import annotations |
|
|
||
| tree.add(line) | ||
| return tree | ||
|
|
Comment on lines
+154
to
+155
| if not options: | ||
| raise ValueError("select_with_arrows() requires at least one option.") |
Comment on lines
+43
to
+44
| def attach_refresh(self, cb): | ||
| self._refresh_cb = cb |
Comment on lines
+204
to
+216
| raise typer.Exit(1) | ||
|
|
||
| live.update(create_selection_panel(), refresh=True) | ||
|
|
||
| except KeyboardInterrupt: | ||
| console.print("\n[yellow]Selection cancelled[/yellow]") | ||
| raise typer.Exit(1) | ||
|
|
||
| run_selection_loop() | ||
|
|
||
| if selected_key is None: | ||
| console.print("\n[red]Selection failed.[/red]") | ||
| raise typer.Exit(1) |
Collaborator
|
Please address Copilot feedback |
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