ó
%}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 m 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 r1e! Z nI e  j" d k rzy# d  d l# Z# e$ e# d ƒ Z Z Wqze k
 rvqz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   Library(   t   sixt   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@   /usr/lib/python2.7/dist-packages/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@   /usr/lib/python2.7/dist-packages/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@   /usr/lib/python2.7/dist-packages/setuptools/command/build_ext.pys	   <genexpr>@   s    s   .abi3s   .pydN(   R   t   get_suffixes(   t   suffixt   _(    (    s@   /usr/lib/python2.7/dist-packages/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@   /usr/lib/python2.7/dist-packages/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@   /usr/lib/python2.7/dist-packages/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&   R3   t   ext_mapR   t   PY3t   getattrR$   t   _get_config_var_837t   lent
   isinstanceR   R7   R8   t   splitextt   shlib_compilert   library_filenamet   libtypet	   use_stubst   _links_to_dynamicR4   R5   (   R)   R@   RA   R?   t   use_abi3t   so_extt   fnt   d(    (    s@   /usr/lib/python2.7/dist-packages/setuptools/command/build_ext.pyR3   f   s"    		c         C   s,   t  j |  ƒ d  |  _ g  |  _ i  |  _ d  S(   N(   R&   t   initialize_optionst   NoneRP   t   shlibsRI   (   R)   (    (    s@   /usr/lib/python2.7/dist-packages/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_optionsR0   t   check_extensions_listRN   R   R[   t   setup_shlib_compilerR1   R2   t
   _full_nameRI   R4   t   links_to_dynamict   FalseRS   RT   R;   R3   t
   _file_nameR7   R8   t   dirnameR5   R:   t   library_dirst   appendR=   t   runtime_library_dirs(   R)   R?   R@   t   ltdt   nsRA   t   libdir(    (    s@   /usr/lib/python2.7/dist-packages/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   R2   t   valuet   macro(    (    s@   /usr/lib/python2.7/dist-packages/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@   /usr/lib/python2.7/dist-packages/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/   R:   R<   (   R)   R?   t	   _compilert   cmd(    (    s@   /usr/lib/python2.7/dist-packages/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@   /usr/lib/python2.7/dist-packages/setuptools/command/build_ext.pys	   <genexpr>Ò   s    (   t   dictt   fromkeysR[   R_   R5   R4   t   anyRq   (   R)   R?   t   lib(    (   Rƒ   R„   s@   /usr/lib/python2.7/dist-packages/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@   /usr/lib/python2.7/dist-packages/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;   R7   R8   R5   R:   R_   R4   (   R    R?   (   R)   (    s@   /usr/lib/python2.7/dist-packages/setuptools/command/build_ext.pys	   <genexpr>Ú   s   c         s   s   |  ] \ } } | | Vq d  S(   N(    (   R    t   baset   fnext(    (    s@   /usr/lib/python2.7/dist-packages/setuptools/command/build_ext.pys	   <genexpr>à   s    (   R0   t	   itertoolst   productt!   _build_ext__get_output_extensionst   list(   R)   t   ns_ext_basest   pairs(    (   R)   s@   /usr/lib/python2.7/dist-packages/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@   /usr/lib/python2.7/dist-packages/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_   R7   R8   R5   R4   t   existsR   R.   t   opent   writet   if_dlR9   Rb   t   closet   distutils.utilR—   R>   R/   R”   t   unlink(   R)   t
   output_dirR?   t   compilet	   stub_filet   fR—   R”   (    (    s@   /usr/lib/python2.7/dist-packages/setuptools/command/build_ext.pyR<   è   sP    				(   t   __name__t
   __module__R'   R(   R3   RY   R\   R^   R}   R   R`   R‰   RŠ   R   Ra   R<   (    (    (    s@   /usr/lib/python2.7/dist-packages/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@   /usr/lib/python2.7/dist-packages/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   AssertionErrorR7   R8   R4   RO   RQ   t
   startswitht   create_static_lib(   R)   R©   Rª   R¡   Rq   Rd   Rf   R|   R«   R¬   R­   R®   R¯   RA   R9   R?   (    (    s@   /usr/lib/python2.7/dist-packages/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   (   R2   (    (    s@   /usr/lib/python2.7/dist-packages/setuptools/command/build_ext.pyRL   A  s    	(*   R7   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   t   setuptools.externR   t   Cython.Distutils.build_extR&   t   ImportErrorR
   R   R   Ra   R   RS   RR   R   R>   R2   t   dlt   hasattrR   R$   RZ   Rx   RL   (    (    (    s@   /usr/lib/python2.7/dist-packages/setuptools/command/build_ext.pyt   <module>   sV   

					Ð			