
Xc        	   @` 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 m Z d  d l	 m
 Z
 d  d l Td  d l 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 d  d l m Z m Z m Z m Z m Z d   Z  d d  Z" e  e# d e"  d  d d  Z$ e  e# d e$  d d d d  d d d d  Z% e  e# d e%  dP d  Z& e  e# d e&  d   Z' d   Z( e  e# d e(  d  d  Z) e  e# d e)  d d d d  Z* e+ d  g d  Z, e  e# d e,  d    Z- e  e# d! e-  dQ e. d% <dR e. d( <dS e. d+ <dT e. d. <dU e. d1 <dV e. d5 <e
 j/ dW dX dY dZ d[ d\ f 7_/ e j0 d8 k rd] e. d< <e   re j1 d=  d_ e
 j/ e
 _/ qn  e2 Z3 d d d  d  d  d>  Z2 e2 e
 _2 e4 Z5 d?   Z4 e4 e
 _4 x\ d@ dA dB dC dD dE dF g D]? Z6 e j7 j8 dG e6 dH  Z9 e9 d k	 r e: e9 dI e4  q q We; Z< dJ   Z; e; e
 _; d  d l= Z= e j> dK e= j?  Z@ e j> dL  ZA e j> dM  ZB e j> dN  ZC dO   ZD eD e
 _D d S(`   i    (   t   divisiont   absolute_importt   print_functionN(   t   copy(   t	   ccompiler(   t   *(   t   DistutilsExecErrort   DistutilsModuleErrort   DistutilsPlatformError(   t   customize_compiler(   t   LooseVersion(   t   log(   t   get_exception(   t   exec_command(   t	   cyg2win32t   is_sequencet   mingw32t
   quote_argst   get_num_build_jobsc         ` 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   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   <lambda>   s    (   t   syst   version_infot   typest
   MethodTypet   Nonet   setattr(   t   klasst   method_nameR   t   m(    (   R   s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   replace_method   s    c         C` s   | d k r9 | } t |  r9 d j t |   } q9 n  t j |  t |  \ } } | r t |  r d j t |   } n  y t |  Wn t k
 r n Xt	 j
 d |  r d } n d } t d | | | f   n  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    s   Too many open filess2   
Try rerunning setup command until build succeeds.t    s)   Command "%s" failed with exit status %d%sN(   R   R   t   joint   listR   t   infoR   t   printt   UnicodeErrort   ret   searchR   (   R   t   cmdt   displayt   st   ot   msg(    (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   CCompiler_spawn   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   t   ost   patht   splitextt   normpatht
   splitdrivet   isabst
   startswitht   rfindt   basenamet   abspatht   src_extensionst   UnknownFileErrorR$   t   obj_extensiont   append(   R   t   source_filenamest	   strip_dirt
   output_dirt	   obj_namest   src_namet   baset   extt   it   dt   obj_name(    (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   CCompiler_object_filenamesK   s&    	$
t   object_filenamesc	         ` s+  | s
 g  St  j d d k  r< 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 r%t |  } t |  } n  |
 |  rZ| |  rZ| j
 | | | f f  qv| j
 | | | f f  qqW| } x' | D] } | |  qWn | j   } t   } t |  d k r| d k r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.

    i    i   i   (   t	   FCompilert	   is_f_filet   has_f90_headert   f77t   f90t   fixt	   compiler_s   Fortran %s compiler: %sR"   s   
s   C compiler: %s
s   compile options: '%s's   
extra options: '%s'c         ` s2   |  \ } \ } }  j  | | |      d  S(   N(   t   _compile(   R   t   objt   srcRF   (   t   cc_argst   extra_postargst   pp_optsR   (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   single_compile   s    t   absoftN(   R   R   t	   fcompilerRL   RM   RN   t   numpy.distutils.fcompilert
   isinstancet   getattrR   R?   R$   t   compiler_soR   R&   t   _setup_compilet   _get_cc_argsR%   t   keyst   compiler_typeR   t   itemsR   t   lent   multiprocessing.poolt   poolt
   ThreadPoolt   mapt   close(   R   t   sourcesRB   t   macrost   include_dirst   debugt   extra_preargsRW   t   dependsRL   RM   RN   R,   t   fct   fcompt   ccompt   objectst   buildRY   t   objects_to_buildt   f77_objectst   other_objectsRT   RU   RF   t   build_itemsR.   t   jobst   multiprocessingRg   (    (   RV   RW   RX   R   s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   CCompiler_compilez   sb    )$	 	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(   R+   t   ignore(    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   allow  s    Rm   t   definet   undeft	   librariest   library_dirst   rpatht   link_objectsN(   R   R&   t	   __class__t   __name__t   set_include_dirsRm   R   t   define_macroR   t   undefine_macrot   set_librariesR   t   set_library_dirsR   t   set_runtime_library_dirsR   t   set_link_objectsR   (   R   R+   R   R   t   namet   valuet   macro(    (   R+   R   s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   CCompiler_customize_cmd   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 Wg  } d t | d  d } x | D] } | j | |  q Wd j	 |  S(   Ni    t   versionR   R   t   object_switcht   compile_switchRm   R   R   R   R   s   %-i   s   s = %ss   
(
   R%   t   executablesRb   R?   t   hasattrR^   t   maxRe   t   reprR$   (	   t   compilert   propst   mxRb   t   keyt   vt   linest   formatt   prop(    (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   _compiler_to_string  s$     c         C` sj   y |  j    Wn n Xt j j d k  rf 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_versionR   t   _global_logt	   thresholdR'   R   R   (   R   (    (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   CCompiler_show_customization,  s    t   show_customizationc         C` s:  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  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 N(   R   s   g++(   s   ccs   c++(   R   R&   R   R   R	   R_   t   removet   AttributeErrort
   ValueErrorR   R   R   R8   t   replacet   warn(   R   t   distt   need_cxxt   at   b(    (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   CCompiler_customizeQ  s&    
"	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   
R"   i    (   R   R)   t   matchR   t   endt   TrueR*   t   group(   R   t   version_stringt   posR    (   R   t   patt   start(    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   matcher  s     	!(    (   R   R   R   R   (    (   R   R   R   s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   simple_version_match  s    c         ` s  | 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 Xt | d 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   (   R)   R   R   R   (   R   R    R   (   R   (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyR     s
    t   use_teeN(
   R   R   t   find_executablest   version_cmdR   R   t   version_matcht   version_patternR   R
   (   R   t   forcet	   ok_statusR   R   t   statust   outputR   (    (   R   s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   CCompiler_get_version  s2    
	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   (   s   msvcR   R   (   Rc   R   R   R_   R   t   platformR8   t	   linker_so(   R   t   cxx(    (    s8   /tmp/pip-build-X4mzal/numpy/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   R2   R   t   get_default_compilert   compiler_classt   KeyErrorR   t
   __import__t   ImportErrort   strR   R   R&   R   R   t   modulest   varsRn   (   t   platR   t   verboset   dry_runR   t   module_namet
   class_namet   long_descriptionR/   t   moduleR   (    (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   new_compiler/  sD    

	
c         C` sw   t  |  } t  |  } t |  | | |  } g  } x= | D]5 } t |  rb | j t |   q: | j |  q: W| S(   N(   R   t   _distutils_gen_lib_optionsR   t   extendR%   R?   (   R   R   t   runtime_library_dirsR   t   rt   lib_optsRG   (    (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   gen_lib_options[  s    	t   msvc9R   t   _msvct   bcppt   cygwinct   emxct   unixcs
   distutils.R   R   c         C` s   t  |  } t |  |  S(   N(   R   t!   _distutils_gen_preprocess_options(   Rl   Rm   (    (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   gen_preprocess_optionsr  s    s   [^\\\'\"%s ]*s   '(?:[^'\\]|\\.)*'s   "(?:[^"\\]|\\.)*"s   \sc         C` s  |  j    }  g  } d } x|  rt j |  |  } | j   } | t |   k rf | j |  |   Pn  |  | t j k r | j |  |   |  | j   }  d } n(|  | d k r |  |  |  | d }  | d } n |  | d k r t	 j |  |  } n9 |  | d k r t
 j |  |  } n t d |  |   | d  k rWt d |  |   n  | j   \ } } t j |  | d | d ! r|  |  |  | d | d !|  | }  | j   d } n | j   } | t |   k r | j |   Pq q W| S(	   Ni    s   \i   t   't   "s!   this can't happen (bad char '%c')s"   bad string (mismatched %s quotes?)i   (   t   stript   _wordchars_reR   R   Re   R?   t   stringt
   whitespacet   lstript
   _squote_ret
   _dquote_ret   RuntimeErrorR   R   t   spant   _has_white_reR*   (   R-   t   wordsR   R    R   t   beg(    (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   split_quoted  s@    		%(    (   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.*s   intel(   s   linux.*R   (   s   linux.*R   (   s   linux.*R   (   s   nts   intelw(   s   nts   intelemw(   R   s   Mingw32CCompilers>   Mingw32 port of GNU C Compiler for Win32(for MSC built Python)(   s   nts   mingw32(   (   s   nts   mingw32(E   t
   __future__R    R   R   R2   R)   R   R   R   t	   distutilsR   t   distutils.ccompilert   distutils.errorsR   R   R   t   distutils.sysconfigR	   t   distutils.versionR
   t   numpy.distutilsR   t   numpy.distutils.compatR   t   numpy.distutils.exec_commandR   t   numpy.distutils.misc_utilR   R   R   R   R   R!   R   R0   t	   CCompilerRJ   R|   R   R   R   R   R   t   FalseR   R   R   t   _default_compilersR   R&   R   t   _distutils_new_compilerR   R   t   _ccR   t   gett   _mR   R  R  R  R}   R	  R  R  R  R  R  (    (    (    s8   /tmp/pip-build-X4mzal/numpy/numpy/distutils/ccompiler.pyt   <module>   s   
(		*-	o)		#9/5	 
 
 
 
 
 

 
	%			"			/