refactor: extract _version.py from __init__.py (PR-3/8)#2550
Open
darion-yaphet wants to merge 2 commits into
Open
refactor: extract _version.py from __init__.py (PR-3/8)#2550darion-yaphet wants to merge 2 commits into
darion-yaphet wants to merge 2 commits into
Conversation
Move version-checking helpers and `specify self` sub-commands into a focused `_version.py` module. Moved symbols: - GITHUB_API_LATEST — GitHub releases API endpoint constant - _get_installed_version — importlib.metadata-based version lookup - _normalize_tag — strip leading 'v' from release tag strings - _is_newer — PEP 440 version comparison - _fetch_latest_release_tag — single outbound call to GitHub API - self_app — Typer sub-app for `specify self` - self_check, self_upgrade — `specify self check/upgrade` commands Dependency rule: _version.py imports only stdlib + packaging + ._console. Backward compatibility: GITHUB_API_LATEST, self_check, self_upgrade remain importable from specify_cli via re-exports in __init__.py. Update test_upgrade.py to import helpers from specify_cli._version and patch at the correct module path (specify_cli._version.*). Add test_version_imports.py as regression guard.
Contributor
There was a problem hiding this comment.
Pull request overview
Part 3 of an 8-part split of specify_cli/__init__.py. Extracts version-checking helpers and the specify self sub-command group into a new focused _version.py module while preserving backward-compat re-exports.
Changes:
- Move
GITHUB_API_LATEST,_get_installed_version,_normalize_tag,_is_newer,_fetch_latest_release_tag,self_app,self_check,self_upgradetosrc/specify_cli/_version.py. - Re-export the public symbols from
specify_cli/__init__.pyand callapp.add_typer(_self_app, name="self")there. - Update
tests/test_upgrade.pypatch paths tospecify_cli._version._get_installed_versionand addtests/test_version_imports.pyregression guard.
Show a summary per file
| File | Description |
|---|---|
| src/specify_cli/_version.py | New module containing version helpers and the self Typer sub-app. |
| src/specify_cli/init.py | Removes the moved code, drops now-unused urllib.error/urllib.request/packaging imports, re-exports moved symbols, and registers _self_app. |
| tests/test_upgrade.py | Updates imports and patch() targets to the new module path. |
| tests/test_version_imports.py | New regression test ensuring re-exports and direct imports remain available. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 0
Collaborator
|
Please fix test and lint errors |
…entication.py PR-3 moved _fetch_latest_release_tag from specify_cli into specify_cli._version. test_upgrade.py was updated at the time, but test_authentication.py::TestFetchLatestReleaseTagDelegation still imported from the old location, causing ImportError on all three delegation tests. Update all three inline imports to the correct module path.
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
Part 3 of 8 in the
__init__.pymodule split refactor.Extracts all version-checking logic and the
specify selfsub-command group from the 5361-line__init__.pyinto a focused_version.pymodule.Moved symbols:
GITHUB_API_LATEST— GitHub releases API endpoint constant_get_installed_version— importlib.metadata-based version lookup_normalize_tag— strip leadingvfrom release tag strings_is_newer— PEP 440 version comparison_fetch_latest_release_tag— single outbound call to GitHub API (5 s timeout)self_app— Typer sub-app forspecify selfself_check,self_upgrade—specify self check/upgradecommandsDependency rule:
_version.pyimports only stdlib +packaging+._console— no other internal modules at module level.Backward compatibility:
GITHUB_API_LATEST,self_check,self_upgraderemain importable fromspecify_clivia re-exports in__init__.py.Test plan
test_upgrade.pyimports tospecify_cli._versionand corrected patch paths tospecify_cli._version._get_installed_versiontests/test_version_imports.pyguards all re-exported symbolstest_upgrade.pyunrelated to this PR — same failures exist onmain)ruff check src/— all checks passed🤖 Generated with Claude Code