B
    @\K                 @   s   d Z ddlmZmZmZ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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 class. A JSON prototype showing all the possible
JSON fields will also be generated.

This directive takes the path to a Bokeh model class as an
argument::

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

Examples
--------

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

    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")


the above usage yields the output:

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

    )absolute_importdivisionprint_functionunicode_literalsN)	unchanged)SphinxError   )	MetaModel   )BokehDirective	py_sig_re)MODEL_DETAIL)BokehModelDirectivesetupc               @   s(   e Zd ZdZdZdZdeiZdd ZdS )r   Tr
   r   modulec             C   s   d | j}t|}|d kr*td| | \}}}}| jd }yt|}W n$ t	k
rv   td||f Y nX t
||d }	|	d krtd|||f t|	tkrtd||f |	 }
tj|
jdddd	d
d}tj|||d}| |dS )N z-Unable to parse signature for bokeh-model: %rr   zEUnable to generate reference docs for %s, couldn't import module '%s'z=Unable to generate reference docs for %s, no model '%s' in %szMUnable to generate reference docs for %s, model '%s' is not of type MetaModelT)Zinclude_defaultsr   ),z: )Z	sort_keysindentZ
separators)namemodule_name
model_jsonz<bokeh-model>)joinZ	argumentsr   matchr   groupsZoptions	importlibimport_moduleImportErrorgetattrtyper	   jsondumpsZto_jsonr   Zrender_parse)selfZsigmZname_prefixZ
model_nameZarglistZretannr   r   modelZ	model_objr   Zrst_text r%   :lib/python3.7/site-packages/bokeh/sphinxext/bokeh_model.pyrun[   s4    


zBokehModelDirective.runN)	__name__
__module____qualname__Zhas_contentZrequired_argumentsZoptional_argumentsr   Zoption_specr'   r%   r%   r%   r&   r   Q   s
   r   c             C   s   |  ddt d S )Npyzbokeh-model)Zadd_directive_to_domainr   )Zappr%   r%   r&   r      s    r   )__doc__Z
__future__r   r   r   r   ZloggingZ	getLoggerr(   logr   r   Zdocutils.parsers.rst.directivesr   Zsphinx.errorsr   r$   r	   Zbokeh_directiver   r   Z	templatesr   __all__r   r   r%   r%   r%   r&   <module>$   s   
1