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	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 model classes.

The ``bokeh-model`` directive will automatically document all the attributes
(including Bokeh properties) of a Bokeh Model subclass. A JSON prototype showing
all the possible JSON fields will also be generated.

This directive takes the name of a Bokeh model class as an argument and its
module as an option:

.. code-block:: rest

    .. bokeh-model:: Foo
        :module: bokeh.sphinxext.sample

Examples
--------

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

.. code-block:: python

    class Foo(Model):
        ''' This is a Foo model. '''
        index = Either(Auto, Enum('abc', 'def', 'xzy'), help="doc for index")
        value = Tuple(Float, Float, help="doc for value")

usage yields the output:

    .. bokeh-model:: Foo
        :module: bokeh.sphinxext.sample

The ``bokeh-model`` direction may be used explicitly, but it can also be used
in conjunction with the :ref:`bokeh.sphinxext.bokeh_autodoc` extension.

    )annotationsN)	unchanged)SphinxError)Model)BokehDeprecationWarning   )PARALLEL_SAFE)BokehDirective	py_sig_re)MODEL_DETAIL)BokehModelDirectivesetupc                   @  s*   e Zd ZdZdZdZeedZdd ZdS )r   Tr   )module	canonicalc              	   C  s.  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	t  tjd
td |	 }
W 5 Q R X tj|
jdddddd}tj||drdn||d}| |dS )N z+Unable to parse signature for bokeh-model: r   z,Unable to generate model reference docs for z, couldn't import module z6Unable to generate model reference docs: no model for z in module z)Unable to generate model reference docs: z, is not a subclass of Modelignore)categoryT)Zinclude_defaults   ),z: )	sort_keysindent
separatorszbokeh.models)namemodule_name
model_jsonz<bokeh-model>)join	argumentsr
   matchr   groupsoptions	importlibimport_moduleImportErrorgetattr
issubclassr   warningscatch_warningsfilterwarningsr   jsondumpsZto_jsonr   render
startswithparse)selfsigmZname_prefixZ
model_nameZarglistZretannr   r   modelZ	model_objr   Zrst_text r1   ?/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/sphinxext/bokeh_model.pyrunf   s2    



zBokehModelDirective.runN)	__name__
__module____qualname__Zhas_contentZrequired_argumentsZoptional_argumentsr   Zoption_specr3   r1   r1   r1   r2   r   \   s   r   c                 C  s   |  ddt tS )z+ Required Sphinx extension setup function. pyzbokeh-model)Zadd_directive_to_domainr   r   )Zappr1   r1   r2   r      s    r   )__doc__
__future__r   logging	getLoggerr4   logr    r(   r%   Zdocutils.parsers.rst.directivesr   Zsphinx.errorsr   Zbokeh.modelr   Zbokeh.util.warningsr    r   Zbokeh_directiver	   r
   Z	templatesr   __all__r   r   r1   r1   r1   r2   <module>   s    '
2