4
4
import debug_gym .gym .utils as utils
5
5
from debug_gym .gym .entities import EvalOutput
6
6
from debug_gym .gym .envs .env import RepoEnv
7
+ from debug_gym .gym .terminal import DockerTerminal , Terminal
7
8
8
9
9
10
class MiniNightmareEnv (RepoEnv ):
@@ -21,13 +22,30 @@ class MiniNightmareEnv(RepoEnv):
21
22
"tomorrow_date" ,
22
23
]
23
24
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
+
24
45
@property
25
46
def instructions (self ) -> str :
26
47
return self .current_sample ["instructions" ]
27
48
28
- def __init__ (self , entrypoint : str = "python -m pytest -s test.py" , ** kwargs ):
29
- super ().__init__ (entrypoint = entrypoint , ** kwargs )
30
-
31
49
def calculate_max_score (self , eval_output : EvalOutput ) -> int :
32
50
return utils .extract_max_score_from_pytest_output (eval_output .output )
33
51
@@ -40,11 +58,26 @@ def eval(self, **kwargs) -> EvalOutput:
40
58
self .last_eval = EvalOutput (success , output )
41
59
return self .last_eval
42
60
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
+
43
75
def reset (self , * , options : dict = None ):
44
76
options = options or {}
45
77
self .current_sample = self .dataset [options ["task_name" ]]
46
78
directory = self .current_sample ["base_directory" ]
47
79
self .setup_workspace (directory , entrypoint = self .entrypoint )
80
+ self .setup_terminal ()
48
81
infos = super ().reset (options = options )
49
82
return infos
50
83
0 commit comments