ó
öÀ„\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 Z d d l	 m
 Z
 d d l m Z 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 d d l m Z m Z m Z d d l m  Z  m! Z! d d l" m# Z# e$ r_d d l% m& Z& m' Z' m( Z( m) Z) n  e j* d „ Z+ d „  Z, d „  Z- e j. d d „ Z/ e j. d d „ Z0 e j. d d „ Z1 e2 d k râe j3 e1 e j. d ƒ ƒ n  d S(   sÎ   
    sphinx.cmd.build
    ~~~~~~~~~~~~~~~~

    Build documentation from a provided source.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿ(   t   print_functionN(   t   SystemMessage(   t	   text_typet   binary_type(   t   __display_version__t   package_dir(   t   Sphinx(   t   SphinxError(   t   __(   t   Teet   format_exception_cut_framest   save_traceback(   t   redt   nocolort   color_terminal(   t   docutils_namespacet   patch_docutils(   t   terminal_safe(   t   Anyt   IOt   Listt   Unionc         C  sî  | j  rU d d  l  } t t t d ƒ ƒ d | ƒt j ƒ  | j t j ƒ  d ƒ n•t d | ƒ | j	 st | j r” t j d  | ƒ t d | ƒ n  t | t ƒ r¼ t t d ƒ d | ƒn.t | t ƒ rt t t d ƒ ƒ d | ƒt t | j d ƒ d | ƒnãt | t ƒ rRt t d | j ƒ d | ƒt t t | ƒ ƒ d | ƒn˜t | t ƒ rÈt t t d	 ƒ ƒ d | ƒt t t | ƒ ƒ d | ƒt |  ƒ } t t t d
 ƒ | ƒ d | ƒn"t | t ƒ r]d t | ƒ k r]t t t d ƒ ƒ d | ƒt t t | ƒ ƒ d | ƒt d | ƒ t t d ƒ d | ƒt t d ƒ d | ƒn t t t d ƒ ƒ d | ƒt t ƒ  j ƒ  d | ƒt |  ƒ } t t t d
 ƒ | ƒ d | ƒt t d ƒ d | ƒt t d ƒ d | ƒd  S(   Niÿÿÿÿs5   Exception occurred while building, starting debugger:t   filei   s   interrupted!s   reST markup error:i    s   %s:s   Encoding error:s[   The full traceback has been saved in %s, if you want to report the issue to the developers.s   recursion depths   Recursion error:s›   This can happen with very large or deeply nested source files.  You can carefully increase the default Python recursion limit of 1000 in conf.py with e.g.:s+       import sys; sys.setrecursionlimit(1500)s   Exception occurred:si   Please also report this if it was a user error, so that a better error message can be provided next time.sb   A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!(   t   pdbt   printR   R   t	   tracebackt	   print_exct   post_mortemt   syst   exc_infot	   verbosityt   Nonet
   isinstancet   KeyboardInterruptR   R   t   argsR   t   categoryR   t   UnicodeErrorR   t   RuntimeErrort   strR
   t   rstrip(   t   appR"   t	   exceptiont   stderrR   t   tbpath(    (    s/   lib/python2.7/site-packages/sphinx/cmd/build.pyt   handle_exception&   sT    	
 

!
c         C  sN   |  d k r t  j ƒ  St |  ƒ } | d k rF t j t d ƒ ƒ ‚ n | Sd S(   s½   
    Special type to handle 'auto' flags passed to 'sphinx-build' via -j flag. Can
    be expanded to handle other special scaling requests, such as setting job count
    to cpu_count.
    t   autoi    s&   job number should be a positive numberN(   t   multiprocessingt	   cpu_countt   intt   argparset   ArgumentTypeErrorR   (   t   valuet   jobs(    (    s/   lib/python2.7/site-packages/sphinx/cmd/build.pyt   jobs_argumentY   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 t d ƒ ƒ|  j d d d d t d ƒ ƒ|  j t d ƒ ƒ } | j d d d d
 d d d d t d ƒ ƒ| j d d d d
 d  d t d! ƒ ƒ| j d" d d d
 d# d t d$ ƒ ƒ| j d% d d& d
 d' d t d( ƒ ƒ| j d) d d* d d+ d, t d
 d- d t d. ƒ ƒ|  j d/ ƒ } | j d0 d d& d
 d1 d t d2 ƒ ƒ| j d3 d d d
 d4 d t d5 ƒ ƒ| j d6 d d7 d d8 d
 d9 d g  d t d: ƒ ƒ| j d; d d< d d8 d
 d= d g  d t d> ƒ ƒ| j d? d d@ d d8 d
 dA d g  d t dB ƒ ƒ| j dC d d d
 dD d t dE ƒ ƒ|  j t dF ƒ ƒ } | j dG d dH d
 dI d dJ d t dK ƒ ƒ| j dL d d d
 dM d t dN ƒ ƒ| j dO d d d
 dP d t dQ ƒ ƒ| j dR d dS dT dU d dV d t dW ƒ ƒ| j dX dY d
 dZ d dS dT d[ d t d\ ƒ ƒ| j d] d d^ d
 d_ d t d` ƒ ƒ| j da d d d
 db d t dc ƒ ƒ| j dd d d d
 de d t df ƒ ƒ| j dg d d d
 dh d t di ƒ ƒ| j dj d d d
 dk d t dl ƒ ƒ|  S(m   Nt   usages5   %(prog)s [OPTIONS] SOURCEDIR OUTPUTDIR [FILENAMES...]t   epilogs5   For more information, visit <http://sphinx-doc.org/>.t   descriptions  
Generate documentation from source files.

sphinx-build generates documentation from the files in SOURCEDIR and places it
in OUTPUTDIR. It looks for 'conf.py' in SOURCEDIR for the configuration
settings.  The 'sphinx-quickstart' tool may be used to generate template files,
including 'conf.py'

sphinx-build can create documentation in different formats. A format is
selected by specifying the builder name on the command line; it defaults to
HTML. Builders can also perform other tasks related to documentation
processing.

By default, everything that is outdated is built. Output only for selected
files can be built by specifying individual filenames.
s	   --versiont   actiont   versiont   destt   show_versions   %%(prog)s %st	   sourcedirt   helps"   path to documentation source filest	   outputdirs   path to output directoryt	   filenamest   nargst   *s?   a list of specific files to rebuild. Ignored if -a is specifieds   general optionss   -bt   metavart   BUILDERt   buildert   defaultt   htmls   builder to use (default: html)s   -at
   store_truet	   force_alls;   write all files (default: only write new and changed files)s   -Et   freshenvs4   don't use a saved environment, always read all filess   -dt   PATHt
   doctreedirsP   path for the cached environment and doctree files (default: OUTPUTDIR/.doctrees)s   -jt   Ni   t   typeR4   s`   build in parallel with N processes where possible (special value "auto" will set N to cpu-count)s   build configuration optionss   -ct   confdirsO   path where configuration file (conf.py) is located (default: same as SOURCEDIR)s   -Ct   noconfigs*   use no config file at all, only -D optionss   -Ds   setting=valuet   appendt   defines(   override a setting in configuration files   -As
   name=valuet
   htmldefines    pass a value into HTML templatess   -tt   TAGt   tagss*   define tag: include "only" blocks with TAGs   -nt   nitpickys1   nit-picky mode, warn about all missing referencess   console output optionss   -vt   countR   i    s$   increase verbosity (can be repeated)s   -qt   quiets,   no output on stdout, just warnings on stderrs   -Qt   really_quiets#   no output at all, not even warningss   --colort   store_constt   constt   yesR-   s-   do emit colored output (default: auto-detect)s   -Ns
   --no-colort   colort   nos1   do not emit colored output (default: auto-detect)s   -wt   FILEt   warnfiles)   write warnings (and errors) to given files   -Wt   warningiserrors   turn warnings into errorss   --keep-goingt
   keep_goings)   With -W, Keep going when getting warningss   -TR   s    show full traceback on exceptions   -PR   s   run Pdb on exception(   R1   t   ArgumentParserR   t   add_argumentR   t   add_argument_groupR5   (   t   parsert   group(    (    s/   lib/python2.7/site-packages/sphinx/cmd/build.pyt
   get_parserj   s‚    	$i   c         C  s!   d d l  m } | j |  d ƒ S(   s   Sphinx build "make mode" entry.iÿÿÿÿ(   t	   make_modei   (   t
   sphinx.cmdRi   t   run_make_mode(   t   argvRi   (    (    s/   lib/python2.7/site-packages/sphinx/cmd/build.pyt	   make_mainÊ   s    c         C  ss  t  ƒ  } | j |  ƒ } | j r- d | _ n | j sE | j | _ n  | j sl t j j	 | j
 d ƒ | _ n  | j } g  } x0 | D]( } t j j | ƒ s‚ | j | ƒ q‚ q‚ W| rÎ | j t d ƒ | ƒ n  y t d ƒ } | j ƒ  } Wn t k
 rd } n X| j r)| r)| j t d ƒ ƒ n  | j d k sQ| j d k r[t ƒ  r[t ƒ  n  t j } t j }	 t j }
 | j rˆd } n  | j ržd } }	 n  |	 r| j ry t | j d ƒ } Wn3 t k
 rø} | j t d ƒ | j | f ƒ n Xt |	 | ƒ }	 |	 }
 n  i  } x | j D]’ } y | j  d	 d
 ƒ \ } } Wn$ t! k
 ri| j t d ƒ ƒ n X| r©t" | t# ƒ r©y | j$ | ƒ } Wq©t% k
 r¥q©Xn  | | | <q!WxÂ | j& D]· } y | j  d	 ƒ \ } } Wn$ t! k
 r| j t d ƒ ƒ n Xy t' | ƒ } WnP t! k
 ri| rjt" | t# ƒ rjy | j$ | ƒ } Wqft% k
 rbqfXqjn X| | d | <qÁW| j( r’t) | d <n  d } y§ | j pª| j } t* | ƒ ƒ t+ ƒ  s t, | j | j | j
 | j | j- | | |	 | j. | j/ | j0 | j1 | j2 | j3 ƒ } | j4 | j | ƒ | j5 SWd QXWd QXWn- t t6 f k
 rn} t7 | | | |
 ƒ d SXd S(   s'   Sphinx build "main" command-line entry.s	   .doctreess   cannot find files %rt   locales&   cannot combine -a option and filenamesR^   R-   t   ws   cannot open warning file %r: %st   =i   s1   -D option argument must be in the form name=values1   -A option argument must be in the form name=values   html_context.%sRV   Ni   (8   Rh   t
   parse_argsRP   R   RO   R=   RL   t   ost   patht   joinR?   R@   t   isfileRQ   t   errorR   t
   __import__t   getpreferredencodingt	   ExceptionRI   R]   R   R   R   t   stdoutR*   RX   RY   R`   t   openR	   RR   t   splitt
   ValueErrorR    R   t   decodeR$   RS   R0   RV   t   TrueR   R   R   RE   RJ   Ra   RU   R   R4   Rb   t   buildt
   statuscodeR!   R,   (   Rl   Rf   R"   R@   t   missing_filest   filenameRn   t   likely_encodingt   statust   warningRv   t   warnfpt   exct   confoverridest   valt   keyR(   RO   (    (    s/   lib/python2.7/site-packages/sphinx/cmd/build.pyt
   build_mainÑ   s¢    					
(
								 
c         C  sc   t  j j t j d ƒ t  j j t j j t d ƒ d ƒ |  d  d g k rU t	 |  ƒ St
 |  ƒ Sd  S(   Nt    Rn   t   sphinxi   s   -M(   RŽ   Rn   t	   setlocalet   LC_ALLt   init_consoleRr   Rs   Rt   R   Rm   RŒ   (   Rl   (    (    s/   lib/python2.7/site-packages/sphinx/cmd/build.pyt   main7  s
    "
t   __main__(4   t   __doc__t
   __future__R    R1   Rn   R.   Rr   R   R   t   docutils.utilsR   t   sixR   R   t   sphinx.localeRŽ   R   R   t   sphinx.applicationR   t   sphinx.errorsR   R   t   sphinx.utilR	   R
   R   t   sphinx.util.consoleR   R   R   t   sphinx.util.docutilsR   R   t   sphinx.util.pycompatR   t   Falset   typingR   R   R   R   R*   R,   R5   Rh   Rl   Rm   RŒ   R’   t   __name__t   exit(    (    (    s/   lib/python2.7/site-packages/sphinx/cmd/build.pyt   <module>
   s8   %3		`f