U
    \Sh%                     @  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 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 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- ddl.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4 e"5e6Z7ej8eddZ9G dd deZ:dddd d!Z;d"d#d$d%d&Z<dS )'zTexinfo builder.    )annotationsN)path)AnyIterable)nodes)OptionParser)
FileOutput)Node)addnodespackage_dir)Sphinx)Builder)Config)ImageAdapter)NoUri)___)logging)	darkgreen)progress_messagestatus_iterator)new_document)copy_asset_file)inline_all_toctrees)SEP	ensuredirmake_filename_from_project)TexinfoTranslatorTexinfoWriterZ	templatestexinfoc                   @  s   e Zd ZdZdZdZedZejdkr2eed7 ZdddgZ	e
Zd	d
ddZdd
ddZd,ddddddZd-dddddddZd	d
ddZdd	dddZddd d!d"d#d$Zd	d
d%d&Zdd	d'd(d)Zd	d
d*d+ZdS ).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None)returnc                 C  s   g | _ g | _d S N)docnamesdocument_dataself r)   J/root/rtd-docs/venv/lib/python3.8/site-packages/sphinx/builders/texinfo.pyinit3   s    zTexinfoBuilder.initzstr | list[str]c                 C  s   dS )Nzall documentsr)   r'   r)   r)   r*   get_outdated_docs7   s    z TexinfoBuilder.get_outdated_docsNstrz
str | None)docnametypr#   c                 C  s   || j krt||d| S )N%)r%   r   )r(   r.   r/   r)   r)   r*   get_target_uri:   s    

zTexinfoBuilder.get_target_uri)from_tor/   r#   c                 C  s   |  ||S r$   )r1   )r(   r2   r3   r/   r)   r)   r*   get_relative_uri?   s    zTexinfoBuilder.get_relative_uric                 C  s   dd | j jD }|s(ttd d S g | _|D ]d}|d }|| jjkr\ttd| q2| j	| |
td r|d d }| j	||d f q2d S )	Nc                 S  s   g | ]}t |qS r)   )list).0xr)   r)   r*   
<listcomp>D   s     z5TexinfoBuilder.init_document_data.<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envZall_docsr&   appendendswithr   )r(   Zpreliminary_document_dataentryr.   r)   r)   r*   init_document_dataC   s     
z!TexinfoBuilder.init_document_datar   )ignoredr#   c                 G  s  |    |   | jD ]}|d d \}}}}|d7 }d } }}	t|dkrb|dd \}}}	d}
t|dkrz|d }
tt| j|dd}tt	d	| " | j
jpg }| j||
|d
}W 5 Q R X tt	d | | t| }t , tjdtd t| jj|fdd }W 5 Q R X ||_||_|d d d |_| j
j|_|pRd|_|	p^d|_|pjd|_||_||_||| |  |d d  W 5 Q R X qd S )N   z.texi       Fzutf-8)Zdestination_pathencodingzprocessing %s)
appendiceswritingignore)categoryT)defaults
componentsZread_config_filesr:   z.info)!rE   copy_assetsr&   lenr   r   joinoutdirr   r   r<   texinfo_appendicesassemble_doctreeZpost_process_imagesr   warningscatch_warningsfilterwarningsDeprecationWarningr   rA   settingsget_default_valuesauthortitleZtexinfo_filenametexinfo_elementsZtexinfo_dir_entryZtexinfo_dir_categoryZtexinfo_dir_descriptionr.   writecopy_image_files)r(   rF   rD   r.   
targetnamer_   r^   ZdirentrydescriptionrO   toctree_onlyZdestinationrL   ZdoctreeZ	docwriterr\   r)   r)   r*   ra   V   sN    


zTexinfoBuilder.writeboolz	list[str]znodes.document)	indexfilere   rL   r#   c                 C  s  t |g| | _tjt|d dd | j|}||d< |rtd}t	 }|t
dd7 }||7 }|tjD ]}||7 }qr|}t| | j||t|g}||d< |D ]"}	| j|	}
|	|
d< ||
 qtd ttd | j|||  |tjD ]}|d	 }	|d
 }t||g}| jD ]R\}}|	|r&|ttd |t|| |td  qzq&|| q|S )N TZnonlr.   z<texinfo output>z<Set title in conf.py>rH   zresolving references...Z
refdocnameZrefsectnamez (in ))setr%   r>   infor   rA   Zget_doctreer   r   sectionr_   findallr
   Ztoctreer   rB   r   Zresolve_referencesZpending_xrefZemphasisr@   
startswithTextr   Zreplace_self)r(   rg   re   rL   treeZnew_treeZnew_sectnodeZ	largetreer.   ZappendixZpendingnodesectnameZnewnodessubdirr_   r)   r)   r*   rW      sL    
 

zTexinfoBuilder.assemble_doctreec                 C  s   |    d S r$   )copy_support_filesr'   r)   r)   r*   rR      s    zTexinfoBuilder.copy_assets)rc   r#   c                 C  s   | j rt| jjj}t| j tddt| j | jj|dD ]}| j | }z:t	
| j|d }t| tt	
| j|t	
|| W q8 tk
r } z ttdt	
| j|| W 5 d }~X Y q8X q8d S )Nzcopying images... Zbrown)stringify_funcz-figureszcannot copy image file %r: %s)Zimagesr   apprA   Zget_original_image_urir   r   rS   	verbosityr   rT   rU   r   r   srcdir	Exceptionr>   r?   )r(   rc   rv   srcdestZimagedirerrr)   r)   r*   rb      s&     



 zTexinfoBuilder.copy_image_filesc              
   C  sx   z@t td* tjddd ttjtd| j	 W 5 Q R X W n2 t
k
rr } zttd| W 5 d }~X Y nX d S )Nzcopying Texinfo support filesz	Makefile Tri   Makefilezerror writing file Makefile: %s)r   r   r>   rl   r   osr   rT   template_dirrU   OSErrorr?   )r(   r}   r)   r)   r*   ru      s    $z!TexinfoBuilder.copy_support_files)N)N)__name__
__module____qualname____doc__nameformatr   epilogr   Zsupported_image_typesr   Zdefault_translator_classr+   r,   r1   r4   rE   ra   rW   rR   rb   ru   r)   r)   r)   r*   r    #   s(   
*,r    r   z.list[tuple[str, str, str, str, str, str, str]])r<   r#   c                 C  s$   t | j}| j|| j| j|ddfgS )z, Better default texinfo_documents settings. zOne line description of projectZMiscellaneous)r   projectZroot_docr^   )r<   filenamer)   r)   r*   default_texinfo_documents   s
    
 r   r   zdict[str, Any])rw   r#   c                 C  s|   |  t | dtd | dg d | di d | dddtg | ddd | d	dd | d
dd ddddS )Nr=   FrV   r`   Ztexinfo_domain_indicesTZtexinfo_show_urlsZfootnoteZtexinfo_no_detailmenuZtexinfo_cross_referencesbuiltin)versionZparallel_read_safeZparallel_write_safe)Zadd_builderr    Zadd_config_valuer   r5   )rw   r)   r)   r*   setup   s    
r   )=r   
__future__r   r   rX   r   typingr   r   Zdocutilsr   Zdocutils.frontendr   Zdocutils.ior   Zdocutils.nodesr	   Zsphinxr
   r   Zsphinx.applicationr   Zsphinx.buildersr   Zsphinx.configr   Z!sphinx.environment.adapters.assetr   Zsphinx.errorsr   Zsphinx.localer   r   Zsphinx.utilr   Zsphinx.util.consoler   Zsphinx.util.displayr   r   Zsphinx.util.docutilsr   Zsphinx.util.fileutilr   Zsphinx.util.nodesr   Zsphinx.util.osutilr   r   r   Zsphinx.writers.texinfor   r   	getLoggerr   r>   rT   r   r    r   r   r)   r)   r)   r*   <module>   s<   
 &	