Rework Tagger fork into Curator movie-library manager (PySide6 GUI, pool index, ČSFD import)
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
"""
|
||||
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`).
|
||||
|
||||
Note: per-feature constants (window size, tag colors, …) live in
|
||||
`src/core/constants.py`; this module is only the version/debug surface used by
|
||||
the build tooling and frozen builds.
|
||||
"""
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user