ó
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 m Z m Z m Z m Z m Z m Z d d l m Z d d l m Z m Z d d l m Z d d	 l m Z m Z d Z d e f d     YZ d   Z  d   Z! d S(   u?    Generate a gallery of Bokeh plots from a configuration file.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   abspatht   dirnamet   existst   isdirt   isfilet   getmtimet   join(   t   SphinxError(   t	   ensuredirt   status_iteratori   (   t   BokehDirective(   t   GALLERY_DETAILt   GALLERY_PAGEu   BokehGalleryDirectiveu   setupt   BokehGalleryDirectivec           B` s   e  Z e Z d  Z d   Z RS(   i   c   	      C` sĺ   |  j  j j j } t | j | j   } t | |  j d  } t t t |   d  } t	 |  r t
 |  r t d | | f   n  t j t |   } g  | d D] } | d ^ q­ } t j d |  } |  j | d  S(   Ni    u   galleryu*   gallery dir %r missing for gallery file %ru   detailsu   namet   namesu   <bokeh-gallery>(   t   statet   documentt   settingst   envR   t   doc2patht   docnameR
   t	   argumentsR   R   R   t   jsont   loadt   openR   t   rendert   _parse(	   t   selfR   t   docdirt   gallery_filet   gallery_dirt   spect   detailR   t   rst_text(    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_gallery.pyt   run:   s    !(   t   __name__t
   __module__t   Falset   has_contentt   required_argumentsR&   (    (    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_gallery.pyR   5   s   c         C` s   t  |  j | j  } | d } t |  rQ t |  rQ t d | | f   n  t |  } t |  t t	 j
 |   } t j t |   } | d } t d   | D  } t |  t |  k  rÜ t d |   n  t | d d t |  |  j d d	   }	 xĚ |	 D]Ä }
 |
 d
 d } t  | |  } | | k rL| j |  n  t |  rpt |  | k rpqn  t | d  P } t t  |  j d d |
 d   } | j t j d |
 d
 d d |   Wd  QXqWx$ | D] } t	 j t  | |   qÜWd  S(   Nu   .jsonu<   could not find gallery file %r for configured gallery dir %ru   detailsc         s` s   |  ] } | d  Vq d S(   u   nameN(    (   t   .0t   x(    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_gallery.pys	   <genexpr>_   s    u#   gallery file %r has duplicate namesu!   creating gallery file entries... u   brownt   stringify_funcc         S` s   |  d d S(   Nu   nameu   .rst(    (   R-   (    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_gallery.pyt   <lambda>h   t    u   nameu   .rstu   wu   ..u   patht   filenameu   .pyt   source_path(   R
   t   srcdirt   bokeh_gallery_dirR   R   R   R	   R   t   sett   ost   listdirR   R   R   t   lenR   t	   verbosityt   removeR   t   writeR   R   (   t   appt   configR"   R!   t   gallery_file_mtimet   extrasR#   t   detailsR   t   details_iterR$   t   detail_file_namet   detail_file_patht   fR2   t
   extra_file(    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_gallery.pyt   config_inited_handlerL   s<    


		"1c         C` s@   |  j  d t d d  d  |  j d t  |  j d t  d S(   u+    Required Sphinx extension setup function. u   bokeh_gallery_diru   docsu   galleryu   htmlu   config-initedu   bokeh-galleryN(   t   add_config_valueR
   t   connectRF   t   add_directiveR   (   R<   (    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_gallery.pyt   setup|   s    (   u   BokehGalleryDirectiveu   setup("   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggerR'   t   logR   R6   t   os.pathR   R   R   R   R   R	   R
   t   sphinx.errorsR   t   sphinx.utilR   R   t   bokeh_directiveR   t	   templatesR   R   t   __all__R   RF   RJ   (    (    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_gallery.pyt   <module>	   s   "4 	0