"""Platform fetcher registry for data collection.""" from importlib import import_module from typing import Dict, Iterable, Optional, Type from .base import PlatformFetcher _PLATFORM_FETCHERS: Dict[str, Type[PlatformFetcher]] = {} def register_platform(name: str): """Register a platform fetcher class by config/platform name.""" normalized = name.strip().lower() if not normalized: raise ValueError("Platform name must not be empty") def decorator(cls: Type[PlatformFetcher]) -> Type[PlatformFetcher]: _PLATFORM_FETCHERS[normalized] = cls return cls return decorator def get_platform_class(name: str) -> Optional[Type[PlatformFetcher]]: return _PLATFORM_FETCHERS.get((name or "").strip().lower()) def get_platform_fetcher(name: str) -> Optional[PlatformFetcher]: cls = get_platform_class(name) return cls() if cls else None def get_registered_platforms() -> Dict[str, Type[PlatformFetcher]]: return dict(_PLATFORM_FETCHERS) def discover_modules(module_names: Iterable[str]) -> None: for module_name in module_names: if module_name: import_module(module_name)