diff --git a/app/services/startup_notification_service.py b/app/services/startup_notification_service.py index a9ac5248..fc7d26aa 100644 --- a/app/services/startup_notification_service.py +++ b/app/services/startup_notification_service.py @@ -5,7 +5,6 @@ """ import logging -import os from datetime import datetime from typing import Final @@ -24,7 +23,6 @@ from app.utils.timezone import format_local_datetime logger = logging.getLogger(__name__) # Константы -VERSION_ENV_VAR: Final[str] = 'VERSION' DEFAULT_VERSION: Final[str] = 'dev' DEFAULT_AUTH_TYPE: Final[str] = 'api_key' @@ -70,10 +68,20 @@ class StartupNotificationService: self.enabled = getattr(settings, 'ADMIN_NOTIFICATIONS_ENABLED', False) def _get_version(self) -> str: - """Получает версию из переменной окружения VERSION.""" - version = os.getenv(VERSION_ENV_VAR, '').strip() - if version: - return version + """Получает версию из pyproject.toml.""" + try: + from pathlib import Path + + pyproject_path = Path(__file__).resolve().parents[2] / 'pyproject.toml' + if pyproject_path.exists(): + for line in pyproject_path.read_text().splitlines(): + if line.strip().startswith('version'): + ver = line.split('=', 1)[1].strip().strip('"').strip("'") + if ver: + return ver + except Exception: + pass + return DEFAULT_VERSION async def _get_users_count(self) -> int: diff --git a/app/services/version_service.py b/app/services/version_service.py index 11aee2db..63f1dff5 100644 --- a/app/services/version_service.py +++ b/app/services/version_service.py @@ -82,16 +82,18 @@ class VersionService: return 'UNKNOW' def _get_current_version(self) -> str: - import os + try: + from pathlib import Path - current = os.getenv('VERSION', '').strip() - - if current: - if '-' in current and current.startswith('v'): - base_version = current.split('-')[0] - if base_version.count('.') == 2: - return base_version - return current + pyproject_path = Path(__file__).resolve().parents[2] / 'pyproject.toml' + if pyproject_path.exists(): + for line in pyproject_path.read_text().splitlines(): + if line.strip().startswith('version'): + ver = line.split('=', 1)[1].strip().strip('"').strip("'") + if ver: + return ver + except Exception: + pass return 'UNKNOW'