Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / tools / telemetry / third_party / modulegraph / scripts / extract_implies.py
blobd6ab353614197508f8dbb52dd8ffbd3a075d2b9f
1 #!/usr/bin/env python
2 """
3 This script looks for ImportModules calls in C extensions
4 of the stdlib.
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 """
12 import re
13 import sys
14 import os
15 import pprint
17 import_re = re.compile('PyImport_ImportModule\w+\("(\w+)"\);')
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
25 module_name = fn[:-2]
26 if module_name.endswith('module'):
27 module_name = module_name[:-6]
29 with open(os.path.join(modules_dir, fn)) as fp:
30 data = fp.read()
32 imports = list(sorted(set(import_re.findall(data))))
33 if imports:
34 yield module_name, imports
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('.', '')))))
43 if __name__ == "__main__":
44 main()