""" Application-level constants for Curator (build/runtime metadata). This module derives the app version and debug flag. The version is loaded from `pyproject.toml` (preferred) with a generated `src/_version.py` fallback for frozen/PyInstaller builds. Debug mode is controlled via `.env` (`ENV_DEBUG`). It is the single source of truth for app metadata used across the GUI and build tooling (`APP_NAME`, `APP_VERSION`/`VERSION`, `APP_TITLE`, `APP_VIEWPORT`). """ import os import tomllib from pathlib import Path from dotenv import load_dotenv load_dotenv() _PYPROJECT_PATH = Path(__file__).parent.parent / "pyproject.toml" _VERSION_FILE = Path(__file__).parent / "_version.py" APP_NAME: str = "Curator" def get_version() -> str: """Return the project version (pyproject → _version.py → unknown).""" # 1. pyproject.toml (preferred) try: with open(_PYPROJECT_PATH, "rb") as f: version = tomllib.load(f)["project"]["version"] # Cache a fallback for frozen/PyInstaller builds (best-effort). try: _VERSION_FILE.write_text( f'"""Auto-generated — do not edit manually."""\n__version__ = "{version}"\n', encoding="utf-8", ) except OSError: pass return version except (FileNotFoundError, KeyError): pass # 2. generated _version.py try: from src._version import __version__ # type: ignore[import] return __version__ except ImportError: pass # 3. last resort return "0.0.0-unknown" def get_debug_mode() -> bool: """Return True when ENV_DEBUG is set to a truthy value in the environment.""" return os.getenv("ENV_DEBUG", "false").lower() in ("true", "1", "yes") APP_VERSION: str = get_version() ENV_DEBUG: bool = get_debug_mode() APP_TITLE: str = f"{APP_NAME} v{APP_VERSION}" + ("-DEV" if ENV_DEBUG else "") # Backwards-compatible alias used by prebuild.py VERSION: str = APP_VERSION # Default main-window geometry (used when no saved geometry exists) APP_VIEWPORT: str = "1000x700"