swe_entry.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. set -e
  3. # assert user name is `root`
  4. if [ "$USER" != "root" ]; then
  5. echo "Error: This script is intended to be run by the 'root' user only." >&2
  6. exit 1
  7. fi
  8. source ~/.bashrc
  9. SWEUTIL_DIR=/swe_util
  10. # Create logs directory
  11. LOG_DIR=/opendevin/logs
  12. mkdir -p $LOG_DIR && chmod 777 $LOG_DIR
  13. # FIXME: Cannot read SWE_INSTANCE_ID from the environment variable
  14. # SWE_INSTANCE_ID=django__django-11099
  15. if [ -z "$SWE_INSTANCE_ID" ]; then
  16. echo "Error: SWE_INSTANCE_ID is not set." >&2
  17. exit 1
  18. fi
  19. # Read the swe-bench-test-lite.json file and extract the required item based on instance_id
  20. item=$(jq --arg INSTANCE_ID "$SWE_INSTANCE_ID" '.[] | select(.instance_id == $INSTANCE_ID)' $SWEUTIL_DIR/eval_data/instances/swe-bench-test-lite.json)
  21. if [[ -z "$item" ]]; then
  22. echo "No item found for the provided instance ID."
  23. exit 1
  24. fi
  25. CONDA_ENV_NAME=$(echo "$item" | jq -r '.repo + "__" + .version | gsub("/"; "__")')
  26. echo "CONDA_ENV_NAME: $CONDA_ENV_NAME"
  27. SWE_TASK_DIR=/opendevin/swe_tasks
  28. mkdir -p $SWE_TASK_DIR
  29. # Dump test_patch to /workspace/test.patch
  30. echo "$item" | jq -r '.test_patch' > $SWE_TASK_DIR/test.patch
  31. # Dump patch to /workspace/gold.patch
  32. echo "$item" | jq -r '.patch' > $SWE_TASK_DIR/gold.patch
  33. # Dump the item to /workspace/instance.json except for the "test_patch" and "patch" fields
  34. echo "$item" | jq 'del(.test_patch, .patch)' > $SWE_TASK_DIR/instance.json
  35. # Clear the workspace
  36. rm -rf /workspace/*
  37. # Copy repo to workspace
  38. if [ -d /workspace/$CONDA_ENV_NAME ]; then
  39. rm -rf /workspace/$CONDA_ENV_NAME
  40. fi
  41. cp -r $SWEUTIL_DIR/eval_data/testbeds/$CONDA_ENV_NAME /workspace
  42. # Reset swe-bench testbed and install the repo
  43. . $SWEUTIL_DIR/miniforge3/etc/profile.d/conda.sh
  44. conda config --set changeps1 False
  45. conda config --append channels conda-forge
  46. conda activate swe-bench-eval
  47. mkdir -p $SWE_TASK_DIR/reset_testbed_temp
  48. mkdir -p $SWE_TASK_DIR/reset_testbed_log_dir
  49. SWE_BENCH_DIR=/swe_util/OD-SWE-bench
  50. output=$(
  51. export PYTHONPATH=$SWE_BENCH_DIR && \
  52. cd $SWE_BENCH_DIR && \
  53. python swebench/harness/reset_swe_env.py \
  54. --swe_bench_tasks $SWEUTIL_DIR/eval_data/instances/swe-bench-test.json \
  55. --temp_dir $SWE_TASK_DIR/reset_testbed_temp \
  56. --testbed /workspace \
  57. --conda_path $SWEUTIL_DIR/miniforge3 \
  58. --instance_id $SWE_INSTANCE_ID \
  59. --log_dir $SWE_TASK_DIR/reset_testbed_log_dir \
  60. --timeout 900 \
  61. --verbose
  62. )
  63. REPO_PATH=$(echo "$output" | awk -F': ' '/repo_path:/ {print $2}')
  64. TEST_CMD=$(echo "$output" | awk -F': ' '/test_cmd:/ {print $2}')
  65. echo "Repo Path: $REPO_PATH"
  66. echo "Test Command: $TEST_CMD"
  67. echo "export SWE_BENCH_DIR=\"$SWE_BENCH_DIR\"" >> ~/.bashrc
  68. echo "export REPO_PATH=\"$REPO_PATH\"" >> ~/.bashrc
  69. echo "export TEST_CMD=\"$TEST_CMD\"" >> ~/.bashrc
  70. if [[ "$REPO_PATH" == "None" ]]; then
  71. echo "Error: Failed to retrieve repository path. Tests may not have passed or output was not as expected." >&2
  72. exit 1
  73. fi
  74. # Activate instance-specific environment
  75. . $SWEUTIL_DIR/miniforge3/etc/profile.d/conda.sh
  76. conda activate $CONDA_ENV_NAME
  77. set +e