Coverage for glotter/__main__.py: 61%
55 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-09-13 19:09 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-09-13 19:09 +0000
1import argparse
2import sys
4from glotter.batch import batch
5from glotter.check import check
6from glotter.download import download
7from glotter.report import report
8from glotter.run import run
9from glotter.test import test
12def main():
13 parser = argparse.ArgumentParser(
14 prog="glotter",
15 usage="""usage: glotter [-h] COMMAND
17Commands:
18 run Run sources or group of sources. Use `glotter run --help` for more information.
19 test Run tests for sources or a group of sources. Use `glotter test --help` for more information.
20 download Download all the docker images required to run the tests
21 report Output a report of discovered sources for configured projects and languages
22 batch Download docker images, run tests, and optionally remove images for each batch
23 check Check for invalid sample program filenames
24""",
25 )
26 parser.add_argument(
27 "command",
28 type=str,
29 help="Subcommand to run",
30 choices=["run", "test", "download", "report", "batch", "check"],
31 )
32 args = parser.parse_args(sys.argv[1:2])
33 commands = {
34 "download": parse_download,
35 "run": parse_run,
36 "test": parse_test,
37 "report": parse_report,
38 "batch": parse_batch,
39 "check": parse_check,
40 }
41 commands[args.command]()
44def parse_download():
45 parser = argparse.ArgumentParser(
46 prog="glotter",
47 description="Download images for a source or a group of sources. This command can be filtered by language, "
48 "project, or a single source. Only one option may be specified.",
49 )
50 _add_parallel_arg(parser, "Download images in parallel")
51 args = _parse_args_for_verb(parser)
52 download(args)
55def parse_run():
56 parser = argparse.ArgumentParser(
57 prog="glotter",
58 description="Run a source or a group of sources. This command can be filtered by language, project"
59 "or a single source. Only one option may be specified.",
60 )
61 args = _parse_args_for_verb(parser)
62 run(args)
65def parse_test():
66 parser = argparse.ArgumentParser(
67 prog="glotter",
68 description="Test a source or a group of sources. This command can be filtered by language, project"
69 "or a single source. Only one option may be specified.",
70 )
71 _add_parallel_arg(parser, "Run tests in parallel")
72 args = _parse_args_for_verb(parser)
73 test(args)
76def _add_parallel_arg(parser, help_msg):
77 parser.add_argument("--parallel", action="store_true", help=help_msg)
80def _parse_args_for_verb(parser):
81 parser.add_argument(
82 "-s",
83 "--source",
84 metavar="SOURCE.EXT",
85 type=str,
86 help="source filename (not path) to run",
87 )
88 parser.add_argument(
89 "-p",
90 "--project",
91 metavar="PROJECT",
92 type=str,
93 help="project to run",
94 )
95 parser.add_argument(
96 "-l",
97 "--language",
98 metavar="LANGUAGE",
99 type=str,
100 help="language to run",
101 )
102 args = parser.parse_args(sys.argv[2:])
103 return args
106def parse_report():
107 parser = argparse.ArgumentParser(
108 prog="glotter",
109 description="Output a report of discovered sources for configured projects and languages",
110 )
111 parser.add_argument(
112 "-o",
113 "--output",
114 metavar="REPORT_PATH",
115 type=str,
116 help="output the report as a csv at REPORT_PATH instead of to stdout",
117 )
118 args = parser.parse_args(sys.argv[2:])
119 report(args)
122def parse_batch():
123 parser = argparse.ArgumentParser(
124 prog="glotter",
125 description="Download images, run tests, and optionally remove image in batches"
126 "project, or a single source. Only one option may be specified.",
127 )
128 parser.add_argument("num_batches", metavar="NUM_BATCHES", type=int, help="number of batches")
129 _add_parallel_arg(
130 parser,
131 "Download images, run tests, and optionally remove images in parallel for each batch",
132 )
133 parser.add_argument(
134 "--batch", type=int, metavar="BATCH", help="batch number (1 to NUM_BATCHES)"
135 )
136 parser.add_argument(
137 "--remove",
138 action="store_true",
139 help="remove docker images are each batch is finished",
140 )
141 args = parser.parse_args(sys.argv[2:])
142 batch(args)
145def parse_check():
146 parser = argparse.ArgumentParser(
147 prog="glotter",
148 description="Check for invalid sample program filenames.",
149 )
150 args = parser.parse_args(sys.argv[2:])
151 check(args)
154if __name__ == "__main__": 154 ↛ 155line 154 didn't jump to line 155 because the condition on line 154 was never true
155 main()