Fix testium --version reporting "unknown" when installed from a wheel

get_testium_version() used pkg_resources (deprecated, slow to import)
and a narrow catch on git.InvalidGitRepositoryError; any other git
exception fell through to the outer except and returned "unknown".

- Use importlib.metadata.version("testium") to read the wheel
  version that setuptools bakes from src/VERSION at build time. Works
  out of any source checkout — pip-installed copies report
  "<x.y> (wheel release)" instead of "unknown".
- Source-checkout path: tried first when prefs.git_supported, broadly
  catches Exception so a missing repo / detached worktree / etc. no
  longer hides the wheel-metadata fallback.
- PyInstaller path: graceful "unknown (binary release)" if the bundled
  VERSION file is unreadable, instead of an unhandled exception.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 09:19:22 +02:00
parent b9475c6e9b
commit 41519c97cb

View File

@@ -31,39 +31,42 @@ def get_version(path :str)-> str:
return "Warning git not supported in your settings, version of {} unknown".format(path) return "Warning git not supported in your settings, version of {} unknown".format(path)
def get_testium_version(): def get_testium_version():
# case where we're executing from an Appimage # AppImage
if 'APPIMAGE' in os.environ: if 'APPIMAGE' in os.environ:
ver = 'unknown' ver = os.getenv('SEQUENCER_REV', 'unknown')
if 'SEQUENCER_REV' in os.environ: return ver + " (binary release)"
ver = os.getenv('SEQUENCER_REV')
return (ver + " (binary release)")
# case where we're executing from pyinstaller exe # PyInstaller frozen exe
if getattr(sys, 'frozen', False): if getattr(sys, 'frozen', False):
file_path = os.path.join(sys._MEIPASS, "VERSION") file_path = os.path.join(sys._MEIPASS, "VERSION")
with open(file_path, 'r') as file: try:
ver = file.read() with open(file_path, 'r') as f:
return (ver + " (binary release)") ver = f.read().strip()
return ver + " (binary release)"
except OSError:
return "unknown (binary release)"
# Executed from sources # Source checkout: prefer git revision when available
try: if prefs.settings.git_supported:
if prefs.settings.git_supported: try:
git = import_module("git") git = import_module("git")
path = tm.get_main_dir() return repo_rev(tm.get_main_dir())
try: except Exception:
return repo_rev(path) # Not a git repo (typical pip install): fall through.
except git.InvalidGitRepositoryError: pass
pkg_rec = import_module("pkg_resources")
try: # Pip-installed wheel: use the package metadata baked from VERSION
ret = pkg_rec.get_distribution("testium").version try:
_cached_versions.update({path: ret}) from importlib.metadata import version as _pkg_version
return str(ret) + " (wheel release)" from importlib.metadata import PackageNotFoundError
except: try:
return "Warning : testium not versioned" return _pkg_version("testium") + " (wheel release)"
else: except PackageNotFoundError:
return "Warning git not supported in your settings, version of testium is unknown." pass
except: except ImportError:
return ("Unknown") pass
return "unknown"
def get_modifications(path : str)-> str: def get_modifications(path : str)-> str: