
    Je'              	          d Z ddlZddlZddlmZ ddl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ZddlmZ ddlmZmZmZ dd	lmZ  ed
      Z ej8                  edd      Z ej8                  edd      Z ej8                  edd      Z ej8                  ed      Z  ed ej8                  dde d      d      Z! ed ej8                  dde       d      Z"d Z#efdZ$efdZ%efdZ&ddddddefdZ'd dZ(d Z)y)!ad  
Process docstrings with Sphinx.

**AUTHORS**:

* Tim Joseph Dumol (2009-09-29): Initial version.
* The Spyder Project Contributors: Several changes to make it work with Spyder.

Originally based on sagenb/misc/sphinxify.py from the
`Sage Notebook project <https://github.com/sagemath/sagenb>`_,
part of the `SageMath <https://www.sagemath.org/>`_ system.
    N)mkdtemp)escape)SystemMessage)EnvironmentFileSystemLoader)Sphinx)_get_module_data_pathget_module_source_pathencodingspyder.plugins.help.utilsstaticcssdark_cssbase_cssjsspyderutilshelpmathjaxMATHJAXPATH)relpath	attr_name
JQUERYPATHc                     d| v xs d| v S )z;Returns whether a string contains Sphinx-style ReST markup.`z:: )	docstrings    E/usr/lib/python3/dist-packages/spyder/plugins/help/utils/sphinxify.pyis_sphinx_markupr!   I   s     91	 12    c                     t               }t        t        j                  t        d            |_        |j                  d      }|j                  ||       S )z-Print a warning message on the rich text view	templateszwarning.html)css_pathtextr   r   ospjoinCONFDIR_PATHloaderget_templaterender)messager%   envwarnings       r    r0   r0   O   sC    
-C!#((<"EFCJ~.G>>8'>::r"   c                     t               }t        t        j                  t        d            |_        |j                  d      }|j                  || |||      S )z+Print a usage message on the rich text viewr$   z
usage.html)r%   titleintro_messagetutorial_messagetutorialr'   )r2   r.   r4   r5   r%   r/   usages          r    r6   r6   W   sS    
-C!#((<"EFCJ\*E<<g)9H  N Nr"   c                     t               }t        t        j                  t        d            |_        |j                  d      }|j                  |||       S )z,Print loading message on the rich text view.r$   zloading.html)r%   loading_imgr.   r'   )r.   r8   r%   r/   loadings        r    r9   r9   `   sO    
-C!#((<"EFCJ~.G>>{G  E Er"    Fc                    |r%t         j                  dk(  r|j                  dd      }|rdnd| ||||t        |t        t
        t        t        j                  dk  rdndt        j                  dk  rdndt        j                  d}|S )	aD  
    Generate the html_context dictionary for our Sphinx conf file.

    This is a set of variables to be passed to the Jinja template engine and
    that are used to control how the webpage is rendered in connection with
    Sphinx

    Parameters
    ----------
    name : str
        Object's name.
    note : str
        A note describing what type has the function or method being
        introspected
    argspec : str
        Argspec of the the function or method being introspected
    math : bool
        Turn on/off Latex rendering on the OI. If False, Latex will be shown in
        plain text.
    collapse : bool
        Collapse sections
    img_path : str
        Path for images relative to the file containing the docstring

    Returns
    -------
    A dict of strings to be used by Jinja to generate the webpage
    nt\/truer:   z1.1z2.0)math_onnameargspecnotecollapseimg_pathbase_css_pathr%   js_pathjquery_pathmathjax_pathright_sphinx_versionsphinx_version_2platform)osrA   replaceBASE_CSS_PATHJS_PATHJQUERY_PATHMATHJAX_PATHsphinx__version__sysrL   )rA   rB   rC   mathrD   rE   r%   contexts           r    generate_contextrX   i   s    > BGGtO##D#.
  R$ "$*$6$6$>bF & 2 2U :",,! ( Nr"   c                 ^   t        j                  t        d            }t               }t	        j
                  |      }t        j                  |d      }d}t        j                  dk(  rut        j                  |      j                  d   }t        j                  |      j                  d   }||k7  }|r*t               }t	        j
                  |      }t        |       t        j                  |d      }	|dk(  rd}
nd	}
t        j                  |d
|
z         }|d   r)|d   r$| j                  dd      } | j                  dd      } t        |d         }dD ]  }|j                  |d|z   dz         } ||d<   t        j                  |	dd      }|j!                  |        |j#                          d|i}t        j                  |d      }t%        ||||||ddddd      }	 |j'                  d|	g       t        j.                  |      r9t        j                  |dd      j1                         }|j                  dd       }nt+        d      }t-        |      S |rt3        j4                  |d!       t3        j4                  |d!       |S # t(        $ r t+        d      }t-        |      cY S w xY w)"a  
    Runs Sphinx on a docstring and outputs the processed documentation.

    Parameters
    ----------
    docstring : str
        a ReST-formatted docstring

    context : dict
        Variables to be passed to the layout template to control how its
        rendered (through the Sphinx variable *html_context*).

    buildername:  str
        It can be either `html` or `text`.

    Returns
    -------
    An Sphinx-processed string, in either HTML or plain text format, depending
    on the value of `buildername`
    r   _buildFr<   r   zdocstring.rsthtmlz.htmlz.txtr   rJ   r@   z\\z\\\\z\**rB   )=,()r\   z**z <span class="argspec-highlight">z</span>wzutf-8r   html_contextdoctreesNT)statusr0   freshenvwarningiserrortagsz`It was not possible to generate rich text help for this object.</br>Please see it in plain text.rz<pre>z<pre class="literal-block">)ignore_errors)r(   r)   r   r   r   to_unicode_from_fsrM   rA   pathlibPathpartsgenerate_configurationrN   r   codecsopenwritecloser   buildr   r	   r0   existsreadshutilrmtree)r   rW   buildernameconfdirsrcdirdestdirtemp_confdir_neededdrive_confdirdrive_srcdirrst_namesuffixoutput_namerB   chardoc_fileconfoverrides
doctreedir
sphinx_appoutputs                      r    	sphinxifyr      s   , hh-.IJKGYF((0Fhhvx(G	ww$  W-33A6||F+11!4+|;iG11':G"7+xx0Hf((7K&$89K %&79+=%%fj9	 %%eS1	 WY'(G/ P//$;dBYNPP !GI{{8S7;HNN9NN#W-M&*-J*k%dD!%e$HJz* zz+[#@EEG)FG 3 4 vgT2
MM&-M)   3 4 v	s   !J
 
J,+J,c                    t        j                  t        d      d      }t        j                  t        j                  t        d      d      }t	        j
                  t        j                  | d             t	        j
                  t        j                  | d             t        j                  ||        t        j                  |t        j                  | d             t        t        j                  | d      d      j                  d       t        t        j                  | dd	      d      j                  d       y
)z
    Generates a Sphinx configuration in `directory`.

    Parameters
    ----------
    directory : str
        Base directory to use
    r   zconf.pyr$   zlayout.htmlr   z__init__.pyra   r:   emptyN)
r(   r)   r   r*   rM   makedirsrv   copyrp   rq   )	directoryconflayouts      r    rn   rn   	  s     88*+FGD XXchh|[9=IFKKK01KKH-.
KKi 
KKK89)]	+S177;)Xw	/5;;B?r"   )r[   )*__doc__ro   rM   os.pathpathr(   rk   rv   rU   tempfiler   xml.sax.saxutilsr   docutils.utilsr   jinja2r   r   rS   sphinx.applicationr   spyder.config.baser	   r
   r   spyder.utilsr   r*   r)   CSS_PATHDARK_CSS_PATHrO   rP   rR   rQ   r!   r0   r6   r9   rX   r   rn   r   r"   r    <module>r      s5    	    
  # : 0  %8 8 ! &&AB388L(E2x<x<
#((<
& $H,4CHHWf5<i-I.;=
 #8+3388GV4;,=-9;3 ' ; @H N ,4 E br 86rdN@r"   