ó
öÀ„\c           @  s  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 m Z d d l m	 Z	 d d l
 m Z d d l 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 m Z m Z e rd d l m Z m Z m Z n  d e j k r=e j d j d ƒ Z  n d d d g Z  d Z! e" d d g ƒ Z# d „  Z$ d „  Z% e& d „ Z' d d „ Z) d „  Z* g  d „ Z+ d d „ Z, g  d „ Z- d „  Z. d „  Z/ d  „  Z0 e j1 d! d" „ Z2 e3 d# k rÿe2 ƒ  n  d S($   s  
    sphinx.ext.apidoc
    ~~~~~~~~~~~~~~~~~

    Parses a directory tree looking for Python modules and packages and creates
    ReST files appropriately to create code documentation with Sphinx.  It also
    creates a modules index (named modules.<suffix>).

    This is derived from the "sphinx-autopackage" script, which is:
    Copyright 2008 SociÃ©tÃ© des arts technologiques (SAT),
    https://sat.qc.ca/

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿ(   t   print_functionN(   t   fnmatch(   t   path(   t   binary_type(   t   __display_version__t   package_dir(   t
   EXTENSIONS(   t   __(   t   rst(   t   FileAvoidWritet	   ensuredirt   walk(   t   Anyt   Listt   Tuplet   SPHINX_APIDOC_OPTIONSt   ,t   memberss   undoc-memberss   show-inheritances   __init__.pys   .pys   .pyxc         C  s0   |  r& |  } | r, | d | 7} q, n | } | S(   s#   Join package and module with a dot.t   .(    (   t   packaget   modulet   name(    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt   makename8   s    c         C  s­   t  j | j d |  | j f ƒ } | j rC t t d ƒ | ƒ d S| j rs t  j | ƒ rs t t d ƒ | ƒ n6 t t d ƒ | ƒ t	 | ƒ  } | j
 | ƒ Wd QXd S(   s0   Write the output file for module/package <name>.s   %s.%ss   Would create file %s.Ns!   File %s already exists, skipping.s   Creating file %s.(   R   t   joint   destdirt   suffixt   dryrunt   printR   t   forcet   isfileR	   t   write(   R   t   textt   optst   fnamet   f(    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt
   write_fileE   s    "	c         C  sG   | r t  j | ƒ } n  d d d g |  d t | ƒ } d | | f S(   s2   Create a heading of <level> [1, 2 or 3 supported].t   =t   -t   ~i   s   %s
%s

(   R   t   escapet   len(   t   levelR   R'   t   underlining(    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt   format_headingT   s    !c         C  s6   d t  | |  ƒ } x t D] } | d | 7} q W| S(   s4   Create the automodule directive and add the options.s   .. automodule:: %s
s	       :%s:
(   R   t   OPTIONS(   R   R   t	   directivet   option(    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt   format_directive]   s    c         C  sU   | j  s t d d | ƒ } n d } | t | |  ƒ 7} t t |  | ƒ | | ƒ d S(   s.   Build the text of the file and write the file.i   s	   %s modulet    N(   t
   noheadingsR+   R/   R#   R   (   R   R   R    R   (    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt   create_module_filef   s
    	c         C  sÎ  t  d | s d n d t | | ƒ ƒ } | j rX | rX | t | | ƒ 7} | d 7} n  g  | D]- }	 t t j |  |	 t ƒ | | ƒ s_ |	 ^ q_ } | rð | t  d d ƒ 7} | d 7} x+ | D]# }	 | d t | | ƒ |	 f 7} q¼ W| d 7} n  g  | D]D }	 t t j |  |	 ƒ | | ƒ r÷ |	 t k r÷ t j |	 ƒ d	 ^ q÷ }
 |
 rw| t  d d
 ƒ 7} | j	 rø| d 7} xú |
 D]} } t | t | | ƒ ƒ } | d | 7} | j
 s¿t  d d | ƒ } n d } | t t | | ƒ | ƒ 7} t | | | ƒ qtWnr xo |
 D]g } t | t | | ƒ ƒ } | j
 s@| t  d d | ƒ 7} n  | t t | | ƒ | ƒ 7} | d 7} qÿW| d 7} n  | j r±| r±| t  d d ƒ 7} | t | | ƒ 7} n  t t | | ƒ | | ƒ d S(   s.   Build the text of the file and write the file.i   s
   %s packages   %s namespaces   
i   t   Subpackagess   .. toctree::

s
       %s.%s
i    t
   Submoduless      %s
s	   %s moduleR0   s   Module contentsN(   R+   R   t   modulefirstR/   t
   shall_skipR   R   t   INITPYt   splitextt   separatemodulesR1   R#   (   t   roott   master_packaget   subroott   py_filesR    t   subst   is_namespacet   excludesR   t   subt   submodst   submodt   modfilet   filetext(    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt   create_package_filer   sR    -
!%	
	
	
t   modulesc         C  s™   t  d d | j d t ƒ} | d 7} | d | j 7} |  j ƒ  d } x; |  D]3 } | j | d ƒ rm qN n  | } | d | 7} qN Wt | | | ƒ d	 S(
   s   Create the module's index.i   s   %sR'   s   .. toctree::
s      :maxdepth: %s

R0   R   s      %s
N(   R+   t   headert   Falset   maxdeptht   sortt
   startswithR#   (   RG   R    R   R   t   prev_moduleR   (    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt   create_modules_toc_file®   s    

c         C  sÞ   | j  r t j |  ƒ r t St j j |  ƒ t k r¢ t } t j |  ƒ } xG t j t j	 | d ƒ ƒ D]* } t
 t j	 | | ƒ | ƒ sg t } qg qg W| r¢ t Sn  t j |  ƒ } | d k rÚ | j d ƒ rÚ | j rÚ t St S(   s%   Check if we want to skip this module.s   *.pys   __init__.pyt   _(   t   implicit_namespacesR   t   existst   Truet   ost   basenameR7   t   dirnamet   globR   t   is_excludedRI   RL   t   includeprivate(   R   R    R@   t   all_skippedt
   basemodulet	   submodulet   filename(    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyR6   Á   s    "
c      
     s™  t  | d t ƒ } t  | d t ƒ } t  | d t ƒ } t t j |  ƒ k sQ | rj |  j t j ƒ d } n d } g  } xt	 |  d | ƒD]\ ‰ } }	 t
 ‡ ‡ f d †  |	 Dƒ ƒ }
 t |
 k } t |
 k oÒ | } | rû |
 j t ƒ |
 j d t ƒ n ˆ |  k r| s| 2q‰ qn  | r)d ‰  n d ‰  t
 ‡  ‡ ‡ f d	 †  | Dƒ ƒ | (| s^| r| s’t |
 ƒ d
 k s’t t j ˆ t ƒ | ƒ r‘ˆ t |  ƒ j t j ƒ j t j d ƒ } | sÖt |
 ƒ d k rt ˆ | | |
 | | | ˆ ƒ | j t | | ƒ ƒ qq‘q‰ ˆ |  k r,| d k s2t ‚ x\ |
 D]T } t t j |  | ƒ | ƒ s9t j | ƒ d } t | | | ƒ | j | ƒ q9q9Wq‰ W| S(   s`   
    Look for every file in the directory tree and create the corresponding
    ReST files.
    t   followlinksRX   RP   iÿÿÿÿc         3  sJ   |  ]@ } t  j | ƒ d  t k r t t  j ˆ | ƒ ˆ  ƒ r | Vq d S(   i   N(   R   R8   t   PY_SUFFIXESRW   R   (   t   .0R"   (   R@   R:   (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pys	   <genexpr>ð   s    i    R   RO   c         3  sA   |  ]7 } | j  ˆ  ƒ r t t j ˆ | ƒ ˆ ƒ r | Vq d  S(   N(   RL   RW   R   R   (   R_   RA   (   t   exclude_prefixesR@   R:   (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pys	   <genexpr>  s    i   N(   R   (   R   RO   (   t   getattrRI   R7   RS   t   listdirt   splitR   t   sept   NoneR   t   sortedt   removet   insertR(   R6   R   t   lstript   replaceRF   t   appendR   t   AssertionErrorR8   R2   (   t   rootpathR@   R    R]   RX   RP   t   root_packaget	   toplevelsR>   t   filesR=   t   is_pkgR?   t
   subpackaget   py_fileR   (    (   R`   R@   R:   s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt   recurse_treeÜ   sJ    "		#4c         C  s(   x! | D] } t  |  | ƒ r t Sq Wt S(   sÄ   Check if the directory is in the exclude list.

    Note: by having trailing slashes, we avoid common prefix issues, like
          e.g. an exclude "foo" also accidentally excluding "foobar".
    (   R   RR   RI   (   R:   R@   t   exclude(    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyRW     s    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 t d ƒ ƒ|  j d d d d t d ƒ ƒ|  j d d d d d
 d d t d t d ƒ ƒ|  j d d d d d
 d d t d d d t d  ƒ ƒ|  j d! d" d d# d
 d$ d t d% ƒ ƒ|  j d& d' d d# d
 d( d t d t d) ƒ ƒ|  j d* d+ d d# d
 d, d t d- ƒ ƒ|  j d. d/ d d# d
 d0 d t d1 ƒ ƒ|  j d2 d3 d d# d
 d4 d t d5 ƒ ƒ|  j d6 d d d
 d7 d d8 d t d9 ƒ ƒ|  j d: d; d d< d
 d7 d t d= ƒ ƒ|  j d> d? d d# d
 d@ d t dA ƒ ƒ|  j dB dC d d# d
 dD d t dE ƒ ƒ|  j dF d d# d
 dG d t dH ƒ ƒ|  j dI dJ d d d
 dK d dL d t dM ƒ ƒ|  j dN dO d d# d
 dP d t dQ ƒ ƒ|  j dR dS d d# d
 dT d t dU ƒ ƒ|  j dV dW d d d
 dX d t dY ƒ ƒ|  j dZ d[ d d d
 d\ d t d] ƒ ƒ|  j d^ d_ d d d
 d	 d t d` ƒ ƒ|  j da db d d d
 dc d t dd ƒ ƒ|  j t de ƒ ƒ } xE t	 D]= } | j df | d dg dh di | d
 dj d t dk ƒ | ƒq·W|  S(l   Nt   usagesH   %(prog)s [OPTIONS] -o <OUTPUT_PATH> <MODULE_PATH> [EXCLUDE_PATTERN, ...]t   epilogs5   For more information, visit <http://sphinx-doc.org/>.t   descriptionsE  
Look recursively in <MODULE_PATH> for Python modules and packages and create
one reST file with automodule directives per package in the <OUTPUT_PATH>.

The <EXCLUDE_PATTERN>s can be file and/or directory patterns that will be
excluded from generation.

Note: By default this script will not overwrite already created files.s	   --versiont   actiont   versiont   destt   show_versions   %%(prog)s %st   module_patht   helps   path to module to documentt   exclude_patternt   nargst   *sG   fnmatch-style file and/or directory patterns to exclude from generations   -os   --output-dirt   storeR   t   requireds   directory to place all outputs   -ds
   --maxdepthRJ   t   typet   defaulti   s;   maximum depth of submodules to show in the TOC (default: 4)s   -fs   --forcet
   store_trueR   s   overwrite existing filess   -ls   --follow-linksR]   sN   follow symbolic links. Powerful when combined with collective.recipe.omelette.s   -ns	   --dry-runR   s%   run the script without creating filess   -es
   --separateR9   s1   put documentation for each module on its own pages   -Ps	   --privateRX   s   include "_private" moduless	   --tocfilet   tocfileRG   s0   filename of table of contents (default: modules)s   -Ts   --no-toct   store_falses%   don't create a table of contents files   -Es   --no-headingsR1   se   don't create headings for the module/package packages (e.g. when the docstrings already contain them)s   -Ms   --module-firstR5   s7   put module documentation before submodule documentations   --implicit-namespacesRP   sN   interpret module paths according to PEP-0420 implicit namespaces specifications   -ss   --suffixR   R   s   file suffix (default: rst)s   -Fs   --fullt   fulls.   generate a full project with sphinx-quickstarts   -as   --append-syspatht   append_syspaths9   append module_path to sys.path, used when --full is givens   -Hs   --doc-projectRH   s(   project name (default: root module name)s   -As   --doc-authort   authors,   project author(s), used when --full is givens   -Vs   --doc-versions*   project version, used when --full is givens   -Rs   --doc-releaset   releasesE   project release, used when --full is given, defaults to --doc-versions   extension optionss   --ext-%st   append_constt   consts   sphinx.ext.%st
   extensionss   enable %s extension(
   t   argparset   ArgumentParserR   t   add_argumentR   RR   t   intRI   t   add_argument_groupR   (   t   parsert   groupt   ext(    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt
   get_parser*  s‚    	i   c      '   C  s„  t  j j t j d ƒ t  j j t j j t d ƒ d ƒ t	 ƒ  } | j
 |  ƒ } t j | j ƒ } | j d) k r | j t j ƒ d | _ n  | j j d ƒ r² | j d | _ n  t j | ƒ sî t t d ƒ | d t j ƒt j d ƒ n  | j st | j ƒ n  g  | j D] } t j | ƒ ^ q} t | | | ƒ } | j rad d	 l m  } | j! ƒ  d } d }	 x; | D]3 }
 |
 j | d ƒ r“qtn  |
 } |	 d
 |
 7}	 qtWt" d | j d t# d d d | j d | j$ pÛd d | j% pêd d | j& p| j% pd d d | j d d d t' d d d d g d t' d t' d t' d | j( d  |	 d! d" d# | d$ | j) ƒ } | j* r†| d j+ | j* ƒ n  t, | j t- ƒ r²| d j. d% ƒ | d <n  t, | j$ t- ƒ rÞ| d j. d% ƒ | d <n  t, | j% t- ƒ r
| d j. d% ƒ | d <n  t, | j& t- ƒ r6| d j. d% ƒ | d <n  | j s€| j/ | d& t' d' | j0 ƒq€n | j1 r€t2 | | | j1 ƒ n  d( S(*   s+   Parse and check the command line arguments.R0   t   localet   sphinxiÿÿÿÿR   i   s   %s is not a directory.t   file(   t
   quickstarts      %s
R   Rd   t   dotRO   t   projectR‹   t   AuthorRz   RŒ   R   t   mastert   indext   epubR   s   sphinx.ext.autodocs   sphinx.ext.viewcodes   sphinx.ext.todot   makefilet	   batchfilet	   make_modet   mastertocmaxdeptht   mastertoctreet   languaget   enR}   RŠ   s   utf-8t   silentt	   overwritei    N(3   Rš   R™   t	   setlocalet   LC_ALLt   init_consoleRS   R   R   R   R˜   t
   parse_argst   abspathR}   RH   Re   Rc   Rd   R   RL   t   isdirR   R   t   syst   stderrt   exitR   R
   R   R   Rt   R‰   t
   sphinx.cmdRœ   RK   t   dictRI   R‹   Rz   RŒ   RR   RJ   RŠ   R   t   extendt
   isinstanceR   t   decodet   generateR   R‡   RN   (   t   argvR•   t   argsRm   Ru   R@   RG   t   qsRM   R   R   t   d(    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt   mainƒ  s|    "		%	
						"	t   __main__(4   t   __doc__t
   __future__R    R   RV   R™   RS   R²   R   R   t   sixR   t   sphinx.localeRš   R   R   t   sphinx.cmd.quickstartR   R   t   sphinx.utilR   t   sphinx.util.osutilR	   R
   R   RI   t   typingR   R   R   t   environRc   R,   R7   t   setR^   R   R#   RR   R+   Re   R/   R2   RF   RN   R6   Rt   RW   R˜   R»   R¿   t   __name__(    (    (    s0   lib/python2.7/site-packages/sphinx/ext/apidoc.pyt   <module>   sL   						<	A		YN