Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Prints all non-system dependencies for the given module. | |
| 7 | |
| 8 The primary use-case for this script is to genererate the list of python modules | |
|
jbudorick
2016/03/11 19:10:06
I'm really not crazy about this. I have a bad feel
agrieve
2016/03/15 02:04:02
Yeah, I'm not 100% set on it either, but I think w
| |
| 9 required for .isolate files. | |
| 10 """ | |
| 11 | |
| 12 import argparse | |
| 13 import imp | |
| 14 import os | |
| 15 import sys | |
| 16 | |
| 17 # Don't use any helper modules, or else they will end up in the results. | |
| 18 | |
| 19 | |
| 20 _SRC_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir)) | |
| 21 | |
| 22 | |
| 23 def ComputePythonDependencies(): | |
| 24 """Gets the paths of imported non-system python modules. | |
| 25 | |
| 26 A path is assumed to be a "system" import if it is outside of chromium's | |
| 27 src/. The paths will be relative to the current directory. | |
| 28 """ | |
| 29 module_paths = (m.__file__ for m in sys.modules.values() | |
| 30 if m is not None and hasattr(m, '__file__')) | |
| 31 | |
| 32 src_paths = set() | |
| 33 for path in module_paths: | |
| 34 if path == __file__: | |
| 35 continue | |
| 36 path = os.path.abspath(path) | |
| 37 if not path.startswith(_SRC_ROOT): | |
| 38 continue | |
| 39 | |
| 40 if path.endswith('.pyc'): | |
| 41 path = path[:-1] | |
| 42 src_paths.add(os.path.relpath(path)) | |
| 43 | |
| 44 return sorted(src_paths) | |
| 45 | |
| 46 | |
| 47 def main(): | |
| 48 parser = argparse.ArgumentParser( | |
| 49 description='Prints all non-system dependencies for the given module.') | |
| 50 parser.add_argument('module', | |
| 51 help='The python module to analyze.') | |
| 52 options = parser.parse_args() | |
| 53 sys.path.append(os.path.dirname(options.module)) | |
| 54 imp.load_source('NAME', options.module) | |
| 55 for path in ComputePythonDependencies(): | |
| 56 print path | |
| 57 | |
| 58 | |
| 59 if __name__ == '__main__': | |
| 60 sys.exit(main()) | |
| OLD | NEW |