SwapStation_Dashboard/core/versioning.py

27 lines
788 B
Python

# core/versioning.py
from pathlib import Path
import os, sys
DEFAULT_VERSION = "v0.0.0"
def _bundle_root() -> Path:
# When frozen by PyInstaller, files are unpacked in sys._MEIPASS
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
return Path(sys._MEIPASS)
# Dev/run-from-source: project root = two levels up from this file (adjust if needed)
return Path(__file__).resolve().parents[1]
def get_version() -> str:
# 1) ENV override (useful for CI)
env = os.getenv("APP_VERSION")
if env:
return env.strip()
# 2) VERSION.txt (works in dev and frozen)
root = _bundle_root()
ver_file = root / "VERSION.txt"
if ver_file.exists():
return ver_file.read_text(encoding="utf-8").strip()
return DEFAULT_VERSION