ó
âq^c           @   so  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 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 m Z e j rů d  d l Z g  e j   D]$ \ Z Z Z e e j k rĚ e ^ qĚ Z n d  d
 l m Z y d  d l m Z e  d  Wn e! k
 r@e Z n Xe d  d  d l
 m" Z# d   Z$ e% Z& e% Z' d Z( e j) d k re* Z' nI e  j+ d k r×y# d  d l, Z, e- e, d  Z' Z& Wq×e! k
 rÓq×Xn  d   Z. d   Z/ d e f d     YZ e' se  j+ d k r>d d d d d d d d d d d 
 Z1 n- d Z( d d d d d d d d d d d 
 Z1 d S(   i˙˙˙˙N(   t	   build_ext(   t	   copy_file(   t   new_compiler(   t   customize_compilert   get_config_var(   t   DistutilsError(   t   log(   t   Library(   t   six(   t   EXTENSION_SUFFIXESs   Cython.Compiler.Maint   LDSHARED(   t   _config_varsc         C   ss   t  j d k re t j   } z, d t d <d t d <d t d <t |   Wd  t j   t j |  Xn
 t |   d  S(   Nt   darwins0   gcc -Wl,-x -dynamiclib -undefined dynamic_lookupR
   s    -dynamiclibt   CCSHAREDs   .dylibt   SO(   t   syst   platformt   _CONFIG_VARSt   copyR   t   cleart   update(   t   compilert   tmp(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyt   _customize_compiler_for_shlib#   s    



t   sharedR   t   ntt   RTLD_NOWc         C   s   t  r
 |  Sd S(   Nt    (   t	   have_rtld(   t   s(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyt   <lambda>D   s    c          C   s5   x. t  D]& }  d |  k r |  S|  d k r |  Sq Wd S(   s;   Return the file extension for an abi3-compliant Extension()s   .abi3s   .pydN(   R	   (   t   suffix(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyt   get_abi3_suffixG   s
    R    c           B   s   e  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 e d  Z RS(   c         C   s@   |  j  d } |  _  t j |   | |  _  | r< |  j   n  d S(   s;   Build extensions in build directory, then copy if --inplacei    N(   t   inplacet
   _build_extt   runt   copy_extensions_to_source(   t   selft   old_inplace(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyR#   Q   s
    	c   
      C   sů   |  j  d  } xă |  j D]Ř } |  j | j  } |  j |  } | j d  } d j | d   } | j |  } t j	 j | t j	 j
 |   } t j	 j |  j |  }	 t |	 | d |  j d |  j | j r |  j | pä t j | t  q q Wd  S(   Nt   build_pyt   .i˙˙˙˙t   verboset   dry_run(   t   get_finalized_commandt
   extensionst   get_ext_fullnamet   namet   get_ext_filenamet   splitt   joint   get_package_dirt   ost   patht   basenamet	   build_libR   R)   R*   t   _needs_stubt
   write_stubt   curdirt   True(
   R%   R'   t   extt   fullnamet   filenamet   modpatht   packaget   package_dirt   dest_filenamet   src_filename(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyR$   Y   s    
	c         C   s  t  j |  |  } | |  j k rţ |  j | } t j oM t | d  oM t   } | r t d  } | t |   } | t   } n  t	 | t
  r˝ t j j |  \ } } |  j j | t  St rţ | j rţ t j j |  \ } } t j j | d |  Sn  | S(   Nt   py_limited_apit
   EXT_SUFFIXs   dl-(   R"   R/   t   ext_mapR   t   PY2t   getattrR    R   t   lent
   isinstanceR   R3   R4   t   splitextt   shlib_compilert   library_filenamet   libtypet	   use_stubst   _links_to_dynamicR0   R1   (   R%   R<   R=   R;   t   use_abi3t   so_extt   fnt   d(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyR/   o   s"    
	c         C   s,   t  j |   d  |  _ g  |  _ i  |  _ d  S(   N(   R"   t   initialize_optionst   NoneRK   t   shlibsRE   (   R%   (    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyRT      s    		c         C   sĆ  t  j |   |  j p g  |  _ |  j |  j  g  |  j D] } t | t  r9 | ^ q9 |  _ |  j rs |  j   n  x& |  j D] } |  j | j	  | _
 q} Wx#|  j D]} | j
 } | |  j | <| |  j | j d  d <|  j rô |  j |  p÷ t } | ot ot | t  } | | _ | | _ |  j |  } | _ t j j t j j |  j |   } | r| | j k r| j j |  n  | rŚ t rŚ t j | j k rŚ | j j t j  qŚ qŚ Wd  S(   NR(   i˙˙˙˙(   R"   t   finalize_optionsR,   t   check_extensions_listRI   R   RV   t   setup_shlib_compilerR-   R.   t
   _full_nameRE   R0   t   links_to_dynamict   FalseRN   RO   R7   R/   t
   _file_nameR3   R4   t   dirnameR1   R6   t   library_dirst   appendR9   t   runtime_library_dirs(   R%   R;   R<   t   ltdt   nsR=   t   libdir(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyRW      s.    				$c         C   sd  t  d |  j d |  j d |  j  } |  _ t |  |  j d  k	 rW | j |  j  n  |  j	 d  k	 r x* |  j	 D] \ } } | j
 | |  qp Wn  |  j d  k	 rĆ x! |  j D] } | j |  qŹ Wn  |  j d  k	 rč | j |  j  n  |  j d  k	 r
| j |  j  n  |  j d  k	 r,| j |  j  n  |  j d  k	 rN| j |  j  n  t j |  | _ d  S(   NR   R*   t   force(   R   R   R*   Re   RK   R   t   include_dirsRU   t   set_include_dirst   definet   define_macrot   undeft   undefine_macrot	   librariest   set_librariesR_   t   set_library_dirst   rpatht   set_runtime_library_dirst   link_objectst   set_link_objectst   link_shared_objectt   __get__(   R%   R   R.   t   valuet   macro(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyRY   §   s(    %
c         C   s&   t  | t  r | j St j |  |  S(   N(   RI   R   t   export_symbolsR"   t   get_export_symbols(   R%   R;   (    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyRx   Â   s    c         C   s   | j    |  j } z` t | t  r4 |  j |  _ n  t j |  |  | j rr |  j d  j	 } |  j
 | |  n  Wd  | |  _ Xd  S(   NR'   (   t   _convert_pyx_sources_to_langR   RI   R   RK   R"   t   build_extensionR7   R+   R6   R8   (   R%   R;   t	   _compilert   cmd(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyRz   Ç   s    
		c            sn   t  j g  |  j D] } | j ^ q    d j | j j d  d  d g   t    f d   | j D  S(   s?   Return true if 'ext' links to a dynamic lib in the same packageR(   i˙˙˙˙R   c         3   s   |  ] }  |   k Vq d  S(   N(    (   t   .0t   libname(   t   libnamest   pkg(    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pys	   <genexpr>Ű   s    (   t   dictt   fromkeysRV   RZ   R1   R0   t   anyRl   (   R%   R;   t   lib(    (   R   R   s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyR[   Ô   s    (&c         C   s   t  j |   |  j   S(   N(   R"   t   get_outputst   _build_ext__get_stubs_outputs(   R%   (    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyR   Ý   s    c            sE     f d     j  D } t j |   j    } t d   | D  S(   Nc         3   s<   |  ]2 } | j  r t j j   j | j j d    Vq d S(   R(   N(   R7   R3   R4   R1   R6   RZ   R0   (   R}   R;   (   R%   (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pys	   <genexpr>ă   s   c         s   s   |  ] \ } } | | Vq d  S(   N(    (   R}   t   baset   fnext(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pys	   <genexpr>é   s    (   R,   t	   itertoolst   productt!   _build_ext__get_output_extensionst   list(   R%   t   ns_ext_basest   pairs(    (   R%   s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyt   __get_stubs_outputsŕ   s    c         c   s(   d Vd V|  j  d  j r$ d Vn  d  S(   Ns   .pys   .pycR'   s   .pyo(   R+   t   optimize(   R%   (    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyt   __get_output_extensionsë   s    c         C   s´  t  j d | j |  t j j | | j j d   d } | rf t j j |  rf t | d   n  |  j	 st
 | d  } | j d j d d d	 t d
  d t j j | j  d d d t d  d d d t d  d d t d  d d d g   | j   n  | r°d d l m } | | g d d d t d |  j	 |  j d   j } | d k r| | g d | d t d |  j	 n  t j j |  r°|  j	 r°t j |  q°n  d  S(!   Ns    writing stub loader for %s to %sR(   s   .pys    already exists! Please delete.t   ws   
s   def __bootstrap__():s-      global __bootstrap__, __file__, __loader__s%      import sys, os, pkg_resources, imps   , dls:      __file__ = pkg_resources.resource_filename(__name__,%r)s      del __bootstrap__s       if '__loader__' in globals():s          del __loader__s#      old_flags = sys.getdlopenflags()s      old_dir = os.getcwd()s      try:s(        os.chdir(os.path.dirname(__file__))s$        sys.setdlopenflags(dl.RTLD_NOW)s(        imp.load_dynamic(__name__,__file__)s      finally:s"        sys.setdlopenflags(old_flags)s        os.chdir(old_dir)s   __bootstrap__()R   i˙˙˙˙(   t   byte_compileR   i    Re   R*   t   install_lib(   R   t   infoRZ   R3   R4   R1   R0   t   existsR   R*   t   opent   writet   if_dlR5   R]   t   closet   distutils.utilR   R:   R+   R   t   unlink(   R%   t
   output_dirR;   t   compilet	   stub_filet   fR   R   (    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyR8   ń   sP    				(   t   __name__t
   __module__R#   R$   R/   RT   RW   RY   Rx   Rz   R[   R   R   R   R\   R8   (    (    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyR    P   s   													i    c         C   s8   |  j  |  j | | | | | | | | |	 |
 | |  d  S(   N(   t   linkt   SHARED_LIBRARY(   R%   t   objectst   output_libnameR   Rl   R_   Ra   Rw   t   debugt   extra_preargst   extra_postargst
   build_tempt   target_lang(    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyRs   #  s
    t   staticc         C   s   | d  k s t  t j j |  \ } } t j j |  \ } } |  j d  j d  rg | d } n  |  j | | | | |  d  S(   Nt   xR   i   (	   RU   t   AssertionErrorR3   R4   R0   RJ   RL   t
   startswitht   create_static_lib(   R%   RĽ   RŚ   R   Rl   R_   Ra   Rw   R§   R¨   RŠ   RŞ   RŤ   R=   R5   R;   (    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyRs   2  s    (2   R3   R   R   t   distutils.command.build_extR    t   _du_build_extt   distutils.file_utilR   t   distutils.ccompilerR   t   distutils.sysconfigR   R   t   distutils.errorsR   t	   distutilsR   t   setuptools.extensionR   t   setuptools.externR   RF   t   impt   get_suffixesR   t   _t   tpt   C_EXTENSIONR	   t   importlib.machineryt   Cython.Distutils.build_extR"   t
   __import__t   ImportErrorR   R   R   R\   R   RN   RM   R   R:   R.   t   dlt   hasattrR   R    RU   Rs   (    (    (    s@   /tmp/pip-build-aSgKnK/setuptools/setuptools/command/build_ext.pyt   <module>   s\   	:

					Đ			