-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_swebench_dataset.py
More file actions
183 lines (167 loc) · 6.64 KB
/
build_swebench_dataset.py
File metadata and controls
183 lines (167 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env python3
import argparse
import logging
import os
from typing import Optional
from datasets import Dataset, DatasetDict, load_dataset
from swebench.harness.constants import (
MAP_REPO_VERSION_TO_SPECS,
MAP_REPO_TO_REQS_PATHS,
)
from swebench.harness.utils import (
get_requirements_by_commit,
)
from swebench.harness.test_spec import (
replace_uninstallable_packages_requirements_txt,
)
from utils import Repo
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)
def create_instance(
example: dict, organization: str
) -> dict:
"""Convert a SWE-bench instance to the commit0 form."""
setup = dict()
raw_info = MAP_REPO_VERSION_TO_SPECS[example["repo"]][example["version"]]
setup["python"] = raw_info["python"]
setup["install"] = raw_info["install"]
setup["specification"] = ""
if "pre_install" in raw_info:
setup["pre_install"] = raw_info["pre_install"]
setup["pre_install"] = []
for one in raw_info["pre_install"]:
if 'apt' in one:
setup["pre_install"].append(one)
else:
setup["install"] = f"{one}; {setup['install']}"
if "packages" in raw_info:
if raw_info["packages"] == "requirements.txt":
packages = replace_uninstallable_packages_requirements_txt(
get_requirements_by_commit(example["repo"], example["environment_setup_commit"])
)
setup["packages"] = [one.split('#')[0].strip().split(';')[0].strip() for one in packages.split('\n') if one.strip() != '']
setup["packages"] = [f"\"{one}\"" for one in setup["packages"] if 'win32' not in one]
setup["packages"] = ' '.join(setup["packages"])
elif raw_info["packages"] == "environment.yml":
pass
else:
setup["packages"] = raw_info["packages"]
if "pip_packages" in raw_info:
setup["pip_packages"] = raw_info["pip_packages"]
owner, repo = example["repo"].split("/")
if repo == "matplotlib":
test_cmd = "pytest --continue-on-collection-errors"
test_dir = "lib/matplotlib/tests"
src_dir = "lib/matplotlib"
if not "pre_install" in setup:
setup["pre_install"] = []
setup["pre_install"] += ["apt-get update", "apt-get install clang"]
elif repo == "pylint":
test_cmd = "pytest --continue-on-collection-errors"
test_dir = "tests/"
src_dir = "pylint/"
elif repo == "sympy":
test_cmd = "pytest --continue-on-collection-errors"
test_dir = "sympy/"
src_dir = "sympy/"
elif repo == "seaborn":
test_cmd = "pytest -n auto --continue-on-collection-errors"
test_dir = "tests/"
src_dir = "seaborn/"
elif repo == "flask":
test_cmd = "pytest --continue-on-collection-errors"
test_dir = "tests/"
src_dir = "src/flask/"
elif repo == "astropy":
test_cmd = "pytest --continue-on-collection-errors"
test_dir = "astropy/"
src_dir = "astropy"
if not "pre_install" in setup:
setup["pre_install"] = []
setup["pre_install"] += ["apt-get update", "apt-get install clang"]
if example["environment_setup_commit"] == "2e89d074b3b2abc2da80e437c93b1d5516a0ca57":
setup["install"] = "pip install setuptools pip; python setup.py develop"
elif repo == "requests":
test_cmd = "pytest --continue-on-collection-errors"
test_dir = "tests/"
src_dir = "src/requests/"
elif repo == "xarray":
test_cmd = "pytest -n auto --continue-on-collection-errors"
test_dir = "tests/"
src_dir = "xarray/"
elif repo == "pytest":
test_cmd = "pytest --continue-on-collection-errors"
test_dir = "testing/"
src_dir = "src/"
elif repo == "sphinx":
test_cmd = "pytest --continue-on-collection-errors"
test_dir = "tests/"
src_dir = "sphinx/"
elif repo == "django":
test_cmd = "PYTHONWARNINGS=always pytest --capture=no --continue-on-collection-errors"
test_dir = "tests/"
src_dir = "django"
if not "pre_install" in setup:
setup["pre_install"] = []
setup["pre_install"] += ["apt-get update", "apt-get install clang"]
elif repo == "scikit-learn":
test_cmd = "pytest --continue-on-collection-errors"
test_dir = "sklearn/"
src_dir = "sklearn/"
if not "pre_install" in setup:
setup["pre_install"] = []
setup["pre_install"] += ["apt-get update", "apt-get install clang"]
setup["install"] = "python setup.py install"
return {
"instance_id": example["instance_id"],
"repo": f"{organization}/{repo}",
"original_repo": f"{owner}/{repo}",
"base_commit": example["base_commit"],
"reference_commit": example["environment_setup_commit"],
"setup": setup,
"test": {"test_cmd": test_cmd, "test_dir": "", "PASS_TO_PASS": example["PASS_TO_PASS"], "FAIL_TO_PASS": example["FAIL_TO_PASS"], "patch": example["patch"], "test_patch": example["test_patch"]},
"src_dir": src_dir,
}
def main(
dataset: str,
organization: str,
token: Optional[str] = None,
) -> None:
"""Main thread for creating task instances from existing repositories
Args:
----
dataset (str): SWE-bench dataset to build
organization (str): under which organization to fork repos to
token (str): GitHub token
"""
if token is None:
# Get GitHub token from environment variable if not provided
token = os.environ.get("GITHUB_TOKEN")
examples = []
ds = load_dataset(dataset, split="test")
for example in ds:
logger.info(f"Working on {example['repo']}")
head = example["environment_setup_commit"]
owner, repo = example["repo"].split("/")
#repo = Repo(owner, repo, organization=organization, head=head, token=token)
# Create task instance
instance = create_instance(example, organization)
examples.append(instance)
ds = Dataset.from_list(examples)
ds = DatasetDict({"test": ds})
hf_name = f"wentingzhao/{dataset.split('/')[-1]}"
ds.push_to_hub(hf_name)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("dataset", type=str, help="SWE-bench dataset to build")
parser.add_argument(
"--organization",
type=str,
default="commit-0",
help="under which organization to fork repos to",
)
parser.add_argument("--token", type=str, help="GitHub token")
args = parser.parse_args()
main(**vars(args))