Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Issues with yanked pkg types-setuptools #232

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions swebench/harness/test_spec.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import hashlib
import json
import platform
Expand Down Expand Up @@ -145,10 +147,34 @@ def make_repo_script_list(specs, repo, repo_directory, base_commit, env_name):
return setup_commands


def make_env_script_list(instance, specs, env_name):
def replace_uninstallable_packages_requirements_txt(requirement_str: str) -> str:
"""Replaces certain packages in a requirements.txt-like string.
For example, some packages have been yanked and we need to replace them with compatible alternatives.
"""
replacements = {
# See https://github.com/princeton-nlp/SWE-bench/issues/199
# This package was sinced yanked, so we need to force pip
# to install it.
# "types-pkg_resources": "types-pkg-resources==0.1.3",
}
requirements = [req.strip() for req in requirement_str.split("\n") if req.strip()]
requirements_replaced = []
for requirement in requirements:
if requirement in replacements:
print(f"Replaced {requirement!r} with {replacements[requirement]!r} (replace_uninstallable_packages)")
requirements_replaced.append(replacements[requirement])
else:
requirements_replaced.append(requirement)
return "\n".join(requirements_replaced) + "\n"


def make_env_script_list(instance: SWEbenchInstance, specs: dict, env_name: str) -> list[str]:
"""
Creates the list of commands to set up the conda environment for testing.
This is the setup script for the environment image.

Returns:
list[str]: List of commands to set up the conda environment
"""
HEREDOC_DELIMITER = "EOF_59812759871"
reqs_commands = [
Expand All @@ -162,7 +188,7 @@ def make_env_script_list(instance, specs, env_name):
reqs_commands.append(cmd)

# Install dependencies
reqs = get_requirements(instance)
reqs = replace_uninstallable_packages_requirements_txt(get_requirements(instance))
path_to_reqs = "$HOME/requirements.txt"
reqs_commands.append(
f"cat <<'{HEREDOC_DELIMITER}' > {path_to_reqs}\n{reqs}\n{HEREDOC_DELIMITER}"
Expand Down
Loading