From d78bf618f9fde727877645b9933a900f0676d713 Mon Sep 17 00:00:00 2001 From: minecraft1024a Date: Wed, 13 Aug 2025 12:35:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BE=9D=E8=B5=96=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=85=8D=E7=BD=AE=EF=BC=8C=E7=A7=BB=E9=99=A4=E4=B8=8D?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E7=9A=84`allowed=5Fauto=5Finstall`=E9=80=89?= =?UTF-8?q?=E9=A1=B9=EF=BC=8C=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3=E4=BB=A5?= =?UTF-8?q?=E6=9B=B4=E6=B8=85=E6=99=B0=E5=9C=B0=E6=8F=8F=E8=BF=B0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=AE=89=E8=A3=85=E5=8A=9F=E8=83=BD=E7=9A=84=E4=B8=BB?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E3=80=82=E8=B0=83=E6=95=B4=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BB=A5=E7=AE=80=E5=8C=96=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E8=87=AA=E5=8A=A8=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E8=A1=8C=E4=B8=BA=E9=80=9A=E8=BF=87=E5=8D=95=E4=B8=80=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=8E=A7=E5=88=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/plugins/dependency-management.md | 9 +++------ src/config/official_configs.py | 5 +---- src/plugin_system/utils/dependency_config.py | 8 +------- src/plugin_system/utils/dependency_manager.py | 4 +--- template/bot_config_template.toml | 5 +---- 5 files changed, 7 insertions(+), 24 deletions(-) diff --git a/docs/plugins/dependency-management.md b/docs/plugins/dependency-management.md index d558c6703..2f07d8821 100644 --- a/docs/plugins/dependency-management.md +++ b/docs/plugins/dependency-management.md @@ -69,7 +69,7 @@ class MyPlugin(BasePlugin): ```toml [dependency_management] -# 是否启用自动安装 +# 是否启用自动安装(主开关) auto_install = true # 安装超时时间(秒) @@ -85,9 +85,6 @@ pip_options = [ "--disable-pip-version-check" ] -# 是否允许自动安装(主开关) -allowed_auto_install = true - # 安装前是否提示用户 prompt_before_install = false @@ -164,10 +161,10 @@ configure_dependency_settings(auto_install_timeout=600) ## 安全考虑 -- 自动安装功能默认启用,但可以通过配置禁用 +- 自动安装功能默认启用,但可以通过`auto_install=false`配置禁用 - 所有安装操作都有详细的日志记录 - 支持设置安装超时以避免长时间挂起 -- 可以通过`allowed_auto_install`全局禁用自动安装 +- 通过单一的`auto_install`开关控制所有自动安装行为 ## 故障排除 diff --git a/src/config/official_configs.py b/src/config/official_configs.py index 7b0c54f1d..b1a0d2dc8 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -871,7 +871,7 @@ class DependencyManagementConfig(ConfigBase): """插件Python依赖管理配置类""" auto_install: bool = True - """是否启用自动安装Python依赖包""" + """是否启用自动安装Python依赖包(主开关)""" auto_install_timeout: int = 300 """安装超时时间(秒)""" @@ -888,9 +888,6 @@ class DependencyManagementConfig(ConfigBase): ]) """pip安装选项""" - allowed_auto_install: bool = True - """是否允许自动安装(主开关),关闭后所有插件都不会自动安装依赖""" - prompt_before_install: bool = False """安装前是否提示用户(暂未实现)""" diff --git a/src/plugin_system/utils/dependency_config.py b/src/plugin_system/utils/dependency_config.py index 6d87ad6fb..8bc4c9d71 100644 --- a/src/plugin_system/utils/dependency_config.py +++ b/src/plugin_system/utils/dependency_config.py @@ -66,13 +66,7 @@ class DependencyConfig: "--disable-pip-version-check" ] - @property - def allowed_auto_install(self) -> bool: - """是否允许自动安装""" - config = self._get_config() - if config and hasattr(config, 'dependency_management'): - return config.dependency_management.allowed_auto_install - return True + @property def prompt_before_install(self) -> bool: diff --git a/src/plugin_system/utils/dependency_manager.py b/src/plugin_system/utils/dependency_manager.py index b51a54c0a..fb15a0b96 100644 --- a/src/plugin_system/utils/dependency_manager.py +++ b/src/plugin_system/utils/dependency_manager.py @@ -38,7 +38,6 @@ class DependencyManager: self.proxy_url = config.proxy_url if proxy_url is None else proxy_url self.install_timeout = config.install_timeout self.pip_options = config.pip_options.copy() - self.allowed_auto_install = config.allowed_auto_install except Exception as e: logger.warning(f"无法加载依赖配置,使用默认设置: {e}") @@ -47,7 +46,6 @@ class DependencyManager: self.proxy_url = proxy_url self.install_timeout = 300 self.pip_options = ["--no-warn-script-location", "--disable-pip-version-check"] - self.allowed_auto_install = True def check_dependencies(self, dependencies: Any, plugin_name: str = "") -> Tuple[bool, List[str], List[str]]: """检查依赖包是否满足要求 @@ -98,7 +96,7 @@ class DependencyManager: if not packages: return True, [] - if not self.auto_install or not self.allowed_auto_install: + if not self.auto_install: logger.info(f"[Plugin:{plugin_name}] 自动安装已禁用,跳过安装: {packages}") return False, packages diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index 634161f28..3f227a018 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -255,7 +255,7 @@ suppress_libraries = ["faiss","httpx", "urllib3", "asyncio", "websockets", "http library_log_levels = { "aiohttp" = "WARNING"} # 设置特定库的日志级别 [dependency_management] # 插件Python依赖管理配置 -# 是否启用自动安装Python依赖包 +# 是否启用自动安装Python依赖包(主开关) auto_install = true # 安装超时时间(秒) @@ -271,9 +271,6 @@ pip_options = [ "--disable-pip-version-check" ] -# 是否允许自动安装(主开关),关闭后所有插件都不会自动安装依赖 -allowed_auto_install = true - # 安装前是否提示用户(暂未实现) prompt_before_install = false