Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Prints all non-system dependencies for the given module. | 6 """Prints all non-system dependencies for the given module. |
| 7 | 7 |
| 8 The primary use-case for this script is to genererate the list of python modules | 8 The primary use-case for this script is to genererate the list of python modules |
| 9 required for .isolate files. | 9 required for .isolate files. |
| 10 """ | 10 """ |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 help='The python module to analyze.') | 75 help='The python module to analyze.') |
| 76 parser.add_argument('--root', default='.', | 76 parser.add_argument('--root', default='.', |
| 77 help='Directory to make paths relative to.') | 77 help='Directory to make paths relative to.') |
| 78 parser.add_argument('--output', | 78 parser.add_argument('--output', |
| 79 help='Write output to a file rather than stdout.') | 79 help='Write output to a file rather than stdout.') |
| 80 parser.add_argument('--whitelist', default=[], action='append', | 80 parser.add_argument('--whitelist', default=[], action='append', |
| 81 dest='whitelists', | 81 dest='whitelists', |
| 82 help='Recursively include all non-test python files ' | 82 help='Recursively include all non-test python files ' |
| 83 'within this directory. May be specified multiple times.') | 83 'within this directory. May be specified multiple times.') |
| 84 options = parser.parse_args() | 84 options = parser.parse_args() |
| 85 sys.path.append(os.path.dirname(options.module)) | 85 # Replace the path entry for print_python_deps.py with the one for the given |
| 86 # module. | |
| 87 sys.path[0] = os.path.dirname(options.module) | |
|
jbudorick
2016/11/10 19:41:02
Do we want anything else in sys.path at all? I'm c
agrieve
2016/11/10 19:45:35
If you clear out sys.path, then normal system impo
jbudorick
2016/11/10 19:49:12
I guess I'm concerned about the case where a modul
| |
| 86 imp.load_source('NAME', options.module) | 88 imp.load_source('NAME', options.module) |
| 87 | 89 |
| 88 paths_set = _ComputePythonDependencies() | 90 paths_set = _ComputePythonDependencies() |
| 89 for path in options.whitelists: | 91 for path in options.whitelists: |
| 90 paths_set.update(os.path.abspath(p) for p in _FindPythonInDirectory(path)) | 92 paths_set.update(os.path.abspath(p) for p in _FindPythonInDirectory(path)) |
| 91 | 93 |
| 92 paths = [os.path.relpath(p, options.root) for p in paths_set] | 94 paths = [os.path.relpath(p, options.root) for p in paths_set] |
| 93 | 95 |
| 94 normalized_cmdline = _NormalizeCommandLine(options) | 96 normalized_cmdline = _NormalizeCommandLine(options) |
| 95 out = open(options.output, 'w') if options.output else sys.stdout | 97 out = open(options.output, 'w') if options.output else sys.stdout |
| 96 with out: | 98 with out: |
| 97 out.write('# Generated by running:\n') | 99 out.write('# Generated by running:\n') |
| 98 out.write('# %s\n' % normalized_cmdline) | 100 out.write('# %s\n' % normalized_cmdline) |
| 99 for path in sorted(paths): | 101 for path in sorted(paths): |
| 100 out.write(path + '\n') | 102 out.write(path + '\n') |
| 101 | 103 |
| 102 | 104 |
| 103 if __name__ == '__main__': | 105 if __name__ == '__main__': |
| 104 sys.exit(main()) | 106 sys.exit(main()) |
| OLD | NEW |