ó
ØÆ÷Xc           @` sP  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l Z e j d  d k  rl d  d l m	 Z	 m
 Z
 n d  d l m	 Z	 m
 Z
 d d d d d	 d
 g Z e j d ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z i  Z d d „ Z e  d k rLd  d l Z d  d l! m" Z" d  d l# Z# e" ƒ  Z$ e$ j% d d d d d d  d! ƒe$ j% d" d d# d d d  d$ ƒe$ j% d% d d& d  d' ƒe$ j% d( d d) d d d  d* ƒe$ j% d+ d d, d  d- ƒe$ j% d. d d/ d d d  d- ƒe$ j% d0 d d1 d  d2 ƒe$ j& e j' ƒ \ Z( Z) e* e) ƒ d3 k  rže+ d4 ƒ ‚ n  e( j, röe# j# d5 ƒ Z- x= e- D]2 Z. e e. ƒ Z/ e0 d6 e/ j1 e/ j1 e/ j2 f ƒ q½Wn  e) d7 Z3 d  d l Z e j4 j5 d8 ƒ Z6 e6 r?e e3 d9 d: e6 g ƒ Z/ n e e3 d9 d: g ƒ Z/ e( j7 rie( j7 Z7 n d; Z7 e( j8 rÐe j9 d< e( j8 ƒ Z: e: s¢e+ d= ƒ ‚ n e: j; d7 ƒ Z1 e: j; d3 ƒ Z< e< e/ j= e1 <n  e( j> rïe0 e/ j> e7 ƒ ƒ n  e( j? re0 e/ j? e7 ƒ ƒ n  e( j@ r'e0 e/ j@ ƒ n  e( jA rLe0 e/ j@ e( jA k ƒ qLn  d S(>   i    (   t   divisiont   absolute_importt   print_functionNi   (   t   RawConfigParsert   NoOptionErrort   FormatErrort   PkgNotFoundt   LibraryInfot   VariableSett   read_configt   parse_flagss   \$\{([a-zA-Z0-9_-]+)\}c           B` s    e  Z d  Z d „  Z d „  Z RS(   sQ   
    Exception thrown when there is a problem parsing a configuration file.

    c         C` s   | |  _  d  S(   N(   t   msg(   t   selfR   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   __init__   s    c         C` s   |  j  S(   N(   R   (   R   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   __str__   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR      s   	c           B` s    e  Z d  Z d „  Z d „  Z RS(   s3   Exception raised when a package can not be located.c         C` s   | |  _  d  S(   N(   R   (   R   R   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR      s    c         C` s   |  j  S(   N(   R   (   R   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR   !   s    (   R   R   R   R   R   (    (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR      s   	c         C` s5  i g  d 6g  d 6g  d 6g  d 6g  d 6} d |  j  d ƒ } xò | D]ê } d | } t | ƒ d	 k rC | j d
 ƒ r’ | d j | d j ƒ  ƒ q-| j d ƒ r¿ | d j | d j ƒ  ƒ q-| j d ƒ rì | d j | d j ƒ  ƒ q-| j d ƒ r| d j | d j ƒ  ƒ q-| d j | ƒ qC qC W| S(   s¶  
    Parse a line from a config file containing compile flags.

    Parameters
    ----------
    line : str
        A single line containing one or more compile flags.

    Returns
    -------
    d : dict
        Dictionary of parsed flags, split into relevant categories.
        These categories are the keys of `d`:

        * 'include_dirs'
        * 'library_dirs'
        * 'libraries'
        * 'macros'
        * 'ignored'

    t   include_dirst   library_dirst	   librariest   macrost   ignoredt    s    -t   -i    s   -Ii   s   -Ls   -ls   -D(   t   splitt   lent
   startswitht   appendt   strip(   t   linet   dt   flagst   flag(    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR
   $   s     
c         C` s   |  j  d d ƒ S(   Ns   \s   \\(   t   replace(   t   val(    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   _escape_backslashN   s    c           B` sD   e  Z d  Z d d „ Z d „  Z d d „ Z d d „ Z d „  Z RS(   s$  
    Object containing build information about a library.

    Parameters
    ----------
    name : str
        The library name.
    description : str
        Description of the library.
    version : str
        Version string.
    sections : dict
        The sections of the configuration file for the library. The keys are
        the section headers, the values the text under each header.
    vars : class instance
        A `VariableSet` instance, which contains ``(name, value)`` pairs for
        variables defined in the configuration file for the library.
    requires : sequence, optional
        The required libraries for the library to be installed.

    Notes
    -----
    All input parameters (except "sections" which is a method) are available as
    attributes of the same name.

    c         C` sL   | |  _  | |  _ | r$ | |  _ n	 g  |  _ | |  _ | |  _ | |  _ d  S(   N(   t   namet   descriptiont   requirest   versiont	   _sectionst   vars(   R   R%   R&   R(   t   sectionsR*   R'   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR   l   s    					c         C` s   t  |  j j ƒ  ƒ S(   sÚ   
        Return the section headers of the config file.

        Parameters
        ----------
        None

        Returns
        -------
        keys : list of str
            The list of section headers.

        (   t   listR)   t   keys(   R   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR+   w   s    t   defaultc         C` s'   |  j  j |  j | d ƒ } t | ƒ S(   Nt   cflags(   R*   t   interpolateR)   R$   (   R   t   sectionR#   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR/   ‡   s    c         C` s'   |  j  j |  j | d ƒ } t | ƒ S(   Nt   libs(   R*   R0   R)   R$   (   R   R1   R#   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR2   ‹   s    c         C` sq   d |  j  d |  j g } |  j r3 | j d ƒ n | j d d j |  j ƒ ƒ | j d |  j ƒ d j | ƒ S(   Ns   Name: %ss   Description: %ss	   Requires:s   Requires: %st   ,s   Version: %ss   
(   R%   R&   R'   R   t   joinR(   (   R   t   m(    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR      s    	N(	   R   R   R   t   NoneR   R+   R/   R2   R   (    (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR   Q   s   	c           B` sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s  
    Container object for the variables defined in a config file.

    `VariableSet` can be used as a plain dictionary, with the variable names
    as keys.

    Parameters
    ----------
    d : dict
        Dict of items in the "variables" section of the configuration file.

    c         C` sT   t  g  | j ƒ  D] \ } } | | f ^ q ƒ |  _ i  |  _ i  |  _ |  j ƒ  d  S(   N(   t   dictt   itemst	   _raw_datat   _ret   _re_subt   _init_parse(   R   R   t   kt   v(    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR   ¦   s    4		c         C` s4   x- |  j  j ƒ  D] \ } } |  j | | ƒ q Wd  S(   N(   R9   R8   t   _init_parse_var(   R   R=   R>   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR<   ®   s    c         C` s+   t  j d | ƒ |  j | <| |  j | <d  S(   Ns   \$\{%s\}(   t   ret   compileR:   R;   (   R   R%   t   value(    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR?   ²   s    c         ` sK   ‡  f d †  } x5 t  j | ƒ rF | | ƒ } | | k r= Pn  | } q W| S(   Nc         ` s>   x7 ˆ  j  j ƒ  D]& } ˆ  j  | j ˆ  j | |  ƒ }  q W|  S(   N(   R:   R-   t   subR;   (   RB   R=   (   R   (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   _interpolate¹   s    $(   t   _VARt   search(   R   RB   RD   t   nvalue(    (   R   s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR0   ¶   s    
c         C` s   t  |  j j ƒ  ƒ S(   sì   
        Return the list of variable names.

        Parameters
        ----------
        None

        Returns
        -------
        names : list of str
            The names of all variables in the `VariableSet` instance.

        (   R,   R9   R-   (   R   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt	   variablesÅ   s    c         C` s   |  j  | S(   N(   R9   (   R   R%   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   __getitem__Ö   s    c         C` s!   | |  j  | <|  j | | ƒ d  S(   N(   R9   R?   (   R   R%   RB   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   __setitem__Ù   s    (
   R   R   R   R   R<   R?   R0   RH   RI   RJ   (    (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR   ™   s   						c         C` s¤   |  j  d ƒ s t d ƒ ‚ n  i  } x' |  j d ƒ D] \ } } | | | <q4 Wx6 d d d g D]% } | | k r^ t d | ƒ ‚ q^ q^ Wd | k r  g  | d <n  | S(   Nt   metas   No meta section found !R%   R&   R(   s6   Option %s (section [meta]) is mandatory, but not foundR'   (   t   has_sectionR   R8   (   t   configR   R%   RB   R=   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt
   parse_metaÝ   s    c         C` sX   |  j  d ƒ s t d ƒ ‚ n  i  } x' |  j d ƒ D] \ } } | | | <q4 Wt | ƒ S(   NRH   s   No variables section found !(   RL   R   R8   R   (   RM   R   R%   RB   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   parse_variablesï   s    c         C` s
   t  t f S(   N(   t   meta_dt   r(   RM   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   parse_sectionsú   s    c         C` s   d |  S(   Ns   %s.ini(    (   t   pkg_name(    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   pkg_to_filenameý   s    c         C` sŽ  | r1 g  | D] } t  j j | |  ƒ ^ q } n	 |  g } t ƒ  } | j | ƒ } t | ƒ d k s} t d t | ƒ ƒ ‚ n  t | ƒ } i  } | j	 d ƒ rÑ x0 | j
 d ƒ D] \ } }	 t |	 ƒ | | <q® Wn  g  | j ƒ  D] }
 |
 d k rÞ |
 ^ qÞ } i  } i  } xs | D]k }
 i  } | j |
 d ƒ rF| j |
 d ƒ | |
 <n  x' | j
 |
 ƒ D] \ } }	 |	 | | <qVW| | |
 <qW| | | | f S(   Ni   s   Could not find file(s) %sRH   RK   R'   (   s   metas	   variables(   t   ost   pathR4   R   t   readR   R   t   strRN   RL   R8   R$   R+   t
   has_optiont   get(   t   filenamet   dirsR   t	   filenamesRM   t   nRK   R*   R%   RB   t   st   secsR+   R'   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   parse_config   s.    +		+c         ` sÞ   ‡  ‡ f d †  ‰  ˆ  |  ƒ \ } } } } d | k r§ d | k r§ | d } | t  j k rx t d | | d f ƒ ‚ n  t  j | } t t j j | j ƒ ƒ | d <n  t d | d d | d d | d d | d	 t	 | ƒ ƒ S(
   Nc         ` sÞ   t  |  ˆ ƒ \ } } } } x° | j ƒ  D]¢ \ } } ˆ  t | ƒ ƒ \ } } }	 }
 x3 | j ƒ  D]% \ } } | | k r_ | | | <q_ q_ Wx? |	 | j ƒ  D]- \ } } | r™ | | | c d | 7<q™ q™ Wq( W| | | | f S(   Ns    %s(   Ra   R8   RT   (   t   fRK   R*   R+   t   reqst   rnamet   rvaluet   nmetat   nvarst	   nsectionst   nreqsR=   R>   t   onamet   ovalue(   t   _read_configR\   (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyRl   %  s    #t   pkgdirt   pkgnames-   You should import %s to get information on %sR%   R&   R(   R+   R*   (
   t   syst   modulest
   ValueErrorR$   RU   RV   t   dirnamet   __file__R   R   (   R]   R\   RK   R*   R+   Rc   Rn   t   mod(    (   Rl   R\   s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   _read_config_imp$  s    
"c         C` sD   y t  |  SWn1 t k
 r? t t |  ƒ | ƒ } | t  |  <| SXd S(   s  
    Return library info for a package from its configuration file.

    Parameters
    ----------
    pkgname : str
        Name of the package (should match the name of the .ini file, without
        the extension, e.g. foo for the file foo.ini).
    dirs : sequence, optional
        If given, should be a sequence of directories - usually including
        the NumPy base directory - where to look for npy-pkg-config files.

    Returns
    -------
    pkginfo : class instance
        The `LibraryInfo` instance containing the build information.

    Raises
    ------
    PkgNotFound
        If the package is not found.

    See Also
    --------
    misc_util.get_info, misc_util.get_pkg_info

    Examples
    --------
    >>> npymath_info = np.distutils.npy_pkg_config.read_config('npymath')
    >>> type(npymath_info)
    <class 'numpy.distutils.npy_pkg_config.LibraryInfo'>
    >>> print(npymath_info)
    Name: npymath
    Description: Portable, core math library implementing C99 standard
    Requires:
    Version: 0.1  #random

    N(   t   _CACHEt   KeyErrorRu   RT   (   Rn   R\   R>   (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyR	   M  s    '
t   __main__(   t   OptionParsers   --cflagst   destR/   t   actiont
   store_truet   helps*   output all preprocessor and compiler flagss   --libsR2   s   output all linker flagss   --use-sectionR1   s/   use this section instead of default for optionss	   --versionR(   s   output versions   --atleast-versiont   min_versions   Minimal versions
   --list-allt   list_alls   --define-variablet   define_variables%   Replace variable with the given valuei   s(   Expect package name on the command line:s   *.inis
   %s	%s - %si   t   NPY_PKG_CONFIG_PATHs   numpy/core/lib/npy-pkg-configt   .R.   s   ([\S]+)=([\S]+)sH   --define-variable option should be of the form --define-variable=foo=bar(B   t
   __future__R    R   R   Ro   R@   RU   t   version_infot   ConfigParserR   R   t   configparsert   __all__RA   RE   t   IOErrorR   R   R
   R$   t   objectR   R   RN   RO   RR   RT   R6   Ra   Ru   Rv   R	   R   t   optparseRy   t   globt   parsert
   add_optiont
   parse_argst   argvt   optionst   argsR   Rq   R   t   filesRb   t   infot   printR%   R&   RS   t   environRZ   R   R1   R€   RF   R5   t   groupRB   R*   R/   R2   R(   R~   (    (    (    s=   /tmp/pip-build-X4mzal/numpy/numpy/distutils/npy_pkg_config.pyt   <module>   s”   	*	HD				$(3		'
						