Add version CLI arg

This commit is contained in:
Miguel Jacq 2025-12-29 14:29:11 +11:00
parent 8c19473e18
commit ad2abed612
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
3 changed files with 72 additions and 25 deletions

32
enroll/version.py Normal file
View file

@ -0,0 +1,32 @@
from __future__ import annotations
def get_enroll_version() -> str:
"""
Best-effort version lookup that works when installed via:
- poetry/pip/wheel
- deb/rpm system packages
Falls back to "0+unknown" when running from an unpacked source tree.
"""
try:
from importlib.metadata import (
packages_distributions,
version,
)
except Exception:
# Very old Python or unusual environment
return "unknown"
# Map import package -> dist(s)
dist_names = []
try:
dist_names = (packages_distributions() or {}).get("enroll", []) or []
except Exception:
dist_names = []
# Try mapped dists first, then a reasonable default
for dist in [*dist_names, "enroll"]:
try:
return version(dist)
except Exception:
return "unknown"