Skip to content

refactor: extract _version.py from __init__.py (PR-3/8)#2550

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

refactor: extract _version.py from __init__.py (PR-3/8)#2550
darion-yaphet wants to merge 2 commits into
github:mainfrom
darion-yaphet:refactor/split-init-pr3

Conversation

@darion-yaphet
Copy link
Copy Markdown
Contributor

Summary

Part 3 of 8 in the __init__.py module split refactor.

Extracts all version-checking logic and the specify self sub-command group from the 5361-line __init__.py 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 (5 s timeout)
  • self_app — Typer sub-app for specify self
  • self_check, self_upgradespecify self check/upgrade commands

Dependency rule: _version.py imports only stdlib + packaging + ._console — no other internal modules at module level.

Backward compatibility: GITHUB_API_LATEST, self_check, self_upgrade remain importable from specify_cli via re-exports in __init__.py.

Test plan

  • Updated test_upgrade.py imports to specify_cli._version and corrected patch paths to specify_cli._version._get_installed_version
  • New tests/test_version_imports.py guards all re-exported symbols
  • 40 tests pass (9 pre-existing failures in test_upgrade.py unrelated to this PR — same failures exist on main)
  • ruff check src/ — all checks passed

🤖 Generated with Claude Code

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.
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

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_upgrade to src/specify_cli/_version.py.
  • Re-export the public symbols from specify_cli/__init__.py and call app.add_typer(_self_app, name="self") there.
  • Update tests/test_upgrade.py patch paths to specify_cli._version._get_installed_version and add tests/test_version_imports.py regression 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

@mnriem
Copy link
Copy Markdown
Collaborator

mnriem commented May 14, 2026

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.
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