Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Do not leave python when calling run.py

Kilian Lieret03c535fe266c
diff --git a/run.py b/run.py
index 8bb863af..bdd5faea 100644
--- a/run.py
+++ b/run.py
@@ -253,7 +253,12 @@ def save_predictions(traj_dir, instance_id, info):
logger.info(f"Saved predictions to {output_file}")
-if __name__ == "__main__":
+def get_args(args=None) -> ScriptArguments:
+ """Parse command line arguments and return a ScriptArguments object.
+
+ Args:
+ args: Optional list of arguments to parse. If not provided, uses sys.argv.
+ """
defaults = ScriptArguments(
suffix="",
environment=EnvironmentArguments(
@@ -288,5 +293,9 @@ if __name__ == "__main__":
yaml.add_representer(str, multiline_representer)
- args = parse(ScriptArguments, default=defaults, add_config_path_arg=False)
+ return parse(ScriptArguments, default=defaults, add_config_path_arg=False, args=args)
+
+
+if __name__ == "__main__":
+ args = get_args()
main(args)
diff --git a/run_replay.py b/run_replay.py
index 72377153..35324480 100644
--- a/run_replay.py
+++ b/run_replay.py
@@ -8,6 +8,7 @@ import yaml
from argparse import ArgumentParser
from sweagent.environment.utils import is_from_github_url
from typing import Any, Dict, List
+import run as runscript
def process_single_traj(traj_path: str, config_file: str, data_path: str, suffix: str, *, forward_args: List[str]):
@@ -78,9 +79,7 @@ def process_single_traj(traj_path: str, config_file: str, data_path: str, suffix
raise ValueError("--data_path must be a .json or .jsonl")
# Call run.py via subprocess
- command = [
- "python",
- "run.py",
+ run_args = [
"--config_file", config_file,
"--data_path", replay_task_instances_path,
"--install_environment", "True",
@@ -90,10 +89,11 @@ def process_single_traj(traj_path: str, config_file: str, data_path: str, suffix
]
if is_github:
# Not sure if this only applies to github urls for data_path
- command.extend(["--skip_existing", "False"])
+ run_args.extend(["--skip_existing", "False"])
if suffix is not None:
- command.extend(["--suffix", suffix])
- subprocess.run(command)
+ run_args.extend(["--suffix", suffix])
+ script_args = runscript.get_args(run_args)
+ runscript.main(script_args)
os.remove(replay_action_trajs_path)
try: