Skip to content

Commit c8b9f20

Browse files
committed
Derive __version__ from installed package metadata
Previously openkb/__init__.py had a hand-written __version__ = "0.1.0" that drifted out of sync with pyproject.toml's version = "0.1.0.dev0", and the chat REPL had a three-level try/except fallback to paper over which string it would actually read. Make pyproject.toml the single source of truth by having __init__.py pull its __version__ from the installed package metadata via importlib.metadata, and simplify _openkb_version in chat.py to just import __version__.
1 parent 95011fb commit c8b9f20

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

openkb/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
__version__ = "0.1.0"
1+
"""OpenKB package."""
2+
from importlib.metadata import PackageNotFoundError, version as _version
3+
4+
try:
5+
__version__ = _version("openkb")
6+
except PackageNotFoundError:
7+
__version__ = "0.0.0+unknown"

openkb/agent/chat.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,8 @@ def _extract_preview(text: str, limit: int = 150) -> str:
8787

8888

8989
def _openkb_version() -> str:
90-
try:
91-
from importlib.metadata import version
92-
return version("openkb")
93-
except Exception:
94-
try:
95-
from openkb import __version__
96-
return __version__
97-
except Exception:
98-
return ""
90+
from openkb import __version__
91+
return __version__
9992

10093

10194
def _display_kb_dir(kb_dir: Path) -> str:

0 commit comments

Comments
 (0)