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]
Enh: Start from clone of python conda environment for speedup (#548)
Kilian Lierete65a1eca7bcf
diff --git a/docker/swe.Dockerfile b/docker/swe.Dockerfileindex 3ea7ad14..fb5a6cc5 100644--- a/docker/swe.Dockerfile+++ b/docker/swe.Dockerfile@@ -37,6 +37,10 @@ RUN conda --version \&& conda init bash \&& conda config --append channels conda-forge+# Cache python versions+RUN conda create -y -n python3.9 python=3.9+RUN conda create -y -n python3.10 python=3.10+# Install python packagesCOPY docker/requirements.txt /root/requirements.txtRUN pip install -r /root/requirements.txtdiff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex 4cf8ea5e..635fa20d 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -935,13 +935,31 @@ class SWEEnv(gym.Env):logger.debug("Created conda environment with environment.yml")self.communicate(f"rm {PATH_TO_ENV_YML}")else:- # Create environment + install packages+ python_env = f"python{install_configs['python']}"+ if self._conda_environment_exists(python_env):+ self.communicate_with_handling(+ f"conda create --name {env_name} --clone {python_env}",+ error_msg="Failed to clone conda environment",+ timeout_duration=LONG_TIMEOUT,+ )+ logger.debug("Cloned python conda environment")+ else:+ self.communicate_with_handling(+ f"conda create -n {env_name} python={install_configs['python']} -y",+ error_msg="Failed to create conda environment",+ timeout_duration=LONG_TIMEOUT,+ )self.communicate_with_handling(- f"conda create -n {env_name} python={install_configs['python']} {packages} -y",- error_msg="Failed to create conda environment",- timeout_duration=LONG_TIMEOUT,+ f"conda activate {env_name}",+ error_msg="Failed to activate conda environment",)- logger.debug("Created conda environment and installed packages")+ if packages.strip():+ self.communicate_with_handling(+ f"conda install {packages} -y",+ error_msg="Failed to install packages",+ timeout_duration=LONG_TIMEOUT,+ )+ logger.debug("Installed conda packages")# Install extra pip packages if specifiedif install_configs.get("pip_packages"):self.communicate_with_handling(diff --git a/tests/test_env.py b/tests/test_env.pyindex 2ad93c67..74474b58 100644--- a/tests/test_env.py+++ b/tests/test_env.py@@ -122,6 +122,21 @@ def test_execute_environment(tmp_path, test_env_args):env.reset()+def test_execute_environment_clone_python_uv(tmp_path, test_env_args):+ """This should clone the existing python 3.10 conda environment for speedup"""+ test_env = {+ "python": "3.10",+ "packages": "pytest",+ "pip_packages": ["tox"],+ }+ env_config_path = Path(tmp_path / "env_config.yml")+ env_config_path.write_text(yaml.dump(test_env))+ test_env_args = dataclasses.replace(test_env_args, environment_setup=env_config_path)+ with swe_env_context(test_env_args) as env:+ env.reset()++@pytest.mark.slow()def test_open_pr(test_env_args):test_env_args = dataclasses.replace(