o
    Ni'                     @  s  d Z ddlmZ ddlZddl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 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 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- erddl.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 e9e:Z;ej<eddZ=G dd deZ>d)d"d#Z?d*d'd(Z@dS )+zTexinfo builder.    )annotationsN)path)TYPE_CHECKINGAny)nodes)OptionParser)
FileOutput)addnodespackage_dir)Builder)ImageAdapter)NoUri)___)logging)	darkgreen)progress_messagestatus_iterator)new_document)inline_all_toctrees)SEPcopyfile	ensuredirmake_filename_from_project)TexinfoTranslatorTexinfoWriter)IterableSet)Node)Sphinx)Config)ExtensionMetadata	templatestexinfoc                   @  s   e Zd ZdZdZdZedZejdkreed7 Zg dZ	e
Zd.d	d
Zd/ddZd0d1ddZd0d2ddZd3ddZd3ddZd4d%d&Zd.d'd(Zd5d*d+Zd.d,d-ZdS )6TexinfoBuilderz=
    Builds Texinfo output to create Info documentation.
    r#   z$The Texinfo files are in %(outdir)s.posixzl
Run 'make' in that directory to run these through makeinfo
(use 'make info' here to do that automatically).)z	image/pngz
image/jpegz	image/gifreturnNonec                 C  s   g | _ g | _d S N)docnamesdocument_dataself r-   K/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/builders/texinfo.pyinit:   s   
zTexinfoBuilder.initstr | list[str]c                 C  s   dS )Nzall documentsr-   r+   r-   r-   r.   get_outdated_docs>   s   z TexinfoBuilder.get_outdated_docsNdocnamestrtyp
str | Nonec                 C  s   || j vr
t||d| S )N%)r)   r   )r,   r2   r4   r-   r-   r.   get_target_uriA   s   

zTexinfoBuilder.get_target_urifrom_toc                 C  s   |  ||S r(   )r7   )r,   r8   r9   r4   r-   r-   r.   get_relative_uriF   s   zTexinfoBuilder.get_relative_uri	_docnamesSet[str]c                 C  s   dd | j jD }|sttd d S g | _|D ],}|d }|| jjvr.ttd| q| j	| |
td }| j	||d f qd S )Nc                 S  s   g | ]}t |qS r-   )list).0xr-   r-   r.   
<listcomp>K   s    z2TexinfoBuilder.prepare_writing.<locals>.<listcomp>zGno "texinfo_documents" config value found; no documents will be writtenr   z?"texinfo_documents" config value references unknown document %sindex   )configtexinfo_documentsloggerwarningr   titlesenvall_docsr*   appendremovesuffixr   )r,   r;   preliminary_document_dataentryr2   r-   r-   r.   prepare_writingJ   s.   zTexinfoBuilder.prepare_writingc              
   C  s  | j D ]}|d d \}}}}|d7 }d } }}	t|dkr(|dd \}}}	d}
t|dkr4|d }
tt| j|dd}ttd	| dd
 | jj	pOg }| j
||
|d}W d    n1 sbw   Y  ttdp | | t| }t  tjdtd t| jj|fdd }W d    n1 sw   Y  ||_||_|d d d |_| jj|_|pd|_|	pd|_|pd|_||_||_||| | |d d  W d    n1 sw   Y  qd S )N   z.texi       Fzutf-8)destination_pathencodingzprocessing %snonl)
appendiceswritingignore)categoryT)defaults
componentsread_config_filesz.info)r*   lenr   r   joinoutdirr   r   rC   texinfo_appendicesassemble_doctreepost_process_imagesr   warningscatch_warningsfilterwarningsDeprecationWarningr   rH   settingsget_default_valuesauthortitletexinfo_filenametexinfo_elementstexinfo_dir_entrytexinfo_dir_categorytexinfo_dir_descriptionr2   writecopy_image_files)r,   r;   rM   r2   
targetnamerl   rk   direntrydescriptionrZ   toctree_onlydestinationrW   doctree	docwriterri   r-   r-   r.   write_documentse   sZ   


	



zTexinfoBuilder.write_documents	indexfilerw   boolrW   	list[str]nodes.documentc              	   C  sl  |h|| _ tt| | j|}||d< |r<td}t }|t	dd7 }||7 }|
tjD ]}||7 }q3|}t| | j ||t|g}||d< |D ]}	| j|	}
|	|
d< ||
 qMtd ttd | j|||  |
tjD ]:}|d }	|d }t||g}| jD ]\}}|	|r|ttdt||td	f  nq	 || qy|S )
Nr2   z<texinfo output>z<Set title in conf.py>rP   zresolving references...
refdocnamerefsectnamez (in ))r)   rE   infor   rH   get_doctreer   r   sectionrl   findallr	   toctreer   rJ   r   resolve_referencespending_xrefemphasisrG   
startswithextendTextr   replace_self)r,   r|   rw   rW   treenew_treenew_sectnode	largetreer2   appendixpendingnodesectnamenewnodessubdirrl   r-   r-   r.   rc      sN   



zTexinfoBuilder.assemble_doctreec                 C  s   |    d S r(   )copy_support_filesr+   r-   r-   r.   copy_assets   s   zTexinfoBuilder.copy_assetsrt   c                 C  s   | j r^t| jjj}t| j tddt| j | jj|dD ]C}| j | }z| j	| d }t
| t| j| || dd W q ty] } zttdt| j|| W Y d }~qd }~ww d S d S )Nzcopying images... brown)stringify_funcz-figuresTforcezcannot copy image file %r: %s)imagesr   apprH   get_original_image_urir   r   r_   	verbosityra   r   r   srcdir	ExceptionrE   rF   r   r`   )r,   rt   r   srcdestimagedirerrr-   r-   r.   rs      s:   


zTexinfoBuilder.copy_image_filesc              
   C  s   z1t td  tjddd ttjtd| j	d dd W d    W d S 1 s*w   Y  W d S  t
yL } zttd| W Y d }~d S d }~ww )Nzcopying Texinfo support filesz	Makefile TrU   Makefiler   zerror writing file Makefile: %s)r   r   rE   r   r   osr   r`   template_dirra   OSErrorrF   )r,   r   r-   r-   r.   r      s   &z!TexinfoBuilder.copy_support_files)r&   r'   )r&   r0   r(   )r2   r3   r4   r5   r&   r3   )r8   r3   r9   r3   r4   r5   r&   r3   )r;   r<   r&   r'   )r|   r3   rw   r}   rW   r~   r&   r   )rt   r3   r&   r'   )__name__
__module____qualname____doc__nameformatr   epilogr   supported_image_typesr   default_translator_classr/   r1   r7   r:   rN   r{   rc   r   rs   r   r-   r-   r-   r.   r$   (   s*    





+
1
r$   rC   r    r&   .list[tuple[str, str, str, str, str, str, str]]c                 C  s$   t | j}| j|| j| j|ddfgS )z*Better default texinfo_documents settings.zOne line description of projectMiscellaneous)r   projectroot_docrk   )rC   filenamer-   r-   r.   default_texinfo_documents   s   
r   r   r   r!   c                 C  s   |  t | dtd | dg d | di d | jdddtthd | dd	d | d
dd | ddd ddddS )NrD   rP   rb   rn   texinfo_domain_indicesT)typestexinfo_show_urlsfootnotetexinfo_no_detailmenuFtexinfo_cross_referencesbuiltin)versionparallel_read_safeparallel_write_safe)add_builderr$   add_config_valuer   setr=   )r   r-   r-   r.   setup   s   
r   )rC   r    r&   r   )r   r   r&   r!   )Ar   
__future__r   r   re   r   typingr   r   docutilsr   docutils.frontendr   docutils.ior   sphinxr	   r
   sphinx.buildersr   !sphinx.environment.adapters.assetr   sphinx.errorsr   sphinx.localer   r   sphinx.utilr   sphinx.util.consoler   sphinx.util.displayr   r   sphinx.util.docutilsr   sphinx.util.nodesr   sphinx.util.osutilr   r   r   r   sphinx.writers.texinfor   r   collections.abcr   r   docutils.nodesr   sphinx.applicationr   sphinx.configr    sphinx.util.typingr!   	getLoggerr   rE   r`   r   r$   r   r   r-   r-   r-   r.   <module>   sB    
 
E