From f9c1751aae6a9aa37df4f881ca690d1332e8b204 Mon Sep 17 00:00:00 2001 From: Alberto Gaona Date: Fri, 15 Sep 2023 10:37:01 -0600 Subject: [PATCH] Add label to identify devtale generated docstrings (#54) --- cli.py | 6 ++++-- devtale/constants.py | 2 ++ devtale/utils.py | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cli.py b/cli.py index f164753..ff5d41b 100644 --- a/cli.py +++ b/cli.py @@ -13,7 +13,7 @@ PHPAggregator, PythonAggregator, ) -from devtale.constants import ALLOWED_EXTENSIONS, LANGUAGES +from devtale.constants import ALLOWED_EXTENSIONS, DOCSTRING_LABEL, LANGUAGES from devtale.utils import ( build_project_tree, extract_code_elements, @@ -350,7 +350,9 @@ def process_file( logger.info("add dev tale summary") summaries = split_text(str(code_elements_dict["summary"]), chunk_size=9000) - tale["file_docstring"] = redact_tale_information("top-level", summaries)["text"] + tale["file_docstring"] = ( + DOCSTRING_LABEL + "\n" + redact_tale_information("top-level", summaries)["text"] + ) logger.info(f"save dev tale in: {save_path}") with open(save_path, "w") as json_file: diff --git a/devtale/constants.py b/devtale/constants.py index 07bc7e5..c769d9c 100644 --- a/devtale/constants.py +++ b/devtale/constants.py @@ -10,3 +10,5 @@ ".go": Language.GO, ".js": Language.JS, } + +DOCSTRING_LABEL = "@DEVTALE-GENERATED:" diff --git a/devtale/utils.py b/devtale/utils.py index feb277c..16bc198 100644 --- a/devtale/utils.py +++ b/devtale/utils.py @@ -9,6 +9,7 @@ from langchain.output_parsers import PydanticOutputParser from langchain.text_splitter import RecursiveCharacterTextSplitter +from devtale.constants import DOCSTRING_LABEL from devtale.schema import FileDocumentation from devtale.templates import ( CODE_EXTRACTOR_TEMPLATE, @@ -186,6 +187,9 @@ def fuse_tales(tales_list, code, code_elements_dict): class_name, code, code_elements_dict["classes"] ): unique_classes.add(class_name) + class_info["class_docstring"] = ( + DOCSTRING_LABEL + "\n" + class_info["class_docstring"] + ) fused_tale["classes"].append(class_info) else: if tale not in errors: @@ -199,6 +203,9 @@ def fuse_tales(tales_list, code, code_elements_dict): method_name, code, code_elements_dict["methods"] ): unique_methods.add(method_name) + method_info["method_docstring"] = ( + DOCSTRING_LABEL + "\n" + method_info["method_docstring"] + ) fused_tale["methods"].append(method_info) else: if tale not in errors: