ó
\K]c           @` sŒ  d  d l  m Z m Z m Z d  d l m Z m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z d  d l j j Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z m Z d  d l m Z i d d 6d d 6Z d „  Z e j e d  ƒ Z e j e d ƒ Z e d „  ƒ Z d „  Z  e  ƒ  Z! d e" f d „  ƒ  YZ# d e" f d „  ƒ  YZ$ d „  Z% d d d „ Z' d „  Z( d „  Z) d S(   i    (   t   print_functiont   divisiont   absolute_import(   t	   CCompilert   new_compiler(   t	   build_ext(   t   customize_compiler(   t   logN(   t   NamedTemporaryFilet   mkdtempt
   gettempdir(   t   contextmanagers   .dlls   .pydt   wins   .sot   defaultc         C` s   t  j t j d  t  d ƒ |  S(   Ni   R   (   t   _configst   gett   syst   platform(   t   arg(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   get_configs   s    i   c         c` sn   z4 t  ƒ  } t t j j | d |  ƒ d ƒ } | VWd  y | j ƒ  t j | ƒ Wn n Xt j | ƒ Xd  S(   Ns   temp%st   wt(   R	   t   opent   ost   patht   joint   closet   removet   rmdir(   t   suffixt   tmpdirt   ntf(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   _gentmpfile   s    	"	
c       	   C` sŸ   t  ƒ  }  t |  ƒ x… d d g D]w } y\ t | ƒ J } d } | j | ƒ | j ƒ  | j ƒ  |  j | j g d t ƒ  ƒWd  QXWq  t	 k
 r– t
 SXq  Wt S(   Ns   .cs   .cxxs   int main(void) { return 0; }t
   output_dir(   R   R   R   t   writet   flushR   t   compilet   nameR
   t	   Exceptiont   Falset   True(   t   compilerR   R   t   simple_c(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   _check_external_compiler0   s    	


&	t   _DummyExtensionc           B` s   e  Z g  Z RS(    (   t   __name__t
   __module__t	   libraries(    (    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyR+   H   s   t	   Toolchainc           B` s‰   e  Z d  „  Z e d „  ƒ Z e j d „  ƒ Z d „  Z d
 d d d d „ Z d d d d d „ Z	 d „  Z
 d „  Z d „  Z d	 „  Z RS(   c         C` s˜   t  s |  j ƒ  n  d d l m } t |  _ t ƒ  |  _ t |  j ƒ t	 | ƒ  ƒ |  _
 |  j
 j ƒ  |  j
 j |  _ |  j
 j |  _ t j d ƒ |  _ d  S(   Ni    (   t   Distributiont   npymath(   t   _external_compiler_okt   _raise_external_compiler_errort   distutils.distR0   R&   t   _verboseR   t	   _compilerR   R   t
   _build_extt   finalize_optionst   library_dirst   _py_lib_dirst   include_dirst   _py_include_dirst   np_misct   get_infot
   _math_info(   t   selfR0   (    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   __init__N   s    	c         C` s   |  j  S(   N(   R5   (   R@   (    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   verbose]   s    c         C` s,   | |  _  t j | r t j n t j ƒ d  S(   N(   R5   R   t   set_thresholdt   INFOt   WARN(   R@   t   value(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyRB   a   s    	c         C` së   d } d } t  j } | j d ƒ rn t  j d k rB d d g } n d d	 g } d
 | | d j | ƒ f } nm | j d ƒ r© d d g } d
 | | d j | ƒ f } n2 | j d ƒ rÑ d } d
 | | f } n
 d | } t | ƒ ‚ d  S(   NsY   Attempted to compile AOT function without the compiler used by `numpy.distutils` present.s(   If using conda try:

#> conda install %st   linuxi   i    s   gcc_linux-32s   gxx_linux-32s   gcc_linux-64s   gxx_linux-64s   %s %st    t   darwins   clang_osx-64s   clangxx_osx-64t   win32s   Cannot find suitable msvc.s   Unknown platform %sI       (   R   R   t
   startswitht   maxsizeR   t   RuntimeError(   R@   t   basemsgt	   conda_msgt   pltt	   compilerst   msgt   winmsg(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyR3   h   s     	  
c         C` s:   |  j  j | d | d | d | d | p* g  d | ƒ} | S(   sÖ  
        Compile the given source files into a separate object file each,
        all beneath the *output_dir*.  A list of paths to object files
        is returned.

        *macros* has the same format as in distutils: a list of 1- or 2-tuples.
        If a 1-tuple (name,), the given name is considered undefined by
        the C preprocessor.
        If a 2-tuple (name, value), the given name is expanded into the
        given value by the C preprocessor.
        R    R;   t   dependst   macrost   extra_preargs(   R6   R#   (   R@   t   sourcesR    R;   RT   RU   t   extra_cflagst   objects(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   compile_objects}   s    	c   	      C` sJ   t  j j | ƒ \ } } |  j j t j | | | | | d | d | ƒd S(   su   
        Create a shared library *output* linking the given *objects*
        and *libraries* (all strings).
        t   export_symbolsRV   N(   R   R   t   splitR6   t   linkR   t   SHARED_OBJECT(	   R@   t   outputRY   R.   R9   R[   t   extra_ldflagsR    t   output_filename(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   link_shared“   s    	c         C` sC   |  j  j t ƒ  ƒ } t j d k r4 | d g } n  | |  j d S(   sJ   
        Get the library arguments necessary to link with Python.
        RJ   t   msvcrtR.   (   R7   t   get_librariesR+   R   R   R?   (   R@   t   libs(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   get_python_libraries¡   s    c         C` s   t  |  j ƒ |  j d S(   sL   
        Get the library directories necessary to link with Python.
        R9   (   t   listR:   R?   (   R@   (    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   get_python_library_dirs­   s    c         C` s   t  |  j ƒ |  j d S(   so   
        Get the include directories necessary to compile against the Python
        and Numpy C APIs.
        R;   (   Rg   R<   R?   (   R@   (    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   get_python_include_dirs³   s    c         C` s   |  j  j | ƒ S(   sR   
        Given a C extension's module name, return its intended filename.
        (   R7   t   get_ext_filename(   R@   t   ext_name(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyRj   º   s    (    (    (    N(    (    (    (   R,   R-   RA   t   propertyRB   t   setterR3   t   NoneRZ   Rb   Rf   Rh   Ri   Rj   (    (    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyR/   L   s   						c          C` s(   d d  l  j j }  |  j } t |  _ d  S(   Ni    (   t   numpy.distutils.exec_commandt	   distutilst   exec_commandt   _exec_command(   t   modt   orig_exec_command(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   _patch_exec_commandÇ   s    	c   	      K` s²  | d k r t j d k } n  | d k r< t j d k } n  d } t j d k r« | r« t j j d d ƒ } t |  ƒ r“ | d d j |  ƒ g }  n | d |  g }  t } n7 t j d k râ t |  ƒ râ d j d „  |  Dƒ ƒ }  n  | pë d } y7 t j	 |  d | d	 | d
 t j
 d t j
 d t ƒ} Wn t k
 r9d SX| j ƒ  \ } } | j ru| rh| d 7} n  | | 7} n  | d d k r’| d  } n  | r¥t | ƒ n  | j | f S(   sg   
    Internal workhorse for exec_command().
    Code from https://github.com/numpy/numpy/pull/7862
    t   posixt   SHELLs   /bin/shs   -cRH   t   ntc         s` s   |  ] } t  | ƒ Vq d  S(   N(   t
   _quote_arg(   t   .0R   (    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pys	   <genexpr>æ   s    t   shellt   envt   stdoutt   stderrt   universal_newlinest    i   s   
iÿÿÿÿN(   R€   i   (   Rn   R   R$   t   environR   t   _is_sequenceR   R&   t
   subprocesst   Popent   PIPER'   t   EnvironmentErrort   communicatet
   returncodet   print(	   t   commandt	   use_shellt   use_teeR|   t
   executablet   sht   proct   textt   err(    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyRr   Î   s>    				c         C` s$   d |  k r  d |  k r  d |  S|  S(   sB   
    Quote the argument for safe use in a shell command line.
    t   "RH   s   "%s"(    (   R   (    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyRy     s    c         C` sD   t  |  t t f ƒ r t Sy t |  ƒ t SWn t k
 r? t SXd  S(   N(   t
   isinstancet   strt   bytesR&   t   lenR'   R%   (   R   (    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyR‚     s    
(   s   .dlls   .pyd(   s   .sos   .so(*   t
   __future__R    R   R   t   distutils.ccompilerR   R   t   distutils.command.build_extR   t   distutils.sysconfigR   Rp   R   t   numpy.distutils.misc_utilt	   misc_utilR=   t	   functoolsR   Rƒ   R   t   tempfileR   R	   R
   t
   contextlibR   R   R   t   partialt   find_shared_endingt   find_pyext_endingR   R*   R2   t   objectR+   R/   Ru   Rn   Rr   Ry   R‚   (    (    (    s2   lib/python2.7/site-packages/numba/pycc/platform.pyt   <module>   s4   
			{	3	