Skip to content

Commit 4fea67f

Browse files
author
github-actions
committed
refactor: Use dynamic versioning via importlib.metadata
- Replace hardcoded __version__ with dynamic version from package metadata - Update version-check workflow to verify installed package version - Eliminates need to manually sync __version__ with pyproject.toml Now when you run 'uv version --bump patch', the __version__ in __init__.py automatically reflects the new version.
1 parent 434da84 commit 4fea67f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.github/workflows/version-check.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ jobs:
3434
PYPROJECT_VERSION=$(uv version | awk '{print $2}')
3535
echo "pyproject.toml version: $PYPROJECT_VERSION"
3636
37-
# Get version from __init__.py (match only the assignment line, not __all__)
38-
INIT_VERSION=$(grep -E '^__version__ = ' src/ryandata_address_utils/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
39-
echo "__init__.py version: $INIT_VERSION"
37+
# Install package to verify dynamic version works
38+
uv sync
39+
40+
# Get version from installed package (dynamic versioning)
41+
PACKAGE_VERSION=$(uv run python -c "from ryandata_address_utils import __version__; print(__version__)")
42+
echo "Package version: $PACKAGE_VERSION"
4043
4144
# Compare versions
42-
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
45+
if [ "$PYPROJECT_VERSION" != "$PACKAGE_VERSION" ]; then
4346
echo "❌ Version mismatch!"
47+
echo "pyproject.toml: $PYPROJECT_VERSION"
48+
echo "Package: $PACKAGE_VERSION"
4449
exit 1
4550
fi
4651

src/ryandata_address_utils/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@
106106
)
107107
from ryandata_address_utils.validation.base import RyanDataValidationBase, ValidationBase
108108

109-
__version__ = "0.7.2"
109+
# Dynamic version from package metadata (set in pyproject.toml)
110+
# This eliminates the need to manually sync versions
111+
from importlib.metadata import version as _get_version
112+
113+
__version__ = _get_version("ryandata-address-utils")
110114
__package_name__ = "ryandata-address-utils"
111115

112116
__all__ = [

0 commit comments

Comments
 (0)