"""BanGUI backend application package. This package exposes the application version based on the project metadata. """ from __future__ import annotations from pathlib import Path from typing import Final import importlib.metadata import tomllib PACKAGE_NAME: Final[str] = "bangui-backend" def _read_pyproject_version() -> str: """Read the project version from ``pyproject.toml``. This is used as a fallback when the package metadata is not available (e.g. when running directly from a source checkout without installing the package). """ project_root = Path(__file__).resolve().parents[1] pyproject_path = project_root / "pyproject.toml" if not pyproject_path.exists(): raise FileNotFoundError(f"pyproject.toml not found at {pyproject_path}") data = tomllib.loads(pyproject_path.read_text(encoding="utf-8")) return str(data["project"]["version"]) def _read_version() -> str: """Return the current package version. Prefer the project metadata in ``pyproject.toml`` when available, since this is the single source of truth for local development and is kept in sync with the frontend and Docker release version. When running from an installed distribution where the ``pyproject.toml`` is not available, fall back to installed package metadata. """ try: return _read_pyproject_version() except FileNotFoundError: return importlib.metadata.version(PACKAGE_NAME) __version__ = _read_version()