Skip to content

Commit db98ba6

Browse files
authored
Avoid copying __pycache__ in the temp workding dir. (#196)
* Avoid copying __pycache__ in the temp workding dir. * Fix tests * Clean up comment
1 parent dbb047c commit db98ba6

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

debug_gym/gym/envs/env.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,13 @@ def setup_workspace(
228228
atexit.register(self._tempdir.cleanup)
229229

230230
self.logger.debug(f"Working directory: {self.working_dir}")
231-
shutil.copytree(self.path, self.working_dir, dirs_exist_ok=True, symlinks=True)
231+
shutil.copytree(
232+
self.path,
233+
self.working_dir,
234+
dirs_exist_ok=True,
235+
symlinks=True,
236+
ignore=shutil.ignore_patterns("__pycache__", "*.pyc"),
237+
)
232238

233239
self.setup_file_filters(readonly_patterns, ignore_patterns)
234240

debug_gym/gym/tools/pdb.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ def use(self, environment, command: str) -> Observation:
156156
else: # other pdb commands, send directly
157157
try:
158158
pdb_out = self.interact_with_pdb(command, environment.run_timeout)
159-
# remove the working dir from the output
160-
pdb_out = pdb_out.replace(f"{environment.working_dir}/", "")
161159
if pdb_out in (
162160
"End of file",
163161
"Blank or comment",

scripts/config_mini_nightmare.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ base:
44
benchmark: "mini_nightmare"
55
problems: "all" # list of problems, e.g., ["config"], or "all"
66
env_kwargs: {
7-
"entrypoint": "python -m pytest -s test.py",
7+
"entrypoint": "python -m pytest --tb=no -s test.py",
88
"dir_tree_depth": 1,
99
"run_timeout": 30,
1010
# shortcut features

tests/gym/tools/test_pdb.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ def test_pdb_pass_empty_path_if_in_session(tmp_path, setup_test_repo):
146146
)
147147
pdb = PDBTool()
148148
_ = pdb.start_pdb(environment)
149+
wd = environment.working_dir
149150

150151
obs = pdb.use(environment, command="b test_pass.py:1").observation
151-
assert obs.startswith("Pdb command output:\nBreakpoint 1 at test_pass.py:1")
152+
assert obs.startswith(f"Pdb command output:\nBreakpoint 1 at {wd}/test_pass.py:1")
152153
obs = pdb.use(environment, command="c").observation
153154
assert "1 B->\tdef test_pass():" in obs
154155
# Now try to set a breakpoint without specifying the file, it should pass
155156
obs = pdb.use(environment, command="b 2").observation
156-
assert obs.startswith("Pdb command output:\nBreakpoint 2 at test_pass.py:2")
157+
assert obs.startswith(f"Pdb command output:\nBreakpoint 2 at {wd}/test_pass.py:2")
157158

158159

159160
def test_pdb_use_default_environment_entrypoint(tmp_path, setup_test_repo):
@@ -241,7 +242,9 @@ def test_pdb_add_new_breakpoint_relative_path(tmp_path, setup_pdb_repo_env):
241242
breakpoints_state = copy.deepcopy(env.current_breakpoints_state)
242243
wd = env.working_dir
243244
pdb_obs = pdb_tool.use(env, "b file1.py:25")
244-
assert "Pdb command output:\nBreakpoint 5 at file1.py:25" in pdb_obs.observation
245+
assert (
246+
f"Pdb command output:\nBreakpoint 5 at {wd}/file1.py:25" in pdb_obs.observation
247+
)
245248
new_breakpoint = {f"{wd}/file1.py|||25": f"b {wd}/file1.py:25"}
246249
expected_state = breakpoints_state | new_breakpoint
247250
assert env.current_breakpoints_state == expected_state
@@ -252,7 +255,9 @@ def test_pdb_add_new_breakpoint_absolute_path(tmp_path, setup_pdb_repo_env):
252255
breakpoints_state = copy.deepcopy(env.current_breakpoints_state)
253256
wd = env.working_dir
254257
pdb_obs = pdb_tool.use(env, f"b {wd}/file1.py:25")
255-
assert "Pdb command output:\nBreakpoint 5 at file1.py:25" in pdb_obs.observation
258+
assert (
259+
f"Pdb command output:\nBreakpoint 5 at {wd}/file1.py:25" in pdb_obs.observation
260+
)
256261
new_breakpoint = {f"{wd}/file1.py|||25": f"b {wd}/file1.py:25"}
257262
expected_state = breakpoints_state | new_breakpoint
258263
assert env.current_breakpoints_state == expected_state
@@ -261,8 +266,11 @@ def test_pdb_add_new_breakpoint_absolute_path(tmp_path, setup_pdb_repo_env):
261266
def test_pdb_add_existing_breakpoint(tmp_path, setup_pdb_repo_env):
262267
pdb_tool, env = setup_pdb_repo_env(tmp_path)
263268
breakpoints_state = copy.deepcopy(env.current_breakpoints_state)
264-
pdb_obs = pdb_tool.use(env, "b file1.py:10")
265-
assert "Pdb command output:\nBreakpoint 5 at file1.py:10" in pdb_obs.observation
269+
wd = env.working_dir
270+
pdb_obs = pdb_tool.use(env, f"b {wd}/file1.py:10")
271+
assert (
272+
f"Pdb command output:\nBreakpoint 5 at {wd}/file1.py:10" in pdb_obs.observation
273+
)
266274
assert env.current_breakpoints_state == breakpoints_state
267275

268276

@@ -276,7 +284,7 @@ def test_pdb_clear_specific(tmp_path, setup_pdb_repo_env):
276284
f"{wd}/file2.py|||15": f"b {wd}/file2.py:15",
277285
}
278286
assert pdb_obs.observation.startswith(
279-
"Pdb command output:\nDeleted breakpoint 2 at file1.py:20\n\nCurrent frame:"
287+
f"Pdb command output:\nDeleted breakpoint 2 at {wd}/file1.py:20\n\nCurrent frame:"
280288
)
281289
assert env.current_breakpoints_state == expected_state
282290

@@ -287,9 +295,10 @@ def test_pdb_clear_not_found(
287295
):
288296
pdb_tool, env = setup_pdb_repo_env(tmp_path)
289297
breakpoints_state = copy.deepcopy(env.current_breakpoints_state)
298+
wd = env.working_dir
290299
pdb_obs = pdb_tool.use(env, "cl file1.py:8")
291300
assert pdb_obs.observation.startswith(
292-
"Pdb command output:\n*** There is no breakpoint at file1.py:8"
301+
f"Pdb command output:\n*** There is no breakpoint at {wd}/file1.py:8"
293302
)
294303
assert env.current_breakpoints_state == breakpoints_state
295304

@@ -568,19 +577,22 @@ def test_use_pdb_syntax_error(tmp_path, setup_pdb_repo_env):
568577

569578
def test_set_current_frame_file_sets_file(tmp_path, setup_pdb_repo_env):
570579
pdb_tool, env = setup_pdb_repo_env(tmp_path)
580+
wd = env.working_dir
571581
# First stop at pytest main file
572582
assert "pytest/__main__.py" in pdb_tool.current_frame_file
573583
# pdb_tool.use calls pdb_tool.set_current_frame_file(env)
574584
obs = pdb_tool.use(env, "b test_fail.py:2")
575-
assert "Pdb command output:\nBreakpoint 5 at test_fail.py:2" in obs.observation
585+
assert (
586+
f"Pdb command output:\nBreakpoint 5 at {wd}/test_fail.py:2" in obs.observation
587+
)
576588
# no `continue` command, so current_frame_file should still be pytest main file
577589
assert "pytest/__main__.py" in pdb_tool.current_frame_file
578590
obs = pdb_tool.use(env, "c")
579591
# At this point, current_frame_file should be set to the file where the breakpoint was set
580-
assert pdb_tool.current_frame_file == f"{env.working_dir}/test_fail.py"
592+
assert pdb_tool.current_frame_file == f"{wd}/test_fail.py"
581593
# observation should contain the test file
582-
assert f"Current frame:\n{env.working_dir}/test_fail.py" in obs.observation
583-
assert "> test_fail.py(2)" in obs.observation
594+
assert f"Current frame:\n{wd}/test_fail.py" in obs.observation
595+
assert f"> {wd}/test_fail.py(2)" in obs.observation
584596

585597

586598
def test_set_current_frame_file_sets_and_returns(tmp_path, setup_pdb_repo_env):
@@ -600,6 +612,7 @@ def fake_interact_with_pdb(command, timeout):
600612
def test_use_multiple_commands_only_first_executed(tmp_path, setup_pdb_repo_env):
601613
pdb_tool, env = setup_pdb_repo_env(tmp_path)
602614
env.current_breakpoints_state = {}
615+
wd = env.working_dir
603616
pdb_tool.restart_pdb(env)
604617
pdb_obs = pdb_tool.use(env, "b")
605618
obs = clean_up_pytest_path(pdb_obs.observation)
@@ -627,7 +640,7 @@ def test_use_multiple_commands_only_first_executed(tmp_path, setup_pdb_repo_env)
627640
assert pdb_obs.source == "pdb"
628641
assert pdb_obs.observation.startswith(
629642
"Multiple commands are not supported. Only the first command will be executed.\n"
630-
"Pdb command output:\nBreakpoint 1 at file1.py:1\n"
643+
f"Pdb command output:\nBreakpoint 1 at {wd}/file1.py:1\n"
631644
"\n"
632645
"Current frame:"
633646
)
@@ -668,7 +681,8 @@ def test_use_starts_pdb_if_not_running(tmp_path, setup_pdb_repo_env):
668681
def test_pdb_list_output_indentation(tmp_path, setup_pdb_repo_env):
669682
"""Test PDB list output indentation for line numbers around 100 (3-digit)"""
670683
pdb_tool, env = setup_pdb_repo_env(tmp_path)
671-
with (env.working_dir / "large_file.py").open("w") as f:
684+
wd = env.working_dir
685+
with (wd / "large_file.py").open("w") as f:
672686
f.write("def dummy_function():\n")
673687
f.write("\n".join(f" 'Line {i+1}'" for i in range(1, 2000)))
674688
f.write("\n\nif __name__ == '__main__':\n")
@@ -677,7 +691,7 @@ def test_pdb_list_output_indentation(tmp_path, setup_pdb_repo_env):
677691
pdb_tool.start_pdb(env)
678692
pdb_obs = pdb_tool.use(env, "b large_file.py:100")
679693
assert (
680-
"Pdb command output:\nBreakpoint 5 at large_file.py:100"
694+
f"Pdb command output:\nBreakpoint 5 at {wd}/large_file.py:100"
681695
) in pdb_obs.observation
682696
pdb_obs = pdb_tool.use(env, "c")
683697
expected_output = (
@@ -698,7 +712,8 @@ def test_pdb_list_output_indentation(tmp_path, setup_pdb_repo_env):
698712

699713
pdb_obs = pdb_tool.use(env, "b large_file.py:1000")
700714
assert (
701-
"Pdb command output:\nBreakpoint 6 at large_file.py:1000" in pdb_obs.observation
715+
f"Pdb command output:\nBreakpoint 6 at {wd}/large_file.py:1000"
716+
in pdb_obs.observation
702717
)
703718
pdb_obs = pdb_tool.use(env, "c")
704719
expected_output = (
@@ -719,7 +734,8 @@ def test_pdb_list_output_indentation(tmp_path, setup_pdb_repo_env):
719734

720735
pdb_obs = pdb_tool.use(env, "b large_file.py:2000")
721736
assert (
722-
"Pdb command output:\nBreakpoint 7 at large_file.py:2000" in pdb_obs.observation
737+
f"Pdb command output:\nBreakpoint 7 at {wd}/large_file.py:2000"
738+
in pdb_obs.observation
723739
)
724740
pdb_obs = pdb_tool.use(env, "c")
725741
expected_output = (

0 commit comments

Comments
 (0)