Skip to content

refactor: move preset command handlers to presets/_commands.py (PR-6/8)#2826

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

refactor: move preset command handlers to presets/_commands.py (PR-6/8)#2826
darion-yaphet wants to merge 2 commits into
github:mainfrom
darion-yaphet:refactor/split-init-pr6

Conversation

@darion-yaphet

Copy link
Copy Markdown
Contributor

Summary

PR-6 of the __init__.py split (continues PR-5's integration co-location). Moves the preset command group out of src/specify_cli/__init__.py into a co-located presets/_commands.py, trimming __init__.py toward a thin registration layer.

Two commits:

  1. presets.pypresets/ package — pure structural move so command handlers can live beside the preset domain logic (mirrors integrations/). presets.py becomes presets/__init__.py; package-relative imports rebased one level deeper. Public import surface (from specify_cli.presets import ...) unchanged.
  2. Move handlers to presets/_commands.py — the preset_app / preset_catalog_app Typer groups and all 12 handlers (list, add, remove, search, resolve, info, set-priority, enable, disable, catalog list/add/remove) move out; __init__.py registers them via _register_preset_cmds(app).

__init__.py drops ~620 lines in the preset region.

Design notes

  • Handlers lazy-import root helpers (_require_specify_project, get_speckit_version, _locate_bundled_preset, _display_project_path) via from .. import inside each function, so test monkeypatching of specify_cli.<helper> keeps working — same pattern PR-5 used.
  • _locate_bundled_preset kept as an explicit re-export in __init__.py for that resolution path.

Test plan

  • python -c "import specify_cli" — OK
  • specify preset --help — full command surface intact
  • uvx ruff check src/ — All checks passed
  • Full suite: 3344 passed, 40 skipped
  • No patch-path updates needed (lazy imports preserve monkeypatch targets)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the CLI by moving the specify preset ... Typer command groups and handlers out of src/specify_cli/__init__.py into a co-located src/specify_cli/presets/_commands.py, continuing the effort to slim __init__.py into a thin registration layer while keeping the public specify_cli.presets import surface stable.

Changes:

  • Introduces presets/_commands.py containing the preset / preset catalog Typer apps and all associated handlers, plus a register(app) entry point.
  • Repackages presets.py into the presets/ package and rebases internal imports accordingly.
  • Updates specify_cli/__init__.py to register preset commands via presets._commands.register() and keeps _locate_bundled_preset re-exported.
Show a summary per file
File Description
src/specify_cli/presets/_commands.py New home for preset CLI Typer apps + command handlers, plus register(app) wiring.
src/specify_cli/presets/init.py Rebased imports to account for presets/ becoming a package.
src/specify_cli/init.py Removes inlined preset command handlers and registers them via presets/_commands.py.

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: 4

Comment thread src/specify_cli/presets/_commands.py Outdated
Comment thread src/specify_cli/presets/_commands.py Outdated
Comment thread src/specify_cli/presets/_commands.py
Comment thread src/specify_cli/presets/_commands.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 2

Comment thread src/specify_cli/presets/_commands.py Outdated
Comment thread src/specify_cli/presets/_commands.py Outdated
@darion-yaphet darion-yaphet force-pushed the refactor/split-init-pr6 branch 2 times, most recently from 844e316 to 74629bc Compare June 8, 2026 16:27
@mnriem mnriem requested a review from Copilot June 9, 2026 12:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 2

Comment thread src/specify_cli/presets/_commands.py Outdated
Comment thread src/specify_cli/presets/_commands.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 6/7 changed files
  • Comments generated: 0 new

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pull in upstream/main and resolve conflicts

Pure structural move to mirror integrations/. presets.py becomes
presets/__init__.py with relative imports rebased one level deeper.
No behavior change; public import surface (from .presets import ...)
preserved. Prepares for co-locating preset command handlers in PR-6/8.
Cut the preset_app / preset_catalog_app Typer groups and all 12 command
handlers out of __init__.py into presets/_commands.py, exposing register(app)
— mirrors the integration co-location from PR-5. __init__.py now registers
via _register_preset_cmds(app), dropping ~620 lines (3282 -> 2663).

Handlers lazy-import root helpers (_require_specify_project, get_speckit_version,
_locate_bundled_preset, _display_project_path) via 'from .. import' so test
monkeypatching of specify_cli.<helper> keeps working. _locate_bundled_preset
kept as an explicit re-export in __init__.py for that resolution path.

CLI surface and public imports unchanged. Full suite: 3162 passed, 40 skipped.
@darion-yaphet darion-yaphet force-pushed the refactor/split-init-pr6 branch from 5574970 to ce3d46d Compare June 10, 2026 04:02
@darion-yaphet

Copy link
Copy Markdown
Contributor Author

Scope change: the URL-hardening commits previously on this branch have been extracted to #2911 so they can be reviewed and merged independently. This PR is now back to a pure code-move (2 commits).

While splitting, we found the moved copy of preset_add in presets/_commands.py was stale — it predated the GitHub release-asset resolution (resolve_github_release_asset_api_url + Accept: application/octet-stream header) that landed on main, so merging the old branch state would have silently reverted that behavior. The move commit has been amended so _commands.py now matches main's __init__.py line-for-line (only import paths differ). Full suite: 3711 passed, 45 skipped.

Suggested merge order: #2911 first, then this PR rebased on top.

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.

3 participants