ó
X¾÷Xc           @   s"  d  d l  m Z d  d l Z d  d l Z d  d l Z y d  d l Z Wn e k
 rc d  d l Z n Xy4 d  d l m	 Z	 d  d l m
 Z
 d  d l m Z Wn% e k
 r¿ Z e e e ƒ ƒ ‚ n Xd  d l m Z d  d l m Z d Z d	 „  Z d
 e j f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   logN(   t   apidoc(   t   application(   t   setup_command(   t   git(   t   optionssi   %(heading)s
%(underline)s

.. automodule:: %(module)s
  :members:
  :undoc-members:
  :show-inheritance:
c         C   sW   xP | D]H } | j  d ƒ r | d k r t |  d | j d d ƒ | d  f <q q Wd  S(   Ns   .pys   __init__.pys   %s.%st   /t   .iýÿÿÿ(   t   endswitht   Truet   replace(   t   argt   dirnamet   filest   filename(    (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyt   _find_modules9   s    t   LocalBuildDocc           B   sb   e  Z d  d g Z d Z e Z d „  Z d
 d „ Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z RS(   t   htmlt   mant   build_sphinxc         C   sj   |  j  j d ƒ } d | k r> t j j | d d d ƒ } n d } t j j | ƒ sf t j | ƒ n  | S(   NR   t
   source_diri   t   apis   doc/source/api(   t   distributiont   get_option_dictt   ost   patht   joint   existst   makedirs(   t   selft   option_dictR   (    (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyt   _get_source_dirF   s     c            s¤  t  j d t j j t j ƒ ƒ i  } |  j ƒ  } xV |  j j D]H } d | k r? x3 t j	 | ƒ D] \ } } } t
 | | | ƒ qa Wq? q? W‡  f d †  ‰ t ‡ f d †  | j ƒ  Dƒ ƒ } t j j | d ƒ }	 t |	 d ƒ ¾ }
 |
 j d ƒ x§ | D]Ÿ } t j j | d | ƒ } d	 | } d
 t | ƒ } t d | d | d | ƒ } t  j d | ƒ t | d ƒ  } | j t | ƒ Wd  QX|
 j d | ƒ q÷ WWd  QXd  S(   Ns   [pbr] Autodocumenting from %sR   c            s   t  ‡  f d †  ˆ Dƒ ƒ S(   Nc         3   s!   |  ] } t  j  ˆ  | ƒ Vq d  S(   N(   t   fnmatch(   t   .0t   pat(   t   module(    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pys	   <genexpr>[   s   (   t   any(   R#   (   t   excluded_modules(   R#   s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyt   includeZ   s    c         3   s!   |  ] } ˆ  | ƒ r | Vq d  S(   N(    (   R!   t   mod(   R&   (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pys	   <genexpr>^   s    s   autoindex.rstt   ws   .. toctree::
   :maxdepth: 1

s   %s.rsts   The :mod:`%s` Modulet   =R#   t   headingt	   underlines   [pbr] Generating %ss
      %s.rst
(   R    t   infoR   R   t   abspatht   curdirR   R   t   packagest   walkR   t   sortedt   keysR   t   opent   writet   lent   dictt   _rst_template(   R   R%   t   modulesR   t   pkgt   dirpatht   dirnamesR   t   module_listt   autoindex_filenamet	   autoindexR#   t   output_filenameR*   R+   t   valuest   output_file(    (   R%   R&   s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyt   generate_autoindexP   s4    	"
		c         C   s<   |  j  ƒ  } d d d d d | g } t j | |  j ƒ d  S(   NR   R   s   -Ht   Moduless   -o(   R   R   t   maint   autodoc_tree_excludes(   R   R   t   cmd(    (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyt   _sphinx_trees   s    c   	      C   s  |  j  s t j ƒ  } n	 t j } i  } |  j r@ |  j | d <n  |  j rY |  j | d <n  |  j rr |  j | d <n  |  j r‹ |  j | d <n  |  j	 r­ d d d d g | d	 <n  t
 j |  j |  j |  j |  j |  j | | d
 |  j d |  j ƒ} | j } |  j d k r)t t | d d ƒ ƒ d k r)d  St |  _	 y | j d |  j ƒ Wn~ t k
 rÉ} d d l m } t | | j ƒ rÃt j j d ƒ t j  j | j! d j" d d ƒ ƒ t j  j d ƒ qÊ‚  n X|  j# r| j j$ | j j% } | j j& d ƒ } t' j( | | ƒ n  d  S(   Nt   projectt   versiont   releaset   todays   app.add_directives   app.add_roles   app.add_generic_roles   app.add_nodet   suppress_warningst   freshenvt   warningiserrorR   t	   man_pagest    i    t	   force_alliÿÿÿÿ(   t   utilss   reST markup error:
t   asciit   backslashreplaces   
t   index()   t   verboset	   cStringIOt   StringIOt   syst   stdoutRH   RI   RJ   RK   t   sphinx_initializedR   t   SphinxR   t
   config_dirt   builder_target_dirt   doctree_dirt   buildert	   fresh_envt   warning_is_errort   configR5   t   getattrR	   t   buildt	   all_filest	   Exceptiont   docutilsRR   t
   isinstancet   SystemMessaget   stderR4   t   stderrt   argst   encodet
   link_indext
   master_doct
   out_suffixt   get_outfilenameR   t   symlink(	   R   t   status_streamt   confoverridest   appt   sphinx_configt   errRR   t   srct   dst(    (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyt   _sphinx_runx   sN    									
	c         C   sý   |  j  j d ƒ } t j ƒ  rA t j d | ƒ t j d | ƒ n  t j | d d ƒ } t j | d d ƒ } t j	 d ƒ sÈ | r |  j
 ƒ  n  | rÈ |  j t | j d d  d	 g ƒ d
 j ƒ  ƒ ƒ qÈ n  x. |  j D]# } | |  _ |  j ƒ  |  j ƒ  qÒ Wd  S(   Nt   pbrR   t   autodoc_tree_index_modulest   AUTODOC_TREE_INDEX_MODULESt   autodoc_index_modulest   AUTODOC_INDEX_MODULESt   SPHINX_DEBUGt   autodoc_exclude_modulesRP   i   (   R   R   R   t   _git_is_installedt   write_git_changelogt   generate_authorsR   t   get_boolean_optionR   t   getenvRG   RB   t   sett   gett   Nonet   splitt   buildersR`   t   finalize_optionsR{   (   R   R   t
   tree_indext
   auto_indexR`   (    (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyt   run¦   s,    					#	
c         C   s    t  j j |  ƒ d g |  _ d  S(   Ns   setup.py(   R   t   BuildDoct   initialize_optionsRE   (   R   (    (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyR’   Á   s    c         C   s#  t  j j |  ƒ |  j j d ƒ } d | j d g  g ƒ d k rU | d d |  _ n  t |  j t ƒ r‰ |  j r‰ |  j j	 d ƒ |  _ n  |  j j
 ƒ  |  _ |  j j ƒ  |  _ |  j j ƒ  |  _ d } |  j j d ƒ } | | k r| | d |  _ |  j | ƒ n  t |  d	 ƒ st |  _ n  d  S(
   NR   s   command lineR`   i    i   t   ,RE   R|   Rb   (   R   R‘   R   R   R   R‰   RŒ   Ri   t   listR‹   t   get_nameRH   t   get_versionRI   RJ   RE   t   ensure_string_listt   hasattrt   FalseRb   (   R   R   t   opt(    (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyR   É   s     N(   t   __name__t
   __module__RŒ   t   command_nameR™   R[   R   RŠ   RB   RG   R{   R   R’   R   (    (    (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyR   @   s   	
#		.		t   LocalBuildLatexc           B   s   e  Z d  g Z d Z RS(   t   latext   build_sphinx_latex(   R›   Rœ   RŒ   R   (    (    (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyRž   æ   s   	(   t	   distutilsR    R    R   RY   RW   t   ImportErrort   iot   sphinxR   R   R   Rg   t   et   strR|   R   R   R7   R   R‘   R   Rž   (    (    (    s)   /tmp/pip-build-h1VYrz/pbr/pbr/builddoc.pyt   <module>   s&   
	¦