Skip to content

refactor: create commands/ package and move init handler (PR-4/8)#2615

Open
darion-yaphet wants to merge 4 commits into
github:mainfrom
darion-yaphet:refactor/split-init-pr4
Open

refactor: create commands/ package and move init handler (PR-4/8)#2615
darion-yaphet wants to merge 4 commits into
github:mainfrom
darion-yaphet:refactor/split-init-pr4

Conversation

@darion-yaphet
Copy link
Copy Markdown
Contributor

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:

  • _agent_config.py — extracts AGENT_CONFIG, AI_ASSISTANT_HELP, AI_ASSISTANT_ALIASES, SCRIPT_TYPE_CHOICES, DEFAULT_INIT_INTEGRATION as a base-layer module (no internal
    imports), breaking the circular dependency that would otherwise occur when commands/init.py imports from init.py
  • commands/init.py — package marker
  • commands/init.py — init command via register(app) pattern; dependencies still in init.py are resolved via lazy imports inside the command body
  • commands/{integration,preset,extension,workflow}.py — placeholder stubs for future PRs

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

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync && uv run pytest
  • Tested with a sample project (if applicable)

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

  • I did use AI assistance (describe below)

Code structure and implementation generated with Claude Code; reviewed and validated manually.

- 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.
@darion-yaphet darion-yaphet requested a review from mnriem as a code owner May 18, 2026 05:47
@darion-yaphet darion-yaphet changed the title Refactor/split init pr4 refactor: create commands/ package and move init handler (PR-4/8) May 18, 2026
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