#! /usr/bin/env python import os import re from itertools import chain _macros = None def macros_list(): # List of macros in pyconfig.h.in. global _macros if _macros is None: with open('pyconfig.h.in') as f: _macros = (m.group('macro') for m in re.finditer(r'\n#\s*undef\s+(?P\S+)(?=[ \n])', f.read())) return _macros def sources_list(): def uncommented_lines(f): for line in f: if not line.startswith('#') and not '-DPy_BUILD_CORE' in line: yield (m.group('source') for m in re.finditer(r'\s+(?P\S+\.c)(?=[ \t\n])', line)) # List of the sources that do not access the interpreter internals. with open('Modules/Setup.dist') as f: return chain(*list(uncommented_lines(f))) def main(): #print(list(macros_list())) #print(list(sources_list())) # Print the list of pyconfig.h.in macros that are being used by one of the # standard library extension modules that do not access the interpreter # internals. for source in sources_list(): with open(os.path.join('Modules', source)) as f: content = f.read() for macro in macros_list(): if macro in content: print('%s: %s' % (source, macro)) if __name__ == '__main__': main()