Coverage for glotter/__main__.py: 61%

55 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-12 02:25 +0000

1import sys 

2import argparse 

3 

4from glotter.run import run 

5from glotter.test import test 

6from glotter.download import download 

7from glotter.report import report 

8from glotter.batch import batch 

9from glotter.check import check 

10 

11 

12def main(): 

13 parser = argparse.ArgumentParser( 

14 prog="glotter", 

15 usage="""usage: glotter [-h] COMMAND 

16 

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]() 

42 

43 

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) 

53 

54 

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) 

63 

64 

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) 

74 

75 

76def _add_parallel_arg(parser, help_msg): 

77 parser.add_argument("--parallel", action="store_true", help=help_msg) 

78 

79 

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 

104 

105 

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) 

120 

121 

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( 

129 "num_batches", metavar="NUM_BATCHES", type=int, help="number of batches" 

130 ) 

131 _add_parallel_arg( 

132 parser, 

133 "Download images, run tests, and optionally remove images in parallel for each batch", 

134 ) 

135 parser.add_argument( 

136 "--batch", type=int, metavar="BATCH", help="batch number (1 to NUM_BATCHES)" 

137 ) 

138 parser.add_argument( 

139 "--remove", 

140 action="store_true", 

141 help="remove docker images are each batch is finished", 

142 ) 

143 args = parser.parse_args(sys.argv[2:]) 

144 batch(args) 

145 

146 

147def parse_check(): 

148 parser = argparse.ArgumentParser( 

149 prog="glotter", 

150 description="Check for invalid sample program filenames.", 

151 ) 

152 args = parser.parse_args(sys.argv[2:]) 

153 check(args) 

154 

155 

156if __name__ == "__main__": 156 ↛ 157line 156 didn't jump to line 157 because the condition on line 156 was never true

157 main()