3

T'íc/$ã
@s˜dZddlZddlmZddlmZmZmZmZmZm	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZddlmZddlm Z m!Z!ddl"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4e#j5e6ƒZ7ejj8eddƒZ9Gdd„deƒZ:eeee;e;e;e;e;e;e;fdœdd„Z<eee;efdœdd „Z=dS)!zTexinfo builder.éN)Úpath)ÚAnyÚDictÚIterableÚListÚTupleÚUnion)Únodes)ÚOptionParser)Ú
FileOutput)ÚNode)ÚaddnodesÚpackage_dir)ÚSphinx)ÚBuilder)ÚConfig)ÚImageAdapter)ÚNoUri)Ú_Ú__)ÚloggingÚprogress_messageÚstatus_iterator)Ú	darkgreen)Únew_document)Úcopy_asset_file)Úinline_all_toctrees)ÚSEPÚ	ensuredirÚmake_filename_from_project)ÚTexinfoTranslatorÚ
TexinfoWriterZ	templatesÚtexinfoc@súeZdZdZdZdZedƒZejdkr2eedƒ7ZdddgZ	e
Zd	d
œdd„Ze
eeefd
œd
d„Zd$eeedœdd„Zd%eeeedœdd„Zd	d
œdd„Zed	dœdd„Zeeeeejdœdd„Zd	d
œdd„Zed	dœd d!„Zd	d
œd"d#„Zd	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/gifN)ÚreturncCsg|_g|_dS)N)ÚdocnamesÚ
document_data)Úself©r)ú9/tmp/pip-build-gk9425m9/sphinx/sphinx/builders/texinfo.pyÚinit/szTexinfoBuilder.initcCsdS)Nz
all documentsr))r(r)r)r*Úget_outdated_docs3sz TexinfoBuilder.get_outdated_docs)ÚdocnameÚtypr%cCs"||jkrt||ƒ‚nd|SdS)Nú%)r&r)r(r-r.r)r)r*Úget_target_uri6s
zTexinfoBuilder.get_target_uri)Úfrom_Útor.r%cCs|j||ƒS)N)r0)r(r1r2r.r)r)r*Úget_relative_uri<szTexinfoBuilder.get_relative_uricCs dd„|jjDƒ}|s(tjtdƒƒdSg|_xl|D]d}|d}||jjkr^tjtdƒ|ƒq4|jj	|ƒ|j
tdƒr„|dd	…}|jj	||dfƒq4WdS)
NcSsg|]}t|ƒ‘qSr))Úlist)Ú.0Úxr)r)r*ú
<listcomp>Asz5TexinfoBuilder.init_document_data.<locals>.<listcomp>zGno "texinfo_documents" config value found; no documents will be writtenrz?"texinfo_documents" config value references unknown document %sÚindexéééûÿÿÿ)ÚconfigÚtexinfo_documentsÚloggerÚwarningrÚtitlesÚenvZall_docsr'ÚappendÚendswithr)r(Zpreliminary_document_dataÚentryr-r)r)r*Úinit_document_data@s

z!TexinfoBuilder.init_document_data)Úignoredr%cGs„|jƒxt|jD]h}|dd…\}}}}|d7}d}}}	t|ƒdkr^|dd…\}}}	d}
t|ƒdkrv|d}
ttj|j|ƒdd}ttd	ƒ|ƒ"|j	j
p¨g}|j||
|d
}
WdQRXttdƒƒ¦|j|
ƒt
|ƒ}t|jj|fdd
jƒ}||_||_|dd…d|_|j	j|_|p,d|_|	p8d|_|pDd|_||_||
_|j|
|ƒ|j|dd…ƒWdQRXqWdS)Néz.texiÚééFzutf-8)Zdestination_pathÚencodingz
processing %s)Ú
appendicesÚwritingT)ÚdefaultsÚ
componentsZread_config_filesr9z.infor;r;)rEr'ÚlenrrÚjoinÚoutdirrrr<Útexinfo_appendicesÚassemble_doctreeZpost_process_imagesr!r
rAÚsettingsÚget_default_valuesÚauthorÚtitleZtexinfo_filenameÚtexinfo_elementsZtexinfo_dir_entryZtexinfo_dir_categoryZtexinfo_dir_descriptionr-ÚwriteÚcopy_image_files)r(rFrDr-Ú
targetnamerXrWZdirentryÚdescriptionÚcategoryÚtoctree_onlyZdestinationrLZdoctreeZ	docwriterrUr)r)r*rZSsD

zTexinfoBuilder.write)Ú	indexfiler_rLr%cCs t|g|ƒ|_tjt|ƒddd|jj|ƒ}||d<|rˆtdƒ}tj	ƒ}|tj
ddƒ7}||7}x|jtj
ƒD]}||7}qtW|}t||j||t|gƒ}||d<x*|D]"}	|jj|	ƒ}
|	|
d<|j|
ƒq¬Wtjdƒtjtdƒƒ|jj|||ƒx |jtjƒD]}|d	}	|d
}tj||ƒg}
x`|jD]V\}}|	j|ƒr2|
jtjtdƒtdƒƒƒ|
jtj||ƒƒ|
jtjddƒƒPq2W|j|
ƒqW|S)
Nú T)Únonlr-z<texinfo output>z<Set title in conf.py>rHzresolving references...Z
refdocnameZrefsectnamez (in ú))Úsetr&r>ÚinforrAZget_doctreerr	ÚsectionrXÚfindallr
ZtoctreerrBrZresolve_referencesZpending_xrefZemphasisr@Ú
startswithZTextrZreplace_self)r(r`r_rLÚtreeZnew_treeZnew_sectÚnodeZ	largetreer-ZappendixZpendingnodeÚsectnameZnewnodesÚsubdirrXr)r)r*rTxsF


zTexinfoBuilder.assemble_doctreecCs|jƒdS)N)Úcopy_support_files)r(r)r)r*Úfinish¢szTexinfoBuilder.finish)r\r%cCsÊ|jrÆt|jjƒj}x°t|jtdƒdt|jƒ|jj|dD]ˆ}|j|}y:t	j
|j|dƒ}t|ƒt
t	j
|j|ƒt	j
||ƒƒWq:tk
rÀ}z"tjtdƒt	j
|j|ƒ|ƒWYdd}~Xq:Xq:WdS)Nzcopying images... Zbrown)Ústringify_funcz-figureszcannot copy image file %r: %s)ZimagesrÚapprAZget_original_image_urirrrPÚ	verbosityrrQrRrrÚsrcdirÚ	Exceptionr>r?)r(r\roÚsrcÚdestZimagedirÚerrr)r)r*r[¥s

zTexinfoBuilder.copy_image_filescCsxy@ttdƒƒ*tjdddttjjtdƒ|j	ƒWdQRXWn2t
k
rr}ztjtdƒ|ƒWYdd}~XnXdS)Nzcopying Texinfo support filesz	Makefile T)rbÚMakefilezerror writing file Makefile: %s)rrr>rerÚosrrQÚtemplate_dirrRÚOSErrorr?)r(rvr)r)r*rmµs$z!TexinfoBuilder.copy_support_files)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚformatrÚepilogrxZsupported_image_typesr Zdefault_translator_classr+rÚstrrr,r0r3rErrZÚboolr	ÚdocumentrTrnr[rmr)r)r)r*r#s&
%*r#)r<r%cCs$t|jƒ}|j||j|j|ddfgS)z, Better default texinfo_documents settings. zOne line description of projectZ
Miscellaneous)rÚprojectZroot_docrW)r<Úfilenamer)r)r*Údefault_texinfo_documents¾s
r‡)rpr%cCs||jtƒ|jdtdƒ|jdgdƒ|jdidƒ|jdddtgƒ|jdddƒ|jdd	dƒ|jd
ddƒddddœS)
Nr=rSrYZtexinfo_domain_indicesTZtexinfo_show_urlsZfootnoteZtexinfo_no_detailmenuFZtexinfo_cross_referencesÚbuiltin)ÚversionZparallel_read_safeZparallel_write_safe)Zadd_builderr#Zadd_config_valuer‡r4)rpr)r)r*ÚsetupÅs
rŠ)>r~rxrÚtypingrrrrrrZdocutilsr	Zdocutils.frontendr
Zdocutils.iorZdocutils.nodesrZsphinxr
rZsphinx.applicationrZsphinx.buildersrZ
sphinx.configrZ!sphinx.environment.adapters.assetrZ
sphinx.errorsrZ
sphinx.localerrZsphinx.utilrrrZsphinx.util.consolerZsphinx.util.docutilsrZsphinx.util.fileutilrZsphinx.util.nodesrZsphinx.util.osutilrrrZsphinx.writers.texinfor r!Ú	getLoggerr{r>rQryr#r‚r‡rŠr)r)r)r*Ú<module>s6 
 &