3
h              .   @   s  d dl mZmZ d dlZddlmZ d dlZd dlZd dlZd dl	Z	d dl
Z
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Zyd dlmZ W n  ek
r   d dlmZ Y nX yd dlZejZd	ZW n ek
r   eZd
ZY nX yd dlZejZ W n ek
r,   ej!Z Y nX yd dl"Z"W n   dZ"Y nX ddlm#Z# ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2 e$e	j3j4Z5e$e(Z6e$e'Z7ej8d  dk rej9 Z:e:dkrej; Z:dd Z<ndd Z<e=Z>dXddZ?dd Z@dYddZAe$dd ZBdd ZCdd  ZDeE ZFeE ZGeE ZHe=eIeIeIeGeGeGeGeIeGeGeIeGeFeHd!ZJd"d# ZKejLejMejMd$d%d& ZNG d'd( d(eEZOejLejMejMejMejMejMejMejMejMejMd)	dZd+d,ZPejQd-ejRZSejQd.ejRZTd/d0 ZUe$d1d2 ZVd3d4 ZWe$d5d6 ZXe$d7d8 ZYe$d9d: ZZe$d;d< Z[G d=d> d>eEZ\da]d[d@dAZ^dBdC Z_d\dDdEZ`d]dFdGZadHdI Zbe	jcjddJre	jcdJ ZedKdL ZfndMdL Zfefd^dOdPZgdQdR ZhdSdT Zid_dVdWZjdS )`    )absolute_importprint_functionN   )__version__)iglob)open)relpath)Iterablez.gz )Utils)cached_functioncached_methodpath_existssafe_makedirscopy_file_to_dir_if_neweris_package_dirwrite_depfile)Errors)Context)CompilationOptionsdefault_optionsget_directive_defaults   c             C   s   t | ts| jtS | S )N)
isinstancebytesencode_fs_encoding)filename r   k/var/www/html/CrowdFlow/Picklecon/ble_analysis_env/lib/python3.6/site-packages/Cython/Build/Dependencies.pyencode_filename_in_py2;   s    

r    c             C   s   | S )Nr   )r   r   r   r   r    @   s    c                s:    st j   d t jjkr( t jj7   fdd| D S )N   c                s$   g | ]}|j  rt| n|qS r   )
startswith_relpath).0path)baser   r   
<listcomp>J   s   z"_make_relative.<locals>.<listcomp>)osgetcwdr%   sep)
file_pathsr&   r   )r&   r   _make_relativeE   s    
r-   c             c   sT  d| kr^t jd| }|r^|j \}}}x2|jdD ]$}xt|| | D ]
}|V  qHW q2W d S d| ksztjdkovd| kr6t }t jdtjdkrdnd	 | d
\}}	|rt|tj }ndg}x|D ]l}
x.tt	|
|	D ]}||kr|j
| |V  qW x6tt	|
dd|	D ] }||kr|j
| |V  qW qW nxt| D ]}|V  q@W d S )N{z(.*){([^}]+)}(.*),z**/\z**\z\*\*[%s]z/\\/r!   r
   *z**)rematchgroupssplitextended_iglobr)   r+   setr   	join_pathadd)patternmbeforeswitchafterZcaser%   seenfirstrestrootr   r   r   r7   N   s2    $




r7   expected non-empty iteratorc             c   s,   d}x| D ]}d}|V  q
W |r(t |d S )NTF)
ValueError)it	error_msgemptyvaluer   r   r   nonemptyo   s    

rJ   c          	   C   sr   t jj| }dt||f jd}tj|}t|d.}|jd}x|r^|j	| |jd}qDW W d Q R X |j
 S )Nz%d:%szUTF-8rbi  )r)   r%   normpathlenr   hashlibsha1r   readupdate	hexdigest)r   r%   prefixr<   fdatar   r   r   	file_hashx   s    


rV   c             C   s   t d krtdyt jjdd}W n tk
r@   t jj }Y nX | jj|d  | jj|d  | jj|d  | j	j|d  | j
j|d  | jj|d	  | jj|d
  d| _x2dD ]*}y| jj| W q tk
r   Y qX qW d S )NzBYou first need to install Pythran to use the np_pythran directive.T)pythoninclude_dirsextra_compile_argsextra_link_argsdefine_macrosundef_macroslibrary_dirs	librarieszc++-fwhole-program-fvisibility=hidden)r_   r`   )pythranRuntimeErrorconfigZmake_extension	TypeErrorrX   extendrY   rZ   r[   r\   r]   r^   languageremoverE   )extZpythran_extZ
bad_optionr   r   r   update_pythran_extension   s&    
ri   c                sj   t | dkr6| d dkr6| d dkr6| dd } d}nd}t| \}   fdd	fd
d| j|D S )a#  
    >>> parse_list("")
    []
    >>> parse_list("a")
    ['a']
    >>> parse_list("a b c")
    ['a', 'b', 'c']
    >>> parse_list("[a, b, c]")
    ['a', 'b', 'c']
    >>> parse_list('a " " b')
    ['a', ' ', 'b']
    >>> parse_list('[a, ",a", "a,", ",", ]')
    ['a', ',a', 'a,', ',']
    r   r   [r!   ]r/    c                s,   | j  } | d dkr$ | dd  S | S d S )Nr   z'"r!   r(   )strip)literal)literalsr   r   unquote   s    zparse_list.<locals>.unquotec                s   g | ]}|j  r |qS r   )rm   )r$   item)rp   r   r   r'      s    zparse_list.<locals>.<listcomp>r(   r(   )rM   strip_string_literalsr6   )s	delimiterr   )ro   rp   r   
parse_list   s    $ru   )namesourcesr[   r\   r^   r]   runtime_library_dirsrX   extra_objectsrY   rZ   export_symbolsdependsrf   
np_pythranc             C   s`   | dkrdS | dkrdS dd l }|jdtd | j } | dkrBdS | dkrNdS td| f d S )NTrueTFalseFr   z1The 'np_python' option requires 'True' or 'False')categoryyyesttrueon1nnorT   falseoff0zinvalid truth value %r)r   r   r   r   r   r   )r   r   rT   r   r   r   )warningswarnDeprecationWarninglowerrE   )valr   r   r   r   _legacy_strtobool   s    r   )startendc             c   sj   t | trRd}xV| jd|}|dkr6| |d  V  d S | || V  |d }qW nx| D ]
}|V  qXW d S )Nr   
r!   r(   )r   
basestringfind)sourcer   r   liner   r   r   	line_iter   s    

r   c               @   s.   e Zd Zd
ddZdd Zdd Zdd	 ZdS )DistutilsInfoNc                s@  i | _ |d k	rxt|D ]ډ  j   s*q d dkr8P  dd  j  t fdddD d }|d k	rdd	  t|d  jd
D \}}}tj|d } jdr|d krq|t	t
fkrt|}|dkrdd	 |D }|tkrt|}|| j |< qW nD|d k	r<x8tD ]0}|dkrqt||d }|r|| j |< qW d S )Nr   #r!   c             3   s   | ]} j |r|V  qd S )N)r"   )r$   k)r   r   r   	<genexpr>  s    z)DistutilsInfo.__init__.<locals>.<genexpr>
distutils:cython:c             S   s   g | ]}|j  qS r   )rm   )r$   rs   r   r   r   r'     s    z*DistutilsInfo.__init__.<locals>.<listcomp>=r[   c             S   s,   g | ]$}d |kr t |jd dn|dfqS )r   r!   N)tupler6   )r$   macror   r   r   r'   	  s   rv   rw   r|   )r   r   )rv   rw   r|   )valuesr   lstripnextrM   	partitiondistutils_settingsgetr"   listtransitive_listru   bool_orr   getattr)selfr   exnkindkey_rI   typer   )r   r   __init__   s<    & 


zDistutilsInfo.__init__c             C   s   |d kr| S x|j j D ]\}}t| }|tkrF|| j krF|| j |< q|tkr|| j kr| j | d d  }x|D ]}||krp|j| qpW |}|| j |< q|tkr| j j|d|B | j |< qW | S )NF)r   itemsr   transitive_strr   appendr   r   )r   otherr   rI   r   allvr   r   r   merge  s"    

zDistutilsInfo.mergec             C   s   |d kr| S t  }x| jj D ]|\}}t| }|ttgkrg }x:|D ]2}||krX|| }t|trl||7 }qD|j| qDW |}n||kr|| }||j|< qW |S )N)r   r   r   r   r   r   r   r   )r   aliasesresolvedr   rI   r   Znew_value_listr   r   r   r   subs+  s$    


zDistutilsInfo.subsc             C   sN   xH| j j D ]:\}}t| }|ttgkr:t||t| }t||| qW d S )N)r   r   r   r   r   r   setattr)r   	extensionr   rI   r   r   r   r   applyA  s
    zDistutilsInfo.apply)NN)__name__
__module____qualname__r   r   r   r   r   r   r   r   r      s   
 r   )	r   qsingle_qdouble_q	hash_markr   r   counter	quote_len__Pyx_Lc             C   s  g }i }d}d }}d}d } }	}
t | }d}d}x||k rL| jd|}|	|k r`| jd|}	|
|k rt| jd|}
t|	|
}|dkrt|	|
}|dkr|dkr|j| |d  P q8|r| |d  dkrd	}x&||ko| ||  dk r|d7 }qW |d	 dkr|d7 }q8| | |kr|dksd||d	 kr|| |d    ko\| |d	  kn  r|d7 }d
||f }| || | ||< | |||  }|j| |j| |j| ||7 }d}|}n|d7 }q8d|krr||k s|dkrr|j| ||d   | jd|}|d7 }d
||f }|dkr:d}n|}| |d | ||< |j| |dkrhP | }}q8||d kr| | | |d    ko| |d	  kn  rd}nd}d}| | }|j| ||  |}||7 }q8W dj||fS )z
    Normalizes every string literal to be of the form '__Pyx_Lxxx',
    returning the normalized code and a mapping of labels to
    string literals.
    r   Fr!   Nr   '"r0   r   z%s%s_r   r   Tr
   r(   r(   r(   r(   r(   r(   r(   r(   r(   )rM   r   minmaxr   join)coderS   Znew_codero   r   r   r   Zin_quoter   r   r   Zcode_lenZ
quote_typer   r   labelZ
full_quoter   Zend_or_noner   r   r   rr   I  s    


D







>rr   z(?:^\s*from +([0-9a-zA-Z_.]+) +cimport)|(?:^\s*cimport +([0-9a-zA-Z_.]+(?: *, *[0-9a-zA-Z_.]+)*))|(?:^\s*cdef +extern +from +['\"]([^'\"]+)['\"])|(?:^\s*include +['\"]([^'\"]+)['\"])zC(?:^\s+\(([0-9a-zA-Z_., ]*)\)[#\n])|(?:^\s+([0-9a-zA-Z_., ]*)[#\n])c             C   s   t tjj| tt|S )N)normalize_existing0r)   r%   dirnamer   r8   )	base_path	rel_pathsr   r   r   normalize_existing  s    r   c             C   sj   g }d}xX|D ]P}t jj|r*|j| qt| |}t|rT|jt jj| | }q|j| qW ||fS )a  
    Given some base directory ``base_dir`` and a list of path names
    ``rel_paths``, normalize each relative path name ``rel`` by
    replacing it by ``os.path.join(base, rel)`` if that file exists.

    Return a couple ``(normalized, needed_base)`` where ``normalized``
    if the list of normalized file names and ``needed_base`` is
    ``base_dir`` if we actually needed ``base_dir``. If no paths were
    changed (for example, if all paths were already absolute), then
    ``needed_base`` is ``None``.
    N)r)   r%   isabsr   r9   r   rL   )base_dirr   
normalizedZneeded_baserelr%   r   r   r   r     s    


r   c             C   s:   t |}g }x(| D ] }t||}|d k	r|j| qW |S )N)r   resolve_dependr   )r{   rX   r   dependr%   r   r   r   resolve_depends  s    

r   c             C   sL   | d dkr| d dkrd S x*|D ]"}t || }t|r"tjj|S q"W d S )Nr   <r!   >r(   )r9   r   r)   r%   rL   )r   rX   dirr%   r   r   r   r     s    

r   c             C   sF   t jjt jjt| }|| kr>t|r>t|t jj|f S f S d S )N)r)   r%   r   abspathstrr   packagebasename)r   r   r   r   r   r     s    r   c             C   s,   t jjt jj| d }djt| |f S )Nr   .)r)   r%   splitextr   r   r   )r   moduler   r   r   fully_qualified_name  s    r   c                s"  t j| dd}|j }W d Q R X t|}t|\}}|jddjdd}g }g }g }xtj|D ]}|j \ }	}
} r|j	  t
j||j d}|r|j \}}|p|}|j fdd|jd	D  qb|	r|jd
d |	jd	D  qb|
r|j	||
  qb|j	||  qbW ||||fS )Nignore)Zerror_handlingz\
rl   	)posc             3   s   | ]}d j  |j V  qdS )z{0}.{1}N)formatrm   )r$   rs   )cimport_fromr   r   r     s   z%parse_dependencies.<locals>.<genexpr>r/   c             s   s   | ]}|j  V  qd S )N)rm   )r$   xr   r   r   r     s    )r   Zopen_source_filerP   r   rr   replacedependency_regexfinditerr5   r   dependency_after_from_regexsearchr   re   r6   )source_filenamefhr   distutils_inforo   cimportsincludesexternsr<   Zcimport_listZexternincludeZm_after_from	multilineZone_lineZ
subimportsr   )r   r   parse_dependencies  s0    
r   c               @   s   e Zd Zd)ddZdd Zedd Zedd	 Zd
d Zdd Z	dd Z
ed*ddZedd Zedd Zdd Zedd Zdd Zdd Zdd  Zd!d" Zd+d#d$Zd%d& Zd'd( ZdS ),DependencyTreeFc             C   s   || _ || _i | _d S )N)contextquiet_transitive_cache)r   r   r   r   r   r   r     s    zDependencyTree.__init__c             C   s   t |rtjj|}t|S )N)r   r)   r%   rL   r   )r   r   r   r   r   r     s    z!DependencyTree.parse_dependenciesc             C   s   t  }x| j|d D ]}ttjj||}t|sD| jj||d}|rdtjj	 |krdtjj
|}|j| |j| j| q| jstd||f  qW |S )Nr!   )source_file_pathr   z*Unable to locate '%s' referenced from '%s')r8   r   r9   r)   r%   r   r   r   Zfind_include_filer+   rL   r:   rQ   included_filesr   print)r   r   r   r   include_pathr   r   r   r  $  s    
zDependencyTree.included_filesc             C   s   | j |d d \}}}t|}t|}t }x@| j|D ]2}| j|\}}}	|j| |j| |j|	 q:W t||\}}
|
r|j|
 t|||fS )Nr   )r   r8   r  cimports_externs_incdirsrQ   r   r:   r   )r   r   r   r   r   incdirsr   Zincluded_cimportsZincluded_externsZincluded_incdirsincdirr   r   r   r  6  s    


z'DependencyTree.cimports_externs_incdirsc             C   s   | j |d S )Nr   )r  )r   r   r   r   r   r   H  s    zDependencyTree.cimportsc             C   s   t |S )N)r   )r   r   r   r   r   r   K  s    zDependencyTree.packagec             C   s   t |S )N)r   )r   r   r   r   r   r   N  s    z#DependencyTree.fully_qualified_nameNc             C   s   |d dk}|r| rt d|d k	r|jd}|r>|jd t| j|}x>|r|d  ry|j  W n tk
r|   d S X |jd qNW dj|| }| jj||d}|r|S |rd S | jj||dS )Nr   r   zNew relative imports.)r   )	NotImplementedErrorr6   popr   r   
IndexErrorr   r   Zfind_pxd_file)r   r   r   Zis_relativemodule_pathZpackage_pathZrelativeZpxdr   r   r   find_pxdQ  s*    


zDependencyTree.find_pxdc             C   s   t jj|\}}|dkr0t|d r0|d g}ng }xJ| j|D ]<}|d d dks@|dkr^q@| j||}|d k	r@|j| q@W t|S )N.pyx.pyz.pxd   zcython.cython)r  r  )r)   r%   r   r   r   r  r   r   )r   r   Zfilename_rootZfilename_extZpxd_listr   Zpxd_filer   r   r   cimported_filesi  s    zDependencyTree.cimported_filesc             C   s*   |h}|j | j| |j | j| |S )N)rQ   r  r  )r   r   Zall_depsr   r   r   immediate_dependenciesz  s    z%DependencyTree.immediate_dependenciesc             C   s   | j || jtjS )N)transitive_merger  r8   union)r   r   r   r   r   all_dependencies  s    zDependencyTree.all_dependenciesc             C   s   t jj|S )N)r)   r%   getmtime)r   r   r   r   r   	timestamp  s    zDependencyTree.timestampc             C   s   | j ||fS )N)r  )r   r   r   r   r   extract_timestamp  s    z DependencyTree.extract_timestampc                s   t  fdd j|D S )Nc                s   g | ]} j |qS r   )r  )r$   rT   )r   r   r   r'     s    z4DependencyTree.newest_dependency.<locals>.<listcomp>)r   r  )r   r   r   )r   r   newest_dependency  s    z DependencyTree.newest_dependencyc             C   s   yt jtjd}|jt|jd x>t| j|D ],}tj	j
|d d
kr6|jt|jd q6W |jt|jt|ddt|ddfjd |j|j jd |j S  tk
r   d	S X d	S )a;  
        Return a fingerprint of a cython file that is about to be cythonized.

        Fingerprints are looked up in future compilations. If the fingerprint
        is found, the cythonization can be skipped. The fingerprint must
        incorporate everything that has an influence on the generated code.
        zUTF-8r!   .c.cpp.hZpy_limited_apiFr|   N)r  r  r  )rN   rO   r   r   rQ   rV   sortedr  r)   r%   r   r   rf   r   Zget_fingerprintrR   IOError)r   r   r   Zcompilation_optionsr<   r   r   r   r   transitive_fingerprint  s    
z%DependencyTree.transitive_fingerprintc       
      C   s   | j |d }|j}| j|\}}}tj }|rjt||}d|kr^tt|d j||d< nt||d< |rt|j	dg }x$t||D ]}	|	|kr|j
|	 qW ||d< |S )Nr   r{   rX   )r   r   r  r)   r*   r-   r   r8   r  r   r   )
r   r   infokwdsr   r   r  ZbasedirrX   incr   r   r   distutils_info0  s     
zDependencyTree.distutils_info0c             C   s   | j || jtjj|j|S )N)r  r"  r   r   r   )r   r   r   r&   r   r   r   r     s    zDependencyTree.distutils_infoc             C   sT   y| j ||f }W n& tk
r8   i  }| j ||f< Y nX | j||||i | jd S )Nr   )r   KeyErrortransitive_merge_helperr  )r   nodeextractr   r@   r   r   r   r    s    zDependencyTree.transitive_mergec             C   s   ||kr|| d fS ||}||kr,||fS zt |||< d }xX||D ]L}	| j|	|||||\}
}|d k	r|d k	r|| || k rn|}|||
}qHW ||krd }|d kr|||< ||fS ||= X d S )N)rM   r$  )r   r%  r&  r   r@   stackoutgoingdepsloopr   Zsub_depsZsub_loopr   r   r   r$    s*    z&DependencyTree.transitive_merge_helper)F)N)NN)r   r   r   r   r   r   r  r  r   r   r   r  r  r  r  r  r  r  r  r"  r   r  r$  r   r   r   r   r     s(   

r   Fc             C   s6   t d kr2| d kr&tdgt ttd} t| |da t S )Nr   )options)r   )	_dep_treer   r   r   r   r   )ctxr   r   r   r   create_dependency_tree  s    
r.  c             C   sf   d|kr>|j dg dg }t|d |}tt|| j |d< | j}|f |}t||d d}||fS )Nr{   rX   r   rv   )	distutilsmodule_name)r   r   r  r8   r{   	__class__dict)templater   rX   r{   r   rh   metadatar   r   r   default_create_extension  s    
r5  c       !         s  |d k	rt dj| |d kr"g }| d kr2g i fS t| tsHt| t rN| g} ddlm} dtjkr|tjd j	tjd jf n|f  fdd| D }t
||d}	t }
t|ts|g}x$|D ]}|
jttjjt| qW g }i }|jjpt}t }x| D ]}t| st|}t|trD|||g }d	}d }|}nt| rd
d |jD }|r|d t|dkrt d|j|f  n|j| q|}|j}t|d}d }n$tdt|t||jf }t |x0t!t"td D ]}tjj||
krq|	j#|}d	|kr6||kr@qn
|r@|}t$j%| ||kry|	j&|||j'}W n" t(k
r   |rw Y nX |d k	rx*|j'j) D ]\}}||kr|||< qW ||d< |gfdd|jD  }d|krx.|d D ]"}t|}||kr|j| qW ||d< |r>d|kr>||d< |j*dd}|||\}}|pht+|dd|_,|j,r|t-| |j| |||< ||jkr tjj.|d |j/dkrdnd } y|jj0|  W n" t1k
r   t d|  Y nX |jj2d| |j3| qW qW ||fS )NzWarning: passing language={0!r} to cythonize() is deprecated. Instead, put "# distutils: language={0}" in your .pyx or .pxd file(s)r   )	Extension
setuptoolszsetuptools.extensionc                s   h | ]}t | r|jqS r   )r   rv   )r$   r<   )extension_classesr   r   	<setcomp>  s    z(create_extension_list.<locals>.<setcomp>)r   r2   c             S   s$   g | ]}t jj|d  dkr|qS )r!   .py.pyx)r:  r;  )r)   r%   r   )r$   rs   r   r   r   r'   6  s    z)create_extension_list.<locals>.<listcomp>r!   zWarning: Multiple cython sources found for extension '%s': %s
See https://cython.readthedocs.io/en/latest/src/userguide/sharing_declarations.html for sharing declarations among Cython files.)r   zUpattern is not of type str nor subclass of Extension (%s) but of type %s and class %sz'%s' doesn't match any filesrv   c                s   g | ]}| kr|qS r   r   )r$   r<   )filepatternr   r   r'   g  s    rw   rf   r|   Fzc++z.cppz.cz@Warning: Cython source file not found in sources list, adding %s)4r  r   r   r   r	   distutils.extensionr6  sysmodulesZ
_Extensionr.  r8   r   rQ   mapr)   r%   r   r7   r+  create_extensionr5  r    r   rw   rM   rv   r   r   reprr   r1  rd   rJ   r  r   r   Z$raise_error_if_module_name_forbiddenr   r   	Exceptionr   r  r   r|   ri   r   rf   rg   rE   insertr:   )!patternsexcluder-  r   r   rf   exclude_failuresr6  Zexplicit_modulesr)  Z
to_excluder;   module_listmodule_metadatarA  r@   r3  rv   r&   Zext_languageZcython_sourcesmsgfiler0  r   r   rI   rw   r   r|   r<   r4  Ztarget_filer   )r8  r<  r   create_extension_list  s    






 









$rL  c	       /         s  |dkrg }d|	krdg|	d< d|	kr2t |	d  |	jdd}
tdkrLd}ntf |	}d|_d|_|dkrztjjddk}tf |	}tf |	}d|_t	j
|}|}	t| ||||||d	\} }t|  t||d
}t|	dd tj f fdd	}tjt}g }x| D ]v} r,x|jD ]}|| qW dd |jD }t|dkrR|j}nd}g }x|jD ]}tjj|\}}|d)krX|jr|d }|}	n&|jdkr|d }|}	n|d }|}	 rtjj|rtjj|d }|jtjdd }tjj |}tjj|}t | |
r4|j!|}t"||| t#j$|rNtjj%|}nd*}||j&|k rx|j&|| } }d}!n |j'|\} }d||j(|k }!|s|| k r>| r| r||krt)dt#j*|  nt)dt#j*|t#j*|f  | r|	j+r|j,|||	}"nd}"|j-|!|||"||	| |j|j||f
 |j-| || j-| n|j-|  rd|| qdW ||_qW |	j+rtjj.|	j+stj/|	j+ |j0  t|}#dtt1|# }$x<t2|#D ]0}%|$j3|%d |#}&||% dd |&f ||%< qW |#dkrd}|rddl4}'|'j5|t6d}(yV|(j7t8|dd})|(j9  x8|)j: sy|)jd W n |'j;k
rz   Y nX qJW W n  t<k
r   |(j=   Y nX |(j  nx|D ]}*t>|*  qW |rt? }+x~|j@ D ]r\}},tjj.|s |+jA|, nNtjjB|dk rtC|dd d!}-z"|-jDtd"d"kr@|+jA|, W d|-j9  X qW |+rx|+D ]}.| jE|. q`W t)d#d$jtFd%d |+D   |	j+rtG|	j+t|	d&d, tHjIjJ  | S )-a  
    Compile a set of source modules into C/C++ files and return a list of distutils
    Extension objects for them.

    :param module_list: As module list, pass either a glob pattern, a list of glob
                        patterns or a list of Extension objects.  The latter
                        allows you to configure the extensions separately
                        through the normal distutils options.
                        You can also pass Extension objects that have
                        glob patterns as their sources. Then, cythonize
                        will resolve the pattern and create a
                        copy of the Extension for every matching file.

    :param exclude: When passing glob patterns as ``module_list``, you can exclude certain
                    module names explicitly by passing them into the ``exclude`` option.

    :param nthreads: The number of concurrent builds for parallel compilation
                     (requires the ``multiprocessing`` module).

    :param aliases: If you want to use compiler directives like ``# distutils: ...`` but
                    can only know at compile time (when running the ``setup.py``) which values
                    to use, you can use aliases and pass a dictionary mapping those aliases
                    to Python strings when calling :func:`cythonize`. As an example, say you
                    want to use the compiler
                    directive ``# distutils: include_dirs = ../static_libs/include/``
                    but this path isn't always fixed and you want to find it when running
                    the ``setup.py``. You can then do ``# distutils: include_dirs = MY_HEADERS``,
                    find the value of ``MY_HEADERS`` in the ``setup.py``, put it in a python
                    variable called ``foo`` as a string, and then call
                    ``cythonize(..., aliases={'MY_HEADERS': foo})``.

    :param quiet: If True, Cython won't print error, warning, or status messages during the
                  compilation.

    :param force: Forces the recompilation of the Cython modules, even if the timestamps
                  don't indicate that a recompilation is necessary.

    :param language: To globally enable C++ mode, you can pass ``language='c++'``. Otherwise, this
                     will be determined at a per-file level based on compiler directives.  This
                     affects only modules found based on file names.  Extension instances passed
                     into :func:`cythonize` will not be changed. It is recommended to rather
                     use the compiler directive ``# distutils: language = c++`` than this option.

    :param exclude_failures: For a broad 'try to compile' mode that ignores compilation
                             failures and simply excludes the failed extensions,
                             pass ``exclude_failures=True``. Note that this only
                             really makes sense for compiling ``.py`` files which can also
                             be used without compilation.

    :param show_all_warnings: By default, not all Cython warnings are printed.
                              Set to true to show all warnings.

    :param annotate: If ``True``, will produce a HTML file for each of the ``.pyx`` or ``.py``
                     files compiled. The HTML file gives an indication
                     of how much Python interaction there is in
                     each of the source code lines, compared to plain C code.
                     It also allows you to see the C/C++ code
                     generated for each line of Cython code. This report is invaluable when
                     optimizing a function for speed,
                     and for determining when to :ref:`release the GIL <nogil>`:
                     in general, a ``nogil`` block may contain only "white" code.
                     See examples in :ref:`determining_where_to_add_types` or
                     :ref:`primes`.


    :param annotate-fullc: If ``True`` will produce a colorized HTML version of
                           the source which includes entire generated C/C++-code.


    :param compiler_directives: Allow to set compiler directives in the ``setup.py`` like this:
                                ``compiler_directives={'embedsignature': True}``.
                                See :ref:`compiler-directives`.

    :param depfile: produce depfiles for the sources if True.
    Nr  r   Zcommon_utility_include_dirdepfileTZCYTHON_FORCE_REGENr   )rF  r-  r   rG  rf   r   )r   	build_dirc                sL   t jj| }t jj| r|} |j|rHt t jjt| |}t|| d S )N)	r)   r%   r   r   r"   r9   r   r#   copy_once_if_newer)filepathrC   Zfilepath_absZmod_dir)rN  r   r   copy_to_build_dir   s    
z$cythonize.<locals>.copy_to_build_dirc             S   s$   g | ]}t jj|d  dkr|qS )r!   .pyx.py)rR  rS  )r)   r%   r   )r$   r   r   r   r   r'     s    zcythonize.<locals>.<listcomp>r!   .pyx.pyz.cppzc++z.cr   r   z Compiling %s because it changed.z&Compiling %s because it depends on %s.z[{0:%d}/{1}] )initializer)	chunksizei    rz	iso8859-1)encodingz#error zFailed compilations: %sz, c             S   s   g | ]
}|j qS r   )rv   )r$   r   r   r   r   r'     s    Z
cache_sizei   d   )rT  rU  r(   i   i  @)Kr   r  ra   r   Zcplusr|   r)   environr   r   Zfrom_optionsrL  fix_windows_unicode_modulesr.  r   r*   collectionsdefaultdictr   r{   rw   rM   rv   r%   r   rf   r   
splitdriver6   r+   r   r   safe_makedirs_oncer  r   r   Zfile_generated_by_this_cythonr  r  r  r  r  decode_filenamecacher  r   existsmakedirssortr   ranger   multiprocessingPool_init_multiprocessing_helperZ	map_asynccythonize_one_helperclosereadyTimeoutErrorKeyboardInterrupt	terminatecythonize_oner8   r   rQ   getsizeio_openrP   rg   r  cleanup_cacher>  stdoutflush)/rH  rF  Znthreadsr   r   forcerf   rG  show_all_warningsr+  rM  Zpythran_optionsZ	c_optionsZcpp_optionsr-  rI  r)  rQ  Zmodules_by_cfileZ
to_compiler<   depZ
cy_sourcesfull_module_nameZnew_sourcesr   r&   rh   c_filer   dependenciesZc_timestampZdep_timestamppriorityfingerprintNZprogress_fmtiprogressrh  poolresultargsZfailed_modulesr?  rT   r   r   )rN  r   	cythonize  s   M



 









 






r  c             C   s   t jdkrd S t jdk s"t jdkr&d S dd }xT| D ]L}y|jjd w4W n tk
r^   Y nX |d	|jjd
dd  |j|_q4W d S )Nwin32r         r   c                s<   G  fdddt }||}|r8|j fdd|D  |S )Nc                   s   e Zd Z fddZdS )zVfix_windows_unicode_modules.<locals>.make_filtered_list.<locals>.FilteredExportSymbolsc                s   | kpt j| |S )N)r   __contains__)r   r   )ignored_symbolr   r   r    s    zcfix_windows_unicode_modules.<locals>.make_filtered_list.<locals>.FilteredExportSymbols.__contains__N)r   r   r   r  r   )r  r   r   FilteredExportSymbols  s   r  c             3   s   | ]}| kr|V  qd S )Nr   )r$   rv   )r  r   r   r     s    zJfix_windows_unicode_modules.<locals>.make_filtered_list.<locals>.<genexpr>)r   re   )r  Zold_entriesr  Zfiltered_listr   )r  r   make_filtered_list  s
    z7fix_windows_unicode_modules.<locals>.make_filtered_listasciiZPyInit_r   r!   )r   r  )r   r  r   r(   )r>  platformversion_inforv   r   UnicodeEncodeErrorrsplitrz   )rH  r  r<   r   r   r   r]    s    

r]  ZXML_RESULTSc                s    fdd}|S )Nc                 s   t j  }d}z"y |   W n   d}Y nX W d t j  | }t| d }d| }d| }|rbd}nd}ttjjt|d d	}|jd
j t	   |j
  X d S )NTFr   z
cythonize.r!   r
   Zfailurez.xmlwaQ  
                    <?xml version="1.0" ?>
                    <testsuite name="%(name)s" errors="0" failures="%(failures)s" tests="1" time="%(t)s">
                    <testcase classname="%(name)s" name="cythonize">
                    %(failure_item)s
                    </testcase>
                    </testsuite>
                )timer   r   r)   r%   r   compile_result_dirwriterm   localsrl  )r  r   successr   rv   ZfailuresZfailure_itemoutput)funcr   r   with_record  s$    z#record_results.<locals>.with_recordr   )r  r  r   )r  r   record_results  s    r  c             C   s   | S )Nr   )r  r   r   r   r    s    Tc
          3      sl  ddl m}
m} ddlm}m} |rXtjj|j	s>t
|j	 t|j	dtjj||f }|t }|d }tjj|stjj|rX|std|	| f  tjj|rtj|d  tjt|d.}tjt|d}tj|| W d Q R X W d Q R X n^tj|d  tjj|}tjtj|0}x(|j D ]}|j|tjj|| q*W W d Q R X d S |sttd	|	tj| f  |d krt|}||_||_ t!j"}|rd
t!_"d
}zy"|
| ||d  j#d
krd}W n| t$|fk
r } z*t%j&j'd|  d}d
d l(}|j)  W Y d d }~X n2 t*k
rH   |r0 d
d l(}|j)  d}Y nX W d |rZ|t!_"X |r|rt|d | ntjj|rhtj+| n|rht,t-d  fdddD }t.|dkr|}tjt|d2}tjt|d d}tj|| W d Q R X W d Q R X nL|}tjtj|d dt/*}x"|D ]}|j'|tjj| q0W W d Q R X tj0|d | d S )Nr   )compile_singler   )CompileError
PyrexErrorz%s-%sz.zipz%sFound compiled %s in cacherK   wbz%sCythonizing %sr   )rz  r!   z%s
c                s   g | ]}t  |d qS )N)r   )r$   attr)r  r   r   r'   .  s   z!cythonize_one.<locals>.<listcomp>r{  h_fileapi_filei_filez.tmpr  )r{  r  r  r  )1Compiler.Mainr  r   ZCompiler.Errorsr  r  r)   r%   rd  rc  r   r9   r   gzip_extr  utime
contextlibclosing	gzip_openr   shutilcopyfileobjr   zipfileZipFilenamelistr&  r   r   rb  r   Zoutput_fileembedded_metadatar   ZLEVELZ
num_errorsEnvironmentErrorr>  stderrr  	traceback	print_excrC  rg   r   filterrM   zipfile_compression_moderename)Zpyx_filer{  r~  r   r+  Zraise_on_failurer  rz  rx  r  r  r   r  r  Zfingerprint_file_baseZgz_fingerprint_fileZzip_fingerprint_filegrT   r   zartifactZold_warning_levelZany_failureser  Z	artifactsZfingerprint_filezipr   )r  r   rq    s    
"&

"
$rq  c             C   s4   dd l }yt|  S  tk
r.   |j   Y nX d S )Nr   )r  rq  rC  r  )r<   r  r   r   r   rk  >  s    rk  c              C   s   dd l } | j | j| j d S )Nr   )signalSIGINTSIG_IGN)r  r   r   r   rj  G  s    rj  333333?c             C   s  ydt jdddtjj| gt jd}|j \}}|j }|dkrbdt|j	 j
 d  }||k rbd S W n ttfk
r|   Y nX d}g }xDtj| D ]6}	t| |	}
tj|
}||j7 }|j|j|j|
f qW ||krx:tt|D ]*\}}}	tj|	 ||8 }||| k rP qW d S )NZduz-sz-k)ru  r   i   )
subprocessPopenr)   r%   r   PIPEcommunicatewaitintrm   r6   OSErrorrE   listdirr9   statst_sizer   st_atimereversedr  unlink)rc  Ztarget_sizeZratiopru  r   resZ
total_sizer   rK  r%   rs   r  sizer   r   r   rt  M  s.     




rt  )N)rD   )r   )NF)NNNFNF)Nr   NFNNFF)NTNNFr
   )r  )k
__future__r   r   r  r
   r   r^  r  rN   r)   r  r  r3   r>  r  globr   ior   rs  os.pathr   r#   r  collections.abcr	   ImportErrorgzipr  r  zlibZIP_DEFLATEDr  
ZIP_STOREDra   r   r   r   r   r   r   r   r   ZCompilerr   r  r   ZCompiler.Optionsr   r   r   r%   r   r9   rO  ra  r  getfilesystemencodingr   getdefaultencodingr    r   r   r-   r7   rJ   rV   ri   ru   objectr   r   r   r   r   r   r  Z
Py_ssize_tr   r   rr   compileMr   r   r   r   r   r   r   r   r   r   r,  r.  r5  rL  r  r]  r\  r   r  r  rq  rk  rj  rt  r   r   r   r   <module>   s   


$


	!
	TZ
	# R
 
 
 
  #

   S	