From b4e09341b354d12d419977eb5907d310eb3d226a Mon Sep 17 00:00:00 2001 From: Arnaud Gelas Date: Thu, 18 Jan 2024 20:47:33 +0100 Subject: [PATCH 1/2] Stop generating unit test for non python files When trying to create a simple HelloWorld with test, metagpt creates test for README.md --- metagpt/roles/qa_engineer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metagpt/roles/qa_engineer.py b/metagpt/roles/qa_engineer.py index 0e323893e..45a1c7715 100644 --- a/metagpt/roles/qa_engineer.py +++ b/metagpt/roles/qa_engineer.py @@ -65,6 +65,8 @@ async def _write_test(self, message: Message) -> None: code_doc = await src_file_repo.get(filename) if not code_doc: continue + if not code_doc.filename.endswith(".py"): + continue test_doc = await tests_file_repo.get("test_" + code_doc.filename) if not test_doc: test_doc = Document( From 6a9bd4a3914b565e98b04752d11cc58ee1f4afe2 Mon Sep 17 00:00:00 2001 From: Arnaud Gelas Date: Thu, 18 Jan 2024 20:48:35 +0100 Subject: [PATCH 2/2] Do not try installing requirements if there are none Do not try running pip install -r requirements.txt if the file does not exist or is empty. It avoids seeing an error in the log. --- metagpt/actions/run_code.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/metagpt/actions/run_code.py b/metagpt/actions/run_code.py index 30b06f1a6..4a26e5137 100644 --- a/metagpt/actions/run_code.py +++ b/metagpt/actions/run_code.py @@ -16,6 +16,7 @@ class. """ import subprocess +from pathlib import Path from typing import Tuple from pydantic import Field @@ -152,11 +153,23 @@ def _install_via_subprocess(cmd, check, cwd, env): return subprocess.run(cmd, check=check, cwd=cwd, env=env) @staticmethod - def _install_dependencies(working_directory, env): + def _install_requirements(working_directory, env): + file_path = Path(working_directory) / "requirements.txt" + if not file_path.exists(): + return + if file_path.stat().st_size == 0: + return install_command = ["python", "-m", "pip", "install", "-r", "requirements.txt"] logger.info(" ".join(install_command)) RunCode._install_via_subprocess(install_command, check=True, cwd=working_directory, env=env) + @staticmethod + def _install_pytest(working_directory, env): install_pytest_command = ["python", "-m", "pip", "install", "pytest"] logger.info(" ".join(install_pytest_command)) RunCode._install_via_subprocess(install_pytest_command, check=True, cwd=working_directory, env=env) + + @staticmethod + def _install_dependencies(working_directory, env): + RunCode._install_requirements(working_directory, env) + RunCode._install_pytest(working_directory, env)