U
    /e                     @  s   d Z ddlmZ ddlZeeZddlZddlZddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ dZG dd deZdd ZdS )a   Thoroughly document Bokeh options classes.

The ``bokeh-options`` directive will automatically document all the properties
of a Bokeh Options class under a heading of "Keyword Args".

This directive takes the name of a Bokeh Options subclass as the argument, and
its module as an option:

.. code-block:: rest

    .. bokeh-options:: Opts
        :module: bokeh.sphinxext.sample

Examples
--------

For the following definition of ``bokeh.sphinxext.sample.Opts``:

.. code-block:: python

    class Opts(Options):
        ''' This is an Options class '''

        host = String(default="localhost", help="a host to connect to")
        port = Int(default=5890, help="a port to connect to")

the above usage yields the output:

    .. bokeh-options:: Opts
        :module: bokeh.sphinxext.sample

    )annotationsN)	unchanged)SphinxError)	type_link)Options   )PARALLEL_SAFE)BokehDirective	py_sig_re)OPTIONS_DETAIL)BokehOptionsDirectivesetupc                   @  s(   e Zd ZdZdZdZdeiZdd ZdS )r   Tr   modulec                 C  sB  d | j}t|}|d kr,td|| \}}}}| jd }zt|}W n( t	k
r|   td| d| Y nX t
||d }	|	d krtd| d| t|	tstd| d	|	i }
g }t|
 D ]P}|
|}|t|t|jt||
|jd krd
nt|j d qtj|d}| |dS )N z-Unable to parse signature for bokeh-options: r   z.Unable to generate options reference docs for z, couldn't import module z6Unable to generate options reference docs: no options z in module z+Unable to generate options reference docs: z is not a subclass of Options )nametypedefaultdoc)optsz<bokeh-options>)join	argumentsr
   matchr   groupsoptions	importlibimport_moduleImportErrorgetattr
issubclassr   sortedZ
propertieslookupappenddictr   propertyreprZinstance_default__doc__textwrapdedentrstripr   renderparse)selfsigmZname_prefixZoptions_nameZarglistZretannmodule_namer   r   Zoptions_objr   Z	prop_nameZ
descriptorZrst_text r0   A/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/sphinxext/bokeh_options.pyrun_   s:    



	zBokehOptionsDirective.runN)	__name__
__module____qualname__Zhas_contentZrequired_argumentsZoptional_argumentsr   Zoption_specr2   r0   r0   r0   r1   r   X   s
   r   c                 C  s   |  ddt tS )z+ Required Sphinx extension setup function. pyzbokeh-options)Zadd_directive_to_domainr   r   )Zappr0   r0   r1   r      s    r   )r&   
__future__r   logging	getLoggerr3   logr   r'   Zdocutils.parsers.rst.directivesr   Zsphinx.errorsr   Zbokeh.core.property._sphinxr   Zbokeh.util.optionsr   r   r   Zbokeh_directiver	   r
   Z	templatesr   __all__r   r   r0   r0   r0   r1   <module>   s   $
0