
    c.                     H   d dl mZ d dlZd dlZd dlZ	 d dlZ	 d dlZ	 d dl	m
Z
 dZd dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ g dZddgZdZd Z G d dej2                        Zy# e$ r d dlZY Zw xY w# e$ r d dlm
Z
 dZY _w xY w# e$ rZ e ee            dZ[ww xY w)    )logN)apidocFT)application)setup_command)git)options)version)autodoc_tree_index_modulesautodoc_index_modulesautodoc_tree_excludesautodoc_exclude_modulesAUTODOC_TREE_INDEX_MODULESAUTODOC_INDEX_MODULESzi%(heading)s
%(underline)s

.. automodule:: %(module)s
  :members:
  :undoc-members:
  :show-inheritance:
c                 |    |D ]7  }|j                  d      s|dk7  sd| |j                  dd      d|d d <   9 y )Nz.pyz__init__.pyT/.)endswithreplace)argdirnamefilesfilenames       ./usr/lib/python3/dist-packages/pbr/builddoc.py_find_modulesr   I   sN     2U#M(A-1 7??34#CR=* +2    c                   F    e Zd ZdgZdZdZd ZddZd Zd Z	d	 Z
d
 Zd Zy)LocalBuildDochtmlbuild_sphinxFc                 d   | j                   j                  d      }| j                   j                  d      }|j                  dd      \  }}d|v r't        j                  j                  |d   d   |      }nd|z   }t        j                  j                  |      st        j                  |       |S )Nr    pbrapi_doc_dir)Napi
source_dir   zdoc/source/)distributionget_option_dictgetospathjoinexistsmakedirs)selfoption_dictpbr_option_dict_r#   r%   s         r   _get_source_dirzLocalBuildDoc._get_source_dirV   s    ''77G++;;EB(,,]MJ;;&k,&?&B&13J '4Jww~~j)KK
#r   Nc                    t        j                  dt        j                  j	                  t        j
                        z         i }| j                         }| j                  j                  D ]2  }d|vst        j                  |      D ]  \  }}}t        |||        4 fdt        fd|j                         D              }t        j                  j                  |d      }	t        |	d      5 }
|
j                  d       |D ]  }t        j                  j                  |d|z        }d	|z  }d
t!        |      z  }t#        |||      }t        j                  d|z         t        |d      5 }|j                  t$        |z         d d d        |
j                  d|z          	 d d d        y # 1 sw Y   )xY w# 1 sw Y   y xY w)Nz[pbr] Autodocumenting from %sr   c                 0     t         fdD               S )Nc              3   J   K   | ]  }t        j                   |        y wN)fnmatch).0patmodules     r   	<genexpr>zDLocalBuildDoc.generate_autoindex.<locals>.include.<locals>.<genexpr>n   s$      8" #??637 8s    #)any)r;   excluded_moduless   `r   includez1LocalBuildDoc.generate_autoindex.<locals>.includem   s"     8&68 8 8 8r   c              3   4   K   | ]  } |      s|  y wr7    )r9   modr?   s     r   r<   z3LocalBuildDoc.generate_autoindex.<locals>.<genexpr>q   s     KSgclSKs   zautoindex.rstwz.. toctree::
   :maxdepth: 1

z%s.rstzThe :mod:`%s` Module=)r;   heading	underlinez[pbr] Generating %sz
   %s.rst
)r   infor*   r+   abspathcurdirr3   r'   packageswalkr   sortedkeysr,   openwritelendict_rst_template)r/   r>   modulesr%   pkgdirpathdirnamesr   module_listautoindex_filename	autoindexr;   output_filenamerE   rF   valuesoutput_filer?   s    `               @r   generate_autoindexz LocalBuildDoc.generate_autoindexc   s   077??299-. 	/))+
$$-- 	;C#~02 ;,GXu!'7E:;	;
	8 KGLLNKKWW\\*oF$c* 	8iOO   & 8"$'',,z/7&/@#B069#g,.	VW(13 .*+ ,/3/ >;%%mf&<=> 678	8 	8> >	8 	8s%   6A?G5F6G6F?;GGc                     | j                         }ddd|dg}t        r|j                  dd       t        j                  || j
                  z          y )Nz-HModulesz-or   r   r   )r3   apidoc_use_paddinginsertr   mainr   )r/   r%   cmds      r   _sphinx_treezLocalBuildDoc._sphinx_tree   sH    ))+
Yj#6JJq(#C$4445r   c                    | j                   st        j                         }nt        j                  }i }| j
                  r| j
                  |d<   | j                  r| j                  |d<   | j                  r| j                  |d<   | j                  r| j                  |d<   | j                  rg d|d<   t        j                  | j                  | j                  | j                  | j                  | j                   ||| j"                  | j$                  	      }d| _	        	 |j'                  | j(                  	       | j>                  r_|j@                  jB                  |j                   jD                  z   }|j                   jG                  d      }tI        jJ                  ||       y y # t*        $ r}d
dlm} t1        ||j2                        r{t        j4                  j7                  d       t        j8                  j7                  |j:                  d
   j=                  dd             t        j8                  j7                  d       n Y d }~d }~ww xY w)Nprojectr	   releasetoday)zapp.add_directivezapp.add_rolezapp.add_generic_rolezapp.add_nodezimage.nonlocal_urisuppress_warnings)freshenvwarningiserrorT)	force_allr   )utilszreST markup error:
asciibackslashreplace
index)&verbose	cStringIOStringIOsysstdoutrf   r	   rg   rh   sphinx_initializedr   Sphinxr%   
config_dirbuilder_target_dirdoctree_dirbuilder	fresh_envwarning_is_errorbuild	all_files	Exceptiondocutilsrm   
isinstanceSystemMessagestderrO   stderrargsencode
link_indexconfig
master_doc
out_suffixget_outfilenamer*   symlink)r/   status_streamconfoverridesapperrrm   srcdsts           r   _sphinx_runzLocalBuildDoc._sphinx_run   s   ||%..0MJJM<<'+||M)$<<'+||M)$<<'+||M)$::%)ZZM'"""2M-.
   OOT__##T%5%5LL-^^D4I4I	K
 #'
	III/ ??**''#++*@*@@C++--g6CJJsC    	&#u223		 67

  !!3!3G4F"H I

  & '	s   F' '	I0BIIc           	         | j                   j                  d      }t        |j                               j	                  t
              }t        t        d t                    }|s|r4d}|r|dt        |      z  z  }|r|d|z  z  }t        j                  |       t        j                         r,t        j                  |       t        j                  |       t        j                   |dd      }t        j                   |d	d
      }t#        j$                  d      sQ|r| j'                          |r=| j)                  t        |j+                  dd dg      d   j-                                      | j/                          t0        j2                  j5                  t6        j8                        t1        j2                  dd      k\  }|st        j                  d       | j:                  dgk7  r(t        j                  d       |r| j:                  | _        |rt>        j@                  jC                  |       S | j:                  D ])  }|| _        | j/                          | jE                          + y )Nr"   c                 ,    t        j                  |       S r7   )r*   getenv)xs    r   <lambda>z#LocalBuildDoc.run.<locals>.<lambda>   s    1 r   zThe autodoc and autodoc_tree features are deprecated in 4.2 and will be removed in a future release. You should use the sphinxcontrib-apidoc Sphinx extension instead. Refer to the pbr documentation for more information.z Deprecated options: %sz% Deprecated environment variables: %s)r0   r
   r   r   r   SPHINX_DEBUGr    r&      zQ[pbr] Support for Sphinx < 1.6 will be dropped in pbr 4.0. Upgrade to Sphinx 1.6+r   a'  [pbr] Sphinx 1.6 added native support for specifying multiple builders in the '[sphinx_build] builder' configuration option, found in 'setup.cfg'. As a result, the '[sphinx_build] builders' option has been deprecated and will be removed in pbr 4.0. Migrate to the 'builder' configuration option.)#r'   r(   setrM   intersection_deprecated_optionslistfilter_deprecated_envsr   warnr   _git_is_installedwrite_git_changeloggenerate_authorsr   get_boolean_optionr*   r   rd   r]   r)   splitfinalize_optionsr	   SemanticVersionfrom_pip_stringsphinx__version__buildersr|   r   BuildDocrunr   )	r/   r0   	warn_optswarn_envmsg
tree_index
auto_indexis_multibuilder_sphinxr|   s	            r   r   zLocalBuildDoc.run   s!   ''77> ((*+889LM	57GHIJC 04	?BB>IIHHSM  "##<  [9//0L0LN
 //0G0GI
 yy( !!#''1r
$$%'',uw01
 	!(!8!8!H!H" #*#:#:1a#@"A &HH 7 8 ==VH$HH > ? &#}}! ))--d33 }} 	G"DL!!#	r   c                 R    t         j                  j                  |        dg| _        y )Nzsetup.py)r   r   initialize_optionsr   )r/   s    r   r   z LocalBuildDoc.initialize_options   s"    11$7 '1\"r   c                    ddl m} t        j                  j	                  |        | j
                  j                  d      }d|j                  dg g      d   v r|d   d   | _        t        | j                  t              s,| j                  r | j                  j                  d      | _        | j
                  j                         | _        | j
                  j                         | _        | j
                  j                         | _        d}| j
                  j                  d	      }||v r|j#                  ||   d         | _        t'        | d
      sd| _        y y )Nr   )utilr    zcommand liner|   r&   ,r   r"   r~   F)r"   r   r   r   r   r'   r(   r)   r   r   r   r   get_namerf   get_versionr	   rg   split_multiliner   hasattrr~   )r/   r   r0   opts       r   r   zLocalBuildDoc.finalize_options  s)    	//5 ''77G[__Y=a@@'	215DM$--.4== MM//4DM((113((446((446 &''77>+)-)=)=C #*%D& t/0$)D! 1r   r7   )__name__
__module____qualname__r   command_namerw   r3   r]   rd   r   r   r   r   rA   r   r   r   r   P   s;    xH!L!8F6*!XEN2*r   r   )	distutilsr   r8   r*   ru   rs   ImportErrorior   
sphinx.extr   r`   r   r   r   estrr"   r   r   r	   r   r   rR   r   r   r   rA   r   r   <module>r      s   "   	 
"%" #$   K 02IJ 2T*M** T*q    "!!"
   c!f
sJ   A' B	 A6 B	 '	A32A36BB	 BB	 	B!BB!