Datasets:
Download scripts/build_indexes.py from CrossSWE/CrossSWE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.75 kB
-
https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/build_indexes.py
- Command line
-
hf download hf://datasets/CrossSWE/CrossSWE-Bench/scripts/build_indexes.py
-
curl -L -o build_indexes.py https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/build_indexes.py
2.75 kB
| """Regenerate task indexes and checksums while preserving source-record hashes.""" | |
| import argparse | |
| import csv | |
| import io | |
| import json | |
| from pathlib import Path | |
| from common import ROOT, sha256 | |
| def build(root): | |
| root = Path(root) | |
| tasks = sorted((json.loads(path.read_text()) for path in (root / 'instances').glob('*/task.json')), | |
| key=lambda task: task['ordinal']) | |
| assert len(tasks) == 171 and [task['ordinal'] for task in tasks] == list(range(1, 172)) | |
| public = {row['instance_id']:row for row in map(json.loads, (root / 'data/crossswe-bench.jsonl').read_text().splitlines())} | |
| assert set(public) == {task['instance_id'] for task in tasks} | |
| binding_path = root / 'data/task-bindings.jsonl' | |
| previous = {row['instance_id']:row for row in map(json.loads, binding_path.read_text().splitlines())} if binding_path.exists() else {} | |
| (root / 'data/instances.jsonl').write_text(''.join(json.dumps(task, ensure_ascii=False, separators=(',', ':')) + '\n' for task in tasks)) | |
| output = io.StringIO() | |
| writer = csv.writer(output, delimiter='\t', lineterminator='\n') | |
| writer.writerow(['ordinal', 'instance_id', 'original_instance_id', 'language', 'task', 'repositories', 'task_path']) | |
| bindings = [] | |
| for task in tasks: | |
| iid = task['instance_id'] | |
| record = public[iid] | |
| writer.writerow([task['ordinal'], iid, task['original_instance_id'], record['language'], record['task'], | |
| ','.join(repo['repo'] for repo in task['repositories']), 'instances/' + iid + '/task.json']) | |
| bindings.append({'instance_id':iid, | |
| 'task_sha256':sha256(root / 'instances' / iid / 'task.json'), | |
| 'source_task_sha256':record['original_task_sha256'], | |
| 'contract_sha256':task['evaluation']['sha256'], | |
| 'source_contract_sha256':previous.get(iid, {}).get('source_contract_sha256', task['evaluation']['sha256'])}) | |
| (root / 'release171.tsv').write_text(output.getvalue()) | |
| binding_path.write_text(''.join(json.dumps(item, ensure_ascii=False, separators=(',', ':')) + '\n' for item in bindings)) | |
| paths = sorted(path for path in root.rglob('*') if path.is_file() | |
| and not any(part in path.relative_to(root).parts for part in ['.git', '.cache', 'workspaces', 'results', '__pycache__']) | |
| and path.name != 'CHECKSUMS.sha256') | |
| (root / 'CHECKSUMS.sha256').write_text(''.join(sha256(path) + ' ' + str(path.relative_to(root)) + '\n' for path in paths)) | |
| if __name__ == '__main__': | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--root', type=Path, default=ROOT) | |
| build(parser.parse_args().root.resolve()) | |