contrib/import-checker.py
changeset 40687 dd028bca9221
parent 40481 90517fad4293
child 41161 98ce494e104d
equal deleted inserted replaced
40686:9b8d1ad851f8 40687:dd028bca9221
   258             if dirname.startswith(prefix):
   258             if dirname.startswith(prefix):
   259                 # Then this directory is redundant.
   259                 # Then this directory is redundant.
   260                 break
   260                 break
   261         else:
   261         else:
   262             stdlib_prefixes.add(dirname)
   262             stdlib_prefixes.add(dirname)
       
   263     sourceroot = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
   263     for libpath in sys.path:
   264     for libpath in sys.path:
   264         # We want to walk everything in sys.path that starts with
   265         # We want to walk everything in sys.path that starts with something in
   265         # something in stdlib_prefixes.
   266         # stdlib_prefixes, but not directories from the hg sources.
   266         if not any(libpath.startswith(p) for p in stdlib_prefixes):
   267         if (os.path.abspath(libpath).startswith(sourceroot)
       
   268             or not any(libpath.startswith(p) for p in stdlib_prefixes)):
   267             continue
   269             continue
   268         for top, dirs, files in os.walk(libpath):
   270         for top, dirs, files in os.walk(libpath):
   269             for i, d in reversed(list(enumerate(dirs))):
   271             for i, d in reversed(list(enumerate(dirs))):
   270                 if (not os.path.exists(os.path.join(top, d, '__init__.py'))
   272                 if (not os.path.exists(os.path.join(top, d, '__init__.py'))
   271                     or top == libpath and d in ('hgdemandimport', 'hgext',
   273                     or top == libpath and d in ('hgdemandimport', 'hgext',