fix: single-source __version__ from package metadata (#78)#87
Merged
Conversation
Previously haclient.__version__ was hardcoded to "0.2.0" while
pyproject.toml declared 1.1.2, causing the two values to drift.
Derive __version__ at import time via importlib.metadata.version("haclient")
so pyproject.toml is the single source of truth. Falls back to
"0.0.0+unknown" only when the package is not installed (e.g. running
straight from a source tree without an install).
Add tests/test_packaging.py asserting __version__ matches the installed
package metadata, preventing future drift.
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.
Closes #78.
Issue validity
Valid. Confirmed the drift firsthand:
pyproject.tomldeclared version1.1.2src/haclient/__init__.pyexposed__version__ = "0.2.0"This is exactly the inconsistency the issue called out.
Fix
Took option 1 from the issue's suggested fixes: keep
haclient.__version__(no breaking change for users) but derive it at import time from installed package metadata, sopyproject.tomlis the single source of truth.Fallback only triggers if the package is not installed (e.g. running from a raw source tree without
pip install).Tests
Added
tests/test_packaging.py:test_version_matches_package_metadata— assertshaclient.__version__ == importlib.metadata.version("haclient"), preventing future drift.test_version_is_non_empty_string— sanity check.Checks run
ruff check src tests— passruff format --check src tests— passmypy src(strict) — pass, no issues in 38 source filespytest tests/ --cov=haclient --cov-fail-under=95— 318 passed, coverage 97.18%Verified locally: