contrib/import-checker.py
changeset 52650 b95b12cb31e2
parent 52644 e627cc25b6f3
child 52656 3e84e001b6c1
equal deleted inserted replaced
52649:d903647abbd3 52650:b95b12cb31e2
     1 #!/usr/bin/env python3
     1 #!/usr/bin/env python3
     2 
     2 
     3 
     3 
     4 import ast
     4 import ast
     5 import collections
     5 import collections
     6 import io
       
     7 import os
     6 import os
     8 import sys
     7 import sys
     9 
     8 
    10 # Import a minimal set of stdlib modules needed for list_stdlib_modules()
     9 # Import a minimal set of stdlib modules needed for list_stdlib_modules()
    11 # to work when run from a virtualenv.  The modules were chosen empirically
    10 # to work when run from a virtualenv.  The modules were chosen empirically
   703     if py or f.endswith('.t'):
   702     if py or f.endswith('.t'):
   704         # Strictly speaking we should sniff for the magic header that denotes
   703         # Strictly speaking we should sniff for the magic header that denotes
   705         # Python source file encoding. But in reality we don't use anything
   704         # Python source file encoding. But in reality we don't use anything
   706         # other than ASCII (mainly) and UTF-8 (in a few exceptions), so
   705         # other than ASCII (mainly) and UTF-8 (in a few exceptions), so
   707         # simplicity is fine.
   706         # simplicity is fine.
   708         with io.open(f, 'r', encoding='utf-8') as src:
   707         with open(f, 'r', encoding='utf-8') as src:
   709             for script, modname, t, line in embedded(f, modname, src):
   708             for script, modname, t, line in embedded(f, modname, src):
   710                 yield script, modname.encode('utf8'), t, line
   709                 yield script, modname.encode('utf8'), t, line
   711 
   710 
   712 
   711 
   713 def main(argv):
   712 def main(argv):