Fix documentation for wrapped functions
This commit is contained in:
parent
19b45e609a
commit
34fba2286a
|
@ -28,7 +28,7 @@ class ThreadedDocumenter(autodoc.FunctionDocumenter):
|
||||||
for i, arg in zip(count(-1, -1), reversed(argspec.args)):
|
for i, arg in zip(count(-1, -1), reversed(argspec.args)):
|
||||||
if (arg == 'self' or
|
if (arg == 'self' or
|
||||||
(arg == 'segment_info' and
|
(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))):
|
(method == 'render_one' and -i == len(argspec.args))):
|
||||||
continue
|
continue
|
||||||
if argspec.defaults and len(argspec.defaults) >= -i:
|
if argspec.defaults and len(argspec.defaults) >= -i:
|
||||||
|
@ -39,14 +39,24 @@ class ThreadedDocumenter(autodoc.FunctionDocumenter):
|
||||||
args.insert(0, arg)
|
args.insert(0, arg)
|
||||||
argspec = ArgSpec(args=args, varargs=None, keywords=None, defaults=tuple(defaults))
|
argspec = ArgSpec(args=args, varargs=None, keywords=None, defaults=tuple(defaults))
|
||||||
else:
|
else:
|
||||||
argspec = getargspec(self.object)
|
if hasattr(self.object, 'powerline_origin'):
|
||||||
args = argspec.args
|
obj = self.object.powerline_origin
|
||||||
defaults = argspec.defaults
|
else:
|
||||||
if args and args[0] == 'segment_info' and getattr(self.object, 'requires_powerline_segment_info', None):
|
obj = self.object
|
||||||
args = args[1:]
|
|
||||||
if defaults and len(defaults) > len(args):
|
argspec = getargspec(obj)
|
||||||
defaults = defaults[1:]
|
args = []
|
||||||
argspec = ArgSpec(args=args, varargs=argspec.varargs, keywords=argspec.keywords, defaults=defaults)
|
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('\\', '\\\\')
|
return formatargspec(*argspec).replace('\\', '\\\\')
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,14 @@ from functools import wraps
|
||||||
import json
|
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):
|
def mergedicts(d1, d2):
|
||||||
'''Recursively merge two dictionaries. First dictionary is modified in-place.
|
'''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 add_divider_highlight_group(highlight_group):
|
||||||
def dec(func):
|
def dec(func):
|
||||||
@wraps(func)
|
@wraps_saveargs(func)
|
||||||
def f(**kwargs):
|
def f(**kwargs):
|
||||||
r = func(**kwargs)
|
r = func(**kwargs)
|
||||||
if r:
|
if r:
|
||||||
|
|
|
@ -477,7 +477,7 @@ except ImportError:
|
||||||
def _get_user(): # NOQA
|
def _get_user(): # NOQA
|
||||||
return os.environ.get('USER', None)
|
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.
|
'''Return the average CPU load as a percentage.
|
||||||
|
|
||||||
Requires the ``psutil`` module.
|
Requires the ``psutil`` module.
|
||||||
|
|
|
@ -14,7 +14,7 @@ from powerline.lib import add_divider_highlight_group
|
||||||
from powerline.lib.vcs import guess
|
from powerline.lib.vcs import guess
|
||||||
from powerline.lib.humanize_bytes import humanize_bytes
|
from powerline.lib.humanize_bytes import humanize_bytes
|
||||||
from powerline.lib.threaded import KwThreadedSegment, with_docstring
|
from powerline.lib.threaded import KwThreadedSegment, with_docstring
|
||||||
from functools import wraps
|
from powerline.lib import wraps_saveargs as wraps
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
vim_funcs = {
|
vim_funcs = {
|
||||||
|
|
|
@ -19,7 +19,7 @@ def u(s):
|
||||||
|
|
||||||
|
|
||||||
def requires_segment_info(func):
|
def requires_segment_info(func):
|
||||||
func.requires_powerline_segment_info = True
|
func.powerline_requires_segment_info = True
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@ class Theme(object):
|
||||||
parsed_segments = []
|
parsed_segments = []
|
||||||
for segment in self.segments[side]:
|
for segment in self.segments[side]:
|
||||||
if segment['type'] == 'function':
|
if segment['type'] == 'function':
|
||||||
if (hasattr(segment['contents_func'], 'requires_powerline_segment_info')
|
if (hasattr(segment['contents_func'], 'powerline_requires_segment_info')
|
||||||
and segment['contents_func'].requires_powerline_segment_info):
|
and segment['contents_func'].powerline_requires_segment_info):
|
||||||
contents = segment['contents_func'](segment_info=self.segment_info, **segment['args'])
|
contents = segment['contents_func'](segment_info=self.segment_info, **segment['args'])
|
||||||
else:
|
else:
|
||||||
contents = segment['contents_func'](**segment['args'])
|
contents = segment['contents_func'](**segment['args'])
|
||||||
|
|
Loading…
Reference in New Issue