Chromium Code Reviews| Index: build/print-python-deps.py |
| diff --git a/build/print-python-deps.py b/build/print-python-deps.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..7ac22ff8d150e58b0cf31aae7222dabef11e18a7 |
| --- /dev/null |
| +++ b/build/print-python-deps.py |
| @@ -0,0 +1,60 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Prints all non-system dependencies for the given module. |
| + |
| +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
|
| +required for .isolate files. |
| +""" |
| + |
| +import argparse |
| +import imp |
| +import os |
| +import sys |
| + |
| +# Don't use any helper modules, or else they will end up in the results. |
| + |
| + |
| +_SRC_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir)) |
| + |
| + |
| +def ComputePythonDependencies(): |
| + """Gets the paths of imported non-system python modules. |
| + |
| + A path is assumed to be a "system" import if it is outside of chromium's |
| + src/. The paths will be relative to the current directory. |
| + """ |
| + module_paths = (m.__file__ for m in sys.modules.values() |
| + if m is not None and hasattr(m, '__file__')) |
| + |
| + src_paths = set() |
| + for path in module_paths: |
| + if path == __file__: |
| + continue |
| + path = os.path.abspath(path) |
| + if not path.startswith(_SRC_ROOT): |
| + continue |
| + |
| + if path.endswith('.pyc'): |
| + path = path[:-1] |
| + src_paths.add(os.path.relpath(path)) |
| + |
| + return sorted(src_paths) |
| + |
| + |
| +def main(): |
| + parser = argparse.ArgumentParser( |
| + description='Prints all non-system dependencies for the given module.') |
| + parser.add_argument('module', |
| + help='The python module to analyze.') |
| + options = parser.parse_args() |
| + sys.path.append(os.path.dirname(options.module)) |
| + imp.load_source('NAME', options.module) |
| + for path in ComputePythonDependencies(): |
| + print path |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |