B
    \                 @   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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 G dd deZdS )a?  
    sphinx.setup_command
    ~~~~~~~~~~~~~~~~~~~~

    Setuptools/distutils commands to assist the building of sphinx
    documentation.

    :author: Sebastian Wiesner
    :contact: basti.wiesner@gmx.net
    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    )print_functionN)Command)DistutilsOptionErrorDistutilsExecError)StringIOstring_types)Sphinx)handle_exception)nocolorcolor_terminal)docutils_namespacepatch_docutils)abspathc               @   sn   e Zd ZdZdZ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 Zdd Zd"ddZ	dd Z
d d! ZdS )#BuildDoca7  
    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 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)nitpickynz1nit-picky mode, warn about all missing referencesz	fresh-envz	all-fileszwarning-is-errorz
link-indexr   c             C   sj   d | _ | _d| _d  | _| _d| _d| _d| _d| _d| _	d| _
d | _d| _d| _d| _d| _d| _d S )NFZhtml r   )	fresh_env	all_filesr   
source_dir	build_dirbuilderwarning_is_errorprojectversionreleasetoday
config_dir
link_indexr   	verbosity	tracebackr   )self r+   3lib/python3.7/site-packages/sphinx/setup_command.pyinitialize_options_   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)docZdocszconf.py)ospathisdirwalkcurdir)r*   ZguessrootZdirnames	filenamesr+   r+   r,   _guess_source_dirq   s    
zBuildDoc._guess_source_dirNc             C   sB   t | |}|d kr"t| || |S t|ts>td|||f |S )Nz'%s' must be a %s (got `%s`))getattrsetattr
isinstancer   r   )r*   ZoptionZwhatdefaultvalr+   r+   r,   _ensure_stringlike~   s    

zBuildDoc._ensure_stringlikec                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 r+   )r/   r0   joinr   ).0r    )r*   r+   r,   
<listcomp>   s   z-BuildDoc.finalize_options.<locals>.<listcomp>)Zensure_string_listr   r6   ZannounceZensure_dirnamer&   r   Zget_finalized_commandr/   r0   r>   r   Z
build_basedoctree_dirr    builder_target_dirs)r*   r=   r+   )r*   r,   finalize_options   s    







zBuildDoc.finalize_optionsc       
      C   s  t  st  | jst }ntj}i }| jr4| j|d< | jrD| j|d< | jrT| j|d< | j	rd| j	|d< | j
rt| j
|d< | jr| j|d< x| jD ]\}}d }y| jp| j}t|b t P t| 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 nD tk
r` } z$t|| |tj | jsPtd
W d d }~X Y nX | j slq|j!j"|jj# }|j$d}	t%&||	 qW d S )Nr"   r#   r$   r%   r   r   )ZfreshenvZwarningiserror)Z	force_allzcaused by %s builder.   index)'r   r
   verboser   sysstdoutr"   r#   r$   r%   r   r   rB   r&   r   r   r   r   rA   r   r!   r=   r   Z
statuscoder   r    name	Exceptionr	   stderrr   
SystemExitr'   ZconfigZ
master_docZ
out_suffixZget_outfilenamer/   symlink)
r*   Zstatus_streamZconfoverridesr    Zbuilder_target_dirZappZconfdirexcsrcdstr+   r+   r,   run   sR    







&zBuildDoc.run)N)__name__
__module____qualname____doc__ZdescriptionZuser_optionsZboolean_optionsr-   r6   r<   rC   rQ   r+   r+   r+   r,   r   "   s0   $
r   )rU   Z
__future__r   r/   rG   Zdistutils.cmdr   Zdistutils.errorsr   r   Zsixr   r   Zsphinx.applicationr   Zsphinx.cmd.buildr	   Zsphinx.util.consoler
   r   Zsphinx.util.docutilsr   r   Zsphinx.util.osutilr   r   r+   r+   r+   r,   <module>   s   