feat: load version dynamically from pyproject.toml

- 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 <noreply@anthropic.com>
This commit is contained in:
2025-12-11 21:34:23 +01:00
co-authored by Claude Opus 4.5
parent ebac19ba6e
commit 09e468e7f8
2 changed files with 39 additions and 2 deletions
+1 -1
View File
@@ -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/
+38 -1
View File
@@ -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")