Skip to content

Commit ae1a5e4

Browse files
committed
Pull changes from #107
1 parent 70d923e commit ae1a5e4

File tree

6 files changed

+64
-8
lines changed

6 files changed

+64
-8
lines changed

debug_gym/gym/envs/aider.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55
from debug_gym.constants import DEBUG_GYM_CACHE_DIR
66
from debug_gym.gym.entities import EvalOutput
77
from debug_gym.gym.envs.env import RepoEnv
8+
from debug_gym.gym.terminal import DockerTerminal, Terminal
89

910

1011
class AiderBenchmarkEnv(RepoEnv):
1112
REPO_URL = "https://github.com/exercism/python"
1213
REPO_PATH = DEBUG_GYM_CACHE_DIR / "exercism"
1314

15+
def __init__(
16+
self,
17+
terminal: Terminal | None = None,
18+
**kwargs,
19+
):
20+
terminal = terminal or DockerTerminal(logger=kwargs.get("logger"))
21+
if not isinstance(terminal, DockerTerminal):
22+
raise ValueError("AiderBenchmarkEnv only supports DockerTerminal.")
23+
24+
super().__init__(terminal=terminal, **kwargs)
25+
1426
@property
1527
def instructions(self) -> str:
1628
return self.current_sample["instructions"]
@@ -31,11 +43,26 @@ def eval(self, **kwargs) -> EvalOutput:
3143
self.last_eval = EvalOutput(success, output)
3244
return self.last_eval
3345

46+
def setup_terminal(self):
47+
self.logger.info(f"Configuring docker container: {self.terminal.container}")
48+
49+
self.terminal.run("git init")
50+
self.terminal.run("git config user.name 'debug-gym'")
51+
self.terminal.run("git config user.email '<>'")
52+
53+
self.terminal.run("git add *.py")
54+
self.terminal.run("git commit -am 'Init'")
55+
56+
self.terminal.run("git add .debugignore")
57+
self.terminal.run("git add .debugreadonly")
58+
self.terminal.run("git commit -am 'Add debug-gym ignore and read-only files'")
59+
3460
def reset(self, *, options: dict = None):
3561
options = options or {}
3662
self.current_sample = self.dataset[options["task_name"]]
3763
directory = self.current_sample["base_directory"]
3864
self.setup_workspace(directory, entrypoint=self.entrypoint)
65+
self.setup_terminal()
3966
infos = super().reset(options=options)
4067
return infos
4168

debug_gym/gym/envs/env.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,12 @@ def current_breakpoints(self):
500500

501501
@property
502502
def patch(self):
503-
command = ["git", "diff", "--no-index", self.path, self.working_dir]
504-
result = subprocess.run(command, text=True, capture_output=True)
505-
patch = result.stdout.replace(str(self.working_dir), str(self.path))
506-
return patch
503+
success, output = self.terminal.run("git diff")
504+
if not success:
505+
self.logger.error("Failed to get git diff. {output}")
506+
return None
507+
508+
return output
507509

508510
def apply_gold_patch(self):
509511
raise NotImplementedError(

debug_gym/gym/envs/mini_nightmare.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import debug_gym.gym.utils as utils
55
from debug_gym.gym.entities import EvalOutput
66
from debug_gym.gym.envs.env import RepoEnv
7+
from debug_gym.gym.terminal import DockerTerminal, Terminal
78

89

910
class MiniNightmareEnv(RepoEnv):
@@ -21,6 +22,17 @@ class MiniNightmareEnv(RepoEnv):
2122
"tomorrow_date",
2223
]
2324

25+
def __init__(
26+
self,
27+
terminal: Terminal | None = None,
28+
**kwargs,
29+
):
30+
terminal = terminal or DockerTerminal(logger=kwargs.get("logger"))
31+
if not isinstance(terminal, DockerTerminal):
32+
raise ValueError("MiniNightmareEnv only supports DockerTerminal.")
33+
34+
super().__init__(terminal=terminal, **kwargs)
35+
2436
@property
2537
def instructions(self) -> str:
2638
return self.current_sample["instructions"]
@@ -41,11 +53,26 @@ def eval(self, **kwargs) -> EvalOutput:
4153
self.last_eval = EvalOutput(success, output)
4254
return self.last_eval
4355

56+
def setup_terminal(self):
57+
self.logger.info(f"Configuring docker container: {self.terminal.container}")
58+
59+
self.terminal.run("git init")
60+
self.terminal.run("git config user.name 'debug-gym'")
61+
self.terminal.run("git config user.email '<>'")
62+
63+
self.terminal.run("git add *.py")
64+
self.terminal.run("git commit -am 'Init'")
65+
66+
self.terminal.run("git add .debugignore")
67+
self.terminal.run("git add .debugreadonly")
68+
self.terminal.run("git commit -am 'Add debug-gym ignore and read-only files'")
69+
4470
def reset(self, *, options: dict = None):
4571
options = options or {}
4672
self.current_sample = self.dataset[options["task_name"]]
4773
directory = self.current_sample["base_directory"]
4874
self.setup_workspace(directory, entrypoint=self.entrypoint)
75+
self.setup_terminal()
4976
infos = super().reset(options=options)
5077
return infos
5178

debug_gym/gym/terminal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,15 @@ def setup_container(self) -> docker.models.containers.Container:
457457
container.rename(container_name)
458458
container.reload()
459459
self._run_setup_commands(container)
460-
self.logger.debug(f"Container {container_name} started successfully.")
460+
self.logger.debug(f"{container} ({container_name}) started successfully.")
461461
atexit.register(self.clean_up)
462462
return container
463463

464464
def _run_setup_commands(self, container):
465465
"""Run setup commands if any. If commands fail, stop the container."""
466466
if self.setup_commands:
467467
setup_commands = " && ".join(self.setup_commands)
468-
self.logger.debug(f"Running setup commands: {setup_commands}")
468+
self.logger.debug(f"{container} Running setup commands: {setup_commands}")
469469
status, output = container.exec_run(
470470
["/bin/bash", "-c", setup_commands],
471471
user="root", # Run as root to allow installations

scripts/config_aider.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ base:
2020
# session_commands define commands that are always executed before starting a shell session or running a single command in the terminal.
2121
# session_commands:["conda activate aider"],
2222
# setup_commands define commands that are executed only once when the terminal is created. This is only supported for Docker terminal.
23-
setup_commands: ["pip install pytest"],
23+
setup_commands: ["apt update", "apt install -y git", "pip install pytest"],
2424
}
2525

2626
# LLM configs

scripts/config_mini_nightmare.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ base:
2020
# session_commands define commands that are always executed before starting a shell session or running a single command in the terminal.
2121
# session_commands:["conda activate aider"],
2222
# setup_commands define commands that are executed only once when the terminal is created. This is only supported for Docker terminal.
23-
setup_commands: ["pip install pytest pandas"],
23+
setup_commands: ["apt update", "apt install -y git", "pip install pytest pandas"],
2424
}
2525

2626
# LLM configs

0 commit comments

Comments
 (0)