1 #!/usr/bin/env python 2 """ 3 This script looks for ImportModules calls in C extensions 4 of the stdlib. 5 6 The current version has harcoded the location of the source 7 tries on Ronald's machine, a future version will be able 8 to rebuild the modulegraph source file that contains 9 this information. 10 """ 11 12 import re 13 import sys 14 import os 15 import pprint 16 17 import_re = re.compile('PyImport_ImportModule\w+\("(\w+)"\);') 18 19 def extract_implies(root): 20 modules_dir = os.path.join(root, "Modules") 21 for fn in os.listdir(modules_dir): 22 if not fn.endswith('.c'): 23 continue 24 25 module_name = fn[:-2] 26 if module_name.endswith('module'): 27 module_name = module_name[:-6] 28 29 with open(os.path.join(modules_dir, fn)) as fp: 30 data = fp.read() 31 32 imports = list(sorted(set(import_re.findall(data)))) 33 if imports: 34 yield module_name, imports 35 36 37 38 def main(): 39 for version in ('2.6', '2.7', '3.1'): 40 print "====", version 41 pprint.pprint(list(extract_implies('/Users/ronald/Projects/python/release%s-maint'%(version.replace('.', ''))))) 42 43 if __name__ == "__main__": 44 main() 45