B
    \4                 @   sb  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j$fddZ%dd Z&dd Z'ej(dd fddZ)ej(dd fddZ*ej(dd fddZ+e,dkr^e-e+ej(dd  dS )z
    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.
    )print_functionN)SystemMessage)	text_typebinary_type)__display_version__package_dir)Sphinx)SphinxError)__)Teeformat_exception_cut_framessave_traceback)rednocolorcolor_terminal)docutils_namespacepatch_docutils)terminal_safec             C   s(  |j r@dd l }tttd|d t  |t d  nt|d |j	sV|jrltd | t|d t
|trttd|d nt
|trtttd|d tt|jd |d nbt
|trttd|j |d ttt||d n*t
|trPtttd|d ttt||d t| }tttd	| |d nt
|trd
t|krtttd|d ttt||d t|d ttd|d ttd|d nftttd|d tt  |d t| }tttd	| |d ttd|d ttd|d d S )Nr   z5Exception occurred while building, starting debugger:)file   zinterrupted!zreST markup error:z%s:zEncoding error:z[The full traceback has been saved in %s, if you want to report the issue to the developers.zrecursion depthzRecursion error:zThis 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.:z+    import sys; sys.setrecursionlimit(1500)zException occurred:ziPlease also report this if it was a user error, so that a better error message can be provided next time.zbA bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!)pdbprintr   r
   	traceback	print_excZpost_mortemsysexc_info	verbosity
isinstanceKeyboardInterruptr   r   argsr	   categoryr   UnicodeErrorr   RuntimeErrorstrr   rstrip)appr   Z	exceptionstderrr   Ztbpath r'   /lib/python3.7/site-packages/sphinx/cmd/build.pyhandle_exception&   sT    








r)   c             C   s8   | dkrt  S t| }|dkr0ttdn|S dS )z
    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.
    autor   z&job number should be a positive numberN)multiprocessing	cpu_countintargparseZArgumentTypeErrorr
   )valuejobsr'   r'   r(   jobs_argumentY   s    r1   c              C   sx  t jdtdtdd} | jddddt d	 | jd
tdd | jdtdd | jddtdd | td}|jddddtdd |jdddtdd |jddd td!d |jd"d#d$td%d& |jd'd(d)td*td+d, | d-}|jd.d#d/td0d& |jd1dd2td3d |jd4d5d6d7g td8d9 |jd:d;d6d<g td=d9 |jd>d?d6d@g tdAd9 |jdBddCtdDd | tdE}|jdFdGdHdItdJdK |jdLddMtdNd |jdOddPtdQd |jdRdSdTdUtdVdW |jdXdYdZdSd[td\d] |jd^d_d`tdad& |jdbddctddd |jdeddftdgd |jdhdditdjd |jdkddltdmd | S )nNz5%(prog)s [OPTIONS] SOURCEDIR OUTPUTDIR [FILENAMES...]z5For more information, visit <http://sphinx-doc.org/>.a  
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.
)ZusageZepilogZdescriptionz	--versionversionZshow_versionz%%(prog)s %s)actiondestr2   	sourcedirz"path to documentation source files)help	outputdirzpath to output directory	filenames*z?a list of specific files to rebuild. Ignored if -a is specified)nargsr6   zgeneral optionsz-bZBUILDERbuilderZhtmlzbuilder to use (default: html))metavarr4   defaultr6   z-a
store_true	force_allz;write all files (default: only write new and changed files))r3   r4   r6   z-Efreshenvz4don't use a saved environment, always read all filesz-dPATH
doctreedirzPpath for the cached environment and doctree files (default: OUTPUTDIR/.doctrees))r<   r4   r6   z-jN   r0   z`build in parallel with N processes where possible (special value "auto" will set N to cpu-count))r<   r=   typer4   r6   zbuild configuration optionsz-cconfdirzOpath where configuration file (conf.py) is located (default: same as SOURCEDIR)z-Cnoconfigz*use no config file at all, only -D optionsz-Dzsetting=valueappenddefinez(override a setting in configuration file)r<   r3   r4   r=   r6   z-Az
name=value
htmldefinez pass a value into HTML templatesz-tZTAGtagsz*define tag: include "only" blocks with TAGz-nnitpickyz1nit-picky mode, warn about all missing referenceszconsole output optionsz-vcountr   r   z$increase verbosity (can be repeated))r3   r4   r=   r6   z-qquietz,no output on stdout, just warnings on stderrz-Qreally_quietz#no output at all, not even warningsz--colorZstore_constZyesr*   z-do emit colored output (default: auto-detect))r3   constr=   r6   z-Nz
--no-colorcolornoz1do not emit colored output (default: auto-detect))r4   r3   rP   r6   z-wZFILEwarnfilez)write warnings (and errors) to given filez-Wwarningiserrorzturn warnings into errorsz--keep-going
keep_goingz)With -W, Keep going when getting warningsz-Tr   z show full traceback on exceptionz-Pr   zrun Pdb on exception)r.   ArgumentParserr
   add_argumentr   Zadd_argument_groupr1   )parsergroupr'   r'   r(   
get_parserj   s    




















rZ   rD   c             C   s   ddl m} || dd S )zSphinx build "make mode" entry.r   )	make_moderD   N)Z
sphinx.cmdr[   Zrun_make_mode)argvr[   r'   r'   r(   	make_main   s    r]   c             C   s  t  }|| }|jrd|_n|js,|j|_|jsDtj|j	d|_|j
}g }x"|D ]}tj|sT|| qTW |r|td|  ytd}| }W n tk
r   d}Y nX |jr|r|td |jdks|jdkrt st  tj}tj}	tj}
|jrd}|jrd }}	|	r|jryt|jd}W n< tk
rv } z|td	|j|f  W dd}~X Y nX t|	|}	|	}
i }x|jD ]}y|d
d\}}W n$ t k
r   |td Y nX |rt!|t"ry|#|}W n t$k
r   Y nX |||< qW x|j%D ]}y|d
\}}W n$ t k
rX   |td Y nX yt&|}W nN t k
r   |rt!|t"ry|#|}W n t$k
r   Y nX Y nX ||d| < qW |j'rd|d< d}y|jp|j}t(|` t) N t*|j|j|j	|j|j+|||	|j,|j-|j.|j/|j0|j1}|2|j| |j3S Q R X W dQ R X W n6 tt4fk
r } zt5||||
 dS d}~X Y nX dS )z'Sphinx build "main" command-line entry.Nz	.doctreeszcannot find files %rlocalez&cannot combine -a option and filenamesrR   r*   wzcannot open warning file %r: %s=rD   z1-D option argument must be in the form name=valuez1-A option argument must be in the form name=valuezhtml_context.%sTrL   r   )6rZ   
parse_argsrG   rF   r5   rB   ospathjoinr7   r8   isfilerH   errorr
   
__import__Zgetpreferredencoding	Exceptionr?   rQ   r   r   r   stdoutr&   rN   rO   rS   openr   rI   split
ValueErrorr   r   decoder!   rJ   r-   rL   r   r   r   r;   r@   rT   rK   r   r0   rU   ZbuildZ
statuscoder   r)   )r\   rX   r   r8   Zmissing_filesfilenamer^   Zlikely_encodingZstatusZwarningrf   ZwarnfpexcZconfoverridesvalkeyr%   rF   r'   r'   r(   
build_main   s    




 

rr   c             C   sN   t jtjd t jtjtdd | d d dgkrBt	| S t
| S d S )N r^   sphinxrD   z-M)rt   r^   	setlocaleLC_ALLZinit_consolerb   rc   rd   r   r]   rr   )r\   r'   r'   r(   main7  s
    rw   __main__).__doc__Z
__future__r   r.   r^   r+   rb   r   r   Zdocutils.utilsr   Zsixr   r   Zsphinx.localert   r   r   Zsphinx.applicationr   Zsphinx.errorsr	   r
   Zsphinx.utilr   r   r   Zsphinx.util.consoler   r   r   Zsphinx.util.docutilsr   r   Zsphinx.util.pycompatr   r&   r)   r1   rZ   r\   r]   rr   rw   __name__exitr'   r'   r'   r(   <module>
   s4   3`f
