Skip to content

Commit

Permalink
Preserving original docstring for hv.opts
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Nov 14, 2018
1 parent 5900103 commit 5b3503c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions holoviews/util/__init__.py
Expand Up @@ -70,6 +70,8 @@ class opts(param.ParameterizedFunction):
%%opts cell magic respectively.
"""

__original_docstring__ = None

strict = param.Boolean(default=False, doc="""
Whether to be strict about the options specification. If not set
to strict (default), any invalid keywords are simply skipped. If
Expand Down Expand Up @@ -222,8 +224,13 @@ def fn(spec=None, **kws):

@classmethod
def _update_backend(cls, backend):

if cls.__original_docstring__ is None:
cls.__original_docstring__ = cls.__doc__

if backend not in Store.loaded_backends():
return

backend_options = Store.options(backend)
all_keywords = set()
for element in backend_options.keys():
Expand All @@ -239,9 +246,9 @@ def _update_backend(cls, backend):
cls._build_completer(element[0],
element_keywords))


kws = ', '.join('{opt}=None'.format(opt=opt) for opt in sorted(all_keywords))
cls.__doc__ = 'opts({kws})'.format(kws=kws) # Keep original docstring
old_doc = cls.__original_docstring__.replace('params(strict=Boolean, name=String)','')
cls.__doc__ = '\n opts({kws})'.format(kws=kws) + old_doc


Store._backend_switch_hooks.append(opts._update_backend)
Expand Down

0 comments on commit 5b3503c

Please sign in to comment.