U
    /eG                     @  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
ZG dd deZdd ZejddZdS )a   Thoroughly document Bokeh enumerations

The ``bokeh-enum`` directive generates useful documentation for enumerations,
including all the allowable values. If the number of values is large, the full
list is put in a collapsible code block.

This directive takes the name of a Bokeh enum variable as the argument and the
module name as an option. An optional description may be added as content:

.. code-block:: rest

    .. bokeh-enum:: baz
        :module: bokeh.sphinxext.sample

        Specify a baz style

Examples
--------

The directive above will generate the following output:

    .. bokeh-enum:: baz
        :module: bokeh.sphinxext.sample

        Specify a baz style

Although ``bokeh-enum`` may be used explicitly, it is more often convenient in
conjunction with the :ref:`bokeh.sphinxext.bokeh_autodoc` extension. Together,
the same output above will be generated directly from the following code:

.. code-block:: python

    #: Specify a baz style
    baz = enumeration("a", "b", "c")

    )annotationsN)	unchanged)SphinxError   )PARALLEL_SAFE)BokehDirective)ENUM_DETAIL)BokehEnumDirectivesetupc                   @  s*   e Zd ZdZdZedd dZdd ZdS )	r	   Tr   c                 C  s   dS )NT )xr   r   >/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/sphinxext/bokeh_enum.py<lambda>^       zBokehEnumDirective.<lambda>)modulenoindexc                 C  s   | j d }| jd }zt|}W n( tk
rJ   td|d| Y nX t||d }t|}t|dkr|d d  d|dd   }t	
|}n|}d }tj|| jd | jd	d
| j||d}| |dS )Nr   r   z&Could not generate reference docs for z: could not import module    (   z .... ir   F)namer   r   content	shortreprfullreprz<bokeh-enum>)	argumentsoptions	importlibimport_moduleImportErrorr   getattrreprlen_wrapperwrapr   rendergetr   parse)selfZ	enum_namemodule_namer   enumr   r   Zrst_textr   r   r   runa   s,    

	zBokehEnumDirective.runN)__name__
__module____qualname__Zhas_contentZrequired_argumentsr   Zoption_specr(   r   r   r   r   r	   X   s   r	   c                 C  s   |  ddt tS )z+ Required Sphinx extension setup function. pyz
bokeh-enum)Zadd_directive_to_domainr	   r   )Zappr   r   r   r
      s    r
   z    )subsequent_indent)__doc__
__future__r   logging	getLoggerr)   logr   textwrapZdocutils.parsers.rst.directivesr   Zsphinx.errorsr    r   Zbokeh_directiver   Z	templatesr   __all__r	   r
   TextWrapperr    r   r   r   r   <module>   s   (
(
