Skip to content

Commit e39d52a

Browse files
kmjones1979claude
andcommitted
fix: derive __version__ from package metadata so it cannot drift
The published wheel reported a version older than itself: oneclaw 0.59.8 said __version__ == "0.59.6", langchain-1claw 0.2.3 said "0.2.2", and 1claw-crewai-tools 0.3.3 said "0.3.0". Two hand-maintained copies of the same number, and releases bumped one of them. __version__ now reads the installed distribution metadata, so pyproject.toml is the only place a version is written. A test asserts the two agree, and fails if a literal is ever put back. Caught by installing the freshly published wheel from PyPI and importing it — which is worth doing after a release rather than trusting that a green publish job means the artifact is right. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019d5ks2kCa4eXD1ftdkECPu
1 parent ef61fff commit e39d52a

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎src/oneclaw/__init__.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@
1818
from oneclaw.resources.sub_orgs import SubOrgsResource
1919
from oneclaw.types import CredentialSource, OneclawClientConfig, OneclawResponse
2020

21-
__version__ = "0.59.6"
21+
# Single source of truth: the version lives in pyproject.toml and is read
22+
# from the installed distribution metadata. A hand-maintained literal here
23+
# drifts the moment a release bumps one and not the other — 0.59.8 shipped
24+
# reporting 0.59.6, so anyone checking __version__ got the wrong answer.
25+
try: # pragma: no cover - trivial
26+
from importlib.metadata import PackageNotFoundError, version as _dist_version
2227

28+
__version__ = _dist_version("oneclaw")
29+
except PackageNotFoundError: # running from a source tree, not installed
30+
__version__ = "0+unknown"
2331
__all__ = [
2432
"OneclawClient",
2533
"create_client",

‎tests/test_version.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (C) 2026 1Claw
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""The package version must match the one that will be published."""
4+
5+
import importlib
6+
import pathlib
7+
import re
8+
9+
10+
def test_dunder_version_matches_pyproject() -> None:
11+
"""__version__ and pyproject.toml must not drift.
12+
13+
They did: oneclaw
14+
shipped a release whose __version__ named an earlier version, because the
15+
literal in __init__.py was hand-maintained alongside the one in
16+
pyproject.toml. __version__ now reads the installed distribution metadata,
17+
so there is one source of truth; this asserts it stayed that way.
18+
"""
19+
root = pathlib.Path(__file__).resolve().parents[1]
20+
declared = re.search(
21+
r'^version\s*=\s*"([^"]+)"', (root / "pyproject.toml").read_text(), re.M
22+
)
23+
assert declared, "pyproject.toml has no version"
24+
25+
mod = importlib.import_module("oneclaw")
26+
assert mod.__version__ == declared.group(1), (
27+
f"__version__ is {mod.__version__} but pyproject.toml says {declared.group(1)}; "
28+
"a published package would report the wrong version"
29+
)

0 commit comments

Comments
 (0)