Files
EventLens-Public/backend/app/version.py
T

26 lines
673 B
Python

import os
import re
from pathlib import Path
_VERSION_PATTERN = re.compile(r"^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$")
_REVISION_PATTERN = re.compile(r"^[0-9a-f]{40}$")
_VERSION_FILE = Path(__file__).resolve().parents[2] / "VERSION"
LOCAL_REVISION = "local"
def read_version() -> str:
value = _VERSION_FILE.read_text(encoding="utf-8").strip()
if not _VERSION_PATTERN.fullmatch(value):
raise RuntimeError("Invalid EventLens VERSION file")
return value
def read_revision() -> str:
value = os.environ.get("EVENTLENS_REVISION", "")
if _REVISION_PATTERN.fullmatch(value):
return value
return LOCAL_REVISION
VERSION = read_version()