From 9c9ec8adf2b856d83614eb322918085723a5ce88 Mon Sep 17 00:00:00 2001 From: Aqr-K <95741669+Aqr-K@users.noreply.github.com> Date: Wed, 3 Sep 2025 14:13:32 +0800 Subject: [PATCH] feat(plugin): Implement robust dependency installation with embedded wheels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 通过在插件中嵌入轮子来支持安装依赖项 --- app/helper/plugin.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/helper/plugin.py b/app/helper/plugin.py index 00be523c..7f001a4a 100644 --- a/app/helper/plugin.py +++ b/app/helper/plugin.py @@ -459,6 +459,17 @@ class PluginHelper(metaclass=WeakSingleton): :param requirements_file: 依赖的 requirements.txt 文件路径 :return: (是否成功, 错误信息) """ + wheels_dir = requirements_file.parent / "wheels" + + find_links_option = [] + if wheels_dir.is_dir(): + # 如果目录存在,增加 --find-links 选项 + logger.debug(f"[PIP] 发现插件内嵌的 wheels 目录: {wheels_dir},将优先从本地安装。") + find_links_option = ["--find-links", str(wheels_dir)] + else: + # 如果不存在,选项为空列表,对后续命令无影响 + logger.debug(f"[PIP] 未发现插件内嵌的 wheels 目录,将仅使用在线源。") + base_cmd = [sys.executable, "-m", "pip", "install", "-r", str(requirements_file)] strategies = []