
6e]c        	   @` s  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	 Z	 d  d l
 Z
 d  d l m Z d  d l m Z d  d l Td  d l m Z m Z m Z m 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 m Z d  d l m  Z  m! Z! m" Z" m# Z# m$ Z$ y d  d l% Z% Wn e& k
 rid  d l' Z% n Xd a) e% j*   Z+ e,   Z- d   Z. d   Z/ d   Z0 e/ e1 d e0  d d  Z2 e/ e1 d e2  d  d d  Z3 e/ e1 d e3  d d d d  d d d d  Z4 e/ e1 d e4  dM d  Z5 e/ e1 d e5  d   Z6 d   Z7 e/ e1 d e7  d  d  Z8 e/ e1 d e8  d d d d   Z9 e: d  g d!  Z; e/ e1 d" e;  d#   Z< e/ e1 d$ e<  dN e= d( <dO e= d+ <dP e= d. <dQ e= d1 <dR e= d4 <dS e= d8 <e j> dT dU dV dW dX dY f 7_> e j? d; k rbdZ e= d? <e"   rbe j@ d@  d\ e j> e _> qbn  eA ZB d d d  d  d  dA  ZA eA e _A eC ZD dB   ZC eC e _C x\ dC dD dE dF dG dH dI g D]? ZE e jF jG dJ eE dK  ZH eH d k	 reI eH dL eC  qqWd S(]   i    (   t   divisiont   absolute_importt   print_functionN(   t   copy(   t	   ccompiler(   t   *(   t   DistutilsExecErrort   DistutilsModuleErrort   DistutilsPlatformErrort   CompileError(   t   customize_compiler(   t   LooseVersion(   t   log(   t   get_exception(   t   filepath_from_subprocess_outputt   forward_bytes_to_stdout(   t	   cyg2win32t   is_sequencet   mingw32t   get_num_build_jobst   _commandline_dep_stringc         C` s#  |  d } t  j j |  s  t St | d   } | j   } Wd QXt | | |  } | d } | | k rp t Sd j | d   }	 g  t j	 |	 d t D]( }
 |
 d k r |
 j
 d  r |
 ^ q } yC t  j |   j } x* | D]" } t  j |  j | k r t Sq WWn t k
 rt SXt S(	   s   
    Check if an objects needs to be rebuild based on its dependencies

    Parameters
    ----------
    obj : str
        object file

    Returns
    -------
    bool
    s   .dt   rNit    t   posixs   
t   :(   t   ost   patht   existst   Truet   opent	   readlinesR   t   joint   shlext   splitt   endswitht   statt   st_mtimet   OSErrort   False(   t   objt   cc_argst   extra_postargst   pp_optst   dep_filet   ft   linest   cmdlinet   last_cmdlinet   contentst   xt   depst   t_obj(    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   _needs_build%   s(    

(c         ` sN   t  j d d k  r+ t j   d  |   } n   f d   } t |  | |  d  S(   Ni    i   c         ` s     |  | |  S(   N(    (   t   selft   argst   kw(   t   func(    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   <lambda>\   R   (   t   syst   version_infot   typest
   MethodTypet   Nonet   setattr(   t   klasst   method_nameR8   t   m(    (   R8   s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   replace_methodW   s    c         C` s   d S(   s   
    Does nothing here, but is called by the get_version method and can be
    overridden by subclasses. In particular it is redefined in the `FCompiler`
    class where more documentation can be found.

    N(    (   R5   (    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   CCompiler_find_executablese   s    t   find_executablesc         C` s  | d k r9 | } t |  r9 d j t |   } q9 n  t j |  y t j |  WnD t j k
 r } | j	 } | j
 } n! t k
 r d } d } n Xd St |  r d j t |   } n  t |  t j d |  r d } n d } t d | | | f   d S(   s  
    Execute a command in a sub-process.

    Parameters
    ----------
    cmd : str
        The command to execute.
    display : str or sequence of str, optional
        The text to add to the log file kept by `numpy.distutils`.
        If not given, `display` is equal to `cmd`.

    Returns
    -------
    None

    Raises
    ------
    DistutilsExecError
        If the command failed, i.e. the exit status was not 0.

    t    R   i   s   Too many open filess2   
Try rerunning setup command until build succeeds.s)   Command "%s" failed with exit status %d%sN(   R>   R   R   t   listR   t   infot
   subprocesst   check_outputt   CalledProcessErrort   outputt
   returncodeR%   R   t   ret   searchR   (   R5   t   cmdt   displayt   exct   ot   st   msg(    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   CCompiler_spawns   s,    	

	t   spawnR   c         C` sG  | d k r d } n  g  } x%| D]} t j j t j j |   \ } } t j j |  d } | t j j |  } | j d  r | j d  d } | |  }	 t j j	 t j j
 |	   }	 |	 | | } n  | |  j k r t d | | f   n  | rt j j	 |  } n  t j j | | |  j  }
 | j |
  q" W| S(   s  
    Return the name of the object files for the given source files.

    Parameters
    ----------
    source_filenames : list of str
        The list of paths to source files. Paths can be either relative or
        absolute, this is handled transparently.
    strip_dir : bool, optional
        Whether to strip the directory from the returned paths. If True,
        the file name prepended by `output_dir` is returned. Default is False.
    output_dir : str, optional
        If given, this path is prepended to the returned paths to the
        object files.

    Returns
    -------
    obj_names : list of str
        The list of paths to the object files corresponding to the source
        files in `source_filenames`.

    R   i   s   ..i   s"   unknown file type '%s' (from '%s')N(   R>   R   R   t   splitextt   normpatht
   splitdrivet   isabst
   startswitht   rfindt   basenamet   abspatht   src_extensionst   UnknownFileErrorR   t   obj_extensiont   append(   R5   t   source_filenamest	   strip_dirt
   output_dirt	   obj_namest   src_namet   baset   extt   it   dt   obj_name(    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   CCompiler_object_filenames   s&    	$
t   object_filenamesc	         ` sV  t    }	 t # t d k r. t j |	  a n  Wd QX| s> g  St j d d k  rp d d l m	 }
 m
 } m } n d d l m	 }
 m
 } m } t  |
  rg  } x\ d d d g D]K } t  d	 |  } | d k r q n  | j d
 | d j |  f  q Wd j |  } n  j } d d j |  f } t j |   j | | | | |   \ } }   }  j  | |    d d j    }  r| d d j   7} n  t j |       f d   } t  |
  rt | j    } g  g  } } x | D] } | | k r| | \ } }  j d k rYt |  } t |  } n  | |  r| |  r| j | | | f f  q| j | | | f f  qqW| } x' | D] } | |  qWn | j   } t |  d k r7|	 d k r7d d l } | j j |	  } | j | |  | j    n x | D] } | |  q>W| S(   s  
    Compile one or more source files.

    Please refer to the Python distutils API reference for more details.

    Parameters
    ----------
    sources : list of str
        A list of filenames
    output_dir : str, optional
        Path to the output directory.
    macros : list of tuples
        A list of macro definitions.
    include_dirs : list of str, optional
        The directories to add to the default include file search path for
        this compilation only.
    debug : bool, optional
        Whether or not to output debug symbols in or alongside the object
        file(s).
    extra_preargs, extra_postargs : ?
        Extra pre- and post-arguments.
    depends : list of str, optional
        A list of file names that all targets depend on.

    Returns
    -------
    objects : list of str
        A list of object file names, one per source file `sources`.

    Raises
    ------
    CompileError
        If compilation fails.

    Ni    i   i   (   t	   FCompilert	   is_f_filet   has_f90_headert   f77t   f90t   fixt	   compiler_s   Fortran %s compiler: %sRF   s   
s   C compiler: %s
s   compile options: '%s's   
extra options: '%s'c         ` s   |  \ } \ } } t  |      s+ d  SxA t rn t " | t k rX t j |  Pn  Wd  QXt j d  q. Wz- t !  j | | |      Wd  QXWd  t  t j	 |  Wd  QXXd  S(   Ng?(
   R4   R   t   _global_lockt   _processing_filest   addt   timet   sleept   _job_semaphoret   _compilet   remove(   R6   R'   t   srcRj   (   R(   R)   R*   R5   (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   single_compile/  s    	
&t   absoft(!   R   Rw   R|   R>   t	   threadingt	   SemaphoreR:   R;   t	   fcompilerRp   Rq   Rr   t   numpy.distutils.fcompilert
   isinstancet   getattrRc   R   t   compiler_soR   RH   t   _setup_compilet   _get_cc_argsRG   t   keyst   compiler_typeR   t   itemst   lent   multiprocessing.poolt   poolt
   ThreadPoolt   mapt   close(   R5   t   sourcesRf   t   macrost   include_dirst   debugt   extra_preargsR)   t   dependst   jobsRp   Rq   Rr   RQ   t   fct   fcompt   ccompt   objectst   buildR   t   objects_to_buildt   f77_objectst   other_objectsR'   R   Rj   t   build_itemsRS   t   multiprocessingR   (    (   R(   R)   R*   R5   s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   CCompiler_compile   sh    +	$	 t   compilec         ` sK  t  j d |  j j   j j f     f d   } | d  rT |  j   j  n  | d  r x*   j D] \ } } |  j | |  qj Wn  | d  r x!   j D] } |  j	 |  q Wn  | d  r |  j
 |  j   j  n  | d  r	|  j |  j   j  n  | d  r(|  j   j  n  | d	  rG|  j   j  n  d
 S(   s  
    Customize compiler using distutils command.

    Parameters
    ----------
    cmd : class instance
        An instance inheriting from `distutils.cmd.Command`.
    ignore : sequence of str, optional
        List of `CCompiler` commands (without ``'set_'``) that should not be
        altered. Strings that are checked for are:
        ``('include_dirs', 'define', 'undef', 'libraries', 'library_dirs',
        'rpath', 'link_objects')``.

    Returns
    -------
    None

    s   customize %s using %sc         ` s"   t    |  d   d  k	 o! |   k S(   N(   R   R>   (   t   attr(   RP   t   ignore(    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   allow  s    R   t   definet   undeft	   librariest   library_dirst   rpatht   link_objectsN(   R   RH   t	   __class__t   __name__t   set_include_dirsR   R   t   define_macroR   t   undefine_macrot   set_librariesR   t   set_library_dirsR   t   set_runtime_library_dirsR   t   set_link_objectsR   (   R5   RP   R   R   t   namet   valuet   macro(    (   RP   R   s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   CCompiler_customize_cmdr  s&    t   customize_cmdc   	   
   C` s  g  } d } t  |  j j    } xH d d d d d d d d	 d
 d g
 D]" } | | k rF | j |  qF qF Wx] | D]U } t |  |  rs t |  |  } t | t |   } | j | t |  f  qs qs Wd t | d  d } g  | D] } | | ^ q } d j	 |  S(   Ni    t   versionR   R   t   object_switcht   compile_switchR   R   R   R   R   s   %-i   s   s = %ss   
(
   RG   t   executablesR   Rc   t   hasattrR   t   maxR   t   reprR   (	   t   compilert   propst   mxR   t   keyt   vt   fmtt   propR-   (    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   _compiler_to_string  s      c         C` st   y |  j    Wn t k
 r! n Xt j j d k  rp t d d  t |  j  t t |    t d d  n  d S(   s   
    Print the compiler customizations to stdout.

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

    Returns
    -------
    None

    Notes
    -----
    Printing is only done if the distutils log threshold is < 2.

    i   R   iP   N(   t   get_versiont	   ExceptionR   t   _global_logt	   thresholdt   printR   R   (   R5   (    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   CCompiler_show_customization  s    t   show_customizationc   
   
   C` sf  t  j d |  j j  t |   | r6y |  j j d  Wn t t f k
 rT n Xt	 |  d  r d |  j
 d k r |  j s3|  j
 d j d  r d \ } } n d \ } } |  j
 d j | |  g |  j
 d	 |  _ q3q6t	 |  d  r
t  j d
 |  j
 f  n  t	 |  d  s6t  j d |  j j  q6n  t	 |  d  rd |  j
 d k s~d |  j
 d k s~d |  j
 d k rt |  _ n t j d k rbd d l } d d l } | j   } z yp t j j | d  } t | d   }	 |	 j d  Wd QX|  j | g d | d d d | d g t |  _ Wn t k
 rLt |  _ n XWd | j |  Xn  d S(   sm  
    Do any platform-specific customization of a compiler instance.

    This method calls `distutils.sysconfig.customize_compiler` for
    platform-specific customization, as well as optionally remove a flag
    to suppress spurious warnings in case C++ code is being compiled.

    Parameters
    ----------
    dist : object
        This parameter is not used for anything.
    need_cxx : bool, optional
        Whether or not C++ has to be compiled. If so (True), the
        ``"-Wstrict-prototypes"`` option is removed to prevent spurious
        warnings. Default is False.

    Returns
    -------
    None

    Notes
    -----
    All the default options used by distutils can be extracted with::

      from distutils import sysconfig
      sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'BASECFLAGS',
                                'CCSHARED', 'LDSHARED', 'SO')

    s   customize %ss   -Wstrict-prototypesR   t   cci    t   gccs   g++s   c++i   s   #### %s #######t   compiler_cxxs   Missing compiler_cxx fix for t   clangR   Ns   file.ct   ws   int a;
Rf   R   s   -MMDs   -MFs   .d(   R   s   g++(   R   s   c++(   R   RH   R   R   R
   R   R~   t   AttributeErrort
   ValueErrorR   R   R   R\   t   replacet   warnR   t   _auto_dependsR   R   t   tempfilet   shutilt   mkdtempR   R   R   t   writeR   R	   R&   t   rmtree(
   R5   t   distt   need_cxxt   at   bR   R   t   tmpdirt   fnR,   (    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   CCompiler_customize  sL    
"	" t	   customizes   [-.\d]+c         ` s       f d   } | S(   sU  
    Simple matching of version numbers, for use in CCompiler and FCompiler.

    Parameters
    ----------
    pat : str, optional
        A regular expression matching version numbers.
        Default is ``r'[-.\d]+'``.
    ignore : str, optional
        A regular expression matching patterns to skip.
        Default is ``''``, in which case nothing is skipped.
    start : str, optional
        A regular expression matching the start of where to start looking
        for version numbers.
        Default is ``''``, in which case searching is started at the
        beginning of the version string given to `matcher`.

    Returns
    -------
    matcher : callable
        A function that is appropriate to use as the ``.version_match``
        attribute of a `CCompiler` class. `matcher` takes a single parameter,
        a version string.

    c         ` s   | j  d d  } d }  rI t j  |  } | s: d  S| j   } n  x^ t r t j  | |  } | sr d  S  r t j   | j d   r | j   } qL n  PqL W| j d  S(   Ns   
RF   i    (   R   RN   t   matchR>   t   endR   RO   t   group(   R5   t   version_stringt   posRB   (   R   t   patt   start(    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   matcherA  s     	!(    (   R   R   R   R   (    (   R   R   R   s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   simple_version_match'  s    c   	      ` si  | r t  |  d  r |  j S|  j   y |  j } Wn t k
 rH d SX| s[ | d r_ d Sy |  j } WnB t k
 r y |  j   Wn t k
 r d SX  f d   } n Xy t j	 | d t j
 } WnD t j k
 r } | j } | j } n/ t k
 rd } d } n Xt |  } d } d } | | k r\| |  } | r\t |  } q\n  | |  _ | S(   s  
    Return compiler version, or None if compiler is not available.

    Parameters
    ----------
    force : bool, optional
        If True, force a new determination of the version, even if the
        compiler already has a version attribute. Default is False.
    ok_status : list of int, optional
        The list of status values returned by the version look-up process
        for which a version string is returned. If the status value is not
        in `ok_status`, None is returned. Default is ``[0]``.

    Returns
    -------
    version : str or None
        Version string, in the format of `distutils.version.LooseVersion`.

    R   i    c         ` s/   t  j   |   } | s d  S| j d  } | S(   NR   (   RN   R   R>   R   (   R   RB   R   (   R   (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyR   z  s
    t   stderri   R   N(   R   R   RE   t   version_cmdR   R>   t   version_matcht   version_patternRI   RJ   t   STDOUTRK   RL   RM   R%   R   R   (	   R5   t   forcet	   ok_statusR   R   RL   RR   t   statusR   (    (   R   s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   CCompiler_get_versionV  sD    
	
	R   c         C` s   |  j  d	 k r |  St |   } | j d g | j d | _ t j j d  r d | j d k r | j d | j d g | j d | _ n | j d g | j d | _ | S(
   s   
    Return the C++ compiler.

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

    Returns
    -------
    cxx : class instance
        The C++ compiler, as a `CCompiler` instance.

    t   msvct   intelwt   intelemwi    i   t   aixt	   ld_so_aixi   (   R   R   R   (   R   R   R   R   R:   t   platformR\   t	   linker_so(   R5   t   cxx(    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   CCompiler_cxx_compiler  s    %t   cxx_compilert   intelccompilert   IntelCCompilers(   Intel C Compiler for 32-bit applicationst   intelt   IntelItaniumCCompilers7   Intel C Itanium Compiler for Itanium-based applicationst   intelet   IntelEM64TCCompilers(   Intel C Compiler for 64-bit applicationst   intelemt   IntelCCompilerWs3   Intel C Compiler for 32-bit applications on WindowsR   t   IntelEM64TCCompilerWs3   Intel C Compiler for 64-bit applications on WindowsR   t   pathccompilert   PathScaleCCompilers2   PathScale Compiler for SiCortex-based applicationst   pathccs   linux.*t   ntt   win32t   mingw32ccompilert   Mingw32CCompilers>   Mingw32 port of GNU C Compiler for Win32(for MSC built Python)R   s+   Setting mingw32 as default compiler for nt.c         C` s  |  d  k r t j }  n  y2 | d  k r6 t |   } n  t | \ } } } WnD t k
 r d |  } | d  k	 r | d | } n  t |   n Xd | } y t |  Wn t k
 r,t	 t
    } t j d t	 |   | d } y t |  Wq-t k
 r(t	 t
    } t d |   q-Xn Xy! t j | }	 t |	  | }
 Wn+ t k
 r{t d d | | f   n X|
 d  | |  } t j d	 |
  | S(
   Ns5   don't know how to compile C/C++ code on platform '%s's    with '%s' compilers   numpy.distutils.s,   %s in numpy.distutils; trying from distutilsi   s4   can't compile C/C++ code: unable to load module '%s's4   can't compile C/C++ code: unable to find class '%s' s   in module '%s's   new_compiler returns %s(   R>   R   R   t   get_default_compilert   compiler_classt   KeyErrorR   t
   __import__t   ImportErrort   strR   R   RH   R   R:   t   modulest   varsR   (   t   platR   t   verboset   dry_runR   t   module_namet
   class_namet   long_descriptionRU   t   moduleR@   (    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   new_compiler  sD    

	
c         C` s_   t  |  | | |  } g  } x= | D]5 } t |  rJ | j t |   q" | j |  q" W| S(   N(   t   _distutils_gen_lib_optionsR   t   extendRG   Rc   (   R   R   t   runtime_library_dirsR   R   t   lib_optsRk   (    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   gen_lib_options  s    	t   msvc9R   t   _msvct   bcppt   cygwinct   emxct   unixcs
   distutils.R   R+  (    (   R  R  s(   Intel C Compiler for 32-bit applications(   R  R
  s7   Intel C Itanium Compiler for Itanium-based applications(   R  R  s(   Intel C Compiler for 64-bit applications(   R  R  s3   Intel C Compiler for 32-bit applications on Windows(   R  R  s3   Intel C Compiler for 64-bit applications on Windows(   R  R  s2   PathScale Compiler for SiCortex-based applications(   s   linux.*R	  (   s   linux.*R  (   s   linux.*R  (   s   linux.*R  (   R  R   (   R  R   (   R  R  s>   Mingw32 port of GNU C Compiler for Win32(for MSC built Python)(   R  R   (   (   R  R   (J   t
   __future__R    R   R   R   RN   R:   R<   R    Rz   RI   R   t	   distutilsR   t   distutils.ccompilert   distutils.errorsR   R   R   R	   t   distutils.sysconfigR
   t   distutils.versionR   t   numpy.distutilsR   t   numpy.distutils.compatR   t   numpy.distutils.exec_commandR   R   t   numpy.distutils.misc_utilR   R   R   R   R   R   R  t   dummy_threadingR>   R|   t   LockRw   t   setRx   R4   RC   RD   t	   CCompilerRV   Rn   R   R   R   R   R   R   R&   R   R  R  t   _default_compilersR  RH   R&  t   _distutils_new_compilerR+  R'  t   _ccR  t   gett   _mR?   (    (    (    s8   lib/python2.7/site-packages/numpy/distutils/ccompiler.pyt   <module>   s   
"(		2		
;-	)		#Q/C	 
 
 
 
 
 

 
	%			"