Skip to content

Commit

Permalink
Merge pull request #261 from 3N4N/enan
Browse files Browse the repository at this point in the history
Fix: issues of 'harness' in Windows
  • Loading branch information
john-b-yang authored Dec 10, 2024
2 parents edd590e + c264a1c commit 2ebd0b8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion swebench/harness/docker_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setup_logger(instance_id: str, log_file: Path, mode="w"):
"""
log_file.parent.mkdir(parents=True, exist_ok=True)
logger = logging.getLogger(f"{instance_id}.{log_file.name}")
handler = logging.FileHandler(log_file, mode=mode)
handler = logging.FileHandler(log_file, mode=mode, encoding='utf-8')
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
Expand Down
2 changes: 2 additions & 0 deletions swebench/harness/dockerfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
_DOCKERFILE_ENV = r"""FROM --platform={platform} sweb.base.{arch}:latest
COPY ./setup_env.sh /root/
RUN sed -i -e 's/\r$//' /root/setup_env.sh
RUN chmod +x /root/setup_env.sh
RUN /bin/bash -c "source ~/.bashrc && /root/setup_env.sh"
Expand All @@ -48,6 +49,7 @@
_DOCKERFILE_INSTANCE = r"""FROM --platform={platform} {env_image_name}
COPY ./setup_repo.sh /root/
RUN sed -i -e 's/\r$//' /root/setup_repo.sh
RUN /bin/bash /root/setup_repo.sh
WORKDIR /testbed/
Expand Down
10 changes: 6 additions & 4 deletions swebench/harness/run_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import docker
import json
import resource
import platform
if platform.system() == 'Linux': import resource
import traceback

from argparse import ArgumentParser
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path
from pathlib import Path,PurePosixPath
from tqdm import tqdm

from swebench.harness.constants import (
Expand Down Expand Up @@ -121,7 +122,7 @@ def run_instance(
logger.info(
f"Intermediate patch for {instance_id} written to {patch_file}, now applying to container..."
)
copy_to_container(container, patch_file, Path(DOCKER_PATCH))
copy_to_container(container, patch_file, PurePosixPath(DOCKER_PATCH))

# Attempt to apply patch to container
val = container.exec_run(
Expand Down Expand Up @@ -511,7 +512,8 @@ def main(
"""
# set open file limit
assert len(run_id) > 0, "Run ID must be provided"
resource.setrlimit(resource.RLIMIT_NOFILE, (open_file_limit, open_file_limit))
if platform.system() == 'Linux':
resource.setrlimit(resource.RLIMIT_NOFILE, (open_file_limit, open_file_limit))
client = docker.from_env()

# load predictions as map of instance_id to prediction
Expand Down
5 changes: 3 additions & 2 deletions swebench/harness/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import posixpath
from pathlib import Path
import re
import requests
Expand Down Expand Up @@ -176,7 +177,7 @@ def get_lines_with_word(text, target_word):
@cache
def get_environment_yml_by_commit(repo: str, commit: str, env_name: str) -> str:
for req_path in MAP_REPO_TO_ENV_YML_PATHS[repo]:
reqs_url = os.path.join(SWE_BENCH_URL_RAW, repo, commit, req_path)
reqs_url = posixpath.join(SWE_BENCH_URL_RAW, repo, commit, req_path)
reqs = requests.get(reqs_url, headers=HEADERS)
if reqs.status_code == 200:
break
Expand Down Expand Up @@ -221,7 +222,7 @@ def get_environment_yml(instance: SWEbenchInstance, env_name: str) -> str:
@cache
def get_requirements_by_commit(repo: str, commit: str) -> str:
for req_path in MAP_REPO_TO_REQS_PATHS[repo]:
reqs_url = os.path.join(SWE_BENCH_URL_RAW, repo, commit, req_path)
reqs_url = posixpath.join(SWE_BENCH_URL_RAW, repo, commit, req_path)
reqs = requests.get(reqs_url, headers=HEADERS)
if reqs.status_code == 200:
break
Expand Down

0 comments on commit 2ebd0b8

Please sign in to comment.