
XXc           @   s  d  Z  y d d l Z Wn e k
 r) n Xd 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 d l
 Z d d l 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 y d d l Z Wn e k
 rd d l Z n Xd d	 l m Z d d l Z e j d
  Z i dK d 6dL d 6dM d 6dN d 6dO d 6dP d 6dQ d 6dR d 6dS d 6dT d 6dU d 6dV d 6dW d 6dX d 6dY d 6dZ d! 6d[ d# 6d\ d% 6d] d( 6d^ d) 6d_ d* 6d` d+ 6da d, 6db d- 6dc d/ 6dd d2 6de d4 6df d5 6dg d6 6dh d7 6di d8 6Z dj Z dk Z dl Z d9   Z  d: dm d;  Z! dn d<  Z" d=   Z# d>   Z$ d?   Z% d@   Z& dA   Z' dB   Z( dC   Z) dD   Z* dE   Z+ dF   Z, dG e	 f dH     YZ- dI e. f dJ     YZ/ d S(o   s  The code in this module is mostly copy/pasted out of the distutils2 source
code, as recommended by Tarek Ziade.  As such, it may be subject to some change
as distutils2 development continues, and will have to be kept up to date.

I didn't want to use it directly from distutils2 itself, since I do not want it
to be an installation dependency for our packages yet--it is still too unstable
(the latest version on PyPI doesn't even install).
iN(   t   defaultdict(   t   log(   t   errors(   t   manifest_maker(   t   dist(   t	   extension(   t   extra_filess   \s*(.*?)\s*\((.*)\)\s*$t   metadatat   namet   versiont   authort   author_emailt
   maintainert   maintainer_emailt	   home_paget   urlt   summaryt   descriptiont   keywordst   long_descriptiont   download_urlt
   classifiert   classifierst   platformt	   platformst   licenset   requires_distt   install_requirest   setup_requires_distt   setup_requirest   provides_distt   providest   obsoletes_distt	   obsoletest   filest   packages_roott   package_dirt   packagest   package_datat   namespace_packagest
   data_filest   scriptst   modulest
   py_modulest   globalt   commandst   cmdclasst   backwards_compatt   use_2to3t   zip_safet   tests_requiret   dependency_linkst   include_package_datac         C   s   |  j  d  } t |  d } | |  } | d } x} | d k r y# t d j |  d | g } PWq6 t k
 r | d k r   n  | d 8} | |  } | | } d } q6 Xq6 WxE | | D]9 } y t | |  } Wq t k
 r t |    q Xq W| S(   s   Resolve a name like ``module.object`` to an object and return it.

    Raise ImportError if the module or name is not found.
    t   .i   ii    t   fromlistt    (   t   splitt   lent
   __import__t   joint   ImportErrort   getattrt   AttributeError(   R   t   partst   cursort   module_namet	   attr_namet   rett   part(    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyt   resolve_name   s*    




s	   setup.cfgc         C   s  t  j d k r t j   } n t j   } t j j |   s^ t j	 d t j j
 |     n  | j |   i  } x[ | j   D]M } t   | | <x7 | j |  D]& \ } } | | | | j d d  <q Wq~ Wt | d d  } t | d d	  } | r!t j j
 |  } t  j j d
 |  n  z| rg  t |  D] }	 |	 d k r7|	 ^ q7} x | D] }	 t |	  }
 y |
 |  Wq\t k
 rt j d  q\t  j   d } t j d |	 | f  t j t j    t  j d  q\Xq\Wn  t j j |  t | |  } t | d <t  | d <t! |  t" |  } | rM| | d <n  t# |  } | rl| | d <n  t$ |  t | d d  } | rt% j& t |   n  Wd | rt  j j' d
  n  X| S(   s  Distutils2 to distutils1 compatibility util.

    This method uses an existing setup.cfg to generate a dictionary of
    keywords that can be used by distutils.core.setup(kwargs**).

    :param file:
        The setup.cfg path.
    :parm script_args:
        List of commands setup.py was called with.
    :raises DistutilsFileError:
        When the setup.cfg file is not found.
    i   i   s   file '%s' does not existt   -t   _R,   t   setup_hooksR"   R#   i    s   pbr.hooks.setup_hooks)   setup hook %s terminated the installationi   s#   setup hook %s raised exception: %s
R4   R1   t   ext_modulest   entry_pointsR   N(   i   i   ((   t   syst   version_infot   configparsert   ConfigParsert   SafeConfigParsert   ost   patht   existsR   t   DistutilsFileErrort   abspatht   readt   sectionst   dictt   itemst   replacet   has_get_optiont   insertt   split_multilineRE   t
   SystemExitR   t   errort   exc_infot	   tracebackt
   format_exct   exitt   pbrt   hookst
   setup_hookt   setup_cfg_to_setup_kwargst   Truet   Falset   register_custom_compilerst   get_extension_modulest   get_entry_pointst   wrap_commandsR   t   set_extra_filest   pop(   RQ   t   script_argst   parsert   configt   sectiont   kt   valueRH   R$   t   hookt   hook_fnt   et   kwargsRI   RJ   t   files_extra_files(    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyt   cfg_to_args   sf    	"	



c   $      C   si  i  } i  } xt  D]} t t  |  d k rB t  | \ } } n- t t  |  d k ro t  | d } | } n  t |  | |  } | s| d k r t |  | d  } | rt |  } d } xF | D]> }	 t |	  }
 z | |
 j   j   d 7} Wd |
 j   Xq W| } qqq n  | t k r3t	 |  } n  | t
 k rNt |  } n0 | t k r~| j   d! k rut } q~t } n  | r| d" k rg  | D] } t j d |  ^ q} n  | d k r=g  } d } x] | D]U } t j | |  } | j d  j   } | j d  j   } | j | | f  qW| | d <q| d k rYi | d 6} q| d# k rmi  } t } d } x | D] } d | k r
| j d d  \ } } | j   | j   } } | | k r| | } | j | j    q?| j   } | | j   <n5 | r&t j d |   n | j | j   j    t } q~W| d k rd| j   } n  | } q| d k ri  } t j   } x6 | D]. } t |  } | |  } | | | j   <qW| } qn  | | | <q Wd |  k rd } |  d } x | D] } g  } t | |  } xW | D]O } t j | |  } | j d  j   }  | j d  } | j |  | f  q$W| | | <qWn  i  }! x | D] }" x | |" D] \ } } | rd |" | f }# d | k r$y  t j  d |  r|" }# n  Wqt! k
 rt" j# d    qXq$n |" }# |! j$ |# g   j |  qWqW|! j% d g   | d <|! | d  <| S($   sq   Processes the setup.cfg options and converts them to arguments accepted
    by setuptools' setup() function.
    i   i   i    R   t   description_fileR7   s   

Nt   truet   tt   1t   yest   yR   R2   s   \1\2s6   (?P<package>[^;]*);?(?P<env_marker>[^#]*?)(?:\s*#.*)?$t   packaget
   env_markerR$   R&   R(   t   =s1   malformed package_data first line %r (misses "=")R.   t   extrass6   (?P<package>[^:]*):?(?P<env_marker>[^#]*?)(?:\s*#.*)?$s   %s:(%s)t   bdist_wheels   (%s)s   Marker evaluation failed, see the following error.  For more information see: http://docs.openstack.org/developer/pbr/compatibility.html#evaluate-markert   extras_require(   s   trueR}   R~   s   yesR   (   s   install_requiresR2   (   s   package_datas
   data_files(&   t   D1_D2_SETUP_ARGSR9   RZ   R\   t   openRU   t   stript   closet
   CSV_FIELDSt	   split_csvt   MULTI_FIELDSt   BOOL_FIELDSt   lowerRg   Rh   t   _VERSION_SPEC_REt   subt   ret   matcht   groupt   appendt   NoneR8   t   extendR   t   DistutilsOptionErrorRX   t   st_distt   DistributionRE   t   get_command_namet   pkg_resourcest   evaluate_markert   SyntaxErrorR   R^   t
   setdefaultRn   ($   Rq   Ro   Rx   t   all_requirementst   argRr   t   optiont   in_cfg_valueRt   t   filenameR{   t   predR   t   requirement_patternt   requirementt   mt   requirement_packageR   R(   t	   firstlinet   prevt   linet   keyR.   R   t   cls_namet   clst   cmdR   t   extrat   extra_requirementst   requirementst   extras_valueR   t	   req_groupt
   extras_key(    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyRf     s    					%

	

!
c         C   s   t  |  d d  } | r t |  } x | D] } t |  } t | d  rX | j } n	 | j } t | d  r| | j } n
 d | } | j } t j	 j
 } | | j | f | | <t j | t j d | <q+ Wn  d S(   s   Handle custom compilers; this has no real equivalent in distutils, where
    additional compilers could only be added programmatically, so we have to
    hack it in somehow.
    R,   t	   compilersR   R   s   custom compiler %ss
   distutils.N(   RZ   R\   RE   t   hasattrR   t   __name__R   t
   __module__t	   distutilst	   ccompilert   compiler_classRK   R*   (   Rq   R   t   compilerR   t   descRA   t   cc(    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyRi     s    	
	c         C   s  d } g  } x|  D]} d | k r: | j  d d  } n | j  d d  } g  | D] } | j   ^ qS } t |  d k r | d d k r i  } x | D] } t |  | |  } | s q n  t |  } | d k r`g  }	 xx | D]p }
 |
 j  d d  }
 t |
  d k r&|
 d j   d f }
 n  |
 d j   |
 d j   f }
 |	 j |
  q W|	 } n  | | | <q W| rd | k r| d | d <n  | j t j | j	 d  |   qq q W| S(   s   Handle extension modulest   sourcest   include_dirst   define_macrost   undef_macrost   library_dirst	   librariest   runtime_library_dirst   extra_objectst   extra_compile_argst   extra_link_argst   export_symbolst	   swig_optst   dependst   :i   R   i   i    R   R   (   s   sourcess   include_dirss   define_macross   undef_macross   library_dirss	   librariess   runtime_library_dirss   extra_objectss   extra_compile_argss   extra_link_argss   export_symbolss	   swig_optss   dependsN(
   R8   R   R9   RZ   R\   R   R   R   t	   ExtensionRn   (   Rq   t   EXTENSION_FIELDSRI   Rr   t   labelst   lt   ext_argst   fieldRt   t   macrost   macro(    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyRj     sT                " 	c         C   s.   d |  k r i  St  d   |  d j   D  S(   s  Process the [entry_points] section of setup.cfg to handle setuptools
    entry points.  This is, of course, not a standard feature of
    distutils2/packaging, but as there is not currently a standard alternative
    in packaging, we provide support for them.
    RJ   c         s   s'   |  ] \ } } | t  |  f Vq d  S(   N(   R\   (   t   .0R   Rt   (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pys	   <genexpr>'  s   (   RW   RX   (   Rq   (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyRk     s    	c         C   s  t  j   } | j   xi t j d  D]X } | j | j k r& t | d  r\ | j   } n | j	 t
  } | | j | j <q& q& Wx| j   D]\ } } i  } x | j |  j   D]k \ } } | d } | j d  s | j d  r | j d d  \ }	 }
 | j |	 i   } | | |
 <q q W| s2q n  d |  k r_| |  d k r_|  d | } n | j |  } t | | |  } | |  j d i   | <q Wd  S(   Ns   distutils.commandst   resolvei   s	   pre_hook.s
   post_hook.R5   R.   (   R   R   t   parse_config_filesR   t   iter_entry_pointsR   R.   R   R   t   loadRh   t   get_command_listt   get_option_dictRX   t
   startswithR8   R   t   get_command_classt   wrap_command(   Rx   R   t   epR.   R   RG   Rd   t   optt   valt	   hook_typet   aliast	   hook_dictt   new_cmdclass(    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyRl   +  s.    
"
c         C   sP   | d  } t  |  | t f i | d 6t d 6| j d  d 6| j d  d 6 S(   Nc         S   s+   |  j  d  | j |   |  j  d  d  S(   Nt   pre_hookt	   post_hook(   t   run_command_hookst   run(   t   selfR.   (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyR   X  s    R   R   R   R   (   t   typet   objectR   t   get(   R   R.   Rd   R   (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyR   W  s
    c         C   sa  | d k r t  d |   n  t |  | d  } | d k rA d Sx| j   D]} t | t  r y t |  } Wq t k
 r t j	   d } t
 j d | | f   q Xn | } t | d  s t
 j d |   n  t j d	 | | |  j    y | |   WqN t j	   d } t j d
 | | f  t j t j    t j d  qN XqN Wd S(   s   Run hooks registered for that command and phase.

    *cmd_obj* is a finalized command object; *hook_kind* is either
    'pre_hook' or 'post_hook'.
    R   R   s   invalid hook kind: %rNi   s   cannot find hook %s: %st   __call__s   hook %r is not callables   running %s %s for command %ss   hook %s raised exception: %s
(   s   pre_hooks	   post_hook(   t
   ValueErrorR=   R   t   valuest
   isinstancet   strRE   R<   RK   R_   R   t   DistutilsModuleErrorR   R   R   t   infoR   R^   R`   Ra   Rb   (   t   cmd_objt	   hook_kindRd   Ru   t   hook_objt   errRw   (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyR   c  s2    		c         C   s0   | |  k r( | |  | k r( |  | | St  Sd  S(   N(   Rh   (   Rq   Rr   R   (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyRZ     s    c         C   s6   g  d   |  j  d  D D] } | r | ^ q }  |  S(   s3   Special behaviour when we have a multi line optionsc         s   s   |  ] } | j    Vq d  S(   N(   R   (   R   R   (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pys	   <genexpr>  s    s   
(   R8   (   Rt   t   element(    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyR\     s    c         C   s6   g  d   |  j  d  D D] } | r | ^ q }  |  S(   s8   Special behaviour when we have a comma separated optionsc         s   s   |  ] } | j    Vq d  S(   N(   R   (   R   t   chunk(    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pys	   <genexpr>  s    t   ,(   R8   (   Rt   R   (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyR     s    c            s     f d   } | S(   s[   A function decorator to monkey-patch a method of the same name on the
    given class.
    c            sU   t    |  j d   } | rQ t | d  rQ t |  d |  t   |  j |   n  |  S(   Nt   _orig(   R=   R   R   R   t   setattr(   t   funct   orig(   R   (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyt   wrapper  s
    (    (   R   R  (    (   R   s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyt   monkeypatch_method  s    t   DefaultGetDictc           B   s   e  Z d  Z d d  Z RS(   sX   Like defaultdict, but the get() method also sets and returns the default
    value.
    c         C   s4   | d  k r |  j   } n  t t |   j | |  S(   N(   R   t   default_factoryt   superR  R   (   R   R   t   default(    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyR     s    N(   R   R   t   __doc__R   R   (    (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyR    s   t
   IgnoreDictc           B   s    e  Z d  Z d   Z d   Z RS(   s   A dictionary that ignores any insertions in which the key is a string
    matching any string in `ignore`.  The ignore list can also contain wildcard
    patterns using '*'.
    c         C   sB   t  j d d j g  | D] } | j d d  ^ q   |  _ d  S(   Ns   (%s)t   |t   *s   .*(   R   t   compileR;   RY   t   _IgnoreDict__ignore(   R   t   ignoret   pat(    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyt   __init__  s    c         C   s3   |  j  j |  r d  St t |   j | |  d  S(   N(   R  R   R  R	  t   __setitem__(   R   R   R   (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyR    s    (   R   R   R  R  R  (    (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyR	    s   	(   s   metadata(   s   metadata(   s   metadata(   s   metadata(   s   metadata(   s   metadata(   s   metadataR   (   s   metadatas   summary(   s   metadata(   s   metadatas   description(   s   metadata(   s   metadatas
   classifier(   s   metadatas   platform(   s   metadata(   s   metadataR   (   s   metadataR   (   s   metadataR   (   s   metadataR    (   s   filess   packages_root(   s   files(   s   files(   s   files(   s   files(   s   files(   s   filess   modules(   s   globals   commands(   R/   R0   (   R/   s   zip_safe(   R/   s   tests_require(   R/   (   R/   (   s   classifierss	   platformss   install_requiress   providess	   obsoletesR'   s   packagess   package_datas
   data_filess   scriptss
   py_moduless   dependency_linksR   s   tests_requires   cmdclass(   R0   s   zip_safes   include_package_data(   s   keywords(    (    (0   R  t   multiprocessingR<   t   loggingRP   R   RK   R`   t   collectionsR    t   distutils.ccompilerR   R   R   R   t   setuptools.command.egg_infoR   t
   setuptoolsR   R   R   RN   RM   Rc   R   t	   pbr.hooksR  R   R   R   R   R   RE   Rz   Rf   Ri   Rj   Rk   Rl   R   R   RZ   R\   R   R  R  RW   R	  (    (    (    s%   /tmp/pip-build-h1VYrz/pbr/pbr/util.pyt   <module>5   s   
              	 \	"	5		,		)						