From df8f92966517920d3998c2144e94a979e7cb2461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Thu, 1 Feb 2024 19:28:05 +0800 Subject: [PATCH] feat: + move remove_white_spaces --- metagpt/repo_parser.py | 19 +++---------------- metagpt/utils/common.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/metagpt/repo_parser.py b/metagpt/repo_parser.py index 72d7f87d5..d4d455c5d 100644 --- a/metagpt/repo_parser.py +++ b/metagpt/repo_parser.py @@ -23,7 +23,7 @@ from pydantic import BaseModel, Field, field_validator from metagpt.const import AGGREGATION, COMPOSITION, GENERALIZATION from metagpt.logs import logger -from metagpt.utils.common import any_to_str, aread +from metagpt.utils.common import any_to_str, aread, remove_white_spaces from metagpt.utils.exceptions import handle_exception @@ -117,7 +117,7 @@ class DotClassAttribute(BaseModel): type_ = val[cix + 1 : eix] default_ = val[eix + 1 :].strip() - type_ = cls.remove_white_spaces(type_) # remove white space + type_ = remove_white_spaces(type_) # remove white space if type_ == "NoneType": type_ = "" if "Literal[" in type_: @@ -133,19 +133,6 @@ class DotClassAttribute(BaseModel): compositions = cls.parse_compositions(composition_val) return cls(name=name, type_=type_, default_=default_, description=v, compositions=compositions) - @staticmethod - def remove_white_spaces(v: str): - """ - Removes white spaces from the provided string, excluding spaces within quotes. - - Args: - v (str): The input string containing white spaces. - - Returns: - str: The input string with white spaces removed, excluding spaces within quotes. - """ - return re.sub(r"(? List[str]: """ @@ -320,7 +307,7 @@ class DotReturn(BaseModel): """ if not v: return DotReturn(description=v) - type_ = DotClassAttribute.remove_white_spaces(v) + type_ = remove_white_spaces(v) compositions = DotClassAttribute.parse_compositions(type_) return cls(type_=type_, description=v, compositions=compositions) diff --git a/metagpt/utils/common.py b/metagpt/utils/common.py index 9f3232c09..3537e76f0 100644 --- a/metagpt/utils/common.py +++ b/metagpt/utils/common.py @@ -603,3 +603,16 @@ def list_files(root: str | Path) -> List[Path]: def parse_json_code_block(markdown_text: str) -> List[str]: json_blocks = re.findall(r"```json(.*?)```", markdown_text, re.DOTALL) return [v.strip() for v in json_blocks] + + +def remove_white_spaces(v: str) -> str: + """ + Removes white spaces from the provided string, excluding spaces within quotes. + + Args: + v (str): The input string containing white spaces. + + Returns: + str: The input string with white spaces removed, excluding spaces within quotes. + """ + return re.sub(r"(?