σ
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
 m Z m Z d d l m Z d Z d d d  Z d d d  Z d d d  Z d d d  Z d   Z d Z d d  Z d S(   uZ   Simplify linking to Bokeh Github resources.

This module proved four new roles that can be uses to easily link to various
resources in the Bokeh Github repository:

``:bokeh-commit:`` : link to a specific commit

``:bokeh-issue:`` : link to an issue

``:bokeh-pull:`` : link to a pull request

``:bokeh-tree:`` : (versioned) link to a source tree URL

Examples
--------

The following code:

.. code-block:: rest

    The repo history shows that :bokeh-commit:`bf19bcb` was made in
    in :bokeh-pull:`1698`, which closed :bokeh-issue:`1694`. This included
    updating all of the files in the :bokeh-tree:`examples` subdirectory.

yields the output:

The repo history shows that :bokeh-commit:`bf19bcb` was made in
in :bokeh-pull:`1698`,which closed :bokeh-issue:`1694`. This included
updating all of the files in the :bokeh-tree:`examples` subdirectory.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   nodest   utils(   t   set_classesu   bokeh_commitu   bokeh_issueu
   bokeh_pullu
   bokeh_treeu   setupc   	      C` s=   | j  j j j } t | | d d d | |  } | g g  f S(   uΉ    Link to a Bokeh Github issue.

    Returns 2 part tuple containing list of nodes to insert into the
    document and a list of system messages.  Both are allowed to be
    empty.

    u   commitu   commit (   t   documentt   settingst   envt   appt   _make_gh_link_node(	   t   namet   rawtextt   textt   linenot   inlinert   optionst   contentR
   t   node(    (    s;   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_github.pyt   bokeh_commitO   s    c         C` sΊ   | j  j j j } y% t |  } | d k r6 t  n  WnO t k
 r | j j d | d | }	 | j | | |	  }
 |
 g |	 g f SXt	 | | d d d t
 |  |  } | g g  f S(   uΉ    Link to a Bokeh Github issue.

    Returns 2 part tuple containing list of nodes to insert into the
    document and a list of system messages.  Both are allowed to be
    empty.

    i    uQ   Github issue number must be a number greater than or equal to 1; "%s" is invalid.t   lineu   issueu   #u   issues(   R   R   R	   R
   t   intt
   ValueErrort   reportert   errort   problematicR   t   str(   R   R   R   R   R   R   R   R
   t	   issue_numt   msgt   prbR   (    (    s;   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_github.pyt   bokeh_issue[   s    	$c         C` sΊ   | j  j j j } y% t |  } | d k r6 t  n  WnO t k
 r | j j d | d | }	 | j | | |	  }
 |
 g |	 g f SXt	 | | d d d t
 |  |  } | g g  f S(   uΉ    Link to a Bokeh Github issue.

    Returns 2 part tuple containing list of nodes to insert into the
    document and a list of system messages.  Both are allowed to be
    empty.

    i    uX   Github pull request number must be a number greater than or equal to 1; "%s" is invalid.R   u   pullu   pull request (   R   R   R	   R
   R   R   R   R   R   R   R   (   R   R   R   R   R   R   R   R
   R   R   R   R   (    (    s;   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_github.pyt
   bokeh_pullq   s    	$c         C` s   | j  j j j } | j j d } d | k r7 d } n  d t | | f }	 | pS i  } t |  t j | | d |	 | }
 |
 g g  f S(   uς   Link to a URL in the Bokeh GitHub tree, pointing to appropriate tags
    for releases, or to master otherwise.

    The link text is simply the URL path supplied, so typical usage might
    look like:

    .. code-block:: none

        All of the examples are located in the :bokeh-tree:`examples`
        subdirectory of your Bokeh checkout.

    Returns 2 part tuple containing list of nodes to insert into the
    document and a list of system messages.  Both are allowed to be
    empty.

    u   versionu   -u   masteru   %s/tree/%s/%st   refuri(	   R   R   R	   R
   t   configt	   _BOKEH_GHR   R   t	   reference(   R   R   R   R   R   R   R   R
   t   tagt   urlR   (    (    s;   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_github.pyt
   bokeh_tree   s    	
c         C` sD   |  j  d t  |  j  d t  |  j  d t  |  j  d t  d S(   u+    Required Sphinx extension setup function. u   bokeh-commitu   bokeh-issueu
   bokeh-pullu
   bokeh-treeN(   t   add_roleR   R   R    R'   (   R
   (    (    s;   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_github.pyt   setup€   s    u   https://github.com/bokeh/bokehc   	      C` sU   d t  | | f } | p i  } t |  t j | | t j |  d | | } | S(   u   Return a link to a Bokeh Github resource.

    Args:
        app (Sphinx app) : current app
        rawtext (str) : text being replaced with link node.
        role (str) : role name
        kind (str) : resource type (issue, pull, etc.)
        api_type (str) : type for api link
        id : (str) : id of the resource to link to
        options (dict) : options dictionary passed to role function

    u   %s/%s/%sR!   (   R#   R   R   R$   R   t   unescape(	   R
   R   t   rolet   kindt   api_typet   idR   R&   R   (    (    s;   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_github.pyR   ±   s    
"(   u   bokeh_commitu   bokeh_issueu
   bokeh_pullu
   bokeh_treeu   setup(   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggert   __name__t   logt   docutilsR   R   t   docutils.parsers.rst.rolesR   t   __all__t   NoneR   R   R    R'   R)   R#   R   (    (    (    s;   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_github.pyt   <module>%   s"   "    	