(args: argparse.Namespace)
| 342 | |
| 343 | |
| 344 | def cmd_prepare(args: argparse.Namespace) -> int: |
| 345 | swebench_repo = _resolve_swebench_repo(args.swebench_repo) |
| 346 | swebench_python = _resolve_python("SWEBENCH_PYTHON") |
| 347 | try: |
| 348 | subprocess.run( |
| 349 | [swebench_python, "-c", "import swebench"], |
| 350 | cwd=str(swebench_repo), |
| 351 | check=True, |
| 352 | capture_output=True, |
| 353 | text=True, |
| 354 | ) |
| 355 | except subprocess.CalledProcessError as exc: |
| 356 | raise SystemExit( |
| 357 | f"The interpreter {swebench_python!r} cannot import `swebench`.\n\n" |
| 358 | "Install the package (editable from your SWE-bench-dev checkout), then retry:\n\n" |
| 359 | f" {swebench_python} -m pip install -e {swebench_repo} " |
| 360 | "fastapi uvicorn tiktoken transformers\n\n" |
| 361 | "Or set SWEBENCH_PYTHON to a Python that already has SWE-bench installed." |
| 362 | ) from exc |
| 363 | |
| 364 | openclaude_repo = _resolve_openclaude_repo(args.openclaude_repo) |
| 365 | skip_openclaude_build = args.skip_openclaude_build |
| 366 | |
| 367 | # 1. Build openclaude dist/cli.mjs if missing. |
| 368 | if not skip_openclaude_build: |
| 369 | dist_cli = openclaude_repo / "dist" / "cli.mjs" |
| 370 | if dist_cli.is_file(): |
| 371 | _info(f"openclaude dist already built: {dist_cli}") |
| 372 | elif not openclaude_repo.is_dir(): |
| 373 | _info(f"openclaude repo not found at {openclaude_repo} — skipping build.") |
| 374 | else: |
| 375 | bun = shutil.which("bun") |
| 376 | if bun is None: |
| 377 | raise SystemExit( |
| 378 | "openclaude needs a build but `bun` was not found on PATH.\n\n" |
| 379 | "Pick one:\n" |
| 380 | " 1) Install Bun: https://bun.com/docs/installation " |
| 381 | "(Windows: PowerShell `irm bun.sh/install.ps1 | iex`)\n" |
| 382 | " 2) Skip the openclaude build for now and only build the SWE-bench text dataset:\n" |
| 383 | " python eval/run_compare.py prepare --skip-openclaude-build\n" |
| 384 | " You must build openclaude yourself later (`bun install && bun run build` in " |
| 385 | "openclaude/) so dist/cli.mjs exists before `run` with the openclaude agent.\n" |
| 386 | ) |
| 387 | _info(f"installing openclaude deps in {openclaude_repo}") |
| 388 | subprocess.run([bun, "install"], cwd=str(openclaude_repo), check=True) # noqa: S603 |
| 389 | _info("building openclaude (bun run build)") |
| 390 | subprocess.run([bun, "run", "build"], cwd=str(openclaude_repo), check=True) # noqa: S603 |
| 391 | if not dist_cli.is_file(): |
| 392 | raise SystemExit(f"openclaude build did not produce {dist_cli}") |
| 393 | |
| 394 | # 2. Build the SWE-bench text dataset (style-3 + oracle) if missing. |
| 395 | dataset_dir = swebench_repo / args.dataset_local |
| 396 | if dataset_dir.is_dir(): |
| 397 | _info(f"text dataset already exists: {dataset_dir}") |
| 398 | else: |
| 399 | cmd = [ |
| 400 | swebench_python, |
| 401 | "-m", |
nothing calls this directly
no test coverage detected