Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Improve handling of incorrect repo_path configs (#340)

Kilian Lieret76f058bec058
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index 1159ddcd..e40dadfd 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -62,7 +62,9 @@ class EnvironmentArguments(FrozenSerializable):
data_path: str
image_name: str
split: str = "dev"
- base_commit: Optional[str] = None # used only with data_path as url
+ # Specify a branch name or a commit hash to checkout before running the task.
+ # Only used when running over a single problem statement/issue.
+ base_commit: Optional[str] = None
container_name: Optional[str] = None
install_environment: bool = True
timeout: int = 35
diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.py
index 9eea8f9c..05217a84 100644
--- a/sweagent/environment/utils.py
+++ b/sweagent/environment/utils.py
@@ -577,18 +577,6 @@ def get_instances(
raise ValueError(msg)
return [instance_from_dict(x) for x in instances]
-
- # If file_path is a directory, attempt load from disk
- if os.path.isdir(file_path):
- try:
- dataset_or_dict = load_from_disk(file_path)
- if isinstance(dataset_or_dict, dict):
- return postproc_instance_list(dataset_or_dict[split])
- return postproc_instance_list(dataset_or_dict)
- except FileNotFoundError:
- # Raised by load_from_disk if the directory is not a dataset directory
- pass
-
# The next if statement is very brittle logic to determine if we're processing a single instance
if file_path.startswith("text://") or (Path(file_path).is_file() and Path(file_path).suffix in ['.md', '.txt']) or is_github_issue_url(file_path):
ib = InstanceBuilder(token=token)
@@ -602,8 +590,24 @@ def get_instances(
return [ib.build()]
- if base_commit is not None:
- raise ValueError("base_commit must be None if data_path is not a github issue url")
+ if base_commit:
+ msg = "base_commit must be empty if running over multiple problem statements"
+ raise ValueError(msg)
+
+ if repo_path:
+ msg = "repo_path must be empty if running over multiple problem statements"
+ raise ValueError(msg)
+
+ # If file_path is a directory, attempt load from disk
+ if os.path.isdir(file_path):
+ try:
+ dataset_or_dict = load_from_disk(file_path)
+ if isinstance(dataset_or_dict, dict):
+ return postproc_instance_list(dataset_or_dict[split])
+ return postproc_instance_list(dataset_or_dict)
+ except FileNotFoundError:
+ # Raised by load_from_disk if the directory is not a dataset directory
+ pass
# If file_path is a file, load the file
if file_path.endswith(".json"):
@@ -611,10 +615,6 @@ def get_instances(
if file_path.endswith(".jsonl"):
return postproc_instance_list([json.loads(x) for x in open(file_path, 'r').readlines()])
- if repo_path:
- msg = "repo_path must be empty if data_path is not a github url or local repo url"
- raise ValueError(msg)
-
# Attempt load from HF datasets as a last resort
try:
return postproc_instance_list(load_dataset(file_path, split=split))