From 89f8fe141e38d108e0396ae0a70fc86f7856cd0c Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Thu, 29 Jan 2026 13:02:04 +0800 Subject: [PATCH] Update plugin and code generation subprocess output (#1048) --- .gitignore | 1 + .../code_generator/utils/format_code.py | 6 +-- backend/plugin/requirements.py | 43 ++++++++----------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 842ccec7..81b7630e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ venv/ .pytest_cache/ .claude/ .serena/ +.agents/ diff --git a/backend/plugin/code_generator/utils/format_code.py b/backend/plugin/code_generator/utils/format_code.py index 6cb71245..2e614afb 100644 --- a/backend/plugin/code_generator/utils/format_code.py +++ b/backend/plugin/code_generator/utils/format_code.py @@ -25,10 +25,10 @@ async def format_python_code(code: str) -> str: 'ruff', 'format', str(temp_file), - stdout=asyncio.subprocess.PIPE, - stderr=asyncio.subprocess.PIPE, + stdout=asyncio.subprocess.DEVNULL, + stderr=asyncio.subprocess.DEVNULL, ) - await process.communicate() + await process.wait() if process.returncode == 0: async with await open_file(temp_file, encoding='utf-8') as f: diff --git a/backend/plugin/requirements.py b/backend/plugin/requirements.py index ab89966e..52f3cce7 100644 --- a/backend/plugin/requirements.py +++ b/backend/plugin/requirements.py @@ -57,32 +57,25 @@ def install_requirements(plugin: str | None) -> None: # noqa: C901 missing_dependencies = True if missing_dependencies: - try: - pip_install = ['uv', 'pip', 'install', '-r', requirements_file] - if not _is_in_virtualenv(): - pip_install.append('--system') - if settings.PLUGIN_PIP_CHINA: - pip_install.extend(['-i', settings.PLUGIN_PIP_INDEX_URL]) + pip_install = ['uv', 'pip', 'install', '-r', requirements_file] + if not _is_in_virtualenv(): + pip_install.append('--system') + if settings.PLUGIN_PIP_CHINA: + pip_install.extend(['-i', settings.PLUGIN_PIP_INDEX_URL]) - max_retries = settings.PLUGIN_PIP_MAX_RETRY - for attempt in range(max_retries): - try: - subprocess.check_call( - pip_install, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - ) - break - except subprocess.TimeoutExpired: - if attempt == max_retries - 1: - raise PluginInstallError(f'插件 {plugin} 依赖安装超时') - continue - except subprocess.CalledProcessError as e: - if attempt == max_retries - 1: - raise PluginInstallError(f'插件 {plugin} 依赖安装失败:{e}') from e - continue - except subprocess.CalledProcessError as e: - raise PluginInstallError(f'插件 {plugin} 依赖安装失败:{e}') from e + max_retries = settings.PLUGIN_PIP_MAX_RETRY + for attempt in range(max_retries): + try: + subprocess.check_call(pip_install) + break + except subprocess.TimeoutExpired: + if attempt == max_retries - 1: + raise PluginInstallError(f'插件 {plugin} 依赖安装超时') + continue + except subprocess.CalledProcessError as e: + if attempt == max_retries - 1: + raise PluginInstallError(f'插件 {plugin} 依赖安装失败:{e}') from e + continue def uninstall_requirements(plugin: str) -> None: