3

T'íc´ã@s dZddlZddlZddlmZddlmZddlmZddl	m
Z
mZddlm
Z
ddlmZdd	lmZmZdd
lmZmZddlmZGdd
„d
eƒZdS)z‚Setuptools/distutils commands to assist the building of sphinx documentation.

:author: Sebastian Wiesner <basti.wiesner@gmx.net>
éN)ÚCommand)ÚDistutilsExecError)ÚStringIO)ÚAnyÚDict)ÚSphinx)Úhandle_exception)Úcolor_terminalÚnocolor)Údocutils_namespaceÚpatch_docutils)Úabspathc@s€eZdZdZdZd8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHgZdddd d*gZd
d/œd0d1„Zed/œd2d3„Z	d
d/œd4d5„Z
d
d/œd6d7„Zd
S)IÚBuildDoca9
    Distutils command to build Sphinx documentation.

    The Sphinx build can then be triggered from distutils, and some Sphinx
    options can be set in ``setup.py`` or ``setup.cfg`` instead of Sphinx's
    own configuration file.

    For instance, from `setup.py`::

       # this is only necessary when not using setuptools/distribute
       from sphinx.setup_command import BuildDoc
       cmdclass = {'build_sphinx': BuildDoc}

       name = 'My project'
       version = '1.2'
       release = '1.2.0'
       setup(
           name=name,
           author='Bernard Montgomery',
           version=release,
           cmdclass=cmdclass,
           # these are optional and override conf.py settings
           command_options={
               'build_sphinx': {
                   'project': ('setup.py', name),
                   'version': ('setup.py', version),
                   'release': ('setup.py', release)}},
       )

    Or add this section in ``setup.cfg``::

       [build_sphinx]
       project = 'My project'
       version = 1.2
       release = 1.2.0
    zBuild Sphinx documentationú	fresh-envÚEúdiscard saved environmentú	all-filesÚaúbuild all filesúsource-dir=ÚsúSource directoryú
build-dir=NúBuild directoryúconfig-dir=Úcú'Location of the configuration directoryúbuilder=Úbú]The builder (or builders) to use. Can be a comma- or space-separated list. Defaults to "html"úwarning-is-errorÚWúTurn warning into errorsúproject=úThe documented project's nameúversion=úThe short X.Y versionúrelease=ú.The full version, including alpha/beta/rc tagsútoday=úCHow to format the current date, used as the replacement for |today|ú
link-indexÚiú!Link index.html to the master docÚ	copyrightúThe copyright stringÚpdbúStart pdb on exceptionÚ	verbosityÚvú$increase verbosity (can be repeated)ÚnitpickyÚnú1nit-picky mode, warn about all missing referencesú
keep-goingú)With -W, keep going when getting warnings)ÚreturncCsxd|_|_d|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_d|_
|jjd|_d|_d|_d|_dS)NFÚhtmlÚé)Ú	fresh_envÚ	all_filesr0Ú
source_dirÚ	build_dirÚbuilderÚwarning_is_errorÚprojectÚversionÚreleaseÚtodayÚ
config_dirÚ
link_indexr.ÚdistributionÚverboser2Ú	tracebackr5Ú
keep_going)Úself©rOú6/tmp/pip-build-gk9425m9/sphinx/sphinx/setup_command.pyÚinitialize_optionsSs"zBuildDoc.initialize_optionscCsHx@dD]8}tjj|ƒsqx$tj|ƒD]\}}}d|kr$|Sq$WqWtjS)NÚdocÚdocszconf.py)rRrS)ÚosÚpathÚisdirÚwalkÚcurdir)rNÚguessÚrootZ	_dirnamesÚ	filenamesrOrOrPÚ_guess_source_dirgs
zBuildDoc._guess_source_dircs ˆjdƒˆjdkr.ˆjƒˆ_ˆjdˆjƒˆjdƒˆjdkrJˆjˆ_ˆjdkrtˆjdƒ}tj	j
t|jƒdƒˆ_tj	j
ˆjdƒˆ_
‡fdd„ˆjDƒˆ_dS)	NrBzUsing source directory %sr@ÚbuildZsphinxZdoctreescs g|]}|tjjˆj|ƒf‘qSrO)rTrUÚjoinrA)Ú.0rB)rNrOrPú
<listcomp>ƒsz-BuildDoc.finalize_options.<locals>.<listcomp>)Úensure_string_listr@r\ÚannounceÚensure_dirnamerHrAÚget_finalized_commandrTrUr^r
Ú
build_baseÚdoctree_dirrBÚbuilder_target_dirs)rNr]rO)rNrPÚfinalize_optionsps







zBuildDoc.finalize_optionsc
"Cs¦tƒstƒ|jstƒ}ntj}i}|jr4|j|d<|jrD|j|d<|jrT|j|d<|j	rd|j	|d<|j
rt|j
|d<|jr„|j|d<x|jD]\}}d}yˆ|j
p¨|j}t|ƒjtƒXt|j|j
||j||||j|j|j|jd}|j|jd|jrtd	|jjƒ‚WdQRXWdQRXWnFtk
rj}z(t|||tjƒ|j sZt!d
ƒ|‚WYdd}~XnX|j"svqŽ|j#j$|jj%}|jj&dƒ}	t'j(||	ƒqŽWdS)NrDrErFrGr.r5)ZfreshenvZwarningiserrorr2rM)Z	force_allzcaused by %s builder.r=Úindex))r	r
rKrÚsysÚstdoutrDrErFrGr.r5rgrHr@rrrrfr>rCr2rMr]r?Z
statuscoderrBÚnameÚ	ExceptionrÚstderrr0Ú
SystemExitrIÚconfigZroot_docZ
out_suffixZget_outfilenamerTÚsymlink)
rNZ
status_streamZ
confoverridesrBZbuilder_target_dirZappZconfdirÚexcÚsrcÚdstrOrOrPÚrun†sT






&zBuildDoc.run)rrr)rrr)rrr)rNr)rrr)rrr)r r!r")r#Nr$)r%Nr&)r'Nr()r)Nr*)r+r,r-)r.Nr/)r0Nr1)r2r3r4)r5r6r7)r8Nr9)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdescriptionÚuser_optionsÚboolean_optionsrQÚstrr\rhrurOrOrOrPrs2$	r)ryrTrjÚ
distutils.cmdrZdistutils.errorsrÚiorÚtypingrrZsphinx.applicationrZsphinx.cmd.buildrZsphinx.util.consoler	r
Zsphinx.util.docutilsrrZsphinx.util.osutilr
rrOrOrOrPÚ<module>s