B
    @\C                 @   s   d Z ddlmZmZmZmZ ddlZeeZ	ddl
mZmZ ddlmZ dZdZddd	Zdd
dZdddZdddZdd ZdddZdS )aE   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::

    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.

    )absolute_importdivisionprint_functionunicode_literalsN)nodesutils)set_classeszhttps://github.com/bokeh/bokeh)BOKEH_GHbokeh_commitbokeh_issue
bokeh_pull
bokeh_treesetupc       	      C   s*   |j jjj}t||ddd||}|gg fS )z 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.

    Zcommitzcommit )documentsettingsenvapp_make_gh_link_node)	namerawtexttextlinenoinlineroptionscontentr   node r   ;lib/python3.7/site-packages/bokeh/sphinxext/bokeh_github.pyr
   P   s    r
   c             C   s   |j jjj}yt|}|dkr"tW n> tk
rb   |jjd| |d}	||||	}
|
g|	gfS X t	||dddt
||}|gg fS )z 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.

    r   zQGithub issue number must be a number greater than or equal to 1; "%s" is invalid.)lineZissue#Zissues)r   r   r   r   int
ValueErrorreportererrorproblematicr   str)r   r   r   r   r   r   r   r   	issue_nummsgprbr   r   r   r   r   \   s    r   c             C   s   |j jjj}yt|}|dkr"tW n> tk
rb   |jjd| |d}	||||	}
|
g|	gfS X t	||dddt
||}|gg fS )z 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.

    r   zXGithub pull request number must be a number greater than or equal to 1; "%s" is invalid.)r   Zpullz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   r   r   r   r   r   s    r   c             C   sd   |j jjj}|jjd }d|kr$d}dt||f }	|p8i }t| tj||fd|	i|}
|
gg fS )a   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.

    version-Zmasterz%s/tree/%s/%srefuri)	r   r   r   r   Zconfigr	   r   r   	reference)r   r   r   r   r   r   r   r   tagurlr   r   r   r   r      s    r   c             C   s4   |  dt |  dt |  dt |  dt d S )Nzbokeh-commitzbokeh-issuez
bokeh-pullz
bokeh-tree)Zadd_roler
   r   r   r   )r   r   r   r   r      s    r   c       	      C   sD   dt ||f }|pi }t| tj||t| fd|i|}|S )a   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

    z%s/%s/%sr+   )r	   r   r   r,   r   Zunescape)	r   r   ZroleZkindZapi_typeidr   r.   r   r   r   r   r      s    r   )NN)NN)NN)NN)N)__doc__Z
__future__r   r   r   r   ZloggingZ	getLogger__name__logZdocutilsr   r   Zdocutils.parsers.rst.rolesr   r	   __all__r
   r   r   r   r   r   r   r   r   r   <module>#   s   






