增加了版本号系统

This commit is contained in:
yml2213
2026-06-25 09:38:54 +08:00
parent f21f82cbed
commit e94b37c602
9 changed files with 131 additions and 22 deletions
+23
View File
@@ -0,0 +1,23 @@
"""应用版本信息。"""
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"