Skip to content

Commit 9e5a46b

Browse files
committed
fix(cli): derive runtime version from package metadata
Use importlib.metadata for CLI and module version reporting so displayed version always matches the installed distribution. Add regression tests for metadata and fallback behavior, and release as v0.1.9. Made-with: Cursor
1 parent 6713ad7 commit 9e5a46b

5 files changed

Lines changed: 31 additions & 5 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "agentic-devkit"
7-
version = "0.1.8"
7+
version = "0.1.9"
88
description = "CLI and catalog for agentic documentation OS templates (greenfield + brownfield overlay)"
99
readme = "README.md"
1010
requires-python = ">=3.10"

src/agentic_devkit/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
"""Agentic dev CLI — init, overlay, and intake for agentic documentation OS templates."""
22

3-
__version__ = "0.1.7"
3+
from importlib.metadata import PackageNotFoundError, version
4+
5+
try:
6+
__version__ = version("agentic-devkit")
7+
except PackageNotFoundError:
8+
__version__ = "0+unknown"

src/agentic_devkit/cli.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""agentic-dev CLI: init, overlay, intake."""
2+
import importlib.metadata
23
import os
34
import subprocess
45
import sys
56
from pathlib import Path
67

7-
from . import __version__
88
from .census import write_census_yaml
99

1010
DEFAULT_GREENFIELD = "gh:your-org/agentic-dev-greenfield"
@@ -50,6 +50,13 @@ def _run_copier(source: str, dest: Path) -> int:
5050
return subprocess.call([sys.executable, "-m", "copier", "copy", source, dest_str])
5151

5252

53+
def _package_version() -> str:
54+
try:
55+
return importlib.metadata.version("agentic-devkit")
56+
except importlib.metadata.PackageNotFoundError:
57+
return "0+unknown"
58+
59+
5360
def cmd_init(dest: str) -> int:
5461
"""Create a new greenfield repo from template."""
5562
source = _greenfield_source()
@@ -125,7 +132,7 @@ def main() -> int:
125132
prog="agentic-dev",
126133
description="Init, overlay, or intake for the agentic documentation OS templates.",
127134
)
128-
ap.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
135+
ap.add_argument("--version", action="version", version=f"%(prog)s {_package_version()}")
129136
sub = ap.add_subparsers(dest="command", required=True)
130137

131138
p_init = sub.add_parser("init", help="Create a new repo from greenfield template")

tests/test_cli_version.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from agentic_devkit import cli
2+
3+
4+
def test_package_version_reads_distribution_metadata(monkeypatch):
5+
monkeypatch.setattr(cli.importlib.metadata, "version", lambda _: "9.9.9")
6+
assert cli._package_version() == "9.9.9"
7+
8+
9+
def test_package_version_falls_back_when_distribution_missing(monkeypatch):
10+
def _raise_not_found(_: str) -> str:
11+
raise cli.importlib.metadata.PackageNotFoundError
12+
13+
monkeypatch.setattr(cli.importlib.metadata, "version", _raise_not_found)
14+
assert cli._package_version() == "0+unknown"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)