ó
mÜJ]c           @` sÚ   d  Z  d d l m Z m Z m Z m Z d d l Z e j 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 d e f d „  ƒ  YZ d „  Z d S(   uç   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")


the above 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.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t	   unchanged(   t   SphinxErrori   (   t	   MetaModeli   (   t   BokehDirectivet	   py_sig_re(   t   MODEL_DETAILu   BokehModelDirectiveu   setupt   BokehModelDirectivec           B` s0   e  Z e Z d  Z d  Z i e d 6Z d „  Z RS(   i   u   modulec      	   C` sk  d j  |  j ƒ } t j | ƒ } | d  k r@ t d | ƒ ‚ n  | j ƒ  \ } } } } |  j d } y t j	 | ƒ } Wn' t
 k
 r¡ t d | | f ƒ ‚ n Xt | | d  ƒ }	 |	 d  k rÜ t d | | | f ƒ ‚ n  t |	 ƒ t k rt d | | f ƒ ‚ n  |	 ƒ  }
 t j |
 j d t ƒ d t d	 d
 d d ƒ} t j d | d | d | ƒ } |  j | d ƒ S(   Nu    u-   Unable to parse signature for bokeh-model: %ru   moduleuE   Unable to generate reference docs for %s, couldn't import module '%s'u=   Unable to generate reference docs for %s, no model '%s' in %suM   Unable to generate reference docs for %s, model '%s' is not of type MetaModelt   include_defaultst	   sort_keyst   indenti   t
   separatorsu   ,u   : t   namet   module_namet
   model_jsonu   <bokeh-model>(   u   ,u   : (   t   joint	   argumentsR   t   matcht   NoneR   t   groupst   optionst	   importlibt   import_modulet   ImportErrort   getattrt   typeR   t   jsont   dumpst   to_jsont   TrueR	   t   rendert   _parse(   t   selft   sigt   mt   name_prefixt
   model_namet   arglistt   retannR   t   modulet   modelt	   model_objR   t   rst_text(    (    s:   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_model.pyt   run`   s4    				(	   t   __name__t
   __module__R    t   has_contentt   required_argumentst   optional_argumentsR   t   option_specR.   (    (    (    s:   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_model.pyR
   W   s   
c         C` s   |  j  d d t ƒ d S(   u+    Required Sphinx extension setup function. u   pyu   bokeh-modelN(   t   add_directive_to_domainR
   (   t   app(    (    s:   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_model.pyt   setup‡   s    (   u   BokehModelDirectiveu   setup(   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggerR/   t   logR   R   t   docutils.parsers.rst.directivesR   t   sphinx.errorsR   R+   R   t   bokeh_directiveR   R   t	   templatesR	   t   __all__R
   R7   (    (    (    s:   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_model.pyt   <module>*   s   " 0