Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: scripts/tools/show_me_the_modules.py

Issue 1241323004: Cross-repo recipe package system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Roll to latest recipes-py Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 from __future__ import print_function
7
8 import collections
9 import inspect
10 import os
11 import sys
12
13 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
14 sys.path.append(os.path.join(os.path.dirname(__file__),
15 '..', '..', 'third_party'))
16
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
23 def trim_doc(docstring):
24 """From PEP 257"""
25 if not docstring:
26 return ''
27 # Convert tabs to spaces (following the normal Python rules)
28 # and split into a list of lines:
29 lines = docstring.expandtabs().splitlines()
30 # Determine minimum indentation (first line doesn't count):
31 indent = sys.maxint
32 for line in lines[1:]:
33 stripped = line.lstrip()
34 if stripped:
35 indent = min(indent, len(line) - len(stripped))
36 # Remove indentation (first line is special):
37 trimmed = [lines[0].strip()]
38 if indent < sys.maxint:
39 for line in lines[1:]:
40 trimmed.append(line[indent:].rstrip())
41 # Strip off trailing and leading blank lines:
42 while trimmed and not trimmed[-1]:
43 trimmed.pop()
44 while trimmed and not trimmed[0]:
45 trimmed.pop(0)
46 return trimmed
47
48 def member_iter(obj):
49 for name in sorted(dir(obj)):
50 if name[0] == '_' and name != '__call__':
51 continue
52 # Check class first to avoid calling property functions.
53 if hasattr(obj.__class__, name):
54 val = getattr(obj.__class__, name)
55 if callable(val) or isinstance(val, property):
56 yield name, val
57 else:
58 val = getattr(obj, name)
59 if callable(val) or inspect.ismodule(val):
60 yield name, val
61
62 def map_to_cool_name(typ):
63 if typ is collections.Mapping:
64 return 'Mapping'
65 return typ
66
67 def p(indent_lvl, *args, **kwargs):
68 sys.stdout.write(' '*indent_lvl)
69 print(*args, **kwargs)
70
71 def pmethod(indent_lvl, name, obj):
72 if isinstance(obj, property):
73 name = '@'+name
74 if obj.fset:
75 name += '(r/w)'
76 p(indent_lvl, name, '', end='')
77 if obj.__doc__:
78 lines = trim_doc(obj.__doc__)
79 p(0, '--', lines[0])
80 else:
81 p(0)
82
83 def main():
84 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])
86 for method in sorted(common_methods):
87 pmethod(1, method, getattr(recipe_api.RecipeApi, method))
88
89 universe = recipe_universe.get_universe()
90 deps = universe.deps_from_paths(
91 { modpath: modpath
92 for modpath in universe.loop_over_recipe_modules() },
93 base_path=None)
94
95 inst = loader.create_recipe_api(
96 deps, recipe_main.RecipeEngine(None, {}, None))
97
98 for mod_name, mod in deps.iteritems():
99 p(0)
100 p(0, "(%s) -- %s" % (mod_name, mod.__path__[0]))
101 if mod.LOADED_DEPS:
102 p(1, 'DEPS:', list(mod.LOADED_DEPS))
103
104 subinst = getattr(inst, mod_name)
105 bases = set(subinst.__class__.__bases__)
106 base_fns = set()
107 for base in bases:
108 for name, _ in inspect.getmembers(base):
109 base_fns.add(name)
110 for cool_base in bases - set((recipe_api.RecipeApi,)):
111 p(1, 'behaves like %s' % map_to_cool_name(cool_base))
112
113 if mod.API.__doc__:
114 for line in trim_doc(mod.API.__doc__):
115 p(2, '"', line)
116
117 for fn_name, obj in member_iter(subinst):
118 if fn_name in base_fns:
119 continue
120 pmethod(1, fn_name, obj)
121
122
123 if __name__ == '__main__':
124 main()
OLDNEW
« no previous file with comments | « scripts/slave/unittests/recipe_simulation_test.py ('k') | scripts/tools/unittests/show_me_the_modules_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698