ยปCore Development>Code coverage>Tools/freeze/makeconfig.py

Python code coverage for Tools/freeze/makeconfig.py

#countcontent
1n/aimport re
2n/aimport sys
3n/a
4n/a# Write the config.c file
5n/a
6n/anever = ['marshal', '_imp', '_ast', '__main__', 'builtins',
7n/a 'sys', 'gc', '_warnings']
8n/a
9n/adef makeconfig(infp, outfp, modules, with_ifdef=0):
10n/a m1 = re.compile('-- ADDMODULE MARKER 1 --')
11n/a m2 = re.compile('-- ADDMODULE MARKER 2 --')
12n/a for line in infp:
13n/a outfp.write(line)
14n/a if m1 and m1.search(line):
15n/a m1 = None
16n/a for mod in modules:
17n/a if mod in never:
18n/a continue
19n/a if with_ifdef:
20n/a outfp.write("#ifndef PyInit_%s\n"%mod)
21n/a outfp.write('extern PyObject* PyInit_%s(void);\n' % mod)
22n/a if with_ifdef:
23n/a outfp.write("#endif\n")
24n/a elif m2 and m2.search(line):
25n/a m2 = None
26n/a for mod in modules:
27n/a if mod in never:
28n/a continue
29n/a outfp.write('\t{"%s", PyInit_%s},\n' %
30n/a (mod, mod))
31n/a if m1:
32n/a sys.stderr.write('MARKER 1 never found\n')
33n/a elif m2:
34n/a sys.stderr.write('MARKER 2 never found\n')
35n/a
36n/a
37n/a# Test program.
38n/a
39n/adef test():
40n/a if not sys.argv[3:]:
41n/a print('usage: python makeconfig.py config.c.in outputfile', end=' ')
42n/a print('modulename ...')
43n/a sys.exit(2)
44n/a if sys.argv[1] == '-':
45n/a infp = sys.stdin
46n/a else:
47n/a infp = open(sys.argv[1])
48n/a if sys.argv[2] == '-':
49n/a outfp = sys.stdout
50n/a else:
51n/a outfp = open(sys.argv[2], 'w')
52n/a makeconfig(infp, outfp, sys.argv[3:])
53n/a if outfp != sys.stdout:
54n/a outfp.close()
55n/a if infp != sys.stdin:
56n/a infp.close()
57n/a
58n/aif __name__ == '__main__':
59n/a test()