mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor: add dynamic runtime settings compatibility proxy
This commit is contained in:
@@ -11,6 +11,24 @@ RuntimeSettingProvider = Callable[[str], Any]
|
||||
_provider: RuntimeSettingProvider | None = None
|
||||
|
||||
|
||||
class RuntimeSettingsCompat:
|
||||
"""为旧模块级 Settings 访问提供动态 runtime 配置代理。"""
|
||||
|
||||
def __getattr__(self, key: str) -> Any:
|
||||
"""读取当前组合根配置;未装配时沿用旧 Settings 回退。"""
|
||||
return get_runtime_setting(key)
|
||||
|
||||
def __setattr__(self, key: str, value: Any) -> None:
|
||||
"""把旧模块级覆盖同步到 legacy Settings,保持测试和插件注入语义。"""
|
||||
legacy_settings = importlib.import_module("app.runtime.config").settings
|
||||
setattr(legacy_settings, key, value)
|
||||
|
||||
def __delattr__(self, key: str) -> None:
|
||||
"""删除旧模块级覆盖,使配置对象恢复其原有属性解析。"""
|
||||
legacy_settings = importlib.import_module("app.runtime.config").settings
|
||||
delattr(legacy_settings, key)
|
||||
|
||||
|
||||
def configure_runtime_setting_provider(provider: RuntimeSettingProvider) -> None:
|
||||
"""由启动组合根登记配置读取器,保持适配器只依赖 runtime 端口。"""
|
||||
global _provider
|
||||
|
||||
Reference in New Issue
Block a user