Skip to content

refactor: extract _assets.py and _utils.py from __init__.py (PR-2/8)#2543

Merged
mnriem merged 2 commits into
github:mainfrom
darion-yaphet:refactor/split-init-pr2
May 13, 2026
Merged

refactor: extract _assets.py and _utils.py from __init__.py (PR-2/8)#2543
mnriem merged 2 commits into
github:mainfrom
darion-yaphet:refactor/split-init-pr2

Conversation

@darion-yaphet
Copy link
Copy Markdown
Contributor

Summary

  • Extract bundle path resolution and version lookup into _assets.py (stdlib only, zero internal imports)
  • Extract system utilities (subprocess, tool detection, file operations) into _utils.py (imports only from ._console)
  • Re-export all moved symbols from __init__.py for full backward compatibility
  • Update test_check_tool.py to patch both specify_cli and specify_cli._utils namespaces since constants are now defined in _utils

Files Changed

File Change
src/specify_cli/_assets.py New — 115 lines, bundle path & version helpers
src/specify_cli/_utils.py New — 281 lines, subprocess & tool detection utilities
src/specify_cli/__init__.py Shrunk by ~380 lines, re-exports preserved
tests/test_utils_assets_imports.py New — import regression guard
tests/test_check_tool.py Patch both namespaces for moved constants

Test plan

  • pytest tests/test_utils_assets_imports.py — all symbols importable from specify_cli
  • pytest tests/test_check_tool.py — patch paths correct after move
  • pytest (full suite) — no regressions

🤖 Generated with Claude Code

Move bundle path resolution and version lookup into _assets.py (stdlib only,
zero internal imports), and system utilities (subprocess, tool detection,
file operations) into _utils.py (imports only from ._console). Re-export all
moved symbols from __init__.py for backward compatibility. Update
test_check_tool.py to patch both specify_cli and specify_cli._utils namespaces
since constants are now defined in _utils.
@darion-yaphet darion-yaphet requested a review from mnriem as a code owner May 13, 2026 14:17
- Add module docstring to _assets.py (stdlib-only, zero internal imports)
- Add blank line after `from __future__ import annotations` in both files
- Replace `Optional[X]` with `X | None` throughout _utils.py (PEP 604)
- Remove unused `Optional` import from _utils.py
- Use explicit re-export form (`X as X`) for public symbols in __init__.py
- Remove unused `subprocess` and `tempfile` imports from __init__.py (moved to _utils.py)
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors specify_cli by extracting asset/bundle location + version helpers into src/specify_cli/_assets.py and system/tooling utilities into src/specify_cli/_utils.py, while keeping specify_cli’s public API stable via re-exports from __init__.py. It also updates and adds tests to guard against import regressions and to patch the new canonical constant locations used by check_tool().

Changes:

  • Added _assets.py for core-pack location helpers and get_speckit_version() (stdlib-only, no internal imports).
  • Added _utils.py for command/tool detection, git helpers, and VSCode settings JSON merge/write utilities (depends only on ._console internally).
  • Updated __init__.py to import/re-export moved symbols and adjusted tests to reflect the new constant ownership in _utils.
Show a summary per file
File Description
src/specify_cli/_assets.py New module containing bundle resolution and version lookup helpers.
src/specify_cli/_utils.py New module containing subprocess/tool detection and JSON merge/copy helpers previously in __init__.py.
src/specify_cli/init.py Re-exports moved helpers/constants; removes large inlined utility implementations.
tests/test_utils_assets_imports.py New regression test ensuring moved symbols remain importable from specify_cli.
tests/test_check_tool.py Updates patches to cover both specify_cli re-exports and the _utils canonical constants.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 0

@mnriem mnriem merged commit 2fb9d3b into github:main May 13, 2026
15 checks passed
@mnriem
Copy link
Copy Markdown
Collaborator

mnriem commented May 13, 2026

Thank you!

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