π OpenHands: AI-Driven Development
Turn off auto linting by default, and on for swe_bench (#1861)
Boxuan Lia57a213c7c3f
diff --git a/evaluation/swe_bench/README.md b/evaluation/swe_bench/README.mdindex 011d095597..ee44f1303b 100644--- a/evaluation/swe_bench/README.md+++ b/evaluation/swe_bench/README.md@@ -43,8 +43,10 @@ sandbox_type = "ssh"use_host_network = truessh_hostname = "localhost"sandbox_timeout = 120+# SWEBench eval specificrun_as_devin = false+enable_auto_lint = true# TODO: Change these to the model you want to evaluate[eval_gpt4_1106_preview]diff --git a/evaluation/swe_bench/swe_env_box.py b/evaluation/swe_bench/swe_env_box.pyindex bd1fc57296..f3d217208a 100644--- a/evaluation/swe_bench/swe_env_box.py+++ b/evaluation/swe_bench/swe_env_box.py@@ -73,6 +73,10 @@ class SWEBenchSSHBox(DockerSSHBox):)config.workspace_base = workspace_mount_pathconfig.workspace_mount_path = workspace_mount_path++ # linting python after editing helps LLM fix indentations+ config.enable_auto_lint = True+sandbox = cls(container_image=SWE_BENCH_CONTAINER_IMAGE,swe_instance_id=instance['instance_id'],diff --git a/opendevin/core/config.py b/opendevin/core/config.pyindex 994436816c..415fc3ca30 100644--- a/opendevin/core/config.py+++ b/opendevin/core/config.py@@ -94,6 +94,9 @@ class AppConfig(metaclass=Singleton):sandbox_timeout: int = 120github_token: str | None = Nonedebug: bool = False+ enable_auto_lint: bool = (+ False # once enabled, OpenDevin would lint files after editing+ )defaults_dict: ClassVar[dict] = {}diff --git a/opendevin/runtime/docker/ssh_box.py b/opendevin/runtime/docker/ssh_box.pyindex b37f49f8c7..9d7e0cc3dc 100644--- a/opendevin/runtime/docker/ssh_box.py+++ b/opendevin/runtime/docker/ssh_box.py@@ -1,5 +1,4 @@import atexit-import jsonimport osimport reimport sys@@ -265,8 +264,6 @@ class DockerSSHBox(Sandbox):def add_to_env(self, key: str, value: str):super().add_to_env(key, value)- # Note: json.dumps gives us nice escaping for free- self.execute(f'export {key}={json.dumps(value)}')def setup_user(self):# Make users sudoers passwordlessdiff --git a/opendevin/runtime/plugins/swe_agent_commands/cursors_edit_linting.sh b/opendevin/runtime/plugins/swe_agent_commands/cursors_edit_linting.shindex 4235f5305d..927b9bda87 100644--- a/opendevin/runtime/plugins/swe_agent_commands/cursors_edit_linting.sh+++ b/opendevin/runtime/plugins/swe_agent_commands/cursors_edit_linting.sh@@ -36,7 +36,7 @@ edit() {# Write the new stuff directly back into the original fileprintf "%s\n" "${new_lines[@]}" >| "$CURRENT_FILE"# Run linter if enabled- if [[ $CURRENT_FILE == *.py && -n "$RUN_LINT_AFTER_EDIT" ]]; then+ if [[ $CURRENT_FILE == *.py && -n "$ENABLE_AUTO_LINT" ]]; thenlint_output=$(flake8 --isolated --select=F821,F822,F831,E111,E112,E113,E999,E902 "$CURRENT_FILE" 2>&1)else# do nothingdiff --git a/opendevin/runtime/plugins/swe_agent_commands/edit_linting.sh b/opendevin/runtime/plugins/swe_agent_commands/edit_linting.shindex 7dd8d2d0e7..1c6dac45ea 100644--- a/opendevin/runtime/plugins/swe_agent_commands/edit_linting.sh+++ b/opendevin/runtime/plugins/swe_agent_commands/edit_linting.sh@@ -68,7 +68,7 @@ edit() {printf "%s\n" "${new_lines[@]}" >| "$CURRENT_FILE"# Run linter if enabled- if [[ $CURRENT_FILE == *.py && -n "$RUN_LINT_AFTER_EDIT" ]]; then+ if [[ $CURRENT_FILE == *.py && -n "$ENABLE_AUTO_LINT" ]]; thenlint_output=$(flake8 --isolated --select=F821,F822,F831,E111,E112,E113,E999,E902 "$CURRENT_FILE" 2>&1)else# do nothingdiff --git a/opendevin/runtime/sandbox.py b/opendevin/runtime/sandbox.pyindex ecce4220ae..64631beb67 100644--- a/opendevin/runtime/sandbox.py+++ b/opendevin/runtime/sandbox.py@@ -1,6 +1,8 @@+import jsonimport osfrom abc import ABC, abstractmethod+from opendevin.core.config import configfrom opendevin.core.schema import CancellableStreamfrom opendevin.runtime.docker.process import Processfrom opendevin.runtime.plugins.mixin import PluginMixin@@ -15,9 +17,13 @@ class Sandbox(ABC, PluginMixin):if key.startswith('SANDBOX_ENV_'):sandbox_key = key.removeprefix('SANDBOX_ENV_')self.add_to_env(sandbox_key, os.environ[key])+ if config.enable_auto_lint:+ self.add_to_env('ENABLE_AUTO_LINT', 'true')def add_to_env(self, key: str, value: str):self._env[key] = value+ # Note: json.dumps gives us nice escaping for free+ self.execute(f'export {key}={json.dumps(value)}')@abstractmethoddef execute(