Skip to content

Commit 8f2a1a7

Browse files
committed
fix small display error and update get file method
1 parent 9f57083 commit 8f2a1a7

File tree

4 files changed

+111
-25
lines changed

4 files changed

+111
-25
lines changed

agent/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,24 @@ python baselines/run_aider.py
3737
- `max_unit_tests_info_length`: Max length of unit tests info. Default: `10000`.
3838
- `max_reference_info_length`: Max length of reference info. Default: `10000`.
3939
- `max_lint_info_length`: Max length of lint info. Default: `10000`.
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
Error Section
51+
52+
53+
54+
Running the agent
55+
56+
Run with Tmux!
57+
58+
process_max_worker set to 3....
59+
60+
currently not handling file with more than 1500 lines...

agent/agent_utils.py

Lines changed: 82 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,93 @@ def get_file_info(file_path: Path, prefix: str = "") -> str:
119119
return "\n".join(filter(None, tree_string))
120120

121121

122-
def get_target_edit_files(target_dir: str, src_prefix: str) -> list[str]:
122+
def collect_test_files(directory: str) -> list[str]:
123+
"""Collect all the test files in the directory."""
124+
test_files = []
125+
subdirs = []
126+
127+
# Walk through the directory
128+
for root, dirs, files in os.walk(directory):
129+
if root.endswith("/"):
130+
root = root[:-1]
131+
# Check if 'test' is part of the folder name
132+
if (
133+
"test" in os.path.basename(root).lower()
134+
or os.path.basename(root) in subdirs
135+
):
136+
for file in files:
137+
# Process only Python files
138+
if file.endswith(".py"):
139+
file_path = os.path.join(root, file)
140+
test_files.append(file_path)
141+
for d in dirs:
142+
subdirs.append(d)
143+
144+
return test_files
145+
146+
147+
def collect_python_files(directory: str) -> list[str]:
148+
"""List to store all the .py filenames"""
149+
python_files = []
150+
151+
# Walk through the directory recursively
152+
for root, _, files in os.walk(directory):
153+
for file in files:
154+
# Check if the file ends with '.py'
155+
if file.endswith(".py"):
156+
file_path = os.path.join(root, file)
157+
python_files.append(file_path)
158+
159+
return python_files
160+
161+
162+
def _find_files_to_edit(base_dir: str, src_dir: str, test_dir: str) -> list[str]:
163+
"""Identify files to remove content by heuristics.
164+
We assume source code is under [lib]/[lib] or [lib]/src.
165+
We exclude test code. This function would not work
166+
if test code doesn't have its own directory.
167+
168+
Args:
169+
----
170+
base_dir (str): The path to local library.
171+
src_dir (str): The directory containing source code.
172+
test_dir (str): The directory containing test code.
173+
174+
Returns:
175+
-------
176+
list[str]: A list of files to be edited.
177+
178+
"""
179+
files = collect_python_files(os.path.join(base_dir, src_dir))
180+
test_files = collect_test_files(os.path.join(base_dir, test_dir))
181+
files = list(set(files) - set(test_files))
182+
183+
# don't edit __init__ files
184+
files = [f for f in files if "__init__" not in f]
185+
# don't edit __main__ files
186+
files = [f for f in files if "__main__" not in f]
187+
# don't edit confest.py files
188+
files = [f for f in files if "conftest.py" not in f]
189+
return files
190+
191+
192+
def get_target_edit_files(target_dir: str, src_dir: str, test_dir: str) -> list[str]:
123193
"""Find the files with functions with the pass statement."""
124-
files = []
125-
for root, _, filenames in os.walk(target_dir):
126-
for filename in filenames:
127-
if filename.endswith(".py"):
128-
file_path = os.path.join(root, filename)
129-
with open(file_path, "r", encoding="utf-8", errors="ignore") as file:
130-
if " pass" in file.read():
131-
files.append(file_path)
194+
files = _find_files_to_edit(target_dir, src_dir, test_dir)
195+
filtered_files = []
196+
for file_path in files:
197+
with open(file_path, "r", encoding="utf-8", errors="ignore") as file:
198+
content = file.read()
199+
if len(content.splitlines()) < 1500:
200+
filtered_files.append(file_path)
132201

133202
# Remove the base_dir prefix
134-
files = [file.replace(target_dir, "").lstrip("/") for file in files]
135-
files = [src_prefix + file for file in files]
203+
filtered_files = [
204+
file.replace(target_dir, "").lstrip("/") for file in filtered_files
205+
]
136206
# Only keep python files
137-
files = [file for file in files if file.endswith(".py")]
138207

139-
return files
208+
return filtered_files
140209

141210

142211
def get_message(

agent/run_agent.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,15 @@ def run_agent_for_repo(
6161
original_repo_name = repo_name
6262
update_queue.put(("start_repo", (original_repo_name, 0)))
6363

64-
repo_name = repo_name.lower()
65-
repo_name = repo_name.replace(".", "-")
64+
# repo_name = repo_name.lower()
65+
# repo_name = repo_name.replace(".", "-")
6666

6767
repo_path = os.path.join(repo_base_dir, repo_name)
6868
repo_path = os.path.abspath(repo_path)
6969

70-
# TODO: remove this to make web3.py work
71-
if repo_name == "web3-py":
72-
repo_path = repo_path.replace("web3-py", "web3.py")
73-
74-
src_dir = os.path.join(repo_path, example["src_dir"])
70+
# # TODO: remove this to make web3.py work
71+
# if repo_name == "web3-py":
72+
# repo_path = repo_path.replace("web3-py", "web3.py")
7573

7674
try:
7775
local_repo = Repo(repo_path)
@@ -121,7 +119,7 @@ def run_agent_for_repo(
121119
raise ValueError("Invalid input")
122120

123121
target_edit_files = get_target_edit_files(
124-
src_dir, src_prefix=example["src_dir"]
122+
repo_path, example["src_dir"], example["test"]["test_dir"]
125123
)
126124

127125
if agent_config.run_tests:
@@ -133,7 +131,7 @@ def run_agent_for_repo(
133131
# when unit test feedback is available, iterate over test files
134132
for test_file in test_files:
135133
update_queue.put(("set_current_file", (repo_name, test_file)))
136-
test_cmd = f"python -m commit0 test {repo_path} {test_file} --branch {branch} --backend {backend} --commit0_dot_file_path {commit0_dot_file_path}"
134+
test_cmd = f"python -m commit0 test {repo_path} {test_file} --branch {branch} --backend {backend} --commit0-dot-file-path {commit0_dot_file_path}"
137135
test_file_name = test_file.replace(".py", "").replace("/", "__")
138136
test_log_dir = experiment_log_dir / test_file_name
139137
lint_cmd = get_lint_cmd(repo_name, agent_config.use_lint_info)

agent/run_agent_no_rich.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ def run_agent_for_repo(
6060
repo_path = os.path.join(repo_base_dir, repo_name)
6161
repo_path = os.path.abspath(repo_path)
6262

63-
src_dir = os.path.join(repo_path, example["src_dir"])
64-
6563
try:
6664
local_repo = Repo(repo_path)
6765
except Exception:
@@ -109,7 +107,7 @@ def run_agent_for_repo(
109107
raise ValueError("Invalid input")
110108

111109
target_edit_files = get_target_edit_files(
112-
src_dir, src_prefix=example["src_dir"]
110+
repo_path, example["src_dir"], example["test"]["test_dir"]
113111
)
114112

115113
if agent_config.run_tests:

0 commit comments

Comments
 (0)