Skip to content

Commit

Permalink
Rename install -> specs
Browse files Browse the repository at this point in the history
  • Loading branch information
john-b-yang committed Jul 8, 2024
1 parent 7137642 commit c762296
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions swebench/harness/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_test_specs_from_dataset(dataset: Union[list[SWEbenchInstance], list[Test
return list(map(make_test_spec, dataset))


def make_repo_script_list(install, repo, repo_directory, base_commit, env_name):
def make_repo_script_list(specs, repo, repo_directory, base_commit, env_name):
"""
Create a list of bash commands to set up the repository for testing.
This is the setup script for the instance image.
Expand All @@ -133,16 +133,16 @@ def make_repo_script_list(install, repo, repo_directory, base_commit, env_name):
setup_commands.append(MAP_REPO_TO_INSTALL[repo])

# Run pre-install set up if provided
if "pre_install" in install:
for pre_install in install["pre_install"]:
if "pre_install" in specs:
for pre_install in specs["pre_install"]:
setup_commands.append(pre_install)

if "install" in install:
setup_commands.append(install["install"])
if "install" in specs:
setup_commands.append(specs["install"])
return setup_commands


def make_env_script_list(instance, install, env_name):
def make_env_script_list(instance, specs, env_name):
"""
Creates the list of commands to set up the conda environment for testing.
This is the setup script for the environment image.
Expand All @@ -152,10 +152,10 @@ def make_env_script_list(instance, install, env_name):
"source /opt/miniconda3/bin/activate",
]
# Create conda environment according to install instructinos
pkgs = install.get("packages", "")
pkgs = specs.get("packages", "")
if pkgs == "requirements.txt":
# Create environment
cmd = f"conda create -n {env_name} python={install['python']} -y"
cmd = f"conda create -n {env_name} python={specs['python']} -y"
reqs_commands.append(cmd)

# Install dependencies
Expand All @@ -174,9 +174,9 @@ def make_env_script_list(instance, install, env_name):
reqs_commands.append(
f"cat <<'{HEREDOC_DELIMITER}' > {path_to_reqs}\n{reqs}\n{HEREDOC_DELIMITER}"
)
if "no_use_env" in install and install["no_use_env"]:
if "no_use_env" in specs and specs["no_use_env"]:
# `conda create` based installation
cmd = f"conda create -c conda-forge -n {env_name} python={install['python']} -y"
cmd = f"conda create -c conda-forge -n {env_name} python={specs['python']} -y"
reqs_commands.append(cmd)

# Install dependencies
Expand All @@ -187,27 +187,27 @@ def make_env_script_list(instance, install, env_name):
cmd = f"conda env create --file {path_to_reqs}"
reqs_commands.append(cmd)

cmd = f"conda activate {env_name} && conda install python={install['python']} -y"
cmd = f"conda activate {env_name} && conda install python={specs['python']} -y"
reqs_commands.append(cmd)

# Remove environment.yml
reqs_commands.append(f"rm {path_to_reqs}")
else:
# Create environment + install dependencies
cmd = f"conda create -n {env_name} python={install['python']} {pkgs} -y"
cmd = f"conda create -n {env_name} python={specs['python']} {pkgs} -y"
reqs_commands.append(cmd)

reqs_commands.append(f"conda activate {env_name}")

# Install additional packages if specified
if "pip_packages" in install:
pip_packages = " ".join(install["pip_packages"])
if "pip_packages" in specs:
pip_packages = " ".join(specs["pip_packages"])
cmd = f"python -m pip install {pip_packages}"
reqs_commands.append(cmd)
return reqs_commands


def make_eval_script_list(instance, install, env_name, repo_directory, base_commit, test_patch):
def make_eval_script_list(instance, specs, env_name, repo_directory, base_commit, test_patch):
"""
Applies the test patch and runs the tests.
"""
Expand All @@ -229,8 +229,8 @@ def make_eval_script_list(instance, install, env_name, repo_directory, base_comm
f"conda activate {env_name}",
f"cd {repo_directory}",
]
if "eval_commands" in install:
eval_commands += install["eval_commands"]
if "eval_commands" in specs:
eval_commands += specs["eval_commands"]
eval_commands += [
f"git config --global --add safe.directory {repo_directory}", # for nonroot user
f"cd {repo_directory}",
Expand All @@ -241,8 +241,8 @@ def make_eval_script_list(instance, install, env_name, repo_directory, base_comm
"source /opt/miniconda3/bin/activate",
f"conda activate {env_name}",
]
if "install" in install:
eval_commands.append(install["install"])
if "install" in specs:
eval_commands.append(specs["install"])
eval_commands += [
reset_tests_command,
apply_test_patch_command,
Expand Down Expand Up @@ -274,12 +274,12 @@ def _from_json_or_obj(key: str) -> Any:

env_name = "testbed"
repo_directory = f"/{env_name}"
install = MAP_REPO_VERSION_TO_SPECS[repo][version]
specs = MAP_REPO_VERSION_TO_SPECS[repo][version]

repo_script_list = make_repo_script_list(install, repo, repo_directory, base_commit, env_name)
env_script_list = make_env_script_list(instance, install, env_name)
repo_script_list = make_repo_script_list(specs, repo, repo_directory, base_commit, env_name)
env_script_list = make_env_script_list(instance, specs, env_name)
eval_script_list = make_eval_script_list(
instance, install, env_name, repo_directory, base_commit, test_patch
instance, specs, env_name, repo_directory, base_commit, test_patch
)
if platform.machine() in {"aarch64", "arm64"}:
# use arm64 unless explicitly specified
Expand Down

0 comments on commit c762296

Please sign in to comment.