Skip to content

Commit ab2bb6b

Browse files
committed
style: format entire codebase with ruff
Applied ruff formatting to 8 files that were not properly formatted: - benchmarks/runner.py - examples/oolong_example.py - examples/subprocess_repl_demo.py - rlm/environments/subprocess_repl.py - tests/clients/test_huggingface.py - tests/environments/test_subprocess_repl.py - tests/test_exceptions.py - tests/test_registry.py This ensures the codebase passes CI formatting checks.
1 parent 31ec69b commit ab2bb6b

9 files changed

Lines changed: 243 additions & 89 deletions

File tree

‎benchmarks/runner.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ def _update_progress(
263263

264264
# Call custom callback if provided
265265
if self.config.progress_callback:
266-
self.config.progress_callback(
267-
stats.completed, stats.total, sample_result, stats
268-
)
266+
self.config.progress_callback(stats.completed, stats.total, sample_result, stats)
269267

270268
# Update display based on mode
271269
if progress_mode == "tqdm" and pbar is not None:
@@ -282,7 +280,7 @@ def _update_progress(
282280
if stats.completed % interval == 0 or stats.completed == stats.total:
283281
print(
284282
f" Progress: {stats.completed}/{stats.total} "
285-
f"({stats.completed/stats.total:.0%}) | "
283+
f"({stats.completed / stats.total:.0%}) | "
286284
f"Acc: {stats.accuracy:.1%} | "
287285
f"Errors: {stats.errors} | "
288286
f"ETA: {self._format_eta(stats.eta_seconds)}"

‎examples/oolong_example.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ def load_random_oolong_row() -> dict:
3232

3333
def main():
3434
# Parse command-line arguments
35-
parser = argparse.ArgumentParser(
36-
description="Run Oolong benchmark example with RLM"
37-
)
35+
parser = argparse.ArgumentParser(description="Run Oolong benchmark example with RLM")
3836
parser.add_argument(
3937
"--backend",
4038
type=str,

‎examples/subprocess_repl_demo.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def demonstrate_isolation():
4747
print(f"Platform: {platform.system()}")
4848
if platform.system() == "Linux":
4949
import shutil
50+
5051
if not shutil.which("bwrap"):
5152
print("Note: bubblewrap not installed - filesystem sandbox disabled")
5253
print()

‎rlm/environments/subprocess_repl.py‎

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,22 @@ def __init__(
298298

299299
# Pre-approved packages (stdlib + user-specified)
300300
self.allowed_packages: set[str] = {
301-
"json", "re", "math", "collections", "itertools",
302-
"functools", "datetime", "random", "string", "typing",
303-
"os", "sys", "io", "time", "pathlib", "copy",
301+
"json",
302+
"re",
303+
"math",
304+
"collections",
305+
"itertools",
306+
"functools",
307+
"datetime",
308+
"random",
309+
"string",
310+
"typing",
311+
"os",
312+
"sys",
313+
"io",
314+
"time",
315+
"pathlib",
316+
"copy",
304317
}
305318
if allowed_packages:
306319
self.allowed_packages.update(allowed_packages)
@@ -472,10 +485,12 @@ def _install_package(self, package: str):
472485
capture_output=True,
473486
)
474487
self._installed_packages.add(package)
475-
self._overhead_stats["package_installs"].append({
476-
"package": package,
477-
"time_ms": (time.perf_counter() - start) * 1000,
478-
})
488+
self._overhead_stats["package_installs"].append(
489+
{
490+
"package": package,
491+
"time_ms": (time.perf_counter() - start) * 1000,
492+
}
493+
)
479494

480495
def _extract_missing_module(self, stderr: str) -> str | None:
481496
"""Extract module name from ImportError/ModuleNotFoundError."""
@@ -580,24 +595,38 @@ def _linux_sandbox_wrap(self, cmd: list[str]) -> list[str]:
580595

581596
bwrap_cmd = [
582597
"bwrap",
583-
"--ro-bind", "/usr", "/usr",
584-
"--ro-bind", "/lib", "/lib",
585-
"--ro-bind", "/bin", "/bin",
586-
"--ro-bind", "/sbin", "/sbin",
598+
"--ro-bind",
599+
"/usr",
600+
"/usr",
601+
"--ro-bind",
602+
"/lib",
603+
"/lib",
604+
"--ro-bind",
605+
"/bin",
606+
"/bin",
607+
"--ro-bind",
608+
"/sbin",
609+
"/sbin",
587610
]
588611

589612
# Add /lib64 if it exists
590613
if os.path.exists("/lib64"):
591614
bwrap_cmd.extend(["--ro-bind", "/lib64", "/lib64"])
592615

593-
bwrap_cmd.extend([
594-
"--ro-bind", self.venv_path, self.venv_path,
595-
"--bind", self.temp_dir, self.temp_dir,
596-
"--unshare-net",
597-
"--unshare-pid",
598-
"--die-with-parent",
599-
"--",
600-
])
616+
bwrap_cmd.extend(
617+
[
618+
"--ro-bind",
619+
self.venv_path,
620+
self.venv_path,
621+
"--bind",
622+
self.temp_dir,
623+
self.temp_dir,
624+
"--unshare-net",
625+
"--unshare-pid",
626+
"--die-with-parent",
627+
"--",
628+
]
629+
)
601630

602631
return bwrap_cmd + cmd
603632

@@ -621,11 +650,13 @@ def execute_code(self, code: str) -> REPLResult:
621650
total_time = time.perf_counter() - total_start
622651

623652
# Track overhead
624-
self._overhead_stats["executions"].append({
625-
"total_ms": total_time * 1000,
626-
"code_ms": (result.execution_time or 0) * 1000,
627-
"overhead_ms": (total_time - (result.execution_time or 0)) * 1000,
628-
})
653+
self._overhead_stats["executions"].append(
654+
{
655+
"total_ms": total_time * 1000,
656+
"code_ms": (result.execution_time or 0) * 1000,
657+
"overhead_ms": (total_time - (result.execution_time or 0)) * 1000,
658+
}
659+
)
629660

630661
return result
631662

@@ -638,13 +669,15 @@ def _try_execute(self, code: str) -> REPLResult:
638669

639670
# Build environment - inherit essential vars for macOS compatibility
640671
env = os.environ.copy()
641-
env.update({
642-
"PATH": os.path.join(self.venv_path, "bin") + ":/usr/bin:/bin",
643-
"HOME": self.temp_dir,
644-
"TMPDIR": self.temp_dir,
645-
"PYTHONDONTWRITEBYTECODE": "1",
646-
"PYTHONNOUSERSITE": "1",
647-
})
672+
env.update(
673+
{
674+
"PATH": os.path.join(self.venv_path, "bin") + ":/usr/bin:/bin",
675+
"HOME": self.temp_dir,
676+
"TMPDIR": self.temp_dir,
677+
"PYTHONDONTWRITEBYTECODE": "1",
678+
"PYTHONNOUSERSITE": "1",
679+
}
680+
)
648681

649682
try:
650683
result = subprocess.run(
@@ -720,9 +753,7 @@ def add_context(
720753
context_path = os.path.join(self.temp_dir, f"context_{context_index}.txt")
721754
with open(context_path, "w") as f:
722755
f.write(context_payload)
723-
self.execute_code(
724-
f"with open(r'{context_path}', 'r') as f:\n {var_name} = f.read()"
725-
)
756+
self.execute_code(f"with open(r'{context_path}', 'r') as f:\n {var_name} = f.read()")
726757
else:
727758
context_path = os.path.join(self.temp_dir, f"context_{context_index}.json")
728759
with open(context_path, "w") as f:
@@ -798,7 +829,9 @@ def get_overhead_summary(self) -> dict:
798829
"packages_installed": [i["package"] for i in installs],
799830
"overhead_percentage": round(
800831
(total_overhead / (total_overhead + total_code_time)) * 100, 1
801-
) if total_code_time > 0 else 0,
832+
)
833+
if total_code_time > 0
834+
else 0,
802835
}
803836

804837
def print_overhead_summary(self):

0 commit comments

Comments
 (0)