o
    NiyC                     @  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	Z	ddl
Z
ddlZddlmZ ddlmZ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m Z m!Z!m"Z" ddl#m$Z$m%Z% ddl&m'Z'm(Z( ddl)m*Z* erddl+m,Z, ddlm-Z- G dd de-Z.e
j/fdXddZ0dYd#d$Z1dZd&d'Z2d[d*d+Z3d\d.d/Z4d]d5d6Z5d^d9d:Z6d_d>d?Z7d`dAdBZ8dadGdHZ9dbdMdNZ:d[dOdPZ;dcdQdRZ<ddd[dTdUZ=e>dVkre?e=e
j@dWd dS )ez+Build documentation from a provided source.    )annotationsN)path)TYPE_CHECKINGAnyTextIO)SystemMessage)__display_version__)Sphinx)SphinxErrorSphinxParallelError)__)TeeStripANSI)color_terminalnocolorredterminal_safe)docutils_namespacepatch_docutils)format_exception_cut_framessave_traceback)	ensuredir)Sequence)Protocolc                   @  s   e Zd ZdddZdS )	SupportsWritetextstrreturn
int | Nonec                C  s   d S N )selfr   r   r   D/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/cmd/build.pywrite#   s    zSupportsWrite.writeN)r   r   r   r   )__name__
__module____qualname__r"   r   r   r   r!   r   "   s    r   appSphinx | Noneargsr   	exceptionBaseExceptionstderrr   r   Nonec                 C  sX  t |tjrd S |jr$tttd|d t  t	t
 d  d S t|d |js/|jrQt
 d }t |trFd|j }t||d ntd | t|d t |tr`ttd|d d S t |tr|tttd|d tt|jd |d d S t |trttd	|j |d tt||d d S t |trtttd
|d ttt||d t| |}tttd| |d d S t |trdt|v rtttd|d ttt||d t|d ttd|d td|d d S t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(Error in parallel process)
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bdbBdbQuitpdbprintr   r   	traceback	print_excpost_mortemsysexc_info	verbosityr   KeyboardInterruptr   r   r(   r
   categoryr   UnicodeErrorr   RuntimeErrorr   rstrip)r&   r(   r)   r+   exc
exc_formattbpathr   r   r!   handle_exception&   s   














rC   valuer   intc                 C  s2   | dkrt  S t| }|dkrtt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 number)multiprocessing	cpu_countrE   argparseArgumentTypeErrorr   )rD   jobsr   r   r!   jobs_argument   s   rL   argparse.ArgumentParserc               	   C  s  t jdtdtdd} | jddddt d	 | jd
dtdd | jddtdd | jddtdd | td}|jdddddtdd |jdddd td!td"d# |jd$d%d&d'td(d) |jd*d+d&d,td-d) | td.}|jd/d0d1d2td3d4 |jd5d6d1d7td8d4 | d9}|jd:d;d&d<td=d) |jd>d?d@dAdBg tdCdD |jdEdFdGdAdHg tdIdD |jdJdKdLdAdMg tdNdD |jdOdPd&dQtdRd) | tdS}|jdTdUdVdWdXtdYdZ |jd[d\d&d]td^d) |jd_d`d&datdbd) |jdcdddedfdgtdhdi |jdjdkdddedltdmdn | tdo}|jdpdqdrdstdtd4 |jdudvd&dwtdxd) |jdyd&t jdz |jd{d|d&d}td~d) |jddd&dtdd) |jdd&dtdd) | jdkrpd| _| S )Nz5%(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versionshow_versionz	%(prog)s )actiondestrQ   	sourcedir
SOURCE_DIRz"path to documentation source files)metavarhelp	outputdir
OUTPUT_DIRzpath to output directory	filenames*zS(optional) a list of specific files to rebuild. Ignored if --write-all is specified)nargsrX   zgeneral optionsz	--builderz-bBUILDERbuilderhtmlz builder to use (default: 'html'))rW   rT   defaultrX   z--jobsz-jNr/   rK   zTrun in parallel with N processes, when possible. 'auto' uses the number of CPU cores)rW   ra   typerT   rX   z--write-allz-a
store_true	force_allz;write all files (default: only write new and changed files))rS   rT   rX   z--fresh-envz-Efreshenvz4don't use a saved environment, always read all fileszpath optionsz--doctree-dirz-dPATH
doctreedirzKdirectory for doctree and environment files (default: OUTPUT_DIR/.doctrees))rW   rT   rX   z
--conf-dirz-cconfdirzDdirectory for the configuration file (conf.py) (default: SOURCE_DIR)zbuild configuration optionsz
--isolatedz-Cnoconfigz<use no configuration file, only use settings from -D optionsz--definez-Dzsetting=valueappenddefinez(override a setting in configuration file)rW   rS   rT   ra   rX   z--html-definez-Az
name=value
htmldefinez pass a value into HTML templatesz--tagz-tTAGtagsz*define tag: include "only" blocks with TAGz
--nitpickyz-nnitpickyz0nitpicky mode: warn about all missing referenceszconsole output optionsz	--verbosez-vcountr:   r   z$increase verbosity (can be repeated))rS   rT   ra   rX   z--quietz-qquietz,no output on stdout, just warnings on stderrz--silentz-Qreally_quietz#no output at all, not even warningsz--colorstore_constcoloryesrF   z-do emit colored output (default: auto-detect))rS   rT   constra   rX   z
--no-colorz-Nnoz1do not emit colored output (default: auto-detect))rS   rT   rw   rX   zwarning control optionsz--warning-filez-wFILEwarnfilez)write warnings (and errors) to given filez--fail-on-warningz-Wwarningiserrorzturn warnings into errorsz--keep-going)rS   rX   z--show-tracebackz-Tr5   z show full traceback on exceptionz--pdbz-Pr3   zrun Pdb on exceptionz--exception-on-warningexception_on_warningzraise an exception on warningsz__main__.pyzsphinx-build)	rI   ArgumentParserr   add_argumentr   add_argument_grouprL   SUPPRESSprog)parsergroupr   r   r!   
get_parser   s  

	


				r   argvSequence[str]c                 C  s   ddl m} || dd S )zSphinx build "make mode" entry.r   	make_moder/   N)
sphinx.cmdr   run_make_moder   r   r   r   r!   	make_mainu  s   r   r   argparse.Namespacec                 C  s   |  |}|S r   )
parse_args)r   r   r(   r   r   r!   _parse_arguments|  s   
r   rj   boolri   rU   
str | Nonec                 C  s   | rd S |s|S |S r   r   )rj   ri   rU   r   r   r!   _parse_confdir  s
   r   rh   rY   c                 C  s   | r| S t j|dS )Nz	.doctrees)osr   join)rh   rY   r   r   r!   _parse_doctreedir  s   r   re   r[   	list[str]c                 C  s"   |r|r|  td d S d S d S )Nz&cannot combine -a option and filenames)errorr   )r   re   r[   r   r   r!   _validate_filenames  s   r   colourc                 C  s(   | dks| dkrt  st  d S d S d S )Nrx   rF   )r   r   )r   r   r   r!   _validate_colour_support  s   
r   rr   rs   rz   :tuple[TextIO | None, TextIO | None, TextIO, TextIO | None]c           	   
   C  s   t j}t j}t j}|rd }|rd  }}d }|rS|rSzt|}tt| t|ddd}W n tyK } z| 	t
d||f  W Y d }~nd }~ww t||}|}||||fS )Nwzutf-8)encodingzcannot open warning file %r: %s)r8   stdoutr+   r   abspathr   dirnameopen	Exceptionr   r   r   )	r   rr   rs   rz   statuswarningr   warnfpr@   r   r   r!   _parse_logging  s(   
"
r   rl   rm   rp   dict[str, Any]c              	   C  s   i }|D ]!}z
| dd\}}W n ty    | td Y nw |||< q|D ]<}z	| d\}}W n tyC   | td Y nw tt t|}W d    n1 sXw   Y  ||d| < q(|rkd|d< |S )N=r/   z1-D option argument must be in the form name=valuez1-A option argument must be in the form name=valuezhtml_context.Trp   )split
ValueErrorr   r   
contextlibsuppressrE   )r   rl   rm   rp   confoverridesvalkeyr   r   r!   _parse_confoverrides  s*   

r   c              
   C  s0  t  }t|| }t|j|j|j|_t|j|j|_t	||j
|j t|j t||j|j|j\|_|_|_}t||j|j|j|_d}zz|jpL|j}t|| t i tdi d|jd|jd|jd|jd|jd|jd|jd	|jd
|jd|jd|j d|j!d|j"ddd|j#d|j$}|%|j
|j |j&W  d   W  d   W W |dur|'  S S 1 sw   Y  W d   n1 sw   Y  W n( t(t)fy } zt*||||j W Y d}~W |dur|'  dS dS d}~ww W |dur|'  dS dS |dur|'  w w )z'Sphinx build "main" command-line entry.Nsrcdirri   outdirrh   buildernamer   r   r   rf   r{   ro   r:   parallel
keep_goingFr3   r|   r.   r   )+r   r   r   rj   ri   rU   r   rh   rY   r   re   r[   r   ru   r   rr   rs   rz   r   r   r   r   rl   rm   rp   r   r   r   r	   r_   rf   r{   ro   r:   rK   r3   r|   build
statuscodecloser   r;   rC   )r   r   r(   r   r&   ri   r@   r   r   r!   
build_main  s   

	
 
.

r   c                  C  s   ddl m } m} dd l}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|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Pygments version:      z```)r   r   docutilsjinja2pygmentsr4   r8   rQ   sphinxr   __version__)r   r   r   r   r   r   r   r!   _bug_report_info  s   r   r   c                C  s   t t jd tj   | stjdd  } | d d dgkr$| dd  } | d d dgkr0t S | d d dgkrHddlm	} |
| dd  S t| S )N r/   r   z--bug-reportz-Mr   r   )locale	setlocaleLC_ALLr   init_consoler8   r   r   r   r   r   r   r   r   r   r!   main!  s   
r   __main__r/   )
r&   r'   r(   r   r)   r*   r+   r   r   r,   )rD   r   r   rE   )r   rM   )r   r   r   rE   )r   rM   r   r   r   r   )rj   r   ri   r   rU   r   r   r   )rh   r   rY   r   r   r   )r   rM   re   r   r[   r   r   r,   )r   r   r   r,   )
r   rM   rr   r   rs   r   rz   r   r   r   )
r   rM   rl   r   rm   r   rp   r   r   r   )r   rE   )r   )A__doc__
__future__r   rI   r1   r   r   rG   r   r3   r8   r5   r   typingr   r   r   docutils.utilsr   sphinx.localer   r   sphinx.applicationr	   sphinx.errorsr
   r   r   sphinx.util._ior   sphinx.util.consoler   r   r   r   sphinx.util.docutilsr   r   sphinx.util.exceptionsr   r   sphinx.util.osutilr   collections.abcr   r   r   r+   rC   rL   r   r   r   r   r   r   r   r   r   r   r   r   r#   
SystemExitr   r   r   r   r!   <module>   s^    
^
 
`




	



0