mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor(config): retire RuntimeSettingsCompat host usage
This commit is contained in:
@@ -13,9 +13,7 @@ from app.runtime.capabilities.model import (
|
||||
SelectorSchema,
|
||||
)
|
||||
from app.runtime.capabilities.registry import CapabilityRegistry
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.settings import get_runtime_setting, has_runtime_setting
|
||||
from app.runtime.extensions.service_config import ServiceConfigHelper
|
||||
from app.schemas.types import (
|
||||
DownloaderType,
|
||||
@@ -63,7 +61,7 @@ class HostModuleConfigSnapshot:
|
||||
def _validate_setting_selector(config: Mapping[str, Any]) -> None:
|
||||
"""限制 setting selector 只能读取已声明的应用设置。"""
|
||||
key = config["key"]
|
||||
if not isinstance(key, str) or not key or not hasattr(settings, key):
|
||||
if not isinstance(key, str) or not key or not has_runtime_setting(key):
|
||||
raise ValueError(f"未知应用设置:{key!r}")
|
||||
|
||||
|
||||
@@ -176,7 +174,7 @@ def capture_host_module_config(
|
||||
service_keys.add(key)
|
||||
|
||||
setting_values = {
|
||||
key: getattr(settings, key)
|
||||
key: get_runtime_setting(key)
|
||||
for key in sorted(setting_keys)
|
||||
}
|
||||
service_values = {
|
||||
|
||||
@@ -12,9 +12,7 @@ from app.runtime.capabilities.model import (
|
||||
CapabilitySpec,
|
||||
)
|
||||
from app.runtime.capabilities.runtime import CapabilityRuntime
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
from app.runtime.events import Event, EventHandlerBinding, eventmanager
|
||||
from app.runtime.extensions.host_module_adapter import (
|
||||
HOST_MODULE_KIND,
|
||||
@@ -259,7 +257,7 @@ class ModuleManager(metaclass=Singleton):
|
||||
if not setting:
|
||||
return True
|
||||
switch, value = setting
|
||||
option = getattr(settings, switch)
|
||||
option = get_runtime_setting(switch)
|
||||
if not option:
|
||||
return False
|
||||
if value is True:
|
||||
|
||||
@@ -7,12 +7,10 @@ from collections.abc import Callable, Mapping
|
||||
from typing import Any, Optional
|
||||
|
||||
from app.foundation.version import compare_version
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.extensions.plugin.contracts import supports_plugin_hook
|
||||
from app.runtime.extensions.plugin.storage import PluginStorage
|
||||
from app.runtime.extensions.plugin.system import PluginSystemServices
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
from app.schemas.plugin import Plugin, PluginInstance, PluginRuntimeStatus
|
||||
from app.schemas.types import SystemConfigKey
|
||||
|
||||
@@ -56,12 +54,15 @@ class PluginCatalogFacade:
|
||||
|
||||
def online(self, force: bool = False) -> list[Plugin]:
|
||||
"""读取所有兼容代际的在线插件目录。"""
|
||||
if not settings.PLUGIN_MARKET:
|
||||
plugin_market = get_runtime_setting('PLUGIN_MARKET')
|
||||
if not plugin_market:
|
||||
return []
|
||||
markets = [item for item in settings.PLUGIN_MARKET.split(",") if item]
|
||||
markets = [item for item in plugin_market.split(",") if item]
|
||||
result = self._market_catalog().collect(
|
||||
markets=markets,
|
||||
compatible_flags=self._system().compatible_flags(settings.VERSION_FLAG),
|
||||
compatible_flags=self._system().compatible_flags(
|
||||
get_runtime_setting('VERSION_FLAG')
|
||||
),
|
||||
force=force,
|
||||
loader=self._market_loader,
|
||||
)
|
||||
@@ -224,14 +225,17 @@ class PluginCatalogFacade:
|
||||
progress_callback: Optional[Callable[..., None]] = None,
|
||||
) -> list[Plugin]:
|
||||
"""异步读取所有兼容代际的在线插件目录。"""
|
||||
if not settings.PLUGIN_MARKET:
|
||||
plugin_market = get_runtime_setting('PLUGIN_MARKET')
|
||||
if not plugin_market:
|
||||
if progress_callback:
|
||||
progress_callback(value=100, text="未配置插件市场,跳过刷新")
|
||||
return []
|
||||
markets = [item for item in settings.PLUGIN_MARKET.split(",") if item]
|
||||
markets = [item for item in plugin_market.split(",") if item]
|
||||
result = await self._market_catalog().async_collect(
|
||||
markets=markets,
|
||||
compatible_flags=self._system().compatible_flags(settings.VERSION_FLAG),
|
||||
compatible_flags=self._system().compatible_flags(
|
||||
get_runtime_setting('VERSION_FLAG')
|
||||
),
|
||||
force=force,
|
||||
loader=self._async_market_loader,
|
||||
progress_callback=progress_callback,
|
||||
@@ -254,7 +258,8 @@ class PluginCatalogFacade:
|
||||
|
||||
def merge(self, higher: list[Plugin], base: list[Plugin]) -> list[Plugin]:
|
||||
"""合并不同代际插件目录并保留市场优先级。"""
|
||||
markets = [item for item in settings.PLUGIN_MARKET.split(",") if item]
|
||||
plugin_market = get_runtime_setting('PLUGIN_MARKET')
|
||||
markets = [item for item in plugin_market.split(",") if item]
|
||||
return self._market_catalog().merge(higher, base, markets)
|
||||
|
||||
def _safe_state(self, plugin_id: str, plugin: Any) -> bool:
|
||||
|
||||
@@ -29,10 +29,9 @@ from app.foundation.version import compare_version
|
||||
from app.runtime.execution import run_in_threadpool_to_completion
|
||||
from app.runtime.log import logger
|
||||
from app.runtime.observability import observe_compat_facade
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
from app.runtime.thread import ThreadHelper
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.events import EventHandlerBinding, eventmanager
|
||||
from app.runtime.reload import ConfigReloadMixin
|
||||
from app.runtime.extensions.plugin.loader import PluginLoader
|
||||
@@ -215,10 +214,10 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
self._monitor_suppression_lock = threading.Lock()
|
||||
self._suppressed_monitor_plugins: Dict[str, int] = {}
|
||||
self._plugin_paths = PluginPathResolver(
|
||||
runtime_root=settings.ROOT_PATH / "app" / "plugins",
|
||||
runtime_root=get_runtime_setting('ROOT_PATH') / "app" / "plugins",
|
||||
running=lambda: self._running_plugins,
|
||||
system=get_plugin_system,
|
||||
strict_system_version=lambda: not settings.DEV,
|
||||
strict_system_version=lambda: not get_runtime_setting('DEV'),
|
||||
log=logger,
|
||||
)
|
||||
self._local_plugin_sync = LocalPluginSyncService(
|
||||
@@ -248,7 +247,7 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
log=logger,
|
||||
)
|
||||
self._plugin_loader = PluginLoader(
|
||||
plugins_root=settings.ROOT_PATH / "app" / "plugins",
|
||||
plugins_root=get_runtime_setting('ROOT_PATH') / "app" / "plugins",
|
||||
import_preparer=lambda **kwargs: _legacy_plugin_import_preparer(**kwargs),
|
||||
import_scanner=lambda **kwargs: _legacy_import_scanner(**kwargs),
|
||||
log=logger,
|
||||
@@ -384,7 +383,7 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
with self.mutation("启动插件"):
|
||||
with self._plugin_quiesce_lock:
|
||||
_legacy_diagnostics_configurator(
|
||||
enabled=settings.DEBUG,
|
||||
enabled=get_runtime_setting('DEBUG'),
|
||||
emitter=logger.warning,
|
||||
)
|
||||
gil_enabled_before = is_gil_enabled()
|
||||
@@ -564,7 +563,7 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
:return: 插件类列表
|
||||
"""
|
||||
return PluginLoader(
|
||||
plugins_root=settings.ROOT_PATH / "app" / "plugins",
|
||||
plugins_root=get_runtime_setting('ROOT_PATH') / "app" / "plugins",
|
||||
import_preparer=lambda **kwargs: _legacy_plugin_import_preparer(**kwargs),
|
||||
import_scanner=lambda **kwargs: _legacy_import_scanner(**kwargs),
|
||||
log=logger,
|
||||
@@ -624,7 +623,10 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
return
|
||||
if (
|
||||
not self.is_plugin_settling()
|
||||
and (settings.DEV or settings.PLUGIN_AUTO_RELOAD)
|
||||
and (
|
||||
get_runtime_setting('DEV')
|
||||
or get_runtime_setting('PLUGIN_AUTO_RELOAD')
|
||||
)
|
||||
):
|
||||
self._plugin_monitor.start()
|
||||
|
||||
@@ -635,7 +637,10 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
self._plugin_monitor.reload(
|
||||
enabled=(
|
||||
not self.is_plugin_settling()
|
||||
and (settings.DEV or settings.PLUGIN_AUTO_RELOAD)
|
||||
and (
|
||||
get_runtime_setting('DEV')
|
||||
or get_runtime_setting('PLUGIN_AUTO_RELOAD')
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -652,7 +657,7 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
运行 watchfiles 监视器的主循环。
|
||||
"""
|
||||
PluginChangeMonitor(
|
||||
runtime_root=settings.ROOT_PATH / "app" / "plugins",
|
||||
runtime_root=get_runtime_setting('ROOT_PATH') / "app" / "plugins",
|
||||
local_roots=get_plugin_system().local_repo_paths,
|
||||
stop_event=self._plugin_monitor.stop_event,
|
||||
recent_sync=self._recent_local_sync,
|
||||
@@ -812,7 +817,7 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
"""
|
||||
|
||||
return PluginLoader(
|
||||
plugins_root=settings.ROOT_PATH / "app" / "plugins",
|
||||
plugins_root=get_runtime_setting('ROOT_PATH') / "app" / "plugins",
|
||||
import_preparer=lambda **kwargs: _legacy_plugin_import_preparer(**kwargs),
|
||||
import_scanner=lambda **kwargs: _legacy_import_scanner(**kwargs),
|
||||
log=logger,
|
||||
|
||||
Reference in New Issue
Block a user