Skip to content

fix: derive __version__ from package metadata#2

Merged
malteos merged 1 commit into
mainfrom
fix/derive-version-from-metadata
May 7, 2026
Merged

fix: derive __version__ from package metadata#2
malteos merged 1 commit into
mainfrom
fix/derive-version-from-metadata

Conversation

@malteos

@malteos malteos commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

After the v0.2.0 release the wheel's metadata correctly said 0.2.0, but commonlid.__version__ (and therefore commonlid version, and summary.json["commonlid_version"]) still reported 0.1.0. Root cause: the publish workflow's bump step (uv version --bump …) only edits pyproject.toml; src/commonlid/__init__.py carried a hand-kept __version__ = "0.1.0" that nothing in CI updates. The release commit a8656dd (chore(release): v0.2.0) only touches pyproject.toml + uv.lock, so the constant went stale.

This PR makes pyproject.toml the single source of truth: __version__ is now read from importlib.metadata.version("commonlid") at import time, with a sentinel fallback ("0.0.0+unknown") for un-installed source-tree imports (e.g. PYTHONPATH=src python …). The mismatch can no longer happen.

The version-derivation lives in a tiny new src/commonlid/_version.py so __init__.py stays lint-clean — RUF067 forbids runtime statements (the try/except) in package __init__.

Files

  • src/commonlid/_version.py (new) — reads version from importlib.metadata.
  • src/commonlid/__init__.py — re-export __version__ from _version.
  • tests/unit/test_cli_stub.py — new regression test:
    def test_version_matches_package_metadata() -> None:
        assert __version__ == _pkg_version("commonlid")

Test plan

  • make lint (ruff)
  • make format-check
  • make typecheck (mypy strict)
  • make test — 231 passed, 39 deselected, 94.60% coverage (1 new test)
  • Manual verification in editable install: commonlid.__version__0.2.0, matching importlib.metadata.version("commonlid")
  • Existing test_version still passes (CLI prints whatever __version__ is)

Follow-up note (out of scope)

This PR fixes the runtime constant going forward, but commonlid==0.2.0 on PyPI right now still ships the stale 0.1.0 constant. The fix is user-visible only after a version bump + new release. No action needed beyond the next release.

🤖 Generated with Claude Code

The publish workflow's `uv version --bump` step only edits
`pyproject.toml`, but `__version__` was a hand-kept constant in
`__init__.py`. After the v0.2.0 release the wheel's metadata said
`0.2.0` while `commonlid.__version__` and every `summary.json`'s
`commonlid_version` field stayed at `0.1.0`.

Make `pyproject.toml` the single source of truth: read the version
from `importlib.metadata.version("commonlid")` at import time, with a
sentinel fallback for un-installed source-tree imports. Lives in a new
`_version.py` to keep `__init__.py` lint-clean (RUF067 forbids
runtime statements there).

Add a regression test asserting `commonlid.__version__` equals
`importlib.metadata.version("commonlid")` so any future drift is
caught by the standard gate run instead of in production.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@malteos malteos merged commit 118d5e3 into main May 7, 2026
5 checks passed
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.

1 participant