From dcb0623d462b8e29a00fd3b1db2dca3e53336c62 Mon Sep 17 00:00:00 2001 From: mannaandpoem <1580466765@qq.com> Date: Fri, 2 Feb 2024 14:59:16 +0800 Subject: [PATCH 1/2] 1. Dev compatible with windows path 2. add @pytest.mark.skip --- metagpt/utils/dependency_file.py | 3 ++- tests/metagpt/test_incremental_dev.py | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/metagpt/utils/dependency_file.py b/metagpt/utils/dependency_file.py index c8b3bc4a4..9ecead244 100644 --- a/metagpt/utils/dependency_file.py +++ b/metagpt/utils/dependency_file.py @@ -96,7 +96,8 @@ class DependencyFile: key = Path(filename).relative_to(root) except ValueError: key = filename - return set(self._dependencies.get(str(key), {})) + key = re.sub(r"\\+", "/", str(key)) + return set(self._dependencies.get(key, {})) def delete_file(self): """Delete the dependency file.""" diff --git a/tests/metagpt/test_incremental_dev.py b/tests/metagpt/test_incremental_dev.py index 964d4c757..92001a5d1 100644 --- a/tests/metagpt/test_incremental_dev.py +++ b/tests/metagpt/test_incremental_dev.py @@ -45,6 +45,7 @@ PROJECT_NAMES = [ ] +@pytest.mark.skip def test_simple_add_calculator(): result = get_incremental_dev_result(IDEAS[0], PROJECT_NAMES[0]) log_and_check_result(result) @@ -115,8 +116,11 @@ def get_incremental_dev_result(idea, project_name, use_review=True): if not project_path.exists(): # If the project does not exist, extract the project file try: - # Use the tar command to extract the .zip file - subprocess.run(["tar", "-xf", f"{project_path}.zip", "-C", str(project_path.parent)], check=True) + if os.name == "nt": + subprocess.run(["tar", "-xf", f"{project_path}.zip", "-C", str(project_path.parent)], check=True) + else: + subprocess.run(["unzip", f"{project_path}.zip", "-d", str(project_path.parent)], check=True) + logger.info(f"Extracted project {project_name} successfully.") except subprocess.CalledProcessError as e: # If the extraction fails, throw an exception raise Exception(f"Failed to extract project {project_name}. Error: {e}") From 5edee1299c058caaf477ef35884f8c112db5f21b Mon Sep 17 00:00:00 2001 From: mannaandpoem <1580466765@qq.com> Date: Fri, 2 Feb 2024 15:37:00 +0800 Subject: [PATCH 2/2] compatible with windows path --- metagpt/utils/dependency_file.py | 5 ++--- tests/metagpt/test_incremental_dev.py | 10 ++++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/metagpt/utils/dependency_file.py b/metagpt/utils/dependency_file.py index 9ecead244..65ccd118d 100644 --- a/metagpt/utils/dependency_file.py +++ b/metagpt/utils/dependency_file.py @@ -93,11 +93,10 @@ class DependencyFile: root = self._filename.parent try: - key = Path(filename).relative_to(root) + key = Path(filename).relative_to(root).as_posix() except ValueError: key = filename - key = re.sub(r"\\+", "/", str(key)) - return set(self._dependencies.get(key, {})) + return set(self._dependencies.get(str(key), {})) def delete_file(self): """Delete the dependency file.""" diff --git a/tests/metagpt/test_incremental_dev.py b/tests/metagpt/test_incremental_dev.py index 92001a5d1..c47397dd7 100644 --- a/tests/metagpt/test_incremental_dev.py +++ b/tests/metagpt/test_incremental_dev.py @@ -6,6 +6,7 @@ @File : test_incremental_dev.py """ import os +import shutil import subprocess import time @@ -116,13 +117,14 @@ def get_incremental_dev_result(idea, project_name, use_review=True): if not project_path.exists(): # If the project does not exist, extract the project file try: - if os.name == "nt": - subprocess.run(["tar", "-xf", f"{project_path}.zip", "-C", str(project_path.parent)], check=True) - else: + if shutil.which("unzip"): subprocess.run(["unzip", f"{project_path}.zip", "-d", str(project_path.parent)], check=True) + elif shutil.which("tar"): + subprocess.run(["tar", "-xf", f"{project_path}.zip", "-C", str(project_path.parent)], check=True) logger.info(f"Extracted project {project_name} successfully.") + except FileNotFoundError as e: + raise FileNotFoundError(f"Neither 'unzip' nor 'tar' command found. Error: {e}") except subprocess.CalledProcessError as e: - # If the extraction fails, throw an exception raise Exception(f"Failed to extract project {project_name}. Error: {e}") check_or_create_base_tag(project_path)