From 465e008cbdd0a4687997829add61245916b9f63c Mon Sep 17 00:00:00 2001 From: mochan Date: Wed, 20 May 2026 14:50:38 +0530 Subject: [PATCH] fix: read __version__ from package metadata + bump to 0.1.0rc2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit codegraph.__version__ was hardcoded to "0.0.1" and drifted from the actual published wheel — 0.1.0rc1 on TestPyPI exposed the gap during the dry-run smoke (`from codegraph import __version__` returned "0.0.1" while the installed package metadata correctly said 0.1.0rc1). Switches __init__.py to read from importlib.metadata.version("polycodegraph") so the in-Python version attribute auto-syncs with pyproject.toml forever. Falls back to "0.0.0+local" only in the corner case of a source checkout without any install (real dev workflows use `pip install -e .` which registers the package metadata). Also adds a regression test (test_version_matches_package_metadata) that locks the auto-sync in place — re-hardcoding the version will now fail CI immediately. Bumps pyproject 0.1.0rc1 → 0.1.0rc2 to land this fix in a fresh TestPyPI dry-run before the real v0.1.0 publish. --- codegraph/__init__.py | 9 ++++++++- pyproject.toml | 2 +- tests/test_cli_smoke.py | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/codegraph/__init__.py b/codegraph/__init__.py index 9dddd8c..4a6e10a 100644 --- a/codegraph/__init__.py +++ b/codegraph/__init__.py @@ -1,3 +1,10 @@ """codegraph — language-agnostic code graph for analysis, PR review, and AI assistants.""" +from importlib.metadata import PackageNotFoundError as _PackageNotFoundError +from importlib.metadata import version as _version -__version__ = "0.0.1" +try: + __version__ = _version("polycodegraph") +except _PackageNotFoundError: + # Source checkout without install (rare — `pip install -e .` registers + # the package and avoids this branch in normal dev setups). + __version__ = "0.0.0+local" diff --git a/pyproject.toml b/pyproject.toml index f8eaea0..6fd74af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "polycodegraph" -version = "0.1.0rc1" +version = "0.1.0rc2" description = "Multi-language code graph builder, analyzer, PR risk reviewer, and MCP server. Supports Python, TypeScript, JavaScript, and Go." readme = "README.md" license = { text = "MIT" } diff --git a/tests/test_cli_smoke.py b/tests/test_cli_smoke.py index 2016b23..1424df0 100644 --- a/tests/test_cli_smoke.py +++ b/tests/test_cli_smoke.py @@ -18,6 +18,18 @@ def test_version_flag() -> None: assert __version__ in result.stdout +def test_version_matches_package_metadata() -> None: + """Regression: __version__ must auto-sync with pyproject via importlib.metadata. + + Catches the failure mode where someone re-hardcodes the version string and + it drifts from the actual published wheel — which is exactly what bit us + pre-0.1.0rc2 (codegraph.__version__ was "0.0.1" while the published wheel + was "0.1.0rc1"). + """ + from importlib.metadata import version as _pkg_version + assert __version__ == _pkg_version("polycodegraph") + + def test_help_lists_subcommands() -> None: result = runner.invoke(app, ["--help"]) assert result.exit_code == 0