Skip to content

Commit 47f8005

Browse files
committed
pre-commit
1 parent 723b377 commit 47f8005

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

baselines/commit0_utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import re
44
import subprocess
5+
from dataclasses import asdict
56
from pathlib import Path
67
from typing import List
78

@@ -210,12 +211,24 @@ def create_branch(repo: git.Repo, branch: str, from_commit: str) -> None:
210211
else:
211212
repo.git.checkout(from_commit)
212213
repo.git.checkout("-b", branch)
213-
except git.exc.GitCommandError as e:
214+
except git.exc.GitCommandError as e: # type: ignore
214215
raise RuntimeError(f"Failed to create or switch to branch '{branch}': {e}")
215216

216217

217218
def args2string(agent_config: AgentConfig) -> str:
218-
from dataclasses import asdict
219+
"""Converts specific fields from an `AgentConfig` object into a formatted string.
220+
221+
Args:
222+
----
223+
agent_config (AgentConfig): A dataclass object containing configuration
224+
options for an agent.
225+
226+
Returns:
227+
-------
228+
str: A string representing the selected key-value pairs from the `AgentConfig`
229+
object, joined by double underscores.
230+
231+
"""
219232
arg_dict = asdict(agent_config)
220233
result_list = []
221234
keys_to_collect = ["model_name", "run_tests", "use_lint_info", "use_spec_info"]
@@ -227,5 +240,5 @@ def args2string(agent_config: AgentConfig) -> str:
227240
else:
228241
value = "0"
229242
result_list.append(f"{key}-{value}")
230-
concatenated_string = '__'.join(result_list)
243+
concatenated_string = "__".join(result_list)
231244
return concatenated_string

baselines/run_agent.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ def run_agent_for_repo(
5959
repo_path = os.path.abspath(repo_path)
6060
try:
6161
local_repo = Repo(repo_path)
62-
except Exception as e:
63-
raise Exception(f"{repo_path} is not a git repo. Check if base_dir is correctly specified.")
62+
except Exception:
63+
raise Exception(
64+
f"{repo_path} is not a git repo. Check if base_dir is correctly specified."
65+
)
6466

6567
target_edit_files = get_target_edit_files(repo_path)
6668

@@ -79,7 +81,7 @@ def run_agent_for_repo(
7981
# set it back to commit 0
8082
# TODO: ask user for permission
8183
if latest_commit.hexsha != example["base_commit"]:
82-
local_repo.git.reset('--hard', example["base_commit"])
84+
local_repo.git.reset("--hard", example["base_commit"])
8385

8486
with DirContext(repo_path):
8587
if commit0_config is None or agent_config is None:

commit0/__main__.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,28 @@ def main() -> None:
6969
repo_or_repo_path = sys.argv[2]
7070
if command == "test-reference":
7171
if len(sys.argv) < 4:
72-
raise ValueError(f"An argument is missing for commit0 test-reference.\nUsage: commit0 test-reference {{repo_dir}} {{test_ids}}")
72+
raise ValueError(
73+
"An argument is missing for commit0 test-reference.\nUsage: commit0 test-reference {repo_dir} {test_ids}"
74+
)
7375
elif len(sys.argv) > 4:
74-
raise ValueError(f"Too many arguments are passed to commit0 test-reference.\nUsage: commit0 test-reference {{repo_dir}} {{test_ids}}")
76+
raise ValueError(
77+
"Too many arguments are passed to commit0 test-reference.\nUsage: commit0 test-reference {repo_dir} {test_ids}"
78+
)
7579
branch = "reference"
7680
test_ids = sys.argv[3]
7781
else:
7882
if len(sys.argv) < 5:
79-
raise ValueError(f"An argument is missing for commit0 test.\nUsage: commit0 test {{repo_dir}} {{branch}} {{test_ids}}")
83+
raise ValueError(
84+
"An argument is missing for commit0 test.\nUsage: commit0 test {repo_dir} {branch} {test_ids}"
85+
)
8086
elif len(sys.argv) > 5:
81-
raise ValueError(f"Too many arguments are passed to commit0 test.\nUsage: commit0 test {{repo_dir}} {{branch}} {{test_ids}}")
87+
raise ValueError(
88+
"Too many arguments are passed to commit0 test.\nUsage: commit0 test {repo_dir} {branch} {test_ids}"
89+
)
8290
branch = sys.argv[3]
8391
test_ids = sys.argv[4]
8492
if branch.startswith("branch="):
85-
branch = branch[len("branch="):]
93+
branch = branch[len("branch=") :]
8694
commit0.harness.run_pytest_ids.main(
8795
config.dataset_name,
8896
config.dataset_split,
@@ -98,15 +106,23 @@ def main() -> None:
98106
elif command == "evaluate" or command == "evaluate-reference":
99107
if command == "evaluate-reference":
100108
if len(sys.argv) < 3:
101-
raise ValueError(f"An argument is missing for commit0 evaluate-reference.\nUsage: commit0 evaluate-reference {{repo_split}}")
109+
raise ValueError(
110+
"An argument is missing for commit0 evaluate-reference.\nUsage: commit0 evaluate-reference {repo_split}"
111+
)
102112
elif len(sys.argv) > 3:
103-
raise ValueError(f"Too many arguments are passed to commit0 evaluate-reference.\nUsage: commit0 evaluate-reference {{repo_split}}")
113+
raise ValueError(
114+
"Too many arguments are passed to commit0 evaluate-reference.\nUsage: commit0 evaluate-reference {repo_split}"
115+
)
104116
branch = "reference"
105117
else:
106118
if len(sys.argv) < 4:
107-
raise ValueError(f"An argument is missing for commit0 evaluate.\nUsage: commit0 evaluate {{repo_split}} {{branch}}")
119+
raise ValueError(
120+
"An argument is missing for commit0 evaluate.\nUsage: commit0 evaluate {repo_split} {branch}"
121+
)
108122
elif len(sys.argv) > 4:
109-
raise ValueError(f"Too many arguments are passed to commit0 evaluate.\nUsage: commit0 evaluate {{repo_split}} {{branch}}")
123+
raise ValueError(
124+
"Too many arguments are passed to commit0 evaluate.\nUsage: commit0 evaluate {repo_split} {branch}"
125+
)
110126
branch = sys.argv[3]
111127
commit0.harness.evaluate.main(
112128
config.dataset_name,

commit0/harness/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main(
2626
continue
2727
clone_url = f"https://github.com/{example['repo']}.git"
2828
clone_dir = os.path.abspath(os.path.join(base_dir, repo_name))
29-
local_repo = clone_repo(clone_url, clone_dir, example["base_commit"], logger)
29+
clone_repo(clone_url, clone_dir, example["base_commit"], logger)
3030

3131

3232
__all__ = []

0 commit comments

Comments
 (0)