From 97f1226d8c801ab06b70875a7feb398b49f1556c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=85=E8=AF=BA=E7=8B=90?= <212194964+foxcyber907@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:03:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BE=9D=E8=B5=96=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin_system/utils/dependency_config.py | 27 ------------------ src/plugin_system/utils/dependency_manager.py | 28 ++++--------------- template/bot_config_template.toml | 9 ------ 3 files changed, 5 insertions(+), 59 deletions(-) diff --git a/src/plugin_system/utils/dependency_config.py b/src/plugin_system/utils/dependency_config.py index e52883432..ee3cd18b9 100644 --- a/src/plugin_system/utils/dependency_config.py +++ b/src/plugin_system/utils/dependency_config.py @@ -47,22 +47,6 @@ class DependencyConfig: return config.dependency_management.mirror_url return "" - @property - def use_proxy(self) -> bool: - """是否使用网络代理""" - config = self._get_config() - if config and hasattr(config, 'dependency_management'): - return config.dependency_management.use_proxy - return False - - @property - def proxy_url(self) -> str: - """网络代理URL""" - config = self._get_config() - if config and hasattr(config, 'dependency_management'): - return config.dependency_management.proxy_url - return "" - @property def install_timeout(self) -> int: """安装超时时间(秒)""" @@ -71,17 +55,6 @@ class DependencyConfig: return config.dependency_management.auto_install_timeout return 300 - @property - def pip_options(self) -> list: - """pip安装选项""" - config = self._get_config() - if config and hasattr(config, 'dependency_management'): - return config.dependency_management.pip_options - return [ - "--no-warn-script-location", - "--disable-pip-version-check" - ] - @property diff --git a/src/plugin_system/utils/dependency_manager.py b/src/plugin_system/utils/dependency_manager.py index a4e0e7b57..ceb0d7d18 100644 --- a/src/plugin_system/utils/dependency_manager.py +++ b/src/plugin_system/utils/dependency_manager.py @@ -19,15 +19,13 @@ class DependencyManager: 负责检查和自动安装插件的Python包依赖 """ - def __init__(self, auto_install: bool = True, use_mirror: bool = False, mirror_url: Optional[str] = None, use_proxy: bool = False, proxy_url: Optional[str] = None): + def __init__(self, auto_install: bool = True, use_mirror: bool = False, mirror_url: Optional[str] = None): """初始化依赖管理器 Args: auto_install: 是否自动安装缺失的依赖 use_mirror: 是否使用PyPI镜像源 mirror_url: PyPI镜像源URL - use_proxy: 是否使用网络代理 - proxy_url: 网络代理URL """ # 延迟导入配置以避免循环依赖 try: @@ -38,20 +36,14 @@ class DependencyManager: self.auto_install = config.auto_install if auto_install is True else auto_install self.use_mirror = config.use_mirror if use_mirror is False else use_mirror self.mirror_url = config.mirror_url if mirror_url is None else mirror_url - self.use_proxy = config.use_proxy if use_proxy is False else use_proxy - 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() except Exception as e: logger.warning(f"无法加载依赖配置,使用默认设置: {e}") self.auto_install = auto_install self.use_mirror = use_mirror or False self.mirror_url = mirror_url or "" - self.use_proxy = use_proxy - self.proxy_url = proxy_url or "" self.install_timeout = 300 - self.pip_options = ["--no-warn-script-location", "--disable-pip-version-check"] def check_dependencies(self, dependencies: Any, plugin_name: str = "") -> Tuple[bool, List[str], List[str]]: """检查依赖包是否满足要求 @@ -240,19 +232,11 @@ class DependencyManager: try: cmd = [sys.executable, "-m", "pip", "install", package] - # 添加镜像源设置(优先) + # 添加镜像源设置 if self.use_mirror and self.mirror_url: cmd.extend(["-i", self.mirror_url]) logger.debug(f"[Plugin:{plugin_name}] 使用PyPI镜像源: {self.mirror_url}") - # 添加代理设置 - if self.use_proxy and self.proxy_url: - cmd.extend(["--proxy", self.proxy_url]) - logger.debug(f"[Plugin:{plugin_name}] 使用网络代理: {self.proxy_url}") - - # 添加配置的pip选项 - cmd.extend(self.pip_options) - logger.debug(f"[Plugin:{plugin_name}] 执行安装命令: {' '.join(cmd)}") result = subprocess.run( @@ -289,13 +273,11 @@ def get_dependency_manager() -> DependencyManager: return _global_dependency_manager -def configure_dependency_manager(auto_install: bool = True, use_mirror: bool = False, mirror_url: Optional[str] = None, use_proxy: bool = False, proxy_url: Optional[str] = None): +def configure_dependency_manager(auto_install: bool = True, use_mirror: bool = False, mirror_url: Optional[str] = None): """配置全局依赖管理器""" global _global_dependency_manager _global_dependency_manager = DependencyManager( auto_install=auto_install, use_mirror=use_mirror, - mirror_url=mirror_url, - use_proxy=use_proxy, - proxy_url=proxy_url - ) \ No newline at end of file + mirror_url=mirror_url + ) \ No newline at end of file diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index 134f642e0..ed08d2382 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -268,15 +268,6 @@ auto_install_timeout = 300 use_mirror = true mirror_url = "https://pypi.tuna.tsinghua.edu.cn/simple" # PyPI镜像源URL,如: "https://pypi.tuna.tsinghua.edu.cn/simple" -# 是否使用网络代理(高级选项) -use_proxy = false -proxy_url = "" # 网络代理URL,如: "http://proxy.example.com:8080" - -# pip安装选项 -pip_options = [ - "--no-warn-script-location", - "--disable-pip-version-check" -] # 安装前是否提示用户(暂未实现) prompt_before_install = false