"""应用版本信息。""" from functools import lru_cache from importlib.metadata import PackageNotFoundError, version as package_version from pathlib import Path import tomllib @lru_cache(maxsize=1) def get_app_version() -> str: """从 pyproject.toml 读取应用版本,读取失败时回退到包元数据。""" pyproject_path = Path(__file__).resolve().parents[2] / "pyproject.toml" if pyproject_path.exists(): with pyproject_path.open("rb") as file: pyproject = tomllib.load(file) version = pyproject.get("project", {}).get("version") if isinstance(version, str) and version: return version try: return package_version("douyu-login-py") except PackageNotFoundError: return "0.0.0"