diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a78408..ae74ebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html ## [Unreleased] +## [0.4.2] — 2026-06-08 + +### Fixed + +- **`__version__` was hardcoded and stale** (`__init__.py`). It read `"0.2.0"` + regardless of the installed release, since nothing tied it to the version in + `pyproject.toml`. It is now derived from the installed distribution metadata + via `importlib.metadata.version("table-stitcher")`, so it always reflects the + actual release (falling back to `"0.0.0+unknown"` when run from an + uninstalled source tree). The release gate now also asserts + `__version__` matches the `pyproject.toml` version, so the two can't drift + again. + ## [0.4.1] — 2026-06-08 ### Fixed diff --git a/pyproject.toml b/pyproject.toml index 43d47a6..29bbd94 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "table-stitcher" -version = "0.4.1" +version = "0.4.2" description = "Reassemble tables split across page boundaries in PDF extraction" readme = "README.md" license = "MIT" diff --git a/scripts/release_gate.sh b/scripts/release_gate.sh index a86d661..c3ffe65 100755 --- a/scripts/release_gate.sh +++ b/scripts/release_gate.sh @@ -69,15 +69,23 @@ else fi echo "==> Smoke-testing installed wheel outside checkout" +EXPECTED_VERSION="$(grep -E '^version = ' pyproject.toml | head -1 | sed -E 's/.*"([^"]+)".*/\1/')" +export EXPECTED_VERSION ( cd "$TMP_ENV" "$TMP_ENV/venv/bin/python" - <<'PY' +import os import pathlib + import table_stitcher package_path = pathlib.Path(table_stitcher.__file__).resolve() +expected = os.environ["EXPECTED_VERSION"] assert "site-packages" in str(package_path), package_path assert table_stitcher.__version__, "missing __version__" +assert table_stitcher.__version__ == expected, ( + f"__version__ {table_stitcher.__version__!r} != pyproject version {expected!r}" +) assert callable(table_stitcher.stitch_tables) print(f"installed {table_stitcher.__version__} from {package_path}") PY diff --git a/src/table_stitcher/__init__.py b/src/table_stitcher/__init__.py index ddf066a..70e7037 100644 --- a/src/table_stitcher/__init__.py +++ b/src/table_stitcher/__init__.py @@ -24,13 +24,20 @@ def inject(self, doc, logical_tables): ... import logging import time +from importlib.metadata import PackageNotFoundError +from importlib.metadata import version as _pkg_version from typing import Any, Optional from .adapters.base import TableStitcherAdapter from .merger import merge_multipage_tables from .models import LogicalTable, MergeTrace, MultiPageConfig, TableMeta -__version__ = "0.2.0" +# Single source of truth: the installed distribution's version (from +# pyproject.toml). Derived rather than hardcoded so it can never drift. +try: + __version__ = _pkg_version("table-stitcher") +except PackageNotFoundError: # running from a source tree without an install + __version__ = "0.0.0+unknown" __all__ = [ "stitch_tables", "extract_table_meta",