Skip to content

Commit dfda009

Browse files
blhsingclaude
andcommitted
Report the real package version instead of hardcoded 0.1.0
`pygit --version`, `pygit diagnose`, and `pygit bugreport` all printed a hardcoded "0.1.0" regardless of the installed version. Derive __version__ from the installed distribution metadata (single source of truth = pyproject), with a "0+unknown" fallback for unbuilt source trees, and use it at all three sites. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 976213f commit dfda009

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

pythongit/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,20 @@
22
from .repo import Repository
33

44
__all__ = ["Repository"]
5-
__version__ = "0.1.0"
5+
6+
7+
def _resolve_version() -> str:
8+
"""Single source of truth: the installed distribution's version (from
9+
pyproject), falling back to a literal when running from an unbuilt source
10+
tree where no distribution metadata is present."""
11+
try:
12+
from importlib.metadata import PackageNotFoundError, version
13+
try:
14+
return version("pure-python-git")
15+
except PackageNotFoundError:
16+
return "0+unknown"
17+
except Exception:
18+
return "0+unknown"
19+
20+
21+
__version__ = _resolve_version()

pythongit/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4879,7 +4879,8 @@ def cmd_diagnose(argv: list[str]) -> int:
48794879
args = ap.parse_args(argv)
48804880
repo = _repo()
48814881
lines = []
4882-
lines.append(f"pythongit version: 0.1.0")
4882+
from . import __version__ as _ppg_version
4883+
lines.append(f"pythongit version: {_ppg_version}")
48834884
lines.append(f"gitdir: {repo.gitdir}")
48844885
lines.append(f"worktree: {repo.path}")
48854886
lines.append(f"branches: {len(refs_mod.list_branches(repo))}")
@@ -4903,8 +4904,9 @@ def cmd_bugreport(argv: list[str]) -> int:
49034904
ap.add_argument("-o", "--output-directory", default=None)
49044905
args = ap.parse_args(argv)
49054906
import platform
4907+
from . import __version__ as _ppg_version
49064908
lines = []
4907-
lines.append(f"pythongit: 0.1.0")
4909+
lines.append(f"pythongit: {_ppg_version}")
49084910
lines.append(f"python: {platform.python_version()}")
49094911
lines.append(f"platform: {platform.platform()}")
49104912
try:

0 commit comments

Comments
 (0)