mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
fix: 增加插件 V3t 运行时兼容门禁 (#6475)
* fix(plugin): enforce declared runtime compatibility * chore(ci): record plugin runtime compatibility edges --------- Co-authored-by: jxxghp <jxxghp@gmail.com>
This commit is contained in:
Vendored
+5
@@ -32,6 +32,7 @@ from importlib.metadata import distributions
|
||||
from requests import Response
|
||||
|
||||
from app.runtime.cache import cached, is_fresh
|
||||
from app.foundation.environment import is_free_threaded_runtime
|
||||
from app.runtime.dependencies import (
|
||||
iter_runtime_profile_requirement_strings,
|
||||
iter_runtime_requirement_strings,
|
||||
@@ -369,6 +370,8 @@ class PluginHelper(metaclass=WeakSingleton):
|
||||
"""
|
||||
if not isinstance(plugin_info, dict):
|
||||
return False
|
||||
if is_free_threaded_runtime() and plugin_info.get("v3t") is False:
|
||||
return False
|
||||
if not get_runtime_setting('VERSION_FLAG'):
|
||||
return True
|
||||
current_flag = get_runtime_setting('VERSION_FLAG')
|
||||
@@ -397,6 +400,8 @@ class PluginHelper(metaclass=WeakSingleton):
|
||||
"""
|
||||
if not isinstance(plugin_info, dict):
|
||||
return False
|
||||
if is_free_threaded_runtime() and plugin_info.get("v3t") is False:
|
||||
return False
|
||||
current_flag = get_runtime_setting('VERSION_FLAG')
|
||||
if not current_flag:
|
||||
return not package_version
|
||||
|
||||
@@ -20,6 +20,7 @@ from app.application.plugin.source import (
|
||||
PluginMarketCandidate,
|
||||
normalize_package_generation,
|
||||
)
|
||||
from app.foundation.environment import is_free_threaded_runtime
|
||||
|
||||
PLUGIN_V3_GENERATIONS = ("v3", "v2", "v1")
|
||||
PluginIndex: TypeAlias = Mapping[str, Mapping[str, Any]]
|
||||
@@ -383,6 +384,8 @@ def _is_v3_compatible(
|
||||
"""按宿主 V3、兼容 V2、基础索引顺序判断候选兼容性。"""
|
||||
if plugin_info.get("v3") is False:
|
||||
return False
|
||||
if is_free_threaded_runtime() and plugin_info.get("v3t") is False:
|
||||
return False
|
||||
if package_generation in {"v3", "v2"}:
|
||||
return True
|
||||
return plugin_info.get("v3") is True or plugin_info.get("v2") is True
|
||||
|
||||
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import importlib.util
|
||||
import json
|
||||
import sys
|
||||
import threading
|
||||
import traceback
|
||||
@@ -11,6 +12,8 @@ from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional
|
||||
|
||||
from app.foundation.environment import is_free_threaded_runtime
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
from app.schemas.plugin import PluginInstance
|
||||
|
||||
|
||||
@@ -73,6 +76,11 @@ class PluginLoader:
|
||||
f"跳过插件目录:{plugin_dir.name}(缺少__init__.py)"
|
||||
)
|
||||
continue
|
||||
if not self._is_runtime_compatible(plugin_dir):
|
||||
self._logger.warning(
|
||||
f"跳过插件 {plugin_dir.name}:声明与当前运行时不兼容"
|
||||
)
|
||||
continue
|
||||
|
||||
try:
|
||||
module_name = f"app.plugins.{plugin_dir.name}"
|
||||
@@ -115,6 +123,11 @@ class PluginLoader:
|
||||
f"虚拟插件实例 {instance.instance_id} 的源码不存在:{source_dir}"
|
||||
)
|
||||
return []
|
||||
if not self._is_runtime_compatible(source_dir):
|
||||
self._logger.warning(
|
||||
f"跳过虚拟插件实例 {instance.instance_id}:声明与当前运行时不兼容"
|
||||
)
|
||||
return []
|
||||
|
||||
module_name = f"app.plugins.{instance.instance_id.lower()}"
|
||||
self.clear_modules(instance.instance_id)
|
||||
@@ -161,6 +174,21 @@ class PluginLoader:
|
||||
)
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def _is_runtime_compatible(plugin_dir: Path) -> bool:
|
||||
"""按载荷自身 package 声明执行运行时兼容门禁,缺失声明时保持兼容。"""
|
||||
package_file = plugin_dir / "package.json"
|
||||
try:
|
||||
package = json.loads(package_file.read_text(encoding="utf-8"))
|
||||
except (FileNotFoundError, OSError, UnicodeDecodeError, json.JSONDecodeError):
|
||||
return True
|
||||
if not isinstance(package, dict):
|
||||
return True
|
||||
version_flag = get_runtime_setting("VERSION_FLAG")
|
||||
if version_flag and package.get(version_flag) is False:
|
||||
return False
|
||||
return not (is_free_threaded_runtime() and package.get("v3t") is False)
|
||||
|
||||
def _execute_instance_module(
|
||||
self,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user