σ
’αSc           @` sb  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z e j d  d k  rx d  d l	 m
 Z
 m Z n d  d l m	 Z	 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 r^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 d0 d d  d! d. e% j& d1 d d2 d! d3 e% j' e j(  \ Z) Z* e+ e*  d4 k  r°e, d5   n  e) j- re$ j$ d6  Z. x= e. D]2 Z/ e  e/  Z0 e1 d7 e0 j2 e0 j2 e0 j3 f  qΟWn  e* d8 Z4 d  d l Z e j5 j6 d9  Z7 e7 rQe  e4 d: d; e7 g  Z0 n e  e4 d: d; g  Z0 e) j8 r{e) j8 Z8 n d< Z8 e) j9 rβe j: d= e) j9  Z; e; s΄e, d>   n e; j< d8  Z2 e; j< d4  Z= e= e0 j> e2 <n  e) j? re1 e0 j? e8   n  e) j@ r e1 e0 j@ e8   n  e) jA r9e1 e0 jA  n  e) jB r^e1 e0 jA e) jB k  q^n  d S(?   i    (   t   divisiont   absolute_importt   print_functionNi   (   t   SafeConfigParsert   NoOptionError(   t   ConfigParserR   R   t   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   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   __init__   s    c         C` s   |  j  S(   N(   R   (   R   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   __str__   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/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   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR      s    c         C` s   |  j  S(   N(   R   (   R   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR   "   s    (   R   R   R   R   R   (    (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR      s   	c         ` s|   t  j  |    t  _ i g  d 6g  d 6g  d 6g  d 6g  d 6     f d   }  j   } x | rw | |  } qb 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   ignoredc         ` s  |  j  d  rY t |   d k r9   d j |  d  q j   }    d j |   nΈ |  j  d  r² t |   d k r   d j |  d  q j   }    d j |   n_ |  j  d  rΩ   d j |  d  n8 |  j  d  r   d	 j |  d  n   d
 j |    j   S(   Ns   -Ii   R   s   -LR   s   -lR   s   -DR   R   (   t
   startswitht   lent   appendt	   get_token(   t   t(   t   dt   lexer(    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt
   next_token@   s     (   t   shlext   Truet   whitespace_splitR   (   t   lineR   R   (    (   R   R   sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR   %   s    		c         C` s   |  j  d d  S(   Ns   \s   \\(   t   replace(   t   val(    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   _escape_backslash[   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)   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR   y   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   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR-      s    t   defaultc         C` s'   |  j  j |  j | d  } t |  S(   Nt   cflags(   R,   t   interpolateR+   R&   (   R   t   sectionR%   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR1      s    c         C` s'   |  j  j |  j | d  } t |  S(   Nt   libs(   R,   R2   R+   R&   (   R   R3   R%   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR4      s    c         C` s{   d |  j  g } | j d |  j  |  j r= | 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(    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR      s    	N(	   R   R   R   t   NoneR   R-   R1   R4   R   (    (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR   ^   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(    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR   ΄   s    4		c         C` s4   x- |  j  j   D] \ } } |  j | |  q Wd  S(   N(   R;   R:   t   _init_parse_var(   R   R?   R@   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/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(    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyRA   ΐ   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=   (   RD   R?   (   R   (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   _interpolateΗ   s    $(   t   _VARt   search(   R   RD   RF   t   nvalue(    (   R   sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR2   Δ   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.   R;   R/   (   R   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt	   variablesΣ   s    c         C` s   |  j  | S(   N(   R;   (   R   R'   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   __getitem__δ   s    c         C` s!   | |  j  | <|  j | |  d  S(   N(   R;   RA   (   R   R'   RD   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   __setitem__η   s    (
   R   R   R   R   R>   RA   R2   RJ   RK   RL   (    (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/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   R:   (   t   configR   R'   RD   R?   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/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(   NRJ   s   No variables section found !(   RN   R   R:   R	   (   RO   R   R'   RD   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   parse_variablesύ   s    c         C` s
   t  t f S(   N(   t   meta_dt   r(   RO   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   parse_sections  s    c         C` s   d |  S(   Ns   %s.ini(    (   t   pkg_name(    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   pkg_to_filename  s    c         C` s­  | r1 g  | D] } t  j j | |   ^ q } n	 |  g } t j d  d k rY t   } n	 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  re| j |
 d  | |
 <n  x' | j |
  D] \ } }	 |	 | | <quW| | |
 <q.W| | | | f S(	   Ni   s   3.1i   s   Could not find file(s) %sRJ   RM   R)   (   s   metas	   variables(   t   ost   pathR6   t   sysR*   R   R   t   readR   R   t   strRP   RN   R:   R&   R-   t
   has_optiont   get(   t   filenamet   dirsR   t	   filenamesRO   t   nRM   R,   R'   RD   t   st   secsR-   R)   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   parse_config  s2    +		+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(   Rd   R:   RV   (   t   fRM   R,   R-   t   reqst   rnamet   rvaluet   nmetat   nvarst	   nsectionst   nreqsR?   R@   t   onamet   ovalue(   t   _read_configR_   (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyRo   7  s    #t   pkgdirt   pkgnames-   You should import %s to get information on %sR'   R(   R*   R-   R,   (
   RY   t   modulest
   ValueErrorR&   RW   RX   t   dirnamet   __file__R   R	   (   R`   R_   RM   R,   R-   Rf   Rq   t   mod(    (   Ro   R_   sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   _read_config_imp6  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   KeyErrorRw   RV   (   Rq   R_   R@   (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyR
   _  s    '
t   __main__(   t   OptionParsers   --cflagst   destR1   t   actiont
   store_truet   helps*   output all preprocessor and compiler flagss   --libsR4   s   output all linker flagss   --use-sectionR3   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   .R0   s   ([\S]+)=([\S]+)sH   --define-variable option should be of the form --define-variable=foo=bar(C   t
   __future__R    R   R   RY   RB   RW   R    t   version_infoR   R   R   t   configparsert   __all__RC   RG   t   IOErrorR   R   R   R&   t   objectR   R	   RP   RQ   RT   RV   R8   Rd   Rw   Rx   R
   R   t   optparseR{   t   globt   parsert
   add_optiont
   parse_argst   argvt   optionst   argsR   Rs   R   t   filesRe   t   infot   printR'   R(   RU   t   environR]   R   R3   R   RH   R7   t   groupRD   R,   R1   R4   R*   R   (    (    (    sX   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/distutils/npy_pkg_config.pyt   <module>   s   	6	ID				((3		'
						