B
    d                 @   s   d Z ddlZddlZddlZddlmZ ddlmZ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mZ dd
lmZ yddlmZ ddlmZ W n, ek
r   ddlmZ ddlmZ Y nX G dd deZ dS )zSetuptools/distutils commands to assist the building of sphinx documentation.

:author: Sebastian Wiesner <basti.wiesner@gmx.net>
    N)StringIO)AnyDictOptional)Sphinx)handle_exception)RemovedInSphinx70Warning)color_terminalnocolor)docutils_namespacepatch_docutils)abspath)Command)	ExecError)DistutilsExecErrorc               @   s   e Zd ZdZdZddddddd	d
dddddddddgZdddddgZddddZedddZ	dddd Z
ddd!d"ZdS )#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
    zBuild Sphinx documentation)z	fresh-envEzdiscard saved environment)z	all-filesazbuild all files)zsource-dir=szSource directory)z
build-dir=NzBuild directory)zconfig-dir=cz'Location of the configuration directory)zbuilder=bz]The builder (or builders) to use. Can be a comma- or space-separated list. Defaults to "html")zwarning-is-errorWzTurn warning into errors)zproject=NzThe documented project's name)zversion=NzThe short X.Y version)zrelease=Nz.The full version, including alpha/beta/rc tags)ztoday=NzCHow to format the current date, used as the replacement for |today|)z
link-indexiz!Link index.html to the master doc)	copyrightNzThe copyright string)pdbNzStart pdb on exception)	verbosityvz$increase verbosity (can be repeated))nitpickynz1nit-picky mode, warn about all missing references)z
keep-goingNz)With -W, keep going when getting warningsz	fresh-envz	all-fileszwarning-is-errorz
link-indexr   N)returnc             C   sx   d | _ | _d| _d | _d | _d| _d| _d| _d| _d| _	d| _
d | _d| _d| _| jjd | _d| _d| _d| _d S )NFhtml    )	fresh_env	all_filesr   
source_dir	build_dirbuilderwarning_is_errorprojectversionreleasetoday
config_dir
link_indexr   distributionverboser   	tracebackr   
keep_going)self r4   a/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sphinx/setup_command.pyinitialize_optionsZ   s"    zBuildDoc.initialize_optionsc             C   sH   x@dD ]8}t j|sqx$t |D ]\}}}d|kr$|S q$W qW t jS )N)docdocszconf.py)ospathisdirwalkcurdir)r3   guessrootZ	_dirnames	filenamesr4   r4   r5   _guess_source_dirn   s    
zBuildDoc._guess_source_dirc                s     d  jd kr.   _ d j   d  jd krJ j _ jd krt d}tj	
t|jd _tj	
 jd _ fdd jD  _d S )	Nr'   zUsing source directory %sr%   buildZsphinxZdoctreesc                s    g | ]}|t j j|fqS r4   )r9   r:   joinr&   ).0r'   )r3   r4   r5   
<listcomp>   s   z-BuildDoc.finalize_options.<locals>.<listcomp>)ensure_string_listr%   rA   announceensure_dirnamer-   r&   get_finalized_commandr9   r:   rC   r   
build_basedoctree_dirr'   builder_target_dirs)r3   rB   r4   )r3   r5   finalize_optionsw   s    







zBuildDoc.finalize_optionsc       
      C   s  t jdtdd t st  | js*t }ntj}i }| j	rD| j	|d< | j
rT| j
|d< | jrd| j|d< | jrt| j|d< | jr| j|d< | jr| j|d	< x| jD ]\}}d }y| jp| j}t|j t X t| j| j|| j|||| j| j| j| jd
}|j| jd |jrtd|jj W d Q R X W d Q R X W nF t k
rz } z&t!|| |tj" | j#sjt$d|W d d }~X Y nX | j%sq|j&j'|jj( }|j)d}	t*+||	 qW d S )Nz$setup.py build_sphinx is deprecated.   )
stacklevelr)   r*   r+   r,   r   r   )ZfreshenvZwarningiserrorr   r2   )Z	force_allzcaused by %s builder.r"   index),warningswarnr   r	   r
   r0   r   sysstdoutr)   r*   r+   r,   r   r   rL   r-   r%   r   r   r   rK   r#   r(   r   r2   rB   r$   Z
statuscoder   r'   name	Exceptionr   stderrr   
SystemExitr.   configZroot_docZ
out_suffixZget_outfilenamer9   symlink)
r3   Zstatus_streamZconfoverridesr'   Zbuilder_target_dirZappZconfdirexcsrcdstr4   r4   r5   run   sV    







(zBuildDoc.run)__name__
__module____qualname____doc__descriptionuser_optionsboolean_optionsr6   strrA   rM   r^   r4   r4   r4   r5   r      s2   $	r   )!rb   r9   rS   rQ   ior   typingr   r   r   Zsphinx.applicationr   Zsphinx.cmd.buildr   Zsphinx.deprecationr   Zsphinx.util.consoler	   r
   Zsphinx.util.docutilsr   r   Zsphinx.util.osutilr   
setuptoolsr   Zsetuptools.errorsr   ImportErrordistutils.cmddistutils.errorsr   r   r4   r4   r4   r5   <module>   s$   