Skip to content

Commit e45d8db

Browse files
authored
Merge pull request #38 from commit-0/fix/typer
Add typer and remove hydra
2 parents 68cfc3a + 929cc90 commit e45d8db

File tree

7 files changed

+278
-172
lines changed

7 files changed

+278
-172
lines changed

.github/workflows/system.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ jobs:
1919
- name: Install the project
2020
run: uv sync
2121
- name: Set up commit0
22-
run: uv run commit0 clone simpy
22+
run: uv run commit0 setup simpy
2323
- name: Build docker images
2424
run: uv run commit0 build simpy
2525
- name: Get tests
2626
run: uv run commit0 get-tests simpy
2727
- name: Test
28-
run: uv run commit0 test-reference simpy tests/test_event.py::test_succeed
28+
run: uv run commit0 test simpy tests/test_event.py::test_succeed --reference
2929
- name: Evaluate
30-
run: uv run commit0 evaluate-reference simpy
30+
run: uv run commit0 evaluate simpy --reference
3131
- name: Lint
3232
run: uv run commit0 lint commit0/harness/lint.py
3333
- name: Save

commit0/__main__.py

Lines changed: 3 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,171 +1,10 @@
1-
import commit0.harness.run_pytest_ids
2-
import commit0.harness.get_pytest_ids
3-
import commit0.harness.build
4-
import commit0.harness.setup
5-
import commit0.harness.evaluate
6-
import commit0.harness.lint
7-
import commit0.harness.save
8-
import copy
9-
import sys
10-
import os
11-
import hydra
12-
from hydra.core.config_store import ConfigStore
13-
from commit0.configs.config_class import Commit0Config
14-
from commit0.harness.constants import COMMANDS, SPLIT
15-
from omegaconf import OmegaConf
1+
from commit0.cli import app as commit0_app
162

173

184
def main() -> None:
19-
command = sys.argv[1]
20-
if command not in COMMANDS:
21-
raise ValueError(
22-
f"command must be from {', '.join(COMMANDS)}, but you provided {command}"
23-
)
24-
# type check config values
25-
cs = ConfigStore.instance()
26-
cs.store(name="user", group="Commit0Config", node=Commit0Config)
27-
# have hydra to ignore all command-line arguments
28-
sys_argv = copy.deepcopy(sys.argv)
29-
cfg_arg = next((arg for arg in sys_argv if arg.startswith("--cfg=")), None)
30-
31-
hydra.initialize(version_base=None, config_path="configs")
32-
config = hydra.compose(config_name="user")
33-
34-
if cfg_arg:
35-
sys_argv.remove(cfg_arg)
36-
config_name = cfg_arg.split("=")[1]
37-
user_config = OmegaConf.load(config_name)
38-
config = OmegaConf.merge(config, user_config)
39-
40-
# after hydra gets all configs, put command-line arguments back
41-
sys.argv = sys_argv
42-
# repo_split: split from command line has a higher priority than split in hydra
43-
if command in [
44-
"clone",
45-
"build",
46-
"evaluate",
47-
"evaluate-reference",
48-
"save",
49-
]:
50-
if len(sys.argv) >= 3:
51-
if sys.argv[2] not in SPLIT:
52-
raise ValueError(
53-
f"repo split must be from {', '.join(SPLIT.keys())}, but you provided {sys.argv[2]}"
54-
)
55-
config.repo_split = sys.argv[2]
56-
config.base_dir = os.path.abspath(config.base_dir)
57-
58-
if command == "clone":
59-
if len(sys.argv) != 3:
60-
raise ValueError(
61-
"You provided an incorrect number of arguments.\nUsage: commit0 clone {repo_split}"
62-
)
63-
commit0.harness.setup.main(
64-
config.dataset_name,
65-
config.dataset_split,
66-
config.repo_split,
67-
config.base_dir,
68-
)
69-
elif command == "build":
70-
if len(sys.argv) != 3:
71-
raise ValueError(
72-
"You provided an incorrect number of arguments.\nUsage: commit0 build {repo_split}"
73-
)
74-
commit0.harness.build.main(
75-
config.dataset_name,
76-
config.dataset_split,
77-
config.repo_split,
78-
config.num_workers,
79-
config.backend,
80-
)
81-
elif command == "get-tests":
82-
if len(sys.argv) != 3:
83-
raise ValueError(
84-
"You provided an incorrect number of arguments.\nUsage: commit0 get-tests {repo_name}"
85-
)
86-
repo = sys.argv[2]
87-
commit0.harness.get_pytest_ids.main(repo, stdout=True)
88-
elif command == "test" or command == "test-reference":
89-
# this command assume execution in arbitrary working directory
90-
repo_or_repo_path = sys.argv[2]
91-
if command == "test-reference":
92-
if len(sys.argv) != 4:
93-
raise ValueError(
94-
"You provided an incorrect number of arguments.\nUsage: commit0 test-reference {repo_dir} {test_ids}"
95-
)
96-
branch = "reference"
97-
test_ids = sys.argv[3]
98-
else:
99-
if len(sys.argv) != 5:
100-
raise ValueError(
101-
"You provided an incorrect number of arguments.\nUsage: commit0 test {repo_dir} {branch} {test_ids}"
102-
)
103-
branch = sys.argv[3]
104-
test_ids = sys.argv[4]
105-
if branch.startswith("branch="):
106-
branch = branch[len("branch=") :]
107-
commit0.harness.run_pytest_ids.main(
108-
config.dataset_name,
109-
config.dataset_split,
110-
config.base_dir,
111-
repo_or_repo_path,
112-
branch,
113-
test_ids,
114-
config.backend,
115-
config.timeout,
116-
config.num_cpus,
117-
stdout=True,
118-
)
119-
elif command == "evaluate" or command == "evaluate-reference":
120-
if command == "evaluate-reference":
121-
if len(sys.argv) != 3:
122-
raise ValueError(
123-
"You provided an incorrect number of arguments.\nUsage: commit0 evaluate-reference {repo_split}"
124-
)
125-
branch = "reference"
126-
else:
127-
if len(sys.argv) != 4:
128-
raise ValueError(
129-
"You provided an incorrect number of arguments.\nUsage: commit0 evaluate {repo_split} {branch}"
130-
)
131-
branch = sys.argv[3]
132-
if branch.startswith("branch="):
133-
branch = branch[len("branch=") :]
134-
commit0.harness.evaluate.main(
135-
config.dataset_name,
136-
config.dataset_split,
137-
config.repo_split,
138-
config.base_dir,
139-
branch,
140-
config.backend,
141-
config.timeout,
142-
config.num_cpus,
143-
config.num_workers,
144-
)
145-
elif command == "lint":
146-
files = sys.argv[1:]
147-
commit0.harness.lint.main(config.base_dir, files)
148-
elif command == "save":
149-
if len(sys.argv) != 5:
150-
raise ValueError(
151-
"You provided an incorrect number of arguments.\nUsage: commit0 save {repo_split} {owner} {branch}"
152-
)
153-
owner = sys.argv[3]
154-
branch = sys.argv[4]
155-
if branch.startswith("branch="):
156-
branch = branch[len("branch=") :]
157-
commit0.harness.save.main(
158-
config.dataset_name,
159-
config.dataset_split,
160-
config.repo_split,
161-
config.base_dir,
162-
owner,
163-
branch,
164-
config.github_token,
165-
)
5+
"""Main function to run the CLI"""
6+
commit0_app()
1667

1678

1689
if __name__ == "__main__":
16910
main()
170-
171-
__all__ = []

0 commit comments

Comments
 (0)