Fix documentation for wrapped functions

This commit is contained in:
ZyX 2013-03-17 21:06:56 +04:00
parent 19b45e609a
commit 34fba2286a
5 changed files with 33 additions and 15 deletions

View File

@ -28,7 +28,7 @@ class ThreadedDocumenter(autodoc.FunctionDocumenter):
for i, arg in zip(count(-1, -1), reversed(argspec.args)):
if (arg == 'self' or
(arg == 'segment_info' and
getattr(self.object, 'requires_powerline_segment_info', None)) or
getattr(self.object, 'powerline_requires_segment_info', None)) or
(method == 'render_one' and -i == len(argspec.args))):
continue
if argspec.defaults and len(argspec.defaults) >= -i:
@ -39,14 +39,24 @@ class ThreadedDocumenter(autodoc.FunctionDocumenter):
args.insert(0, arg)
argspec = ArgSpec(args=args, varargs=None, keywords=None, defaults=tuple(defaults))
else:
argspec = getargspec(self.object)
args = argspec.args
defaults = argspec.defaults
if args and args[0] == 'segment_info' and getattr(self.object, 'requires_powerline_segment_info', None):
args = args[1:]
if defaults and len(defaults) > len(args):
defaults = defaults[1:]
argspec = ArgSpec(args=args, varargs=argspec.varargs, keywords=argspec.keywords, defaults=defaults)
if hasattr(self.object, 'powerline_origin'):
obj = self.object.powerline_origin
else:
obj = self.object
argspec = getargspec(obj)
args = []
defaults = []
for i, arg in zip(count(-1, -1), reversed(argspec.args)):
if (arg == 'segment_info' and getattr(self.object, 'powerline_requires_segment_info', None)):
continue
if argspec.defaults and len(argspec.defaults) >= -i:
default = argspec.defaults[i]
defaults.append(default)
args.append(arg)
else:
args.insert(0, arg)
argspec = ArgSpec(args=args, varargs=argspec.varargs, keywords=argspec.keywords, defaults=tuple(defaults))
return formatargspec(*argspec).replace('\\', '\\\\')

View File

@ -3,6 +3,14 @@ from functools import wraps
import json
def wraps_saveargs(wrapped):
def dec(wrapper):
r = wraps(wrapped)(wrapper)
r.powerline_origin = getattr(wrapped, 'powerline_origin', wrapped)
return r
return dec
def mergedicts(d1, d2):
'''Recursively merge two dictionaries. First dictionary is modified in-place.
'''
@ -15,7 +23,7 @@ def mergedicts(d1, d2):
def add_divider_highlight_group(highlight_group):
def dec(func):
@wraps(func)
@wraps_saveargs(func)
def f(**kwargs):
r = func(**kwargs)
if r:

View File

@ -477,7 +477,7 @@ except ImportError:
def _get_user(): # NOQA
return os.environ.get('USER', None)
def cpu_load_percent(**kwargs): # NOQA
def cpu_load_percent(measure_interval=.5): # NOQA
'''Return the average CPU load as a percentage.
Requires the ``psutil`` module.

View File

@ -14,7 +14,7 @@ from powerline.lib import add_divider_highlight_group
from powerline.lib.vcs import guess
from powerline.lib.humanize_bytes import humanize_bytes
from powerline.lib.threaded import KwThreadedSegment, with_docstring
from functools import wraps
from powerline.lib import wraps_saveargs as wraps
from collections import defaultdict
vim_funcs = {

View File

@ -19,7 +19,7 @@ def u(s):
def requires_segment_info(func):
func.requires_powerline_segment_info = True
func.powerline_requires_segment_info = True
return func
@ -72,8 +72,8 @@ class Theme(object):
parsed_segments = []
for segment in self.segments[side]:
if segment['type'] == 'function':
if (hasattr(segment['contents_func'], 'requires_powerline_segment_info')
and segment['contents_func'].requires_powerline_segment_info):
if (hasattr(segment['contents_func'], 'powerline_requires_segment_info')
and segment['contents_func'].powerline_requires_segment_info):
contents = segment['contents_func'](segment_info=self.segment_info, **segment['args'])
else:
contents = segment['contents_func'](**segment['args'])