Skip to content

Commit 2a81d68

Browse files
authored
Merge pull request #9 from commit-0/hydra
OmegaConf integration
2 parents bb3213c + 0940d07 commit 2a81d68

File tree

4 files changed

+64
-85
lines changed

4 files changed

+64
-85
lines changed

commit0/harness/run_pytest_ids.py

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
from datasets import load_dataset
23
import docker
34
from enum import StrEnum, auto
45
import os
@@ -7,6 +8,9 @@
78
from pathlib import Path
89
import logging
910

11+
from omegaconf import DictConfig, OmegaConf
12+
import hydra
13+
1014
from commit0.harness.constants import RUN_PYTEST_LOG_DIR
1115
from commit0.harness.docker_build import (
1216
close_logger,
@@ -32,7 +36,7 @@
3236

3337

3438
class ExecutionBackend(StrEnum):
35-
DOCKER = auto()
39+
LOCAL = auto()
3640
MODAL = auto()
3741

3842

@@ -194,72 +198,41 @@ def run_modal(
194198
)
195199

196200

197-
def main(
198-
repo: str,
199-
test_ids_ls: list[str],
200-
timeout: int,
201-
branch_name: str,
202-
backend: ExecutionBackend,
203-
) -> None:
204-
with open("config.yml", "r") as file:
205-
data = yaml.safe_load(file)
206-
spec = make_spec(data["repos"][repo])
207-
test_ids = " ".join(test_ids_ls)
208-
hashed_test_ids = get_hash_string(test_ids)
201+
@hydra.main(version_base=None, config_path="configs", config_name="base")
202+
def main(config: DictConfig) -> None:
203+
OmegaConf.to_yaml(config)
204+
dataset = load_dataset(config.dataset_name, split="test")
205+
for example in dataset:
206+
if example["repo"].endswith(config.repo):
207+
spec = make_spec(example)
208+
break
209209

210+
hashed_test_ids = get_hash_string(config.test_ids)
210211
# set up logging
211-
log_dir = RUN_PYTEST_LOG_DIR / repo / hashed_test_ids
212+
log_dir = RUN_PYTEST_LOG_DIR / config.repo / hashed_test_ids
212213
log_dir.mkdir(parents=True, exist_ok=True)
213214
log_file = log_dir / "run_pytest.log"
214-
logger = setup_logger(repo, log_file)
215+
logger = setup_logger(config.repo, log_file)
215216

216217
# make eval file
217218
eval_script = spec.eval_script.format(
218-
local_repo=f"{data['base_repo_dir']}/{repo}",
219-
branch_name=branch_name,
220-
test_ids=test_ids,
221-
ip=get_ip(data["backend"]),
219+
local_repo=f"{config.base_dir}/{config.repo}",
220+
branch_name=config.branch,
221+
test_ids=config.test_ids,
222+
ip=get_ip(config.backend),
222223
user=get_user(),
223224
)
224225
eval_file = Path(log_dir / "eval.sh")
225226
eval_file.write_text(eval_script)
226227

227-
if ExecutionBackend(backend) == ExecutionBackend.DOCKER:
228-
run_docker(spec, logger, eval_file, timeout, log_dir)
229-
elif ExecutionBackend(backend) == ExecutionBackend.MODAL:
230-
run_modal(spec, logger, eval_file, timeout, log_dir)
231-
232-
233-
def add_init_args(parser: argparse.ArgumentParser) -> None:
234-
parser.add_argument("--repo", type=str, help="which repo to run unit tests")
235-
parser.add_argument(
236-
"--test_ids", type=str, nargs="+", help="which test ids / files / directories"
237-
)
238-
parser.add_argument(
239-
"--branch_name", type=str, help="which git branch to run unit tests"
240-
)
241-
parser.add_argument(
242-
"--timeout",
243-
type=int,
244-
default=1_800,
245-
help="Timeout (in seconds) for running tests for each instance",
246-
)
247-
parser.add_argument(
248-
"--backend",
249-
choices=[backend.value for backend in ExecutionBackend],
250-
default=ExecutionBackend.DOCKER.value,
251-
help="Execution backend [docker, modal]",
252-
)
228+
if ExecutionBackend(config.backend) == ExecutionBackend.LOCAL:
229+
run_docker(spec, logger, eval_file, config.timeout, log_dir)
230+
elif ExecutionBackend(config.backend) == ExecutionBackend.MODAL:
231+
run_modal(spec, logger, eval_file, config.timeout, log_dir)
253232

254233

255234
def run(args: argparse.Namespace) -> None:
256-
main(
257-
repo=args.repo,
258-
test_ids_ls=args.test_ids,
259-
timeout=args.timeout,
260-
branch_name=args.branch_name,
261-
backend=args.backend,
262-
)
235+
main()
263236

264237

265238
__all__ = []

commit0/harness/setup.py

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import argparse
21
import logging
32
import os
43

54
import docker
5+
import hydra
66
import yaml
77
from datasets import load_dataset
8+
from omegaconf import DictConfig, OmegaConf
9+
810
from typing import Iterator
911
from commit0.harness.utils import clone_repo
1012
from commit0.harness.constants import REPO_IMAGE_BUILD_DIR, RepoInstance
1113
from commit0.harness.docker_build import build_repo_images
1214
from commit0.harness.spec import make_spec
1315

16+
1417
logging.basicConfig(
1518
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
1619
)
1720
logger = logging.getLogger(__name__)
1821

1922

20-
def main(
21-
hf_name: str,
22-
base_dir: str,
23-
config_file: str,
24-
) -> None:
23+
@hydra.main(version_base=None, config_path="configs", config_name="base")
24+
def main(config: DictConfig) -> None:
2525
dataset: Iterator[RepoInstance] = load_dataset(hf_name, split="test") # type: ignore
2626
out = dict()
2727
specs = []
@@ -38,40 +38,15 @@ def main(
3838
clone_url, out[repo_name]["local_path"], example["base_commit"], logger
3939
)
4040

41-
config_file = os.path.abspath(config_file)
42-
with open(config_file, "w") as f:
43-
yaml.dump(out, f, default_flow_style=False)
44-
logger.info(f"Config file has been written to {config_file}")
4541
logger.info("Start building docker images")
4642
logger.info(f"Please check {REPO_IMAGE_BUILD_DIR} for build details")
4743
client = docker.from_env()
4844
build_repo_images(client, specs)
4945
logger.info("Done building docker images")
5046

5147

52-
def add_init_args(parser: argparse.ArgumentParser) -> None:
53-
parser.add_argument("--hf_name", type=str, help="HF dataset name")
54-
parser.add_argument(
55-
"--base_dir",
56-
type=str,
57-
default="repos/",
58-
help="base directory to write repos to",
59-
)
60-
parser.add_argument(
61-
"--config_file",
62-
type=str,
63-
default="config.yml",
64-
help="where to write config file to",
65-
)
66-
parser.set_defaults(func=run)
67-
68-
69-
def run(args: argparse.Namespace) -> None:
70-
main(
71-
hf_name=args.hf_name,
72-
base_dir=args.base_dir,
73-
config_file=args.config_file,
74-
)
48+
def run() -> None:
49+
main()
7550

7651

7752
__all__ = []

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies = [
2323
"wget",
2424
"ruff>=0.6.4",
2525
"pre-commit>=3.8.0",
26+
"hydra-core>=1.3.2",
2627
"modal>=0.64.95",
2728
]
2829
scripts = { commit0 = "commit0.__main__:main" }

uv.lock

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)