Skip to content

Commit 587eb94

Browse files
committed
Fix version detection to use importlib.metadata for installed packages
1 parent 776bc6b commit 587eb94

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/gitfetch/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77

88

99
def _get_version() -> str:
10-
"""Get version from pyproject.toml."""
10+
"""Get version from package metadata or pyproject.toml."""
11+
try:
12+
# Try to get version from package metadata
13+
from importlib import metadata
14+
return metadata.version("gitfetch")
15+
except (ImportError, metadata.PackageNotFoundError):
16+
pass
17+
18+
# Fallback: try to read from pyproject.toml (works in development)
1119
pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml"
1220
try:
1321
with open(pyproject_path, "r", encoding="utf-8") as f:

0 commit comments

Comments
 (0)