
Xc           @` s  d  Z  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 d d l	 Z	 d d l
 m Z d d l m Z m Z d d l m Z d d l m Z m Z d d l m Z d d	 l m Z m Z m Z m Z m Z d d
 l m Z d d
 l m Z  d   Z! d e j f d     YZ" e j# d e j$  j% Z& e j# d e j$  j% Z' e j# d e j$  j% Z( e j# d e j$  j) Z* e j# d e j$  j) Z+ d   Z, d   Z- d   Z. e j# d e j$  j% Z/ e j# d e j$  j% Z0 d   Z1 d S(   s    Build swig and f2py sources.
i    (   t   divisiont   absolute_importt   print_functionN(   t	   build_ext(   t   newer_groupt   newer(   t   get_platform(   t   DistutilsErrort   DistutilsSetupError(   t   log(   t   fortran_ext_matcht
   appendpatht	   is_stringt   is_sequencet   get_cmd(   t   process_filec         C` s   t  j d  } t | d  } z t |  d  } zm xf | D]^ } | j |  } | r | j | j d | j d  | | j d    q: | j |  q: WWd | j   XWd | j   Xd S(   sP   Substitute any occurrence of @foo@ by d['foo'] from source file into
    target.s   @([a-zA-Z_]+)@t   rt   ws   @%s@i   N(   t   ret   compilet   opent   searcht   writet   replacet   groupt   close(   t   targett   sourcet   dt   vart   fst   ftt   lt   m(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyt
   subst_vars   s    6t	   build_srcc           B` s   e  Z d  Z d* d, d- d. d/ d0 d1 d2 d d d d f g	 Z d d g Z g  Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d    Z d!   Z d"   Z d#   Z g  d$  Z d%   Z d&   Z d'   Z d(   Z d)   Z RS(3   s1   build sources from SWIG, F2PY files or a functions
   build-src=R   s   directory to "build" sources tos
   f2py-opts=s!   list of f2py command line optionss   swig=s   path to the SWIG executables
   swig-opts=s!   list of SWIG command line optionss   swig-cppsA   make SWIG create C++ files (default is autodetected from sources)s
   f2pyflags=s3   additional flags to f2py (use --f2py-opts= instead)s
   swigflags=s3   additional flags to swig (use --swig-opts= instead)t   forcet   fs2   forcibly build everything (ignore file timestamps)t   inplacet   is=   ignore build-lib and put compiled extensions into the source s,   directory alongside your pure Python modulesc         C` s   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 d  |  _
 d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   t   Nonet
   extensionst   packaget
   py_modulest   py_modules_dictR#   t	   build_libt
   build_baseR$   R&   t   package_dirt	   f2pyflagst	   f2py_optst	   swigflagst	   swig_optst   swig_cppt   swig(   t   self(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyt   initialize_optionsD   s     															c         C` s  |  j  d d d d  |  j d  k r7 |  j j |  _ n  |  j j |  _ |  j j pU g  |  _ |  j j pj g  |  _ |  j j	 p g  |  _	 |  j
 d  k r d t   t j d d !f } t j j |  j d |  |  _
 n  i  |  _ |  j r|  j r t j d	  n |  j |  _ d  |  _ n  |  j d  k r1g  |  _ n t j |  j  |  _ |  j r|  j rht j d
  n |  j |  _ d  |  _ n  |  j d  k rg  |  _ n t j |  j  |  _ |  j d  } |  j d  k r| j |  _ n  |  j d  k r| j |  _ n  x d d g D] } d | j d d  } t | | d   } | rt |  |  r_t j d |  qt j  d | | f  t! |  | |  qqWd  S(   Nt   buildR.   R-   R$   s   .%s-%si    i   t   srcs0   ignoring --f2pyflags as --f2py-opts already useds0   ignoring --swigflags as --swig-opts already usedR   R5   t   swig_opts   --t   _t   -s-   both build_src and build_ext define %s options+   using "%s=%s" option from build_ext command(   s
   build_bases
   build_base(   s	   build_libs	   build_lib(   s   forces   force("   t   set_undefined_optionsR*   R(   t   distributiont   ext_packaget   ext_modulesR)   t	   librariesR+   t
   data_filesR#   R   t   syst   versiont   ost   patht   joinR.   R,   R0   R1   R	   t   warnt   shlext   splitR2   R3   t   get_finalized_commandR&   R4   R   t   getattrt   infot   setattr(   R6   t   plat_specifierR   t   ct   ot   v(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyt   finalize_optionsV   sV    	"					c         C` s1   t  j d  |  j p |  j s# d  S|  j   d  S(   NR#   (   R	   RM   R)   RA   t   build_sources(   R6   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyt   run   s    c         C` s   |  j  r! |  j d  j |  _ n  |  j   x |  j D] } |  j |   q5 W|  j r |  j |  j  x! |  j D] } |  j |  qo Wn  |  j	   |  j
   d  S(   Nt   build_py(   R&   RK   t   get_package_dirt   build_py_modules_sourcesRA   t   build_library_sourcesR)   t   check_extensions_listt   build_extension_sourcest   build_data_files_sourcest   build_npy_pkg_config(   R6   t   libname_infot   ext(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyRT      s    	
	
c         C` s  |  j  s d  St j d  d d l m } g  } x|  j  D]} t | t  r_ | j |  q: t | t  r| \ } } |  j	 r |  j
 d j | j t j    } n t j j |  j |  } g  | D] } t | d  r | ^ q } g  | D] } t | d  s | ^ q } x | D] } | j j d k r@| |  }	 n	 |   }	 |	 d  k	 rt |	 t  rt| j |	  qt |	 t  r| j |	  qt t |	    qqW| | | f  }
 | j | |
 f  q: t t |    q: W| |  j  (d  S(   Ns   building data_files sourcesi    (   t   get_data_filest   .t   __call__i   (   RB   R	   RM   t   numpy.distutils.misc_utilR`   t
   isinstancet   strt   appendt   tupleR&   RW   RG   RJ   RE   t   sepRF   R#   t   hasattrt   __code__t   co_argcountR(   t   listt   extendt	   TypeErrort   repr(   R6   R`   t   new_data_filest   dataR   t   filest	   build_dirR%   t   funcst   st	   filenames(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR\      s:    		'((	c         C` s  d d  l  } | \ } } } t j j |  } x$ | j   D] \ } }	 |	 | | <q: W|  j d k r{ t j j | |  }
 n t j j |  j | |  }
 t j j t j j	 |  d  } t j j |
 |  } t j j
 |
  s t j |
  n  t | | |  t j j | |  } | | f S(   Ni    i   (   t   shutilRE   RF   t   dirnamet   itemsR&   RG   R#   t   basenamet   splitextt   existst   makedirsR"   (   R6   RM   t   gdRw   t   templatet   install_dirt
   subst_dictt   template_dirt   kRR   t   generated_dirt	   generatedt   generated_patht   full_install_dir(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyt   _build_npy_pkg_config   s     	"c         C` s<  t  j d  t j t d   } | j d k s> | j   n  t } i  } |  j d k rh d } t } n! t	 | d  r | j
 } t } n  | r8x |  j j j   D] \ } } |  j j | } t j j t j j |  |  } i | d 6}	 xB | D]: }
 |  j |
 |	  \ } } |  j j j | | g f  q Wq Wn  d  S(   Ns(   build_src: building npy-pkg config filest   installi   Ra   t   install_libbaset   prefix(   R	   RM   t   copyR   t	   finalizedRS   t   FalseR&   t   TrueRi   R   R>   t   installed_pkg_configRy   R/   RE   RF   RG   t   abspathR   RB   Rf   (   R6   t   install_cmdt
   build_npkgR~   t
   top_prefixt   pkgt   infost   pkg_pathR   R   RM   R   R   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR]      s*    			!c         C` sT  |  j  s d  St j d  g  } x#|  j  D]} t |  r5t |  d k r5| \ } } } |  j rx |  j |  } n- t j j	 |  j
 t j j	 | j d     } t | d  r t j j	 | | d  } | |  } n  | d  k r q* n  | | | f g } | |  j k rg  |  j | <n  |  j | c | 7<q* | j |  q* W| |  j  (d  S(   Ns   building py_modules sourcesi   Ra   Rb   s   .py(   R+   R	   RM   R   t   lenR&   RW   RE   RF   RG   R#   RJ   Ri   R(   R,   Rf   (   R6   t   new_py_modulesR   R*   t   module_baseRs   R   t   modules(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyRX     s,    		c         C` s   t  | j d g    } | s" d  St j d |  |  j | | | f  } |  j | | | f  } |  j |  \ } } | r t j d |  j |  n  | | d <d  S(   Nt   sourcess   building library "%s" sourcess#   %s - nothing done with h_files = %s(   Rl   t   getR	   RM   t   generate_sourcest   template_sourcest   filter_h_filesR*   (   R6   t   lib_namet
   build_infoR   t   h_files(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyRY     s    	
c         C` s  t  | j  } t j d | j  |  j | j  } | j d  } d j | d d ! } |  j rx |  j	 |  |  _
 n  |  j | |  } |  j | |  } |  j | |  } |  j | |  } |  j | |  } |  j |  \ } } | |  j k rg  |  j | <n  g  } xF | D]> } t j j t j j |   d }	 | j | |	 | f  qW|  j | c | 7<|  j |  \ } }
 |
 rt j d | |
  n  | | _ d  S(   Ns   building extension "%s" sourcesRa   i    is#   %s - nothing done with h_files = %s(   Rl   R   R	   RM   t   namet   get_ext_fullnameRJ   RG   R&   RW   t   ext_target_dirR   R   t   swig_sourcest   f2py_sourcest   pyrex_sourcest   filter_py_filesR,   RE   RF   R{   Rz   Rf   R   (   R6   R_   R   t   fullnamet   modpathR*   t   py_filesR   R%   t   moduleR   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR[   6  s2    	"	c   
      C` s^  g  } g  } x7 | D]/ } t  |  r5 | j |  q | j |  q W| sP | S|  j rr t |  rr |  j } nK t |  r | d } n	 | j } t j j |  j	 g | j
 d  d    } |  j |  x | D] } | | |  } | s q n  t |  r5g  | D] }	 t j d |	 f  ^ q| j |  q t j d | f  | j |  q W| S(   Ni    Ra   is     adding '%s' to sources.(   R   Rf   R&   R   R   R   RE   RF   RG   R#   RJ   t   mkpathR	   RM   Rm   (
   R6   R   t	   extensiont   new_sourcest   func_sourcesR   Rs   R   t   funcRu   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR   ^  s4    	'c         C` s   |  j  | d g  S(   Ns   .py(   t   filter_files(   R6   R   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s    c         C` s   |  j  | d d d g  S(   Ns   .hs   .hpps   .inc(   R   (   R6   R   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s    c         C` sh   g  } g  } xO | D]G } t  j j |  \ } } | | k rM | j |  q | j |  q W| | f S(   N(   RE   RF   R{   Rf   (   R6   R   t   extsR   Rr   R   t   baseR_   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s    c         C` s  g  } t  |  r; | d j d  } | d j d  } n | j } | j } x| D]} t j j |  \ } } | d k r|  j r t j j |  }	 n t	 |  j
 t j j |   }	 |  j |	  t j j |	 t j j |   }
 |  j st | g | |
  ryt |  r3t j d |
  t |  } n t j d |
  t |  } t |
 d  } | j |  | j   n  t |
  rt j j |
  } | | k rt j d |  | j |  qn  | j |
  qT | j |  qT W| S(	   Ni   t   dependst   include_dirss   .srcs   from_template:> %ss   conv_template:> %sR   s     adding '%s' to include_dirs.(   R   R   R   R   RE   RF   R{   R&   Rx   R   R#   R   RG   Rz   R$   R   t   _f_pyf_ext_matchR	   RM   t   process_f_filet   process_c_fileR   R   R   t   _header_ext_matchRf   (   R6   R   R   R   R   R   R   R   R_   t
   target_dirt   target_filet   outstrt   fidR   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s>    			!c   	      C` s   g  } | j  j d  d } xg | D]_ } t j j |  \ } } | d k ru |  j | | | |  } | j |  q# | j |  q# W| S(   s@   Pyrex not supported; this remains for Cython support (see below)Ra   is   .pyx(   R   RJ   RE   RF   R{   t   generate_a_pyrex_sourceRf   (	   R6   R   R   R   t   ext_nameR   R   R_   R   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s    	c         C` s   g  S(   s   Pyrex is not supported, but some projects monkeypatch this method.

        That allows compiling Cython code, see gh-6955.
        This method will remain here for compatibility reasons.
        (    (   R6   R   R   R   R   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s    c         C` s  g  } g  } g  } i  } g  } | j  j d  d } d }	 x| D]}
 t j j |
  \ } } | d k r|  j r t j j |  } n t |  j t j j |   } t j j	 |
  r	t
 |
  } | | k r t d |
 | | f   n  t j j | | d  } n t j d |
  | } d }	 t j j | | d  } t j j	 |  st j d	 | | f  t j j |  } t j j | | d  } t j j	 |  st d
 | f   n  t j d |  n  | j |  | j |
  | | |
 <| j |  qA t |  r| j |
  qA | j |
  qA W| p9| s@| Sx | D] } |  j |  qGW| j |  j } |  j j rxH |  j j D]7 \ } } | | j k r| j | j d g    qqWn  t j d |  | rt |  d k rt d | f   n  | d }
 | |
 } t j j |  p-d } |
 g | j } |  j s[t | | d  r|	 rt j d |
  d d  l } | j j  | d | |
 g  qt j d |
  n	t! |  r| d } n	 | j  } t j j |  j g | j d  d    } t j j | | d  } | j |  | | j } |  j sLt | | d  r|	 rt j d |  |  j |  d d  l } | j j  | d d | g d | g |  n t j d |  t j j	 |  st" d | f   n  t j j |  j d  } t j j |  j d  } t j d |  | j |  |  j | j# k rnt j d |  j  | j# j |  j  n  |	 s%d d  l } t j j | j j$  } t j j | d d  } t j j | d d  } t% | |  st% | |  ru|  j t j j |   |  j& | |  |  j& | |  qunP t j j	 |  sMt d | f   n  t j j	 |  sut d | f   n  x` d d  g D]R } t j j | | |  } t j j	 |  rt j d |  | j |  qqW| | S(!   NRa   ii    s   .pyfs;   mismatch of extension names: %s provides %r but expected %rs   module.cs.     source %s does not exist: skipping f2py'ing.i   sd     target %s does not exist:
   Assuming %smodule.c was generated with "build_src --inplace" command.s
   %r missings&      Yes! Using %r as up-to-date target.t   f2py_optionss   f2py options: %ssC   only one .pyf file is allowed per extension module but got more: %rR   s   f2py: %ss   --build-dirs+     skipping '%s' f2py interface (up-to-date)s	   f2py:> %ss   --lowers   -ms3     skipping f2py fortran files for '%s' (up-to-date)s!   f2py target file %r not generateds   fortranobject.cs   fortranobject.hs     adding '%s' to sources.s     adding '%s' to include_dirs.R9   s   f2py target_c file %r not founds   f2py target_h file %r not founds   -f2pywrappers.fs   -f2pywrappers2.f90('   R   RJ   RE   RF   R{   R&   Rx   R   R#   t   isfilet   get_f2py_modulenameR   RG   R	   t   debugRH   RM   Rf   R
   R   R   R1   R>   RA   Rm   R   R   R   R$   R   t
   numpy.f2pyt   f2pyt   run_mainR   R   R   t   __file__R   t	   copy_file(   R6   R   R   R   R   t	   f_sourcest   f2py_targetst   target_dirsR   t	   skip_f2pyR   R   R_   R   R   R   R   R   R   R   t   numpyt   target_ct   target_ht   source_ct   source_ht   name_extt   filename(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s    				
#

		%		c         C` s  g  } g  } i  } g  } g  } d } d | j  k rR d }	 t }
 | j  j d  n$ |  j rj d }	 t }
 n d  }	 t }
 d } | j j d  d } x| D]} t j	 j
 |  \ } } | d k rP|  j r t j	 j |  } |  j } n$ t |  j t j	 j |   } | } t j	 j |  rBt |  } | | d k r\t d	 | | | d f   n  |	 d  k rt |  }	 |	 d k }
 n t |  } | d  k rt j d
 | |	 f  n\ |	 | k rt j d |	 | | f  | d k rt j d  t }
 qt j d |  n  |
 r d } n  t j	 j | d | | f  } n t j d |  | d } d } t | |  } t j	 j |  st j d | | f  t j	 j |  } t | |  } t j	 j |  st d | f   n  t j d |  n  | j |  | j |  | j t j	 j | | d   | j |  | d | | <q | j |  q W| sk| S| ry| | Sx | D] } |  j |  qW|  j p|  j   } | d g | j  } |
 r| j d  n  x" | j D] } | j d |  qWx | D] } | | } | g | j } |  j s<t | | d  rt j  d t j	 j! |  |
 r`d pcd | f  |  j" | |  j  d | d | | g  qt j# d |  qW| | S(   Ns   .cs   -c++s   c++i    Ra   is   .ii   s;   mismatch of extension names: %s provides %r but expected %rs>   source %r does not define swig target, assuming %s swig targets0   expected %r but source %r defines %r swig targetsA   resetting swig target to c++ (some targets may have .c extension)s$   assuming that %r has c++ swig targets   .cpps	   %s_wrap%ss.     source %s does not exist: skipping swig'ing.si     target %s does not exist:
   Assuming %s_wrap.{c,cpp} was generated with "build_src --inplace" command.s
   %r missings&      Yes! Using %r as up-to-date target.s   .pys   -pythons   -IR   s   %s: %ss   ++t    s   -os   -outdirs+     skipping '%s' swig interface (up-to-date)($   R3   R   t   removeR4   R(   R   R   RJ   RE   RF   R{   R&   Rx   R   R   R#   R   t   get_swig_modulenameR   t   get_swig_targetR	   RH   RG   t   _find_swig_targetRf   R   R5   t	   find_swigR   R   R$   R   RM   Rz   t   spawnR   (   R6   R   R   R   R   t   swig_targetsR   R   t
   target_extt   typt   is_cppt	   skip_swigR   R   R   R_   R   t   py_target_dirR   t   typ2R   R   R5   t   swig_cmdR   R   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR   \  s    								
		 
$	(   s
   build-src=R   s   directory to "build" sources toN(   s
   f2py-opts=Ns!   list of f2py command line options(   s   swig=Ns   path to the SWIG executable(   s
   swig-opts=Ns!   list of SWIG command line options(   s   swig-cppNsA   make SWIG create C++ files (default is autodetected from sources)(   s
   f2pyflags=Ns3   additional flags to f2py (use --f2py-opts= instead)(   s
   swigflags=Ns3   additional flags to swig (use --swig-opts= instead)(   s   forceR%   s2   forcibly build everything (ignore file timestamps)(   t   __name__t
   __module__t   descriptionR(   t   user_optionst   boolean_optionst   help_optionsR7   RS   RU   RT   R\   R   R]   RX   RY   R[   R   R   R   R   R   R   R   R   R   (    (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR#   .   sB   		:			$					(	'			%			s"   .*[.](f90|f95|f77|for|ftn|f|pyf)\Zs   .*[.](inc|h|hpp)\ZsQ   \s*%module\s*(.*\(\s*package\s*=\s*"(?P<package>[\w_]+)".*\)|)\s*(?P<name>[\w_]+)s   -[*]-\s*c\s*-[*]-s   -[*]-\s*c[+][+]\s*-[*]-c         C` sY   t  |  d  } d  } | j   } t |  r6 d } n  t |  rK d } n  | j   | S(   NR   s   c++RP   (   R   R(   t   readlinet   _has_cpp_headert   _has_c_headerR   (   R   R%   t   resultt   line(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s    		
c         C` sY   t  |  d  } d  } x3 | D]+ } t |  } | r | j d  } Pq q W| j   | S(   NR   R   (   R   R(   t   _swig_module_name_matchR   R   (   R   R%   R   R   R!   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s    
c         C` sP   xI d d g D]; } t  j j |  d | | f  } t  j j |  r Pq q W| S(   Ns   .cpps   .cs	   %s_wrap%s(   RE   RF   RG   R   (   R   R   R_   R   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s
    s%   \s*python\s*module\s*(?P<name>[\w_]+)s4   \s*python\s*module\s*(?P<name>[\w_]*?__user__[\w_]*)c         C` sh   d  } t |   } xE | D]= } t |  } | r t |  rC q n  | j d  } Pq q W| j   | S(   NR   (   R(   R   t   _f2py_module_name_matcht   _f2py_user_module_name_matchR   R   (   R   R   R%   R   R!   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyR     s    
(2   t   __doc__t
   __future__R    R   R   RE   R   RC   RI   R   t   distutils.commandR   t   distutils.dep_utilR   R   t   distutils.utilR   t   distutils.errorsR   R   t   numpy.distutilsR	   Rc   R
   R   R   R   R   t   numpy.distutils.from_templateR   R   t   numpy.distutils.conv_templateR   R"   R#   R   t   It   matchR   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_src.pyt   <module>   s@   (	  							