Skip to content

Commit 0bf63d3

Browse files
committed
refactor: streamline configuration variable access
- Replace YAML-based configuration handling with pydantic-settings and TOML for enhanced reliability and ease of use. - Refactor file path operations to use pathlib.Path, adopting a more modern and object-oriented approach. - Rebuild the CLI entry point using Click to improve maintainability and user experience. - Version bumped to 0.1.0 to mark the significant updates in configuration management and CLI design.
1 parent 660a3e1 commit 0bf63d3

28 files changed

+422
-541
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 忽略私人配置文件,包含有api_key等信息
2-
config private.yml
3-
private.yml
2+
config private.toml
3+
private.toml
44

55
# Byte-compiled / optimized / DLL files
66
__pycache__/
@@ -181,4 +181,5 @@ prompt_output/
181181
log.txt
182182
.chroma_db
183183
config.yml
184+
config.toml
184185
.pre-commit-config.yaml

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ repo_path: /path/to/your/repo
104104
project_hierarchy: .project_hierarchy # This is a folder, where we store the project hierarchy and metainfo. This can be shared with your team members.
105105
Markdown_Docs_folder: Markdown_Docs # The folder in the root directory of your target repository to store the documentation.
106106
ignore_list: ["ignore_file1.py", "ignore_file2.py", "ignore_directory"] # Ignore some py files or folders that you don't want to generate documentation for by giving relative paths in ignore_list.
107-
whitelist_path: /path/of/whitelist_path_json #if you provide the whitelist json with the same structure in Metainfo, RepoAgent will only process the given part. This is useful in a very big project, like "higgingface Transformers"
108107
109108
language: en # Two-letter language codes (ISO 639-1 codes), e.g. `language: en` for English. Refer to Supported Language for more languages.
110109
max_thread_count: 10 # We support multiprocessing to speedup the process

config.yml.template

Lines changed: 0 additions & 51 deletions
This file was deleted.

pdm.lock

Lines changed: 92 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ authors = [
33
{name = "Qinyu Luo", email = "qinyuluo123@gmail.com"},
44
]
55
maintainers = [
6-
{name = "Arno Edwards", email = "Arno.Edwards@outlook.com"},
6+
{name = "Edwards Arno", email = "Edwards.Arno@outlook.com"},
77
]
88
license = {text = "Apache-2.0"}
99
requires-python = ">=3.10,<4.0"
@@ -24,15 +24,15 @@ dependencies = [
2424
"tomli-w>=1.0.0",
2525
]
2626
name = "repoagent"
27-
version = "0.0.6"
27+
version = "0.1.0"
2828
description = "An Agent designed to offer an intelligent approach for generating project documentation."
2929
readme = "README.md"
3030

3131
[project.urls]
3232
repository = "https://github.com/LOGIC-10/RepoAgent"
3333

3434
[project.scripts]
35-
repoagent = "repo_agent.main:app"
35+
repoagent = "repo_agent.main:cli"
3636

3737
[tool.pdm]
3838
[tool.pdm.dev-dependencies]

repo_agent/__main__.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,4 @@
1-
import os
2-
import sys
1+
from .main import cli
32

4-
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) #修改当前工作目录
5-
6-
from repo_agent.runner import Runner, delete_fake_files
7-
from repo_agent.log import logger
8-
from repo_agent.config import CONFIG
9-
from repo_agent.doc_meta_info import MetaInfo, DocItem
10-
from repo_agent.utils.meta_info_utils import make_fake_files, delete_fake_files
11-
12-
if len(sys.argv) == 1:
13-
runner = Runner()
14-
runner.run()
15-
logger.info("文档任务完成。")
16-
elif len(sys.argv) == 2:
17-
if sys.argv[1] == "clean":
18-
delete_fake_files()
19-
elif sys.argv[1] == "print":
20-
runner = Runner()
21-
runner.meta_info.target_repo_hierarchical_tree.print_recursive()
22-
elif sys.argv[1] == "diff":
23-
runner = Runner()
24-
if runner.meta_info.in_generation_process: # 如果不是在生成过程中,就开始检测变更
25-
print("this command only support pre-check")
26-
exit()
27-
file_path_reflections, jump_files = make_fake_files()
28-
new_meta_info = MetaInfo.init_meta_info(file_path_reflections, jump_files)
29-
new_meta_info.load_doc_from_older_meta(runner.meta_info)
30-
delete_fake_files()
31-
32-
ignore_list = CONFIG.get("ignore_list", [])
33-
DocItem.check_has_task(new_meta_info.target_repo_hierarchical_tree, ignore_list)
34-
if new_meta_info.target_repo_hierarchical_tree.has_task:
35-
print("the following docs will be generated/updated:")
36-
new_meta_info.target_repo_hierarchical_tree.print_recursive(diff_status = True, ignore_list = ignore_list)
37-
else:
38-
print("no docs will be generated/updated, check your source-code update")
3+
if __name__ == "__main__":
4+
cli()

repo_agent/change_detector.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import git
2-
import re, os
1+
import os
2+
import re
33
import subprocess
4+
5+
import git
46
from colorama import Fore, Style
57

6-
from repo_agent.config import CONFIG
78
from repo_agent.file_handler import FileHandler
9+
from repo_agent.settings import setting
810

911

1012
class ChangeDetector:
@@ -166,7 +168,7 @@ def get_to_be_staged_files(self):
166168
print(f"{Fore.LIGHTYELLOW_EX}target_repo_path{Style.RESET_ALL}: {self.repo_path}")
167169
print(f"{Fore.LIGHTMAGENTA_EX}already_staged_files{Style.RESET_ALL}:{staged_files}")
168170

169-
project_hierarchy = CONFIG["project_hierarchy"]
171+
project_hierarchy = setting.project.hierarchy_name
170172
# diffs是所有未暂存更改文件的列表。这些更改文件是相对于工作区(working directory)的,也就是说,它们是自上次提交(commit)以来在工作区发生的更改,但还没有被添加到暂存区(staging area)
171173
# 比如原本存在的md文件现在由于代码的变更发生了更新,就会标记为未暂存diff
172174
diffs = self.repo.index.diff(None)
@@ -178,7 +180,7 @@ def get_to_be_staged_files(self):
178180
# 处理untrack_files中的内容
179181
for untracked_file in untracked_files:
180182
# 连接repo_path和untracked_file以获取完整的绝对路径
181-
if untracked_file.startswith(CONFIG["Markdown_Docs_folder"]):
183+
if untracked_file.startswith(setting.project.markdown_docs_name):
182184
to_be_staged_files.append(untracked_file)
183185
continue
184186
print(f"rel_untracked_file:{rel_untracked_file}")
@@ -187,7 +189,7 @@ def get_to_be_staged_files(self):
187189
if rel_untracked_file.endswith(".md"):
188190
# 把rel_untracked_file从CONFIG['Markdown_Docs_folder']中拆离出来。判断是否能跟暂存区中的某一个.py文件对应上
189191
rel_untracked_file = os.path.relpath(
190-
rel_untracked_file, CONFIG["Markdown_Docs_folder"]
192+
rel_untracked_file, setting.project.markdown_docs_name
191193
)
192194
corresponding_py_file = os.path.splitext(rel_untracked_file)[0] + ".py"
193195
print(
@@ -198,7 +200,7 @@ def get_to_be_staged_files(self):
198200
to_be_staged_files.append(
199201
os.path.join(
200202
self.repo_path.lstrip("/"),
201-
CONFIG["Markdown_Docs_folder"],
203+
setting.project.markdown_docs_name,
202204
rel_untracked_file,
203205
)
204206
)
@@ -211,7 +213,7 @@ def get_to_be_staged_files(self):
211213

212214
for unstaged_file in unstaged_files:
213215
# 连接repo_path和unstaged_file以获取完整的绝对路径
214-
if unstaged_file.startswith(CONFIG["Markdown_Docs_folder"]):
216+
if unstaged_file.startswith(setting.project.markdown_docs_name):
215217
# abs_unstaged_file = os.path.join(self.repo_path, unstaged_file)
216218
# # # 获取相对于仓库根目录的相对路径
217219
# # rel_unstaged_file = os.path.relpath(abs_unstaged_file, self.repo_path)
@@ -227,7 +229,7 @@ def get_to_be_staged_files(self):
227229
if unstaged_file.endswith(".md"):
228230
# 把rel_unstaged_file从CONFIG['Markdown_Docs_folder']中拆离出来。判断是否能跟暂存区中的某一个.py文件对应上
229231
rel_unstaged_file = os.path.relpath(
230-
rel_unstaged_file, CONFIG["Markdown_Docs_folder"]
232+
rel_unstaged_file, setting.project.markdown_docs_name
231233
)
232234
corresponding_py_file = os.path.splitext(rel_unstaged_file)[0] + ".py"
233235
print(f"corresponding_py_file:{corresponding_py_file}")
@@ -236,7 +238,7 @@ def get_to_be_staged_files(self):
236238
to_be_staged_files.append(
237239
os.path.join(
238240
self.repo_path.lstrip("/"),
239-
CONFIG["Markdown_Docs_folder"],
241+
setting.project.markdown_docs_name,
240242
rel_unstaged_file,
241243
)
242244
)

repo_agent/chat_engine.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import inspect
2+
import os
13
import sys
2-
import tiktoken
34
import time
4-
import inspect
5-
from repo_agent.log import logger
6-
from repo_agent.settings import setting, max_input_tokens_map
7-
from repo_agent.prompt import SYS_PROMPT, USR_PROMPT
5+
from dataclasses import dataclass
6+
7+
import tiktoken
8+
from openai import APIConnectionError, OpenAI
9+
810
from repo_agent.doc_meta_info import DocItem
911
from repo_agent.log import logger
10-
from openai import OpenAI, APIConnectionError
11-
from dataclasses import dataclass
12+
from repo_agent.prompt import SYS_PROMPT, USR_PROMPT
13+
from repo_agent.settings import max_input_tokens_map, setting
14+
1215

1316
def get_import_statements():
1417
source_lines = inspect.getsourcelines(sys.modules[__name__])[0]
@@ -255,7 +258,7 @@ def get_relationship_description(referencer_content, reference_letter):
255258
for k, v in max_input_tokens_map.items()
256259
if (v - max_tokens) > total_tokens
257260
} # 抽取出所有上下文长度大于当前总输入tokens的模型
258-
for model_name, max_input_length in larger_models:
261+
for model_name, max_input_length in larger_models.items():
259262
if max_input_length - max_tokens > total_tokens:
260263
try:
261264
# Attempt to make a request with the larger model

repo_agent/chat_with_repo/__init__.py

Whitespace-only changes.

repo_agent/chat_with_repo/gradio_interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import gradio as gr
22
import markdown
3+
34
from repo_agent.log import logger
45

56

0 commit comments

Comments
 (0)