ó
öÀ„\c           @  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 e rñ d d l m Z m Z m Z m Z n  d e f d „  ƒ  YZ d S(   s?  
    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.
iÿÿÿÿ(   t   print_functionN(   t   Command(   t   DistutilsOptionErrort   DistutilsExecError(   t   StringIOt   string_types(   t   Sphinx(   t   handle_exception(   t   nocolort   color_terminal(   t   docutils_namespacet   patch_docutils(   t   abspath(   t   Anyt   Dictt   Listt   Tuplet   BuildDocc           B  sŒ   e  Z d  Z d Z d- d. d/ d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< g Z d d d d d% g Z d( „  Z d) „  Z d0 d* „ Z	 d+ „  Z
 d, „  Z RS(=   s7  
    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
    s   Build Sphinx documentations	   fresh-envt   Es   discard saved environments	   all-filest   as   build all filess   source-dir=t   ss   Source directorys
   build-dir=s   Build directorys   config-dir=t   cs'   Location of the configuration directorys   builder=t   bs]   The builder (or builders) to use. Can be a comma- or space-separated list. Defaults to "html"s   warning-is-errort   Ws   Turn warning into errorss   project=s   The documented project's names   version=s   The short X.Y versions   release=s.   The full version, including alpha/beta/rc tagss   today=sC   How to format the current date, used as the replacement for |today|s
   link-indext   is!   Link index.html to the master doct	   copyrights   The copyright stringt   pdbs   Start pdb on exceptiont   nitpickyt   ns1   nit-picky mode, warn about all missing referencesc         C  s™   t  |  _ |  _ t  |  _ d  |  _ |  _ d |  _ t  |  _ d |  _	 d |  _
 d |  _ d |  _ d  |  _ t  |  _ d |  _ d |  _ t  |  _ t  |  _ d  S(   Nt   htmlt    i    (   t   Falset	   fresh_envt	   all_filesR   t   Nonet
   source_dirt	   build_dirt   buildert   warning_is_errort   projectt   versiont   releaset   todayt
   config_dirt
   link_indexR   t	   verbosityt	   tracebackR   (   t   self(    (    s3   lib/python2.7/site-packages/sphinx/setup_command.pyt   initialize_options_   s    												c         C  sc   xY d D]Q } t  j j | ƒ s% q n  x0 t  j | ƒ D] \ } } } d | k r5 | Sq5 Wq Wt  j S(   Nt   doct   docss   conf.py(   R1   R2   (   t   ost   patht   isdirt   walkt   curdir(   R/   t   guesst   roott   dirnamest	   filenames(    (    s3   lib/python2.7/site-packages/sphinx/setup_command.pyt   _guess_source_dirq   s    c         C  s^   t  |  | ƒ } | d  k r/ t |  | | ƒ | St | t ƒ sZ t d | | | f ƒ ‚ n  | S(   Ns   '%s' must be a %s (got `%s`)(   t   getattrR"   t   setattrt
   isinstanceR   R   (   R/   t   optiont   whatt   defaultt   val(    (    s3   lib/python2.7/site-packages/sphinx/setup_command.pyt   _ensure_stringlike~   s    c         C  s  |  j  d ƒ |  j d  k rB |  j ƒ  |  _ |  j d |  j ƒ n  |  j d ƒ |  j d  k rm |  j |  _ n  |  j d  k r¯ |  j d ƒ } t	 j
 j t | j ƒ d ƒ |  _ n  t	 j
 j |  j d ƒ |  _ g  |  j D]$ } | t	 j
 j |  j | ƒ f ^ qÔ |  _ d  S(   NR%   s   Using source directory %sR#   t   buildt   sphinxt   doctrees(   t   ensure_string_listR#   R"   R<   t   announcet   ensure_dirnameR+   R$   t   get_finalized_commandR3   R4   t   joinR   t
   build_baset   doctree_dirR%   t   builder_target_dirs(   R/   RE   R%   (    (    s3   lib/python2.7/site-packages/sphinx/setup_command.pyt   finalize_options‰   s    $c   
      C  s#  t  ƒ  s t ƒ  n  |  j s( t ƒ  } n	 t j } i  } |  j rP |  j | d <n  |  j ri |  j | d <n  |  j r‚ |  j | d <n  |  j	 r› |  j	 | d <n  |  j
 r´ |  j
 | d <n  |  j rÍ |  j | d <n  xO|  j D]D\ } } d  } y§ |  j pû |  j } t | ƒ ƒ t ƒ  s t |  j |  j | |  j | | | d |  j d |  j ƒ} | j d	 |  j ƒ | j rƒt d
 | j j ƒ ‚ n  Wd  QXWd  QXWnA t k
 rÓ} t | |  | t j ƒ |  j sÔt  d ƒ ‚ qÔn X|  j! sãq× n  | j" j# | j j$ } | j j% d ƒ }	 t& j' | |	 ƒ q× Wd  S(   NR'   R(   R)   R*   R   R   t   freshenvt   warningiserrort	   force_alls   caused by %s builder.i   t   index((   R	   R   t   verboseR   t   syst   stdoutR'   R(   R)   R*   R   R   RO   R"   R+   R#   R   R
   R   RN   R    R&   RE   R!   t
   statuscodeR   R%   t   namet	   ExceptionR   t   stderrR   t
   SystemExitR,   t   configt
   master_doct
   out_suffixt   get_outfilenameR3   t   symlink(
   R/   t   status_streamt   confoverridesR%   t   builder_target_dirt   appt   confdirt   exct   srct   dst(    (    s3   lib/python2.7/site-packages/sphinx/setup_command.pyt   run    sT    	
								 
			&		(   s	   fresh-envR   s   discard saved environment(   s	   all-filesR   s   build all files(   s   source-dir=R   s   Source directoryN(   s
   build-dir=Ns   Build directory(   s   config-dir=R   s'   Location of the configuration directory(   s   builder=R   s]   The builder (or builders) to use. Can be a comma- or space-separated list. Defaults to "html"(   s   warning-is-errorR   s   Turn warning into errors(   s   project=Ns   The documented project's name(   s   version=Ns   The short X.Y version(   s   release=Ns.   The full version, including alpha/beta/rc tags(   s   today=NsC   How to format the current date, used as the replacement for |today|(   s
   link-indexR   s!   Link index.html to the master doc(   R   Ns   The copyright string(   R   Ns   Start pdb on exception(   R   R   s1   nit-picky mode, warn about all missing references(   t   __name__t
   __module__t   __doc__t   descriptionR"   t   user_optionst   boolean_optionsR0   R<   RD   RP   Rj   (    (    (    s3   lib/python2.7/site-packages/sphinx/setup_command.pyR   "   s0   $					(    Rm   t
   __future__R    R3   RV   t   distutils.cmdR   t   distutils.errorsR   R   t   sixR   R   t   sphinx.applicationR   t   sphinx.cmd.buildR   t   sphinx.util.consoleR   R	   t   sphinx.util.docutilsR
   R   t   sphinx.util.osutilR   R   t   typingR   R   R   R   R   (    (    (    s3   lib/python2.7/site-packages/sphinx/setup_command.pyt   <module>   s   %