refactor: move preset command handlers to presets/_commands.py (PR-6/8)#2826
Conversation
There was a problem hiding this comment.
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.pycontaining thepreset/preset catalogTyper apps and all associated handlers, plus aregister(app)entry point. - Repackages
presets.pyinto thepresets/package and rebases internal imports accordingly. - Updates
specify_cli/__init__.pyto register preset commands viapresets._commands.register()and keeps_locate_bundled_presetre-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
35a36e1 to
566974e
Compare
566974e to
844e316
Compare
844e316 to
74629bc
Compare
74629bc to
0387473
Compare
mnriem
left a comment
There was a problem hiding this comment.
Please pull in upstream/main and resolve conflicts
7d8d62c to
5574970
Compare
5574970 to
ce3d46d
Compare
|
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 Suggested merge order: #2911 first, then this PR rebased on top. |
|
Setting to draft so it does NOT get merged before PR #2911 |
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.
ce3d46d to
4381b82
Compare
There was a problem hiding this comment.
✅ Ready to approve
The change is a straightforward refactor with consistent registration wiring and corresponding test updates, without introducing behavioral changes in the moved handlers.
Note: this review does not count toward required approvals for merging.
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 0 new
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
…ack (#3086) (#3091) * fix(presets): use _repo_root() for bundled-core source-checkout fallback The tier-5 fallback in PresetResolver.resolve() and _find_bundled_core() computed the repo root as Path(__file__).parent.parent.parent. After presets.py was moved to presets/__init__.py (#2826) that chain is one level short, resolving to src/ and looking for src/templates/commands/<cmd>.md, which never exists. As a result, wrap-strategy presets found no core base layer in source/editable installs. Use the shared _repo_root() helper so both fallbacks resolve against the actual repo-root templates/ tree. Wheel installs were unaffected (core_pack path), so this only impacts source/editable checkouts. Refs #3086 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test(presets): restore dropped def for oserror-manifest test A prior edit accidentally removed the def test_resolve_extension_command_via_manifest_skips_oserror_manifests line, orphaning its body inside the new bundled-core test. Restore the test definition so pytest collects it again. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test(presets): move bundled-core tests into TestPresetResolver The two tier-5 fallback regression tests exercise collect_all_layers() and resolve(), not resolve_core(), so they belong in TestPresetResolver rather than TestResolveCore. Relocate them for clearer suite navigation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
PR-6 of the
__init__.pysplit (continues PR-5's integration co-location). Moves thepresetcommand group out ofsrc/specify_cli/__init__.pyinto a co-locatedpresets/_commands.py, trimming__init__.pytoward a thin registration layer.Two commits:
presets.py→presets/package — pure structural move so command handlers can live beside the preset domain logic (mirrorsintegrations/).presets.pybecomespresets/__init__.py; package-relative imports rebased one level deeper. Public import surface (from specify_cli.presets import ...) unchanged.presets/_commands.py— thepreset_app/preset_catalog_appTyper groups and all 12 handlers (list,add,remove,search,resolve,info,set-priority,enable,disable,catalog list/add/remove) move out;__init__.pyregisters them via_register_preset_cmds(app).__init__.pydrops ~620 lines in the preset region.Design notes
_require_specify_project,get_speckit_version,_locate_bundled_preset,_display_project_path) viafrom .. importinside each function, so test monkeypatching ofspecify_cli.<helper>keeps working — same pattern PR-5 used._locate_bundled_presetkept as an explicit re-export in__init__.pyfor that resolution path.Test plan
python -c "import specify_cli"— OKspecify preset --help— full command surface intactuvx ruff check src/— All checks passed