o
    Ni                      @  s   d Z ddlm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	Z	ddl
mZ ddlmZmZmZmZ ddlmZ ejd	krHdd
lmZ nddlmZ erVddlmZ g dZG dd dZdddZdS )a  sphinx-build -M command-line handling.

This replaces the old, platform-dependent and once-generated content
of Makefile / make.bat.

This is in its own module so that importing it is fast.  It should not
import the main Sphinx modules (like sphinx.applications, sphinx.builders).
    )annotationsN)path)TYPE_CHECKING)
build_main)blueboldcolor_terminalnocolor)rmtree)      )chdir)_chdir)Sequence)) htmlzto make standalone HTML files)r   dirhtmlz2to make HTML files named index.html in directories)r   
singlehtmlz to make a single large HTML file)r   picklezto make pickle files)r   jsonzto make JSON files)r   htmlhelpz+to make HTML files and an HTML help project)r   qthelpz'to make HTML files and a qthelp project)r   devhelpz(to make HTML files and a Devhelp project)r   epubzto make an epub)r   latexz9to make LaTeX files, you can set PAPER=a4 or PAPER=letter)posixlatexpdfz.to make LaTeX and PDF files (default pdflatex))r   
latexpdfjaz8to make LaTeX files and run them through platex/dvipdfmx)r   textzto make text files)r   manzto make manual pages)r   texinfozto make Texinfo files)r   infoz3to make Texinfo files and run them through makeinfo)r   gettextzto make PO message catalogs)r   changesz9to make an overview of all changed/added/deprecated items)r   xmlz!to make Docutils-native XML files)r   	pseudoxmlz0to make pseudoxml-XML files for display purposes)r   	linkcheckz)to check all external links for integrity)r   doctestz>to run all doctests embedded in the documentation (if enabled))r   coveragez7to run coverage check of the documentation (if enabled))r   cleanz+to remove everything in the build directoryc                   @  sh   e Zd Zd dd	Zd!ddZd"ddZd#ddZd"ddZd"ddZd"ddZ	d"ddZ
d$d%ddZdS )&Make
source_dirstr	build_diroptsSequence[str]returnNonec                C  s   || _ || _g || _d S Nr+   r-   r.   )selfr+   r-   r.    r5   H/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/cmd/make_mode.py__init__@   s   zMake.__init__compsc                 G  s   t j| jg|R  S r2   )r   joinr-   )r4   r8   r5   r5   r6   build_dir_joinE   s   zMake.build_dir_joinintc                 C  s   t | j}t | j}t | jsdS t | js#td| j  dS ||kr0td| j  dS t ||g|krBtd| j  dS td| j  t	| jD ]	}t
| | qOdS )Nr   zError: %r is not a directory!   z&Error: %r is same as source directory!z.Error: %r directory contains source directory!zRemoving everything under %r...)r   abspathr+   r-   existsisdirprint
commonpathoslistdirr
   r:   )r4   r+   r-   itemr5   r5   r6   build_cleanH   s"   zMake.build_cleanc                 C  st   t  st  ttdtj  tdtdfd   tD ]\}}}|r(tj	|kr7tdt|
d d|  qd S )Nz
Sphinx v%sz'Please use `make %s' where %s is one oftarget   z  
   )r   r	   r@   r   sphinx__display_version__r   BUILDERSrB   nameljust)r4   osnamebnamedescriptionr5   r5   r6   
build_help[   s   zMake.build_helpc              	   C  sP  |  ddkr	dS tjdkrdnd}tjd|}| ds&td| zqt	| 
d_ d	| jv rbtd
d}tj|ddg|tjd}W d    n1 sPw   Y  |ratd| 
dd
  n!d| jv r|t|dddg}|r{td| 
d  nt|dg}|W  d    W S 1 sw   Y  W d S  ty   td|  Y dS w )Nr   r   r<   win32make.batmakeMAKEInvalid $MAKE command: %rz-Q__LATEXSTDOUT__wall-pdfzLATEXOPTS=-halt-on-error)stdoutstderrzLatex error: check %sz-qzLATEXMKOPTS=-silentz"Latex error: check .log file in %sError: Failed to run: %s)run_generic_buildsysplatformrB   environgetlower
startswithRuntimeErrorr   r:   r.   open
subprocesscallSTDOUTr@   OSError)r4   make_fallbackmakecmdoutfile
returncoder5   r5   r6   build_latexpdfe   s`   



("zMake.build_latexpdfc                 C  s   |  ddkr	dS tjdkrdnd}tjd|}| ds&td| z"t	| 
d t|d	gW  d    W S 1 sAw   Y  W d S  tyX   td
|  Y dS w )Nr   r   r<   rR   rS   rT   rU   rV   rY   r\   )r]   r^   r_   rB   r`   ra   rb   rc   rd   r   r:   rf   rg   ri   r@   )r4   rj   rk   r5   r5   r6   build_latexpdfja   s   (zMake.build_latexpdfjac                 C  s   |  ddkr	dS tjdd}| dstd| z"t| d t	
|dgW  d    W S 1 s8w   Y  W d S  tyO   td|  Y dS w )	Nr    r   r<   rU   rT   rV   r!   r\   )r]   rB   r`   ra   rb   rc   rd   r   r:   rf   rg   ri   r@   )r4   rk   r5   r5   r6   
build_info   s   (zMake.build_infoc                 C  s&   |  dd}| jd|ddkrdS dS )Nr"   z	.doctrees)
doctreedirr   r<   )r:   r]   )r4   dtdirr5   r5   r6   build_gettext   s   zMake.build_gettextNbuilderrq   
str | Nonec                 C  sd   t dd}|dv r| jdd| dg |d u r| d}d|d	|| j| |g}t|| j S )
NPAPERr   >   a4letterz-Dzlatex_elements.papersize=paperdoctreesz	--builderz--doctree-dir)rB   getenvr.   extendr:   r+   r   )r4   rt   rq   
paper_sizeargsr5   r5   r6   r]      s   
zMake.run_generic_build)r+   r,   r-   r,   r.   r/   r0   r1   )r8   r,   r0   r,   )r0   r;   )r0   r1   r2   )rt   r,   rq   ru   r0   r;   )__name__
__module____qualname__r7   r:   rE   rQ   rn   ro   rp   rs   r]   r5   r5   r5   r6   r*   ?   s    






0

r*   r~   r/   r0   r;   c                 C  sn   t | dk rtdtjd dS | d }t| d | d | dd  d}d| }t||r2t|| S ||S )	Nr   zJError: at least 3 arguments (builder, source dir, build dir) are required.)filer<   r   rG   r3   build_)lenr@   r^   r[   r*   hasattrgetattrr]   )r~   builder_namerT   
run_methodr5   r5   r6   run_make_mode   s   


r   )r~   r/   r0   r;   )__doc__
__future__r   rB   rf   r^   r   typingr   rI   sphinx.cmd.buildr   sphinx.util.consoler   r   r   r	   sphinx.util.osutilr
   version_info
contextlibr   r   collections.abcr   rK   r*   r   r5   r5   r5   r6   <module>   s(    	
  