Skip to content

Commit a1e41ba

Browse files
committed
deduce version from git if ran from source
1 parent e598f5d commit a1e41ba

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

pum/pum_config.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import importlib.metadata
99
import glob
1010
import os
11+
import subprocess
1112
from typing import TYPE_CHECKING
1213

1314
from .dependency_handler import DependencyHandler
@@ -26,7 +27,6 @@
2627

2728
try:
2829
PUM_VERSION = packaging.version.Version(importlib.metadata.version("pum"))
29-
PUM_VERSION = packaging.version.Version("9.9.9")
3030
except importlib.metadata.PackageNotFoundError:
3131
# Fallback: try to read from pum-*.dist-info/METADATA
3232
dist_info_dirs = glob.glob(os.path.join(os.path.dirname(__file__), "..", "pum-*.dist-info"))
@@ -44,8 +44,47 @@
4444
# Pick the highest version
4545
PUM_VERSION = max((packaging.version.Version(v) for v in versions))
4646
else:
47-
PUM_VERSION = packaging.version.Version("0.0.0")
48-
PUM_VERSION = packaging.version.Version("0.8.9")
47+
# Fallback: try to get version from git (for development from source)
48+
try:
49+
git_dir = Path(__file__).parent.parent / ".git"
50+
if git_dir.exists():
51+
result = subprocess.run(
52+
["git", "describe", "--tags", "--always", "--dirty"],
53+
cwd=Path(__file__).parent.parent,
54+
capture_output=True,
55+
text=True,
56+
check=False,
57+
)
58+
if result.returncode == 0 and result.stdout.strip():
59+
git_version = result.stdout.strip()
60+
# Clean up git version to be PEP 440 compatible
61+
# e.g., "0.9.2-10-g1234567" -> "0.9.2.post10"
62+
# e.g., "0.9.2" -> "0.9.2"
63+
# e.g., "1234567" (no tags) -> "0.0.0+1234567"
64+
if "-" in git_version:
65+
parts = git_version.split("-")
66+
if len(parts) >= 3 and parts[0][0].isdigit():
67+
# Tagged version with commits after: "0.9.2-10-g1234567"
68+
base_version = parts[0]
69+
commits_after = parts[1]
70+
PUM_VERSION = packaging.version.Version(
71+
f"{base_version}.post{commits_after}"
72+
)
73+
else:
74+
# Untagged: just use the commit hash
75+
PUM_VERSION = packaging.version.Version(f"0.0.0+{parts[0]}")
76+
elif git_version[0].isdigit():
77+
# Clean tag version
78+
PUM_VERSION = packaging.version.Version(git_version)
79+
else:
80+
# Just a commit hash (no tags)
81+
PUM_VERSION = packaging.version.Version(f"0.0.0+{git_version}")
82+
else:
83+
PUM_VERSION = packaging.version.Version("0.0.0")
84+
else:
85+
PUM_VERSION = packaging.version.Version("0.0.0")
86+
except Exception:
87+
PUM_VERSION = packaging.version.Version("0.0.0")
4988

5089

5190
logger = logging.getLogger(__name__)

0 commit comments

Comments
 (0)