Skip to content

Commit e018ab4

Browse files
committed
fixed all errors
1 parent 1857e70 commit e018ab4

File tree

6 files changed

+61
-12
lines changed

6 files changed

+61
-12
lines changed

commit0/__main__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
import copy
55
import sys
66
import hydra
7+
from hydra.core.config_store import ConfigStore
8+
from commit0.configs.config_class import Commit0Config
79

810

911
def main() -> None:
1012
command = sys.argv[1]
13+
# type check config values
14+
cs = ConfigStore.instance()
15+
cs.store(name="base", node=Commit0Config)
1116
# have hydra to ignore all command-line arguments
1217
sys_argv = copy.deepcopy(sys.argv)
1318
sys.argv = [sys.argv[0]]
14-
hydra.initialize(version_base=None, config_path="../configs")
19+
hydra.initialize(version_base=None, config_path="configs")
1520
config = hydra.compose(config_name="base")
1621
# after hydra gets all configs, put command-line arguments back
1722
sys.argv = sys_argv
@@ -21,7 +26,9 @@ def main() -> None:
2126
config.dataset_name, config.dataset_split, config.base_dir
2227
)
2328
elif command == "build":
24-
commit0.harness.build.main(config.dataset_name, config.dataset_split)
29+
commit0.harness.build.main(
30+
config.dataset_name, config.dataset_split, config.num_workers
31+
)
2532
elif command == "test":
2633
repo = sys.argv[2]
2734
test_ids = sys.argv[3]

commit0/configs/__init__.py

Whitespace-only changes.

commit0/configs/base.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defaults:
2+
- _self_
3+
4+
# shared in all steps
5+
dataset_name: wentingzhao/commit0_docstring
6+
dataset_split: test
7+
8+
# clone related
9+
base_dir: repos/
10+
11+
# build related
12+
build: all
13+
num_workers: 8
14+
15+
# test related
16+
backend: local
17+
branch: ai
18+
timeout: 1_800

commit0/configs/config_class.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from dataclasses import dataclass
2+
from typing import Literal
3+
4+
5+
@dataclass
6+
class Commit0Config:
7+
# shared in all steps
8+
dataset_name: str
9+
dataset_split: str
10+
11+
# clone related
12+
base_dir: str
13+
14+
# build related
15+
# which repo to build, all or one repo
16+
build: str
17+
num_workers: int
18+
19+
# test related
20+
backend: str
21+
# which branch to work on
22+
branch: str
23+
# timeout for running pytest
24+
timeout: int

commit0/harness/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
logger = logging.getLogger(__name__)
1515

1616

17-
def main(dataset_name: str, dataset_split: str) -> None:
17+
def main(dataset_name: str, dataset_split: str, num_workers: int) -> None:
1818
dataset: Iterator[RepoInstance] = load_dataset(dataset_name, split=dataset_split) # type: ignore
1919
specs = []
2020
for example in dataset:
2121
spec = make_spec(example)
2222
specs.append(spec)
2323

2424
client = docker.from_env()
25-
build_repo_images(client, specs)
25+
build_repo_images(client, specs, num_workers)
2626
logger.info("Done building docker images")
2727

2828

commit0/harness/docker_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,20 +385,20 @@ def exec_run_with_timeout(
385385
# Local variables to store the result of executing the command
386386
exec_result = ""
387387
exec_id = None
388-
exception = None
389388
timed_out = False
390389

391390
# Wrapper function to run the command
392391
def run_command() -> None:
393-
nonlocal exec_result, exec_id, exception
392+
nonlocal exec_result, exec_id
394393
try:
395-
exec_id = container.client.api.exec_create(container=container.id, cmd=cmd)["Id"]
396-
exec_stream = container.client.api.exec_start(exec_id=exec_id, stream=True)
394+
exec_id = container.client.api.exec_create(container=container.id, cmd=cmd)[ # pyright: ignore
395+
"Id"
396+
]
397+
exec_stream = container.client.api.exec_start(exec_id=exec_id, stream=True) # pyright: ignore
397398
for chunk in exec_stream:
398399
exec_result += chunk.decode("utf-8", errors="replace")
399-
except Exception as e:
400-
print(e)
401-
exception = e
400+
except docker.errors.APIError as e:
401+
raise Exception(f"Container {container.id} cannot execute {cmd}.\n{str(e)}")
402402

403403
# Start the command in a separate thread
404404
thread = threading.Thread(target=run_command)
@@ -409,7 +409,7 @@ def run_command() -> None:
409409
# If the thread is still alive, the command timed out
410410
if thread.is_alive():
411411
if exec_id is not None:
412-
exec_pid = container.client.api.exec_inspect(exec_id=exec_id)["Pid"]
412+
exec_pid = container.client.api.exec_inspect(exec_id=exec_id)["Pid"] # pyright: ignore
413413
container.exec_run(f"kill -TERM {exec_pid}", detach=True)
414414
timed_out = True
415415
end_time = time.time()

0 commit comments

Comments
 (0)