refactor: extract _assets.py and _utils.py from __init__.py (PR-2/8)#2543
Merged
Conversation
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.
- 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)
Contributor
There was a problem hiding this comment.
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.pyfor core-pack location helpers andget_speckit_version()(stdlib-only, no internal imports). - Added
_utils.pyfor command/tool detection, git helpers, and VSCode settings JSON merge/write utilities (depends only on._consoleinternally). - Updated
__init__.pyto 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
approved these changes
May 13, 2026
Collaborator
|
Thank you! |
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.
Summary
_assets.py(stdlib only, zero internal imports)_utils.py(imports only from._console)__init__.pyfor full backward compatibilitytest_check_tool.pyto patch bothspecify_cliandspecify_cli._utilsnamespaces since constants are now defined in_utilsFiles Changed
src/specify_cli/_assets.pysrc/specify_cli/_utils.pysrc/specify_cli/__init__.pytests/test_utils_assets_imports.pytests/test_check_tool.pyTest plan
pytest tests/test_utils_assets_imports.py— all symbols importable fromspecify_clipytest tests/test_check_tool.py— patch paths correct after movepytest(full suite) — no regressions🤖 Generated with Claude Code