From 09e468e7f8c9f40962504cf63285f341633cf6fe Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Thu, 11 Dec 2025 21:34:23 +0100 Subject: [PATCH] feat: load version dynamically from pyproject.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add _get_version_from_pyproject() function to config.py - APP_VERSION now uses default_factory to load from pyproject.toml - Add pyproject.toml to Docker build for version detection - Add LIBRARY_DESK configuration settings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- Dockerfile | 2 +- src/core/config.py | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index faf674e..67ad11a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /app RUN apt-get update && apt-get install -y curl \ && rm -rf /var/lib/apt/lists/* -COPY requirements.txt . +COPY requirements.txt pyproject.toml ./ RUN pip install --no-cache-dir -r requirements.txt COPY src/ ./src/ diff --git a/src/core/config.py b/src/core/config.py index c2ecabc..0321290 100644 --- a/src/core/config.py +++ b/src/core/config.py @@ -4,11 +4,34 @@ Following best practice of splitting config across domains. """ from enum import Enum from functools import lru_cache +from pathlib import Path from pydantic import Field, HttpUrl from pydantic_settings import BaseSettings, SettingsConfigDict +def _get_version_from_pyproject() -> str: + """ + Load version from pyproject.toml. + + Falls back to "unknown" if file cannot be read. + """ + try: + # Find pyproject.toml relative to this file + config_dir = Path(__file__).parent + pyproject_path = config_dir.parent.parent / "pyproject.toml" + + if pyproject_path.exists(): + content = pyproject_path.read_text() + for line in content.splitlines(): + if line.strip().startswith("version"): + # Parse: version = "1.0.0" + return line.split("=", 1)[1].strip().strip('"').strip("'") + except Exception: + pass + return "unknown" + + class Environment(str, Enum): """Application environment.""" DEVELOPMENT = "development" @@ -32,7 +55,7 @@ class Config(BaseSettings): # Application APP_NAME: str = "OpenAI-Compatible API" - APP_VERSION: str = "0.2.5" + APP_VERSION: str = Field(default_factory=_get_version_from_pyproject) ENVIRONMENT: Environment = Environment.DEVELOPMENT DEBUG: bool = Field(default=False, description="Debug mode") @@ -87,6 +110,20 @@ class Config(BaseSettings): description="Redis connection timeout in seconds" ) + # Library-Desk Configuration (The Librarian backend) + LIBRARY_DESK_HOST: HttpUrl = Field( + default="http://localhost:8089", + description="Library-Desk API URL" + ) + LIBRARY_DESK_API_KEY: str = Field( + default="", + description="API key for Library-Desk authentication" + ) + LIBRARY_DESK_TIMEOUT: int = Field( + default=60, + description="Library-Desk request timeout in seconds" + ) + # Logging LOG_LEVEL: str = Field(default="INFO", description="Logging level") ENABLE_BENCHMARKS: bool = Field(default=True, description="Enable performance benchmarking")