ó
´¼÷Xc           @   s  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	 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 Z y d  d l m Z 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 rvy# d  d l" Z" e# e" d ƒ Z Z Wqve k
 rrqv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 „
 Z' n- d Z d d d d d d d d d d d „
 Z' d „  Z( d S(   iÿÿÿÿN(   t	   build_ext(   t	   copy_file(   t   new_compiler(   t   customize_compilert   get_config_var(   t   DistutilsError(   t   log(   t   Libraryt   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-g7Urym/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-g7Urym/setuptools/setuptools/command/build_ext.pyt   <lambda>;   s    c          C   sN   xG d „  t  j ƒ  Dƒ D]/ \ }  } } d |  k r6 |  S|  d k r |  Sq Wd S(   s;   Return the file extension for an abi3-compliant Extension()c         s   s(   |  ] } | d  t  j k r | Vq d S(   i   N(   t   impt   C_EXTENSION(   t   .0R   (    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pys	   <genexpr>@   s    s   .abi3s   .pydN(   R   t   get_suffixes(   t   suffixt   _(    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyt   get_abi3_suffix>   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-g7Urym/setuptools/setuptools/command/build_ext.pyR&   H   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-g7Urym/setuptools/setuptools/command/build_ext.pyR'   P   s    
	c         C   s  t  j |  | ƒ } | |  j k rý |  j | } t j oL t | d ƒ oL 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%   R2   t   ext_mapt   sixt   PY3t   getattrR#   t   _get_config_var_837t   lent
   isinstanceR   R6   R7   t   splitextt   shlib_compilert   library_filenamet   libtypet	   use_stubst   _links_to_dynamicR3   R4   (   R(   R?   R@   R>   t   use_abi3t   so_extt   fnt   d(    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyR2   f   s"    		c         C   s,   t  j |  ƒ d  |  _ g  |  _ i  |  _ d  S(   N(   R%   t   initialize_optionst   NoneRP   t   shlibsRH   (   R(   (    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyRY   {   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_listRN   R   R[   t   setup_shlib_compilerR0   R1   t
   _full_nameRH   R3   t   links_to_dynamict   FalseRS   RT   R:   R2   t
   _file_nameR6   R7   t   dirnameR4   R9   t   library_dirst   appendR<   t   runtime_library_dirs(   R(   R>   R?   t   ltdt   nsR@   t   libdir(    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyR\      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-   Rj   RP   R   t   include_dirsRZ   t   set_include_dirst   definet   define_macrot   undeft   undefine_macrot	   librariest   set_librariesRd   t   set_library_dirst   rpatht   set_runtime_library_dirst   link_objectst   set_link_objectst   link_shared_objectt   __get__(   R(   R   R1   t   valuet   macro(    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyR^   ž   s(    %
c         C   s&   t  | t ƒ r | j St j |  | ƒ S(   N(   RN   R   t   export_symbolsR%   t   get_export_symbols(   R(   R>   (    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyR}   ¹   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   RN   R   RP   R%   t   build_extensionR:   R.   R9   R;   (   R(   R>   t	   _compilert   cmd(    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyR   ¾   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(    (   R   t   libname(   t   libnamest   pkg(    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pys	   <genexpr>Ò   s    (   t   dictt   fromkeysR[   R_   R4   R3   t   anyRq   (   R(   R>   t   lib(    (   Rƒ   R„   s@   /tmp/pip-build-g7Urym/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-g7Urym/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(   R:   R6   R7   R4   R9   R_   R3   (   R   R>   (   R(   (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pys	   <genexpr>Ú   s   c         s   s   |  ] \ } } | | Vq d  S(   N(    (   R   t   baset   fnext(    (    s@   /tmp/pip-build-g7Urym/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-g7Urym/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-g7Urym/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    Rj   R-   t   install_lib(   R   t   infoR_   R6   R7   R4   R3   t   existsR   R-   t   opent   writet   if_dlR8   Rb   t   closet   distutils.utilR—   R=   R.   R”   t   unlink(   R(   t
   output_dirR>   t   compilet	   stub_filet   fR—   R”   (    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyR;   è   sP    				(   t   __name__t
   __module__R&   R'   R2   RY   R\   R^   R}   R   R`   R‰   RŠ   R   Ra   R;   (    (    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyR    G   s   													i    c         C   s8   |  j  |  j | | | | | | | | |	 |
 | | ƒ d  S(   N(   t   linkt   SHARED_LIBRARY(   R(   t   objectst   output_libnameR¡   Rq   Rd   Rf   R|   t   debugt   extra_preargst   extra_postargst
   build_tempt   target_lang(    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyRx     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   (	   RZ   t   AssertionErrorR6   R7   R3   RO   RQ   t
   startswitht   create_static_lib(   R(   R©   Rª   R¡   Rq   Rd   Rf   R|   R«   R¬   R­   R®   R¯   R@   R8   R>   (    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyRx   )  s    c         C   s"   t  j d k  r d }  n  t |  ƒ S(   sŠ   
    In https://github.com/pypa/setuptools/pull/837, we discovered
    Python 3.3.0 exposes the extension suffix under the name 'SO'.
    i   i   R   (   i   i   i   (   R   t   version_infoR   (   R1   (    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyRL   A  s    	()   R6   R   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   RI   t   Cython.Distutils.build_extR%   t   ImportErrorR	   R   R   Ra   R   RS   RR   R   R=   R1   t   dlt   hasattrR   R#   RZ   Rx   RL   (    (    (    s@   /tmp/pip-build-g7Urym/setuptools/setuptools/command/build_ext.pyt   <module>   sV   

					Ð			