MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Doc/tools/check-html-ids.py:101–178  ·  view source on GitHub ↗
(argv)

Source from the content-addressed store, hash-verified

99
100
101def main(argv):
102 parser = argparse.ArgumentParser()
103 parser.add_argument(
104 '-v',
105 '--verbose',
106 action='store_true',
107 help='print out more information',
108 )
109 subparsers = parser.add_subparsers(dest='command', required=True)
110
111 collect = subparsers.add_parser(
112 'collect', help='collect IDs from a set of HTML files'
113 )
114 collect.add_argument(
115 'htmldir', type=Path, help='directory with HTML documentation'
116 )
117 collect.add_argument(
118 '-o',
119 '--outfile',
120 help='File to save the result in; default <htmldir>/html-ids.json.gz',
121 )
122
123 check = subparsers.add_parser('check', help='check two archives of IDs')
124 check.add_argument(
125 'baseline_file', type=Path, help='file with baseline IDs'
126 )
127 check.add_argument('checked_file', type=Path, help='file with checked IDs')
128 check.add_argument(
129 '-x',
130 '--exclude-file',
131 type=Path,
132 help='file with IDs to exclude from the check',
133 )
134
135 args = parser.parse_args(argv[1:])
136
137 if args.verbose:
138 verbose_print = functools.partial(print, file=sys.stderr)
139 else:
140
141 def verbose_print(*args, **kwargs):
142 """do nothing"""
143
144 if args.command == 'collect':
145 ids = gather_ids(args.htmldir, verbose_print=verbose_print)
146 if args.outfile is None:
147 args.outfile = args.htmldir / 'html-ids.json.gz'
148 with gzip.open(args.outfile, 'wt', encoding='utf-8') as zfile:
149 json.dump({'ids_by_page': ids}, zfile)
150
151 if args.command == 'check':
152 with gzip.open(args.baseline_file) as zfile:
153 baseline = json.load(zfile)['ids_by_page']
154 with gzip.open(args.checked_file) as zfile:
155 checked = json.load(zfile)['ids_by_page']
156 excluded = set()
157 if args.exclude_file:
158 with open(args.exclude_file, encoding='utf-8') as file:

Callers 1

check-html-ids.pyFile · 0.70

Calls 15

add_subparsersMethod · 0.95
parse_argsMethod · 0.95
gather_idsFunction · 0.85
setFunction · 0.85
do_checkFunction · 0.85
add_parserMethod · 0.80
partialMethod · 0.80
verbose_printFunction · 0.70
openFunction · 0.50
add_argumentMethod · 0.45
openMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…