44import debug_gym .gym .utils as utils
55from debug_gym .gym .entities import EvalOutput
66from debug_gym .gym .envs .env import RepoEnv
7+ from debug_gym .gym .terminal import DockerTerminal , Terminal
78
89
910class MiniNightmareEnv (RepoEnv ):
@@ -21,13 +22,30 @@ class MiniNightmareEnv(RepoEnv):
2122 "tomorrow_date" ,
2223 ]
2324
25+ def __init__ (
26+ self ,
27+ entrypoint : str = "python -m pytest -s test.py" ,
28+ terminal : Terminal | None = None ,
29+ ** kwargs ,
30+ ):
31+ terminal = terminal or DockerTerminal (
32+ base_image = "python:3.12-slim" ,
33+ setup_commands = [
34+ "apt update" ,
35+ "apt install -y git" ,
36+ "pip install pytest pandas" ,
37+ ],
38+ logger = kwargs .get ("logger" ),
39+ )
40+ if not isinstance (terminal , DockerTerminal ):
41+ raise ValueError ("MiniNightmareEnv only supports DockerTerminal." )
42+
43+ super ().__init__ (entrypoint = entrypoint , terminal = terminal , ** kwargs )
44+
2445 @property
2546 def instructions (self ) -> str :
2647 return self .current_sample ["instructions" ]
2748
28- def __init__ (self , entrypoint : str = "python -m pytest -s test.py" , ** kwargs ):
29- super ().__init__ (entrypoint = entrypoint , ** kwargs )
30-
3149 def calculate_max_score (self , eval_output : EvalOutput ) -> int :
3250 return utils .extract_max_score_from_pytest_output (eval_output .output )
3351
@@ -40,11 +58,26 @@ def eval(self, **kwargs) -> EvalOutput:
4058 self .last_eval = EvalOutput (success , output )
4159 return self .last_eval
4260
61+ def setup_terminal (self ):
62+ self .logger .info (f"Configuring docker container: { self .terminal .container } " )
63+
64+ self .terminal .run ("git init" )
65+ self .terminal .run ("git config user.name 'debug-gym'" )
66+ self .terminal .run ("git config user.email '<>'" )
67+
68+ self .terminal .run ("git add *.py" )
69+ self .terminal .run ("git commit -am 'Init'" )
70+
71+ self .terminal .run ("git add .debugignore" )
72+ self .terminal .run ("git add .debugreadonly" )
73+ self .terminal .run ("git commit -am 'Add debug-gym ignore and read-only files'" )
74+
4375 def reset (self , * , options : dict = None ):
4476 options = options or {}
4577 self .current_sample = self .dataset [options ["task_name" ]]
4678 directory = self .current_sample ["base_directory" ]
4779 self .setup_workspace (directory , entrypoint = self .entrypoint )
80+ self .setup_terminal ()
4881 infos = super ().reset (options = options )
4982 return infos
5083
0 commit comments