
R!Mc           @   s  d  d l  m  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 m Z d   Z d   Z e   Z e   Z i e d	 6e d
 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6Z d   Z d e f d     YZ d d  Z d   Z d e f d     YZ d a d d  Z g  d d d   Z g  d! d e d"  Z  d d#  Z! d$   Z" d S(%   i(   t   globN(   t   set(   t	   Extension(   t   Utils(   t   Contextt   CompilationOptionst   default_optionsc            s#   d  j       f d   } | S(   Ns
   __%s_cachec            sf   t  |   d   } | d  k r7 i  } t |   |  n  | | k rK | | S  |  |  } | | <| S(   N(   t   getattrt   Nonet   setattr(   t   selft   argst   cachet   res(   t   ft
   cache_name(    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   wrapper   s    (   t   __name__(   R   R   (    (   R   R   s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   cached_method   s    	c            s   |  d d k r6 |  d d k r6 |  d d !}  d } n d } t  |   \ }      f d   } g  |  j |  D] } | |  ^ qm S(	   Ni    t   [it   ]i   t   ,t    c            s3   |  j    }  |  d d k r+   |  d d !S|  Sd  S(   Ni    t   'i   i(   t   strip(   t   literal(   t   literals(    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   unquote!   s    (   t   strip_string_literalst   split(   t   st	   delimiterR   t   item(    (   R   s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt
   parse_list   s     	t   namet   sourcest   define_macrost   undef_macrost	   librariest   library_dirst   runtime_library_dirst   include_dirst   extra_objectst   extra_compile_argst   extra_link_argst   export_symbolst   dependst   languagec         c   sX   d } xK t  rS |  j d |  } | d k r: |  | Vd  S|  | | !V| d } q	 Wd  S(   Ni    s   
ii   (   t   Truet   find(   t   sourcet   startt   end(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt	   line_iter>   s    		t   DistutilsInfoc           B   s)   e  Z d d d   Z d   Z d   Z RS(   c   	      C   s  i  |  _  | d  k	 r0xrt |  D]} | j   } | d k rT | d d k rT Pn  | d j   } | d  d k r" | d } | j d  } t | |  j    } | | d j   } t | } | t t f k rt	 |  } | d k rg  | D] } t
 | j d   ^ q } qn  | |  j  | <q" q" WnZ | d  k	 rxK t D]@ } | d k r[qCn  t | | d   } | rC| |  j  | <qCqCWn  d  S(   Nt    i    t   #i   i
   s
   distutils:t   =R$   R"   R#   (   s   names   sources(   t   valuesR   R5   R   t   indext   strt   distutils_settingst   listt   transitive_listR!   t   tupleR   R   (	   R
   R2   t   exnt   linet   ixt   keyt   valuet   typet   macro(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   __init__J   s2    	

.c         C   s   | d  k r |  Sx | j j   D] \ } } t | } | t k ra | |  j k ra | |  j | <q  | t k r  | |  j k r |  j | } x: | D]" } | | k r | j |  q q Wq | |  j | <q  q  W|  S(   N(   R   R:   t   itemsR=   t   transitive_strR?   t   append(   R
   t   otherRD   RE   RF   t   allt   v(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   mergee   s    
c         C   s   | d  k r |  St   } x |  j j   D] \ } } t | } | t t g k r g  } xP | D]H } | | k r} | | } n  t | t  r | | 7} q^ | j |  q^ W| } n | | k r | | } n  | | j | <q) W| S(   N(	   R   R6   R:   RI   R=   R>   R?   t
   isinstanceRK   (   R
   t   aliasest   resolvedRD   RE   RF   t   new_value_listRN   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   subsv   s$    	
	N(   R   t
   __module__R   RH   RO   RT   (    (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyR6   H   s   	t   __Pyx_Lc      
   C   s  g  } i  } d } d } } t  } t  } xTt r~|  j d |  }	 |  j d |  }
 |  j d |  } t |
 |  } | d k r t |
 |  } n  | d k r |	 d k r | j |  |  Pq+ | r|  | d d k r<| r<d } x. | | k r|  | | d k r| d 7} q W| d d k r<| d 7} q+ q<n  |  | | t |  !| k r| d 7} d	 | | f } |  | t |  | !| | <| j d
 | | | f  | t |  7} t  } | } q{| d 7} q+ d |	 k r|	 | k  s| d k r|  j d |	  } | d k rd } n  | j |  | |	 d ! | d 7} d	 | | f } |  |	 d | !| | <| j |  | d k rPn  | } | } q+ t  } t |   | d k r|  | d |  | k o|  | d k n r|  | d } n
 |  | } | } } xK | d k rP|  | d d k rP|  | d d k rCt } n  | d 8} qW| j |  | | ! | } | t |  7} q+ Wd j |  | f S(   s   
    Normalizes every string literal to be of the form '__Pyx_Lxxx',
    returning the normalized code and a mapping of labels to
    string literals.
    i    R8   R   t   "ii   s   \i   s   %s%s_s   %s%s%ss   
i   t   rRbBuUt   rRR7   N(	   t   FalseR0   R1   t   mint   maxRK   t   lenR   t   join(   t   codet   prefixt   new_codeR   t   counterR3   t   qt   in_quotet   rawt	   hash_markt   single_qt   double_qt   kt   labelR4   t   marker(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyR      sv    
	 #
	
	$	
	F

#	c         C   sK  t  j |  d  } z | j   } Wd  | j   Xt |  } t |  \ } } | j d d  } d | k r | j d d  } n  t j d  } g  } g  } g  } x | j	 |  D] }	 |	 j
   }
 |
 d r | j |
 d  q |
 d r | j |
 d	  q |
 d
 r"| j | |
 d  q | j | |
 d  q W| | | | f S(   Nt   rUs   \
R   s   	st   (cimport +([0-9a-zA-Z_.]+)\b)|(from +([0-9a-zA-Z_.]+) +cimport)|(include +'([^']+)')|(cdef +extern +from +'([^']+)')i    i   i   i   i   i   i   (   R   t   open_source_filet   readt   closeR6   R   t   replacet   ret   compilet   finditert   groupsRK   (   t   source_filenamet   fhR2   t   distutils_infoR   t
   dependancyt   cimportst   includest   externst   mRt   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   parse_dependencies   s.    


t   DependencyTreec           B   s   e  Z d    Z d   Z e e  Z d   Z e e  Z d   Z d   Z e e  Z d   Z e e  Z d d  Z
 e e
  Z
 d   Z e e  Z d   Z d	   Z e e  Z d
   Z d   Z d   Z d d d  Z d   Z d   Z RS(   c         C   s   | |  _  i  |  _ d  S(   N(   t   contextt   _transitive_cache(   R
   R   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyRH      s    	c         C   s
   t  |  S(   N(   R}   (   R
   Ru   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyR}     s    c   	      C   s   |  j  |  d  \ } } } t |  } t |  } x | D] } t j j t j j |  |  } t j j |  s |  j j | d   } n  | r |  j
 |  \ } } | j |  | j |  q; d | | f GHq; Wt |  t |  f S(   Ni   s*   Unable to locate '%s' referenced from '%s'(   R}   R   t   ost   pathR^   t   dirnamet   existsR   t   find_include_fileR   t   cimports_and_externst   updateR@   (	   R
   t   filenameRy   Rz   R{   t   includet   include_patht   at   b(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyR     s    !c         C   s   |  j  |  d S(   Ni    (   R   (   R
   R   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyRy     s    c         C   s[   t  j j |  } t  j j t  j j | d   rS |  j |  t  j j |  f Sd Sd  S(   Ns   __init__.py(    (   R   R   R   R   R^   t   packaget   basename(   R
   R   t   dir(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyR     s    ! c         C   s?   t  j j t  j j |   d } d j |  j |  | f  S(   Ni    t   .(   R   R   t   splitextR   R^   R   (   R
   R   t   module(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   fully_qualifeid_name%  s    "c         C   s   | d d k r t  d   n  | d  k	 rx d j |  j |  t | j d    } |  j j | d   } | rx | Sn  |  j j | d   S(   Ni    R   s   New relative imports.(   t   NotImplementedErrorR   R^   R   R@   R   R   t   find_pxd_file(   R
   R   R   t   relativet   pxd(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   find_pxd*  s    +c      
   C   s  | d d k r> t  j j | d  d  r> | d  d g } n g  } |  j |  } t d  g  |  j |  D] } |  j | |  ^ qi  } t |  t d | k  t |  k r d | f GHd j	 |  GHd j	 |  GHn  t
 | t d  g  |  j |  D] } |  j | |  ^ q   S(   Nis   .pyxs   .pxdt   cythons   missing cimports   
	(   R   R   R   Ry   t   filterR   R   R]   t   intR^   R@   (   R
   R   t   self_pxdR   R|   R   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   cimported_files6  s    *7(c         C   sv   t  |  j |   } xT t |  j |  d  D]: } | j t j j t j j t j j	 |  |    q. Wt
 |  S(   N(    (   R>   R   t   sumR   RK   R   R   t   normpathR^   R   R@   (   R
   R   RM   t   extern(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   immediate_dependenciesD  s    8c         C   s   t  j j |  S(   N(   R   R   t   getmtime(   R
   R   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt	   timestampK  s    c         C   s   |  j  |  | f S(   N(   R   (   R
   R   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   extract_timestampO  s    c         C   s   |  j  | |  j t  S(   N(   t   transitive_mergeR   R\   (   R
   R   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   newest_dependencyS  s    c         C   s   |  j  |  d S(   Ni   (   R}   (   R
   R   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   distutils_info0V  s    c         C   s+   |  j  | |  j t j  j |  j |  S(   N(   R   R   R6   RO   RT   (   R
   R   RQ   t   base(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyRw   Y  s    	c         C   se   y |  j  | | f } Wn( t k
 rA i  } |  j  | | f <n X|  j | | | | i  |  j  d S(   Ni    (   R   t   KeyErrort   transitive_merge_helperR   (   R
   t   nodet   extractRO   t   seen(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyR   ^  s    c         C   s  | | k r | | d  f S| |  } | | k r< | | f Sz t |  | | <d  } x | |  D]q }	 |  j |	 | | | | |  \ }
 } | d  k	 r | d  k	 r | | | | k  r q | } n  | | |
  } qb W| | k r d  } n  | d  k r| | | <n  | | f SWd  | | =Xd  S(   N(   R   R]   R   (   R
   R   R   RO   R   t   stackt   outgoingt   depst   loopt   nextt   sub_depst   sub_loop(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyR   f  s*    
$ 		N(   R   RU   RH   R}   R   R   Ry   R   R   R   R   R   R   R   R   R   R   Rw   R   R   (    (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyR~      s.   														c         C   sF   t  d  k rB |  d  k r3 t d g t t   }  n  t |   a  n  t  S(   NR   (   t	   _dep_treeR   R   R   R   R~   (   t   ctx(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   create_dependency_tree  s
    c      	   C   sH  t    } t |  } t    } t | t  s9 | g } n  x! | D] } | j t |   q@ Wt |  t  sx |  g }  n  g  } x|  D]} t | t  r | }	 d  }
 d } d  } t } n t | t  r0| j	 d }	 t
 j j |	  d d
 k r| j |  q n  | }
 |
 j } t d |
  } |
 j } n t |   xt |	  D] } | | k raqIn  | j |  } d | k r| j |  } n | } | | k rI| j | | |  j } | d  k	 r x9 | j j   D]% \ } } | | k r| | | <qqWn  | j | d | d | g |   | d	 } | j |  qIqIWq W| S(   Nt   *i    i   s   .pys   .pyxRA   R"   R#   i(   s   .pys   .pyx(   R   R   RP   R>   R   R    R<   R   R   R#   R   R   R   RK   R"   R6   t	   __class__t	   TypeErrorR   R   Rw   R:   RI   t   add(   t   patternst   excludeR   RQ   R   R   t
   to_excludet   patternt   module_listt   filepatternt   templateR"   R   t   exn_typet   filet   pkgt   module_namet   kwdsRD   RE   R|   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   create_extension_list  s^    				

i    c         K   s  d | k r d g | d <n  t  |   } t  |   } t | _ | j   } t |  d | d | d | }  t |  }	 g  }
 x|  D]} g  } xk| j D]`} t j j	 |  \ } } | d k r| j
 d k r | d	 } | } n | d
 } | } t j j |  rt j j |  } n d } | |	 j |  k  rS|	 j |  | } } d } n. |	 j |  \ } } d | |	 j |  k } | | k  r| s| | k rd | GHqd | | f GHn  |
 j | | | | f  n  | j |  q | j |  q W| | _ q W|
 j   | rhy/ d d  l } | j |  } | j t |
  Wqht k
 rdd GHd } qhXn  | sx- |
 D]" \ } } } } t | | |  quWn  |  S(   NR   R   R   R   RQ   s   .pyxs   .pys   c++s   .cpps   .cii    i   s    Compiling %s because it changed.s&   Compiling %s because it depends on %s.s3   multiprocessing required for parallel cythonization(   s   .pyxs   .py(   R   R0   t   cplust   create_contextR   R   R#   R   R   R   R/   R   R   R   R   R   RK   t   sortt   multiprocessingt   Poolt   mapt   cythonize_one_helpert   ImportErrort   cythonize_one(   R   R   t   nthreadsRQ   t   quiett   optionst	   c_optionst   cpp_optionsR   R   t
   to_compileR|   t   new_sourcesR2   R   t   extt   c_filet   c_timestampt   dep_timestampt   dept   priorityR   t   poolt   pyx_file(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt	   cythonize  sj     		
	
	
c   
      C   s   d d l  m } m } d d l m } m } | d  k rG t |  } n  | | _ d } y. | |  g |  } | j	 d k r d } n  Wn9 t
 | f k
 r }	 t j j t |	  d  d } n X| r | d  |    n  d  S(   Ni(   Rr   R   (   t   CompileErrort
   PyrexErrori    i   s   
(   t   Cython.Compiler.MainRr   R   t   Cython.Compiler.ErrorsR   R   R   R   t   output_filet
   num_errorst   EnvironmentErrort   syst   stderrt   writeR<   (
   R   R   R   Rr   R   R   R   t   any_failurest   resultt   e(    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyR     s    	
c         C   s   t  |  d   S(   Ni   (   R   (   R|   (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyR     s    (#   R    Rq   R   R   R   R   t   distutils.extensionR   t   CythonR   R   R   R   R   R   R!   t   objectRJ   R?   R<   R>   R=   R5   R6   R   R}   R~   R   R   R   R   RZ   R   R   R   (    (    (    s:   C:\Python27\Lib\site-packages\Cython\Build\Dependencies.pyt   <module>   sF   $				
	
EN	 	5?