mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-11 00:01:55 +08:00
物理分身是早期实现:复制整个插件目录,再用字符串替换改写副本源码里的类名、
plugin_config_prefix 和联邦构建产物。虚拟实例接管后,分身不再复制目录,
由装载器改写类身份、按实例 ID 隔离配置与数据,这套改写器随之失去调用者。
求证依据(全仓 git grep,覆盖 app/、tests/、scripts/、docs/、skills/):
- PluginPackageManager.clone() 无任何生产调用者。分身的唯一生产路径是
POST /api/v1/plugin/clone/{plugin_id} -> PluginManager.clone_plugin()
-> PluginCloneService.clone(),后者只写 PluginInstance 记录与隔离配置,
不碰包适配器。clone() 也没有经 PluginSystemServices 暴露出去。
- clone() 的四个私有实现 _modify_plugin_files / _modify_python_file /
_modify_federation_files / _rename_federation_assets,消费者只有 clone()
自身与 PluginSystemServices 的同名透传。
- PluginSystemServices 的四个透传,消费者只有 PluginManager 的 _modify_* shim。
- PluginManager 的四个 shim 无任何调用者。动态可达性已单独排查:
全仓没有 getattr/字符串反射指向这些名字;app/runtime/compat/manifest.py
不登记它们的别名(只有 app.core.plugin -> 本模块的模块级映射);
app/sdk/ 不再导出;PluginManager 与 PluginPackageManager 都没有
__getattr__ 兜底,属性不存在即 AttributeError;官方插件基线
official-plugin-baseline.json 零命中。
- @observe_compat_facade("PluginManager") 只包装类上已存在的方法,
不会凭空合成属性,因此 shim 删除后 enforce_facade 再也匹配不到
notices.py 里那四条 key,登记随之成为不可达数据,一并删除。
替代路径:这四条弃用声明当初承诺的替代目标是
get_plugin_system().package._modify_*(),那是一次「门面搬到适配器」的
重定位登记,本次连同能力一起下线;分身能力本身的替代路径是虚拟实例
PluginCloneService.clone(),它已在生产链路上,见
docs/v2-to-v3-overview.md §3.6「不复制插件源码,也能保持各实例配置隔离」。
既有磁盘上的旧物理分身不受影响:卸载路径读取 is_clone 属性并调用
remove_plugin_package() 的逻辑原样保留,只是不再产生新的物理分身。
这是对已公告弃用 API(DeprecationStage.SILENT,since v3.0.0)的正式移除。
连带改动:
- package.py 的 import re 仅服务于 _modify_python_file,同步移除;模块
docstring 去掉「分身处理」。
- system.py 的 typing.cast 仅服务于被删透传,同步移除。
- tests/test_plugin_package_manager.py::test_clone_rewrites_python_and_federation_assets
是这套改写器的唯一测试,且只覆盖已无调用者的路径,随实现一并删除。
(删的是测试函数不是测试文件,tests/run.py 的分片装箱不变。)
- mypy 低水位随实现下降:app/runtime/extensions/plugin/manager.py 的
assignment 8->4(四个 shim 的 version/icon 参数 str = None)、
no-untyped-def 12->11(_rename_federation_assets 缺返回标注),
fixture 与 docs/refactor/optimization-checklist.md 的全量 mypy 计数
9,371 -> 9,366 同步更新。依赖、复杂度、ruff、并发等其余基线无变化。
Co-authored-by: jxxghp <jxxghp@gmail.com>
119 lines
3.9 KiB
Python
119 lines
3.9 KiB
Python
"""插件市场、包和依赖系统能力的运行时注入端口。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Callable
|
|
from pathlib import Path
|
|
from typing import Any, Optional
|
|
|
|
|
|
class PluginSystemServices:
|
|
"""保存由启动组合根注入的插件外部系统适配器。"""
|
|
|
|
def __init__(
|
|
self,
|
|
*,
|
|
market: Any,
|
|
package: Any,
|
|
dependency: Any,
|
|
dependency_manifest_status: Callable[[Path], Optional[bool]],
|
|
compatible_flags: Callable[[Optional[str]], list[str]],
|
|
frozen: Callable[[], bool],
|
|
install: Callable[..., tuple[bool, str]],
|
|
) -> None:
|
|
"""记录市场、包、安装 Gateway、依赖和代际兼容计算端口。"""
|
|
self.market = market
|
|
self.package = package
|
|
self.dependency = dependency
|
|
self.dependency_manifest_status = dependency_manifest_status
|
|
self.compatible_flags = compatible_flags
|
|
self.frozen = frozen
|
|
self.install = install
|
|
|
|
def local_repo_paths(self) -> list[Path]:
|
|
"""返回可监测的本地插件仓库路径。"""
|
|
return self.market.get_local_repo_paths()
|
|
|
|
def local_candidate(self, plugin_id: str, **kwargs: Any) -> Optional[dict]:
|
|
"""读取指定本地插件候选。"""
|
|
return self.market.get_local_candidate(plugin_id, **kwargs)
|
|
|
|
def local_candidates(self) -> dict[str, dict]:
|
|
"""读取全部本地插件候选。"""
|
|
return self.market.get_local_candidates()
|
|
|
|
def local_repo_url(
|
|
self,
|
|
plugin_id: str,
|
|
repo_path: Optional[object] = None,
|
|
package_version: Optional[str] = None,
|
|
) -> str:
|
|
"""构造本地插件来源标识。"""
|
|
return self.market.make_local_repo_url(
|
|
plugin_id,
|
|
repo_path,
|
|
package_version,
|
|
)
|
|
|
|
def annotate_system_version(self, plugin_info: dict) -> dict:
|
|
"""补充插件条目的主程序版本兼容信息。"""
|
|
return self.market.annotate_system_version(plugin_info)
|
|
|
|
def is_package_compatible(self, plugin_info: dict, package_version: str) -> bool:
|
|
"""判断插件条目是否兼容指定代际。"""
|
|
return self.market.is_package_compatible(plugin_info, package_version)
|
|
|
|
def is_frozen(self) -> bool:
|
|
"""判断当前宿主是否为不可写的冻结运行模式。"""
|
|
return self.frozen()
|
|
|
|
def install_plugin(
|
|
self,
|
|
*,
|
|
plugin_id: str,
|
|
repo_url: str | None,
|
|
package_version: str | None = None,
|
|
release_version: str | None = None,
|
|
force: bool = False,
|
|
local_sync: bool = False,
|
|
explicit_source: bool = False,
|
|
startup_token: object | None = None,
|
|
) -> tuple[bool, str]:
|
|
"""从同步运行时线程进入宿主唯一安装 Gateway。"""
|
|
return self.install(
|
|
plugin_id=plugin_id,
|
|
repo_url=repo_url,
|
|
package_version=package_version,
|
|
release_version=release_version,
|
|
force=force,
|
|
local_sync=local_sync,
|
|
explicit_source=explicit_source,
|
|
startup_token=startup_token,
|
|
)
|
|
|
|
def remove_plugin_package(self, plugin_id: str) -> bool:
|
|
"""通过唯一包事务 owner 删除插件物理目录。"""
|
|
return bool(self.package.remove_plugin(plugin_id))
|
|
|
|
|
|
_services: Optional[PluginSystemServices] = None
|
|
|
|
|
|
def configure_plugin_system(services: PluginSystemServices) -> None:
|
|
"""由启动组合根装配插件外部系统能力。"""
|
|
global _services
|
|
_services = services
|
|
|
|
|
|
def reset_plugin_system() -> None:
|
|
"""清除已装配服务,仅供隔离测试恢复进程状态。"""
|
|
global _services
|
|
_services = None
|
|
|
|
|
|
def get_plugin_system() -> PluginSystemServices:
|
|
"""返回已装配的插件外部系统端口。"""
|
|
if _services is None:
|
|
raise RuntimeError("插件外部系统服务尚未由启动组合根装配")
|
|
return _services
|