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

Side by Side Diff: recipe_engine/doc.py

Issue 1921943002: doc: General improvements. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Rebase license. Created 4 years, 6 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
« no previous file with comments | « no previous file | recipe_engine/loader.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The LUCI Authors. All rights reserved. 2 # Copyright 2013 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be 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
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 def map_to_cool_name(typ): 57 def map_to_cool_name(typ):
58 if typ is collections.Mapping: 58 if typ is collections.Mapping:
59 return 'Mapping' 59 return 'Mapping'
60 return typ 60 return typ
61 61
62 def p(indent_lvl, *args, **kwargs): 62 def p(indent_lvl, *args, **kwargs):
63 sys.stdout.write(' '*indent_lvl) 63 sys.stdout.write(' '*indent_lvl)
64 print(*args, **kwargs) 64 print(*args, **kwargs)
65 65
66 def pmethod(indent_lvl, name, obj): 66 def pmethod(indent_lvl, name, obj):
67 if getattr(obj, '__original', None):
68 obj = obj.__original
69
67 if isinstance(obj, property): 70 if isinstance(obj, property):
68 name = '@'+name 71 name = '@'+name
69 if obj.fset: 72 if obj.fset:
70 name += '(r/w)' 73 name += '(r/w)'
71 p(indent_lvl, name, '', end='') 74
75 try:
76 arg_spec = inspect.getargspec(obj)
77 except TypeError:
78 arg_spec = None
79
80 meth_name = name
81 if arg_spec:
82 meth_name += inspect.formatargspec(*arg_spec)
83
84 p(indent_lvl, meth_name, '', end='')
72 if obj.__doc__: 85 if obj.__doc__:
73 lines = trim_doc(obj.__doc__) 86 lines = trim_doc(obj.__doc__)
74 p(0, '--', lines[0]) 87 p(0, '--', lines[0])
75 else: 88 else:
76 p(0) 89 p(0)
77 90
78 def main(universe): 91 def main(universe_view):
79 common_methods = set(k for k, v in member_iter(recipe_api.RecipeApi)) 92 common_methods = set(k for k, v in member_iter(recipe_api.RecipeApi))
80 p(0, 'Common Methods -- %s' % os.path.splitext(recipe_api.__file__)[0]) 93 p(0, 'Common Methods -- %s' % os.path.splitext(recipe_api.__file__)[0])
81 for method in sorted(common_methods): 94 for method in sorted(common_methods):
82 pmethod(1, method, getattr(recipe_api.RecipeApi, method)) 95 pmethod(1, method, getattr(recipe_api.RecipeApi, method))
83 96
84 deps = {} 97 deps = {}
85 for package, module_name in universe.loop_over_recipe_modules(): 98 universe = universe_view.universe
86 deps[module_name] = universe.load(package, module_name) 99 for module_name in universe_view.loop_over_recipe_modules():
100 deps[module_name] = universe.load(universe_view.package, module_name)
87 101
88 inst = loader.create_recipe_api( 102 inst = loader.create_recipe_api(
89 deps, recipe_run.RecipeEngine(None, {}, universe)) 103 deps, recipe_run.RecipeEngine(None, {}, universe))
90 104
91 for mod_name, mod in deps.iteritems(): 105 for mod_name, mod in sorted(deps.iteritems(), key=lambda it: it[0]):
92 p(0) 106 p(0)
93 p(0, "(%s) -- %s" % (mod_name, mod.__path__[0])) 107 p(0, "(%s) -- %s" % (mod_name, mod.__path__[0]))
94 if mod.LOADED_DEPS: 108 if mod.LOADED_DEPS:
95 p(1, 'DEPS:', list(mod.LOADED_DEPS)) 109 p(1, 'DEPS:', list(mod.LOADED_DEPS))
96 110
97 subinst = getattr(inst, mod_name) 111 subinst = getattr(inst, mod_name)
98 bases = set(subinst.__class__.__bases__) 112 bases = set(subinst.__class__.__bases__)
99 base_fns = set() 113 base_fns = set()
100 for base in bases: 114 for base in bases:
101 for name, _ in inspect.getmembers(base): 115 for name, _ in inspect.getmembers(base):
102 base_fns.add(name) 116 base_fns.add(name)
103 for cool_base in bases - set((recipe_api.RecipeApi,)): 117 for cool_base in bases - set((recipe_api.RecipeApi,)):
104 p(1, 'behaves like %s' % map_to_cool_name(cool_base)) 118 p(1, 'behaves like %s' % map_to_cool_name(cool_base))
105 119
106 if mod.API.__doc__: 120 if mod.API.__doc__:
107 for line in trim_doc(mod.API.__doc__): 121 for line in trim_doc(mod.API.__doc__):
108 p(2, '"', line) 122 p(2, '"', line)
109 123
110 for fn_name, obj in member_iter(subinst): 124 for fn_name, obj in member_iter(subinst):
111 if fn_name in base_fns: 125 if fn_name in base_fns:
112 continue 126 continue
113 pmethod(1, fn_name, obj) 127 pmethod(1, fn_name, obj)
OLDNEW
« no previous file with comments | « no previous file | recipe_engine/loader.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698