refactor: create commands/ package and move init handler (PR-4/8)#2615
Open
darion-yaphet wants to merge 5 commits into
Open
refactor: create commands/ package and move init handler (PR-4/8)#2615darion-yaphet wants to merge 5 commits into
darion-yaphet wants to merge 5 commits into
Conversation
- Extract agent configuration constants (AGENT_CONFIG, AI_ASSISTANT_HELP, SCRIPT_TYPE_CHOICES, etc.) to _agent_config.py to avoid circular imports - Create commands/ package skeleton with stub modules for each command group - Move init command handler (~670 lines) from __init__.py to commands/init.py using the register(app) pattern; lazy imports inside the handler body prevent circular dependencies with __init__.py - Re-export AGENT_CONFIG, AI_ASSISTANT_HELP, SCRIPT_TYPE_CHOICES from __init__.py for backward compatibility - Add tests/test_commands_package.py to verify package structure
…s/init.py _stdin_is_interactive and select_with_arrows are now bound in specify_cli.commands.init, not specify_cli directly.
- Remove shutil, shlex top-level imports (used lazily inside functions) - Remove rich.live.Live import (moved to commands/init.py) - Mark select_with_arrows and _locate_bundled_workflow as explicit re-exports to satisfy ruff F401
Aligns with the project convention established in _console.py, _assets.py, _utils.py, and other modules.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the specify_cli package by introducing a commands/ subpackage and moving the specify init command implementation out of src/specify_cli/__init__.py, while preserving backwards-compatible imports and CLI behavior.
Changes:
- Add
src/specify_cli/commands/package and move theinitcommand intocommands/init.pyusing aregister(app)pattern. - Extract agent-related constants into a new base module
src/specify_cli/_agent_config.pyand re-export them fromspecify_cli. - Add/adjust tests to ensure the new package layout is importable and that
initremains registered; update one mock patch target.
Show a summary per file
| File | Description |
|---|---|
| tests/test_commands_package.py | Adds import/registration coverage for the new commands/ package and agent-config re-exports. |
| tests/integrations/test_integration_claude.py | Updates mock.patch targets to the new commands.init locations. |
| src/specify_cli/commands/init.py | Introduces the new commands package marker. |
| src/specify_cli/commands/init.py | New home for the specify init command with register(app) wiring. |
| src/specify_cli/commands/extension.py | Placeholder stub for future extraction. |
| src/specify_cli/commands/integration.py | Placeholder stub for future extraction. |
| src/specify_cli/commands/preset.py | Placeholder stub for future extraction. |
| src/specify_cli/commands/workflow.py | Placeholder stub for future extraction. |
| src/specify_cli/_agent_config.py | Extracts agent/integration constants from __init__.py. |
| src/specify_cli/init.py | Re-exports agent config constants and registers init via commands.init.register(app). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 10/10 changed files
- Comments generated: 4
Comment on lines
+120
to
+135
| By default, project files are downloaded from the latest GitHub release. | ||
| Use --offline to scaffold from assets bundled inside the specify-cli | ||
| package instead (no internet access required, ideal for air-gapped or | ||
| enterprise environments). | ||
|
|
||
| NOTE: Starting with v0.6.0, bundled assets will be used by default and | ||
| the --offline flag will be removed. The GitHub download path will be | ||
| retired because bundled assets eliminate the need for network access, | ||
| avoid proxy/firewall issues, and guarantee that templates always match | ||
| the installed CLI version. | ||
|
|
||
| This command will: | ||
| 1. Check that required tools are installed (git is optional) | ||
| 2. Let you choose your coding agent integration, or default to Copilot | ||
| in non-interactive sessions | ||
| 3. Download template from GitHub (or use bundled assets with --offline) |
Comment on lines
+387
to
+388
| sys._specify_tracker_active = True | ||
|
|
| @@ -0,0 +1,2 @@ | |||
| """CLI command groups — each module exposes a register(app) function.""" | |||
Potential fix for pull request finding Update command package documentation and init help text to reflect the current implementation: init uses bundled assets and integration setup, while placeholder command modules are import anchors until extracted. Remove the unused tracker-active flag assignment that had no reader in the codebase. Constraint: --offline is hidden/no-op and init no longer downloads templates from GitHub releases Rejected: Add no-op register functions to placeholder modules | would imply extracted command groups are implemented there Confidence: high Scope-risk: narrow Directive: Keep CLI help text aligned with the actual init scaffolding path Tested: uv run specify init --help; uv run pytest tests/test_commands_package.py tests/test_agent_config_consistency.py -q; uv run pytest tests/test_commands_package.py tests/test_console_imports.py tests/integrations/test_cli.py -q Not-tested: full test suite
c3270d7 to
6ffc129
Compare
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.
Description
Part 4 of 8 in the init.py module split refactor.
Creates the commands/ subpackage and moves the init command handler (~670 lines) out of init.py into commands/init.py, using a register(app) pattern to avoid
circular imports.
New modules:
imports), breaking the circular dependency that would otherwise occur when commands/init.py imports from init.py
Backward compatibility: All re-exported symbols (AGENT_CONFIG, AI_ASSISTANT_HELP, SCRIPT_TYPE_CHOICES, select_with_arrows, _locate_bundled_workflow) remain importable
from specify_cli.
init.py reduction: ~780 lines removed.
Testing
uv run pytest: 2910 passed, 35 skipped. Fixed one test whose mock.patch target moved from specify_cli._stdin_is_interactive →
specify_cli.commands.init._stdin_is_interactive.
AI Disclosure
Code structure and implementation generated with Claude Code; reviewed and validated manually.