| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 from __future__ import print_function | 6 from __future__ import print_function |
| 7 | 7 |
| 8 import collections | 8 import collections |
| 9 import inspect | 9 import inspect |
| 10 import os | 10 import os |
| 11 import sys | 11 import sys |
| 12 | 12 |
| 13 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | 13 from . import loader |
| 14 sys.path.append(os.path.join(os.path.dirname(__file__), | 14 from . import main as recipe_main |
| 15 '..', '..', 'third_party')) | 15 from . import package |
| 16 | 16 from . import recipe_api |
| 17 from recipe_engine import main as recipe_main | |
| 18 from recipe_engine import recipe_api | |
| 19 from recipe_engine import loader | |
| 20 | |
| 21 from slave import recipe_universe | |
| 22 | 17 |
| 23 def trim_doc(docstring): | 18 def trim_doc(docstring): |
| 24 """From PEP 257""" | 19 """From PEP 257""" |
| 25 if not docstring: | 20 if not docstring: |
| 26 return '' | 21 return '' |
| 27 # Convert tabs to spaces (following the normal Python rules) | 22 # Convert tabs to spaces (following the normal Python rules) |
| 28 # and split into a list of lines: | 23 # and split into a list of lines: |
| 29 lines = docstring.expandtabs().splitlines() | 24 lines = docstring.expandtabs().splitlines() |
| 30 # Determine minimum indentation (first line doesn't count): | 25 # Determine minimum indentation (first line doesn't count): |
| 31 indent = sys.maxint | 26 indent = sys.maxint |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 name = '@'+name | 68 name = '@'+name |
| 74 if obj.fset: | 69 if obj.fset: |
| 75 name += '(r/w)' | 70 name += '(r/w)' |
| 76 p(indent_lvl, name, '', end='') | 71 p(indent_lvl, name, '', end='') |
| 77 if obj.__doc__: | 72 if obj.__doc__: |
| 78 lines = trim_doc(obj.__doc__) | 73 lines = trim_doc(obj.__doc__) |
| 79 p(0, '--', lines[0]) | 74 p(0, '--', lines[0]) |
| 80 else: | 75 else: |
| 81 p(0) | 76 p(0) |
| 82 | 77 |
| 83 def main(): | 78 def main(package_cfg): |
| 84 common_methods = set(k for k, v in member_iter(recipe_api.RecipeApi)) | 79 common_methods = set(k for k, v in member_iter(recipe_api.RecipeApi)) |
| 85 p(0, 'Common Methods -- %s' % os.path.splitext(recipe_api.__file__)[0]) | 80 p(0, 'Common Methods -- %s' % os.path.splitext(recipe_api.__file__)[0]) |
| 86 for method in sorted(common_methods): | 81 for method in sorted(common_methods): |
| 87 pmethod(1, method, getattr(recipe_api.RecipeApi, method)) | 82 pmethod(1, method, getattr(recipe_api.RecipeApi, method)) |
| 88 | 83 |
| 89 universe = recipe_universe.get_universe() | 84 if isinstance(package_cfg, package.PackageDeps): |
| 90 deps = universe.deps_from_paths( | 85 package_deps = package_cfg |
| 91 { modpath: modpath | 86 else: |
| 92 for modpath in universe.loop_over_recipe_modules() }, | 87 package_deps = package.PackageDeps.create(package_cfg) |
| 93 base_path=None) | 88 universe = loader.RecipeUniverse(package_deps) |
| 89 deps = universe.deps_from_spec( |
| 90 # TODO(luqui): This doesn't handle name scoping correctly (e.g. same-named |
| 91 # modules in different packages). |
| 92 { modpath: modpath.split('/')[-1] |
| 93 for modpath in universe.loop_over_recipe_modules() }) |
| 94 | 94 |
| 95 inst = loader.create_recipe_api( | 95 inst = loader.create_recipe_api( |
| 96 deps, recipe_main.RecipeEngine(None, {}, None)) | 96 deps, recipe_main.RecipeEngine(None, {}, None)) |
| 97 | 97 |
| 98 for mod_name, mod in deps.iteritems(): | 98 for mod_name, mod in deps.iteritems(): |
| 99 p(0) | 99 p(0) |
| 100 p(0, "(%s) -- %s" % (mod_name, mod.__path__[0])) | 100 p(0, "(%s) -- %s" % (mod_name, mod.__path__[0])) |
| 101 if mod.LOADED_DEPS: | 101 if mod.LOADED_DEPS: |
| 102 p(1, 'DEPS:', list(mod.LOADED_DEPS)) | 102 p(1, 'DEPS:', list(mod.LOADED_DEPS)) |
| 103 | 103 |
| 104 subinst = getattr(inst, mod_name) | 104 subinst = getattr(inst, mod_name) |
| 105 bases = set(subinst.__class__.__bases__) | 105 bases = set(subinst.__class__.__bases__) |
| 106 base_fns = set() | 106 base_fns = set() |
| 107 for base in bases: | 107 for base in bases: |
| 108 for name, _ in inspect.getmembers(base): | 108 for name, _ in inspect.getmembers(base): |
| 109 base_fns.add(name) | 109 base_fns.add(name) |
| 110 for cool_base in bases - set((recipe_api.RecipeApi,)): | 110 for cool_base in bases - set((recipe_api.RecipeApi,)): |
| 111 p(1, 'behaves like %s' % map_to_cool_name(cool_base)) | 111 p(1, 'behaves like %s' % map_to_cool_name(cool_base)) |
| 112 | 112 |
| 113 if mod.API.__doc__: | 113 if mod.API.__doc__: |
| 114 for line in trim_doc(mod.API.__doc__): | 114 for line in trim_doc(mod.API.__doc__): |
| 115 p(2, '"', line) | 115 p(2, '"', line) |
| 116 | 116 |
| 117 for fn_name, obj in member_iter(subinst): | 117 for fn_name, obj in member_iter(subinst): |
| 118 if fn_name in base_fns: | 118 if fn_name in base_fns: |
| 119 continue | 119 continue |
| 120 pmethod(1, fn_name, obj) | 120 pmethod(1, fn_name, obj) |
| 121 | |
| 122 | |
| 123 if __name__ == '__main__': | |
| 124 main() | |
| OLD | NEW |