
\c        
   @  sw  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 m Z m Z d d l m Z d d l Z d d l m Z d d l m Z d d l m Z m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d d l m  Z! e" rd d l# m$ Z$ m% Z% m& Z& m' Z' m( Z( m) Z) d d l
 m* Z* d d l m+ Z+ d d l, m- Z- d d l. m/ Z/ d d l0 m1 Z1 n  d e2 f d     YZ3 d   Z4 d   Z5 d   Z6 d d  Z7 d d e6 e5 d d d e" d d 	 Z9 d   Z: d d d  Z; d d d   Z< d!   Z= e	 j> d" d#  Z? e@ d$ k rse?   n  d S(%   s"  
    sphinx.ext.autosummary.generate
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Usable as a library or script to generate automatic RST source files for
    items referred to in autosummary:: directives.

    Each generated RST file contains a single auto*:: directive which
    extracts the docstring of the referred item.

    Example Makefile rule::

       generate:
               sphinx-autogen -o source/generated source/*.rst

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
i(   t   print_functionN(   t   FileSystemLoadert   TemplateNotFound(   t   SandboxedEnvironment(   t   __display_version__(   t   package_dir(   t   import_by_namet   get_documenter(   t   BuiltinTemplateLoader(   t   __(   t   SphinxComponentRegistry(   t   safe_getattr(   t	   ensuredir(   t   escape(   t   Anyt   Callablet   Dictt   Listt   Tuplet   Type(   t
   BaseLoader(   t   addnodes(   t   Builder(   t   BuildEnvironment(   t
   Documentert   DummyApplicationc           B  s   e  Z d  Z d   Z RS(   s3   Dummy Application class for sphinx-autogen command.c         C  s   t    |  _ d  S(   N(   R
   t   registry(   t   self(    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyt   __init__9   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyR   6   s   c         C  s   d d l  m } m } m } m } m } m } m } m } | | | | | | | | g }	 x$ |	 D] }
 |  j	 j
 |
 j |
  q_ Wd  S(   Ni(   t   ModuleDocumentert   ClassDocumentert   ExceptionDocumentert   DataDocumentert   FunctionDocumentert   MethodDocumentert   AttributeDocumentert   InstanceAttributeDocumenter(   t   sphinx.ext.autodocR    R!   R"   R#   R$   R%   R&   R'   R   t   add_documentert   objtype(   t   appR    R!   R"   R#   R$   R%   R&   R'   t   documenterst
   documenter(    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyt   setup_documenters>   s    :		c         C  s   t  |   d  S(   N(   t   print(   t   msg(    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyt   _simple_infoN   s    c         C  s   t  d |  d t j d  S(   Ns	   WARNING: t   file(   R/   t   syst   stderr(   R0   (    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyt   _simple_warnS   s    t   =c         C  s1   d |  k r t  d   n  |  d | t |   S(   Ns   
s   Can only underline single lines(   t
   ValueErrort   len(   t   titlet   line(    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyt
   _underlineX   s    s   .rstc
   "        s9  t  t |    }
 t |
  d k r@ |
 d  d g |
 d }
 n  | t d  d j |
   | rz | t d  |  n  | d  k	 r g  |  D] } t j j | |  ^ q }  n  d  } t j j t d d	 d
  g } d  } | d  k	 rt	   } | j
 | d | n% | r| j d |  n  t |  } t d |  } t | j d <t | j d <t | j d <t |   } g  } x|t t |  d t D]b\ } } } | d  k rqn  | pt j j |  } t |  y t |  \ } } } } Wn* t k
 r} | d | | f  qn Xt j j | | |  } t j j |  rIqn  | j |  t | d  } t   | |  } | d  k	 r| j |  } n= y | j d | j  } Wn  t k
 r| j d  } n Xg  t   f d  } i  } | j d k r{t  |  | d <| | d d | \ | d <| d <| | d d | \ | d <| d <| | d  d | \ | d! <| d" <n | j d k rt  |  | d <t t  |   t | j! j"    | d# <| | d$ d% g  \ | d& <| d' <| | d(  \ | d) <| d* <n  | j# d+  } | j d; k rad+ j | d,   } | d, } d+ j | d,  }  | | d <n d+ j | d-   | d- } }  | | d. <| | d <|  | d/ <| d- | d0 <| j | d1 <t |  d2 | d <| j$ |   }! | j% |!  Wd  QXqW| r5t& | d3 | d4 | d5 | d6 | d7 | d8 | d9 | d:   n  d  S(<   Ni   i
   s   ...is,   [autosummary] generating autosummary for: %ss   , s   [autosummary] writing to %st   extt   autosummaryt	   templatest   dirsi    t   loadert	   underlineR   t   et   keys%   [autosummary] failed to import %r: %st   ws   autosummary/%s.rsts   autosummary/base.rstc   
        s   g  } x t  |   D] } y t |  |  } Wn t k
 rB q n Xt   | |   } | j | k r | s t | d d   |  j k r | j |  q q q Wg  | D]( } | | k s | j	 d  r | ^ q }	 |	 | f S(   NR   t   _(
   t   dirR   t   AttributeErrorR   R*   t   getattrt   NoneR   t   appendt
   startswith(
   t   objt   typt   include_publict   importedt   itemst   namet   valueR-   t   xt   public(   R+   (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyt   get_members   s    !(t   modulet   memberst   functionRO   t	   functionst   all_functionst   classt   classest   all_classest	   exceptiont
   exceptionst   all_exceptionst   inherited_memberst   methodR   t   methodst   all_methodst	   attributet
   attributest   all_attributest   .iit   fullnamet   objnameRQ   R*   R6   t
   output_dirt   suffixt   warnt   infot	   base_patht   buildert   template_dirR+   (   Rb   Re   ('   t   listt   sortedR8   R	   t   joinRI   t   ost   pathR   R   t   initt   insertR   R   R;   t   filterst
   rst_escapet   find_autosummary_in_filest   sett   strt   abspathR   R   t   ImportErrort   isfileRJ   t   openR   t   get_templateR*   R   t   TrueRF   t   __dict__t   keyst   splitt   rendert   writet   generate_autosummary_docs("   t   sourcesRk   Rl   Rm   Rn   Ro   Rp   Rq   t   imported_membersR+   t   showed_sourcest   filenamet   template_dirst   template_loadert   template_envRP   t	   new_filesRQ   Rv   t   template_nameRL   t   parentt   mod_nameRB   t   fnt   ft   doct   templateRU   t   nst   partst   cls_namet   obj_namet   rendered(    (   R+   s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyR   a   s    +	(
	##&)# 



c      
   C  sm   g  } x` |  D]X } t  j | d d d d d 2 } | j   j   } | j t | d |  Wd QXq W| S(   s^   Find out what items are documented in source/*.rst.

    See `find_autosummary_in_lines`.
    t   rt   encodings   utf-8t   errorst   ignoreR   N(   t   codecsR   t   readt
   splitlinest   extendt   find_autosummary_in_lines(   t	   filenamest
   documentedR   R   t   lines(    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyR{      s    #c   	      C  s   yG t  |   \ } } } } t j |  j   } t | d |  d | SWnU t k
 rZ nE t k
 r } t d |  | f  n t k
 r t d |   n Xg  S(   sn   Find out what items are documented in the given object's docstring.

    See `find_autosummary_in_lines`.
    RV   R   s   Failed to import '%s': %ss_   Failed to import '%s'; the module executes module level statement and it might call sys.exit().(	   R   t   pydoct   getdocR   R   RG   R   R/   t
   SystemExit(	   RQ   RV   R   t	   real_nameRL   R   t   modnameR   RB   (    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyt   find_autosummary_in_docstring  s    c         C  s  t  j d  } t  j d  } t  j d  } t  j d  } t  j d  } t  j d  } g  }	 d }
 d } | } t } d } x |  D]} | r| j |  } | r | j d  }
 | r t j j t j j	 |  |
  }
 q q n  | j |  } | r| j d  j
   } q n  | j
   j d	  r0q n  | j |  } | r| j d  j
   } | j d
  rv| d } n  | r| j | d  rd | | f } n  |	 j | |
 | f  q n  | j
   s | j | d  rq n  t } n  | j |  } | r*t } | j d  } d }
 d } q n  | j |  } | rs| j d  j
   } |	 j t | d |  q n  | j |  } | r | j d  } q q q W|	 S(   s  Find out what items appear in autosummary:: directives in the
    given lines.

    Returns a list of (name, toctree, template) where *name* is a name
    of an object and *toctree* the :toctree: path of the corresponding
    autosummary directive (relative to the root of the file name), and
    *template* the value of the :template: option. *toctree* and
    *template* ``None`` if the directive does not have the
    corresponding options set.
    s   ^(\s*)\.\.\s+autosummary::\s*s.   ^\s*\.\.\s+automodule::\s*([A-Za-z0-9_.]+)\s*$s4   ^\s*\.\.\s+(current)?module::\s*([a-zA-Z0-9_.]+)\s*$s%   ^\s+(~?[_a-zA-Z][a-zA-Z0-9_.]*)\s*.*?s   ^\s+:toctree:\s*(.*?)\s*$s   ^\s+:template:\s*(.*?)\s*$t    i   t   :t   ~Rh   s   %s.%st    R   i   N(   t   ret   compileRI   t   Falset   matcht   groupRu   Rv   Rt   t   dirnamet   stripRK   RJ   R   t   searchR   R   (   R   RV   R   t   autosummary_ret   automodule_ret	   module_ret   autosummary_item_ret   toctree_arg_ret   template_arg_reR   t   toctreeR   t   current_modulet   in_autosummaryt   base_indentR:   t   mRQ   (    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyR     sx    		 		
c          C  s"  t  j d d d t d  d t d   }  |  j d d d	 d
 d d	 d t |  j d d d d t d  |  j d d d d d
 d d t d  |  j d d d d d
 d d d d t d  |  j d d d d d
 d d d  d t d   |  j d! d" d d# d
 d$ d t d t d%  |  S(&   Nt   usages#   %(prog)s [OPTIONS] <SOURCE_FILE>...t   epilogs5   For more information, visit <http://sphinx-doc.org/>.t   descriptions  
Generate ReStructuredText using autosummary directives.

sphinx-autogen is a frontend to sphinx.ext.autosummary.generate. It generates
the reStructuredText files from the autosummary directives contained in the
given input files.

The format of the autosummary directive is documented in the
``sphinx.ext.autosummary`` Python module and can be read using::

  pydoc sphinx.ext.autosummary
s	   --versiont   actiont   versiont   destt   show_versions   %%(prog)s %st   source_filet   nargst   +t   helps&   source files to generate rST files fors   -os   --output-dirt   storeRk   s    directory to place all output ins   -ss   --suffixRl   t   defaultt   rsts/   default suffix for files (default: %(default)s)s   -ts   --templatesR>   s0   custom template directory (default: %(default)s)s   -is   --imported-memberst
   store_trueR   s0   document imported members (default: %(default)s)(   t   argparset   ArgumentParserR	   t   add_argumentR   RI   R   (   t   parser(    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyt
   get_parsern  s,    	i   c      
   C  s   t  j j t j d  t  j j t j j t d  d  t	   } t
 |  t   j |   } t | j | j d | j d | j d | j d | d  S(   NR   t   localet   sphinxRh   Rq   R   R+   (   R   R   t	   setlocalet   LC_ALLt   init_consoleRu   Rv   Rt   R   R   R.   R   t
   parse_argsR   R   Rk   Rl   R>   R   (   t   argvR+   t   args(    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyt   main  s    "	
		t   __main__(A   R   t
   __future__R    R   R   R   Ru   R   R   R3   t   jinja2R   R   t   jinja2.sandboxR   t   sphinx.localeR   R   R   t   sphinx.ext.autosummaryR   R   t   sphinx.jinja2glueR   R	   t   sphinx.registryR
   t   sphinx.util.inspectR   t   sphinx.util.osutilR   t   sphinx.util.rstR   Rz   R   t   typingR   R   R   R   R   R   R   R   t   sphinx.buildersR   t   sphinx.environmentR   R(   R   t   objectR   R.   R1   R5   R;   RI   R   R{   R   R   R   R   R   R   (    (    (    s>   lib/python2.7/site-packages/sphinx/ext/autosummary/generate.pyt   <module>   sV   .						W	+