instance_swe_entry.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. source ~/.bashrc
  3. SWEUTIL_DIR=/swe_util
  4. # Create logs directory
  5. LOG_DIR=/openhands/logs
  6. mkdir -p $LOG_DIR && chmod 777 $LOG_DIR
  7. # FIXME: Cannot read SWE_INSTANCE_ID from the environment variable
  8. # SWE_INSTANCE_ID=django__django-11099
  9. if [ -z "$SWE_INSTANCE_ID" ]; then
  10. echo "Error: SWE_INSTANCE_ID is not set." >&2
  11. exit 1
  12. fi
  13. # Read the swe-bench-test-lite.json file and extract the required item based on instance_id
  14. item=$(jq --arg INSTANCE_ID "$SWE_INSTANCE_ID" '.[] | select(.instance_id == $INSTANCE_ID)' $SWEUTIL_DIR/eval_data/instances/swe-bench-instance.json)
  15. if [[ -z "$item" ]]; then
  16. echo "No item found for the provided instance ID."
  17. exit 1
  18. fi
  19. WORKSPACE_NAME=$(echo "$item" | jq -r '.repo + "__" + .version | gsub("/"; "__")')
  20. echo "WORKSPACE_NAME: $WORKSPACE_NAME"
  21. SWE_TASK_DIR=/openhands/swe_tasks
  22. mkdir -p $SWE_TASK_DIR
  23. # Dump test_patch to /workspace/test.patch
  24. echo "$item" | jq -r '.test_patch' > $SWE_TASK_DIR/test.patch
  25. # Dump patch to /workspace/gold.patch
  26. echo "$item" | jq -r '.patch' > $SWE_TASK_DIR/gold.patch
  27. # Dump the item to /workspace/instance.json except for the "test_patch" and "patch" fields
  28. echo "$item" | jq 'del(.test_patch, .patch)' > $SWE_TASK_DIR/instance.json
  29. # Clear the workspace
  30. if [ -d /workspace ]; then
  31. rm -rf /workspace/*
  32. else
  33. mkdir /workspace
  34. fi
  35. # Copy repo to workspace
  36. if [ -d /workspace/$WORKSPACE_NAME ]; then
  37. rm -rf /workspace/$WORKSPACE_NAME
  38. fi
  39. cp -r /testbed/ /workspace/$WORKSPACE_NAME/
  40. # Reset swe-bench testbed and install the repo
  41. . /opt/miniconda3/etc/profile.d/conda.sh
  42. conda activate testbed
  43. mkdir -p $SWE_TASK_DIR/reset_testbed_temp
  44. mkdir -p $SWE_TASK_DIR/reset_testbed_log_dir
  45. REPO_PATH=/workspace/$WORKSPACE_NAME
  46. echo "Repo Path: $REPO_PATH"
  47. # echo "Test Command: $TEST_CMD"
  48. echo "export REPO_PATH=\"$REPO_PATH\"" >> ~/.bashrc
  49. # echo "export TEST_CMD=\"$TEST_CMD\"" >> ~/.bashrc
  50. if [[ "$REPO_PATH" == "None" ]]; then
  51. echo "Error: Failed to retrieve repository path. Tests may not have passed or output was not as expected." >&2
  52. exit 1
  53. fi
  54. # Activate instance-specific environment
  55. . /opt/miniconda3/etc/profile.d/conda.sh
  56. conda activate testbed
  57. # set +e