B
    d3                 @   s  d 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Zddlm	Z	 ddl
mZmZmZ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 ddlmZm Z m!Z!m"Z" ddl#m$Z$m%Z% ddl&m'Z'm(Z( ej)fee ee*eddddZ+e,e-dddZ.ej/dddZ0ej1dd fee, e-dddZ2ej1dd fee, ej3dddZ4ej1dd fee, e-dddZ5e-ddd Z6ej1dd fee, e-dd!d"Z7e8d#kre9e7ej1dd  dS )$z+Build documentation from a provided source.    N)path)AnyListOptionalTextIO)SystemMessage)__display_version__package_dir)Sphinx)SphinxError)__)Teeformat_exception_cut_framessave_traceback)color_terminalnocolorredterminal_safe)docutils_namespacepatch_docutils)abspath	ensuredir)appargs	exceptionstderrreturnc             C   s(  t |tjrd S |jrHtttd|d t  t	t
 d  nt|d |js^|jrttd | t|d t |trttd|d nt |trtttd|d tt|jd |d nZt |trttd|j |d tt||d n&t |trTt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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 )Nz5Exception occurred while building, starting debugger:)file   zInterrupted!zreST markup error:r   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!)
isinstancebdbZBdbQuitpdbprintr   r   	traceback	print_excZpost_mortemsysexc_info	verbosityKeyboardInterruptr   r   r   r   categorystrUnicodeErrorr   RuntimeErrorr   rstrip)r   r   r   r   Ztbpath r.   ]/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sphinx/cmd/build.pyhandle_exception   sV    








r0   )valuer   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argparseArgumentTypeErrorr   )r1   jobsr.   r.   r/   jobs_argumentQ   s    r9   )r   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...]z:For more information, visit <https://www.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.
)usageepilogdescriptionz	--versionversionZshow_versionz%%(prog)s %s)actiondestr=   	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)nargsrA   zgeneral optionsz-bZBUILDERbuilderhtmlzbuilder to use (default: html))metavarr?   defaultrA   z-a
store_true	force_allz;write all files (default: only write new and changed files))r>   r?   rA   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))rH   r?   rA   z-jN   r8   z`build in parallel with N processes where possible (special value "auto" will set N to cpu-count))rH   rI   typer?   rA   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)rH   r>   r?   rI   rA   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))r>   r?   rI   rA   z-qquietz,no output on stdout, just warnings on stderrz-Qreally_quietz#no output at all, not even warningsz--colorstore_constyesr2   z-do emit colored output (default: auto-detect))r>   constrI   rA   z-Nz
--no-colorcolornoz1do not emit colored output (default: auto-detect))r?   r>   r^   rA   z-w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)r6   ArgumentParserr   add_argumentr   add_argument_groupr9   )parsergroupr.   r.   r/   
get_parsera   s    




















rj   rP   )argvr   c             C   s   ddl m} || dd S )zSphinx build "make mode" entry.r   )	make_moderP   N)Z
sphinx.cmdrl   Zrun_make_mode)rk   rl   r.   r.   r/   	make_main   s    rm   c          
   C   s,  t  }|| }|jrd |_n|js,|j|_|jsDtj|j	d|_|j
r^|jr^|td |jdksx|jdkr~t s~t  tj}tj}tj}|jrd }|jrd  }}|r.|jr.y,t|j}tt| t|jddd}W n< tk
r } z|td|j|f  W d d }~X Y nX t||}|}||_||_||_i }	xR|jD ]H}
y|
 d	d
\}}
W n$ t!k
r   |td Y nX |
|	|< qLW xx|j"D ]n}
y|
 d	\}}
W n$ t!k
r   |td Y nX yt#|
}
W n t!k
r   Y nX |
|	d| < qW |j$r"d|	d< |	|_%|S )Nz	.doctreesz&cannot combine -a option and filenamesr`   r2   wzutf-8)encodingzcannot open warning file %r: %s=rP   z1-D option argument must be in the form name=valuez1-A option argument must be in the form name=valuezhtml_context.%sTrX   )&rj   
parse_argsrS   rR   r@   rN   osr   joinrB   rK   rC   errorr   r_   r   r   r%   stdoutr   rZ   r[   rb   r   r   dirnameopen	Exceptionr   statuswarningrU   split
ValueErrorrV   r5   rX   confoverrides)rk   rh   r   ry   rz   rt   rb   Zwarnfpexcr}   valkeyr.   r.   r/   _parse_arguments   sj    


 
r   c             C   s   t | }d}y|jp|j}t|l t Z t|j|j|j|j|j|j	|j
|j|j|j|j|j|j|j|j}||j|j |jS Q R X W dQ R X W n6 ttfk
r } zt||||j dS d}~X Y nX dS )z'Sphinx build "main" command-line entry.Nr   )r   rR   r@   r   r   r
   rB   rN   rF   r}   ry   rz   rL   rc   rW   r'   r8   rd   r!   buildrK   rC   Z
statuscoderx   r(   r0   rt   )rk   r   r   rR   r~   r.   r.   r/   
build_main  s    r   c              C   s   ddl m } m} dd l}dd l}td td tdtj  d|   d tdtj d td	|   td
tj  td|j	  td|j	  td dS )Nr   )platformpython_implementationz<Please paste all output below into the bug report template

z```textzPlatform:              z; ()zPython version:        zPython implementation: zSphinx version:        zDocutils version:      zJinja2 version:        z```)
r   r   docutilsjinja2r"   r%   r=   sphinxr   __version__)r   r   r   r   r.   r.   r/   _bug_report_info   s    r   c             C   sf   t jtjd t jtjtdd | d d dgkr@t	 S | d d dgkrZt
| S t| S d S )N localer   rP   z--bug-reportz-M)r   r   	setlocaleLC_ALLZinit_consolerr   r   rs   r	   r   rm   r   )rk   r.   r.   r/   main2  s    r   __main__):__doc__r6   r    r   r3   rr   r!   r%   r#   r   typingr   r   r   r   Zdocutils.utilsr   Zsphinx.localer   r   r	   Zsphinx.applicationr
   Zsphinx.errorsr   r   Zsphinx.utilr   r   r   Zsphinx.util.consoler   r   r   r   Zsphinx.util.docutilsr   r   Zsphinx.util.osutilr   r   r   BaseExceptionr0   r*   r5   r9   re   rj   rk   rm   	Namespacer   r   r   r   __name__exitr.   r.   r.   r/   <module>   s>   4_"$F""
