mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-21 00:05:36 +02:00
- Add default instances to all nested config classes (TorrentConfig, NotificationConfig, IndexerConfig, MetadataProviderConfig, AuthConfig) - Add default values to AllEncompassingConfig fields to prevent validation errors during testing - Update GitHub workflow to copy config.example.toml before running tests - Ensures tests can run without requiring complete configuration files while maintaining production functionality Fixes test collection errors where pydantic validation failed due to missing required config sections.
81 lines
2.6 KiB
Python
81 lines
2.6 KiB
Python
import os
|
|
from pathlib import Path
|
|
from typing import Type, Tuple
|
|
|
|
from pydantic import AnyHttpUrl
|
|
from pydantic_settings import (
|
|
BaseSettings,
|
|
SettingsConfigDict,
|
|
PydanticBaseSettingsSource,
|
|
TomlConfigSettingsSource,
|
|
)
|
|
|
|
from media_manager.auth.config import AuthConfig
|
|
from media_manager.database.config import DbConfig
|
|
from media_manager.indexer.config import IndexerConfig
|
|
from media_manager.metadataProvider.config import MetadataProviderConfig
|
|
from media_manager.notification.config import NotificationConfig
|
|
from media_manager.torrent.config import TorrentConfig
|
|
|
|
config_path = os.getenv("CONFIG_FILE")
|
|
|
|
if config_path is None:
|
|
# Default to config folder approach
|
|
config_dir = os.getenv("CONFIG_DIR", "/app/config")
|
|
config_path = Path(config_dir) / "config.toml"
|
|
else:
|
|
config_path = Path(config_path)
|
|
|
|
|
|
class LibraryItem(BaseSettings):
|
|
name: str
|
|
path: str
|
|
|
|
|
|
class BasicConfig(BaseSettings):
|
|
image_directory: Path = Path(__file__).parent.parent / "images"
|
|
tv_directory: Path = Path(__file__).parent.parent / "data" / "tv"
|
|
movie_directory: Path = Path(__file__).parent.parent / "data" / "movies"
|
|
torrent_directory: Path = Path(__file__).parent.parent / "data" / "torrents"
|
|
|
|
frontend_url: AnyHttpUrl = "http://localhost:3000/web/"
|
|
cors_urls: list[str] = []
|
|
development: bool = False
|
|
|
|
tv_libraries: list[LibraryItem] = []
|
|
movie_libraries: list[LibraryItem] = []
|
|
|
|
|
|
class AllEncompassingConfig(BaseSettings):
|
|
model_config = SettingsConfigDict(
|
|
toml_file=config_path, case_sensitive=False, env_nested_delimiter="__"
|
|
)
|
|
"""
|
|
This class is used to load all configurations from the environment variables.
|
|
It combines the BasicConfig with any additional configurations needed.
|
|
"""
|
|
misc: BasicConfig = BasicConfig()
|
|
torrents: TorrentConfig = TorrentConfig()
|
|
notifications: NotificationConfig = NotificationConfig()
|
|
metadata: MetadataProviderConfig = MetadataProviderConfig()
|
|
indexers: IndexerConfig = IndexerConfig()
|
|
database: DbConfig = DbConfig()
|
|
auth: AuthConfig = AuthConfig()
|
|
|
|
@classmethod
|
|
def settings_customise_sources(
|
|
cls,
|
|
settings_cls: Type[BaseSettings],
|
|
init_settings: PydanticBaseSettingsSource,
|
|
env_settings: PydanticBaseSettingsSource,
|
|
dotenv_settings: PydanticBaseSettingsSource,
|
|
file_secret_settings: PydanticBaseSettingsSource,
|
|
) -> Tuple[PydanticBaseSettingsSource, ...]:
|
|
return (
|
|
init_settings,
|
|
env_settings,
|
|
dotenv_settings,
|
|
TomlConfigSettingsSource(settings_cls),
|
|
file_secret_settings,
|
|
)
|