a
    4Df4                  	   @   s.  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mZm	Z	 d dl
mZ d dlZddlmZ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mZmZ ddlmZ ddlm Z  d dl!Z"ej#dkZ$e$sdd Z%ndd Z%ej#dk rd dl&Z&dd Z'nd dl(Z)d dl*m+Z+ dd Z'G dd deeZ,ed;ddZ-d<ddZ.d=dd Z/d!d" Z0ed#d$ Z1i Z2e1d%Z3d>d&d'Z4d(d) Z5e.ej67e  d*ddd+d+dddf	d,d-Z8de8_9e:d.j;Z<d/d0 Z=e:d1Z>d2d3 Z?zd d4lm@Z@ W n eAy   d5d6 Z@Y n0 d7d8 ZBG d9d: d:eCZDdS )?    )absolute_importN)Distribution	Extension)	build_ext   )Contextdefault_options)CythonTransformEnvTransform)SkipDeclarations)parse_from_strings)_unicode   )strip_string_literals	cythonizecached_function)Pipeline)get_cython_cache_dir)   c                 C   s   t | tr| dS | S d S )Nascii)
isinstancebytesdecode)s r   `/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/Cython/Build/Inline.py
to_unicode   s    

r   c                 C   s   | S Nr   xr   r   r   <lambda>#       r    )r      c                 C   s   t | |S r   )impload_dynamic)namemodule_pathr   r   r   r$   '   s    r$   )ExtensionFileLoaderc                 C   s2   t jj| t| |d}t j|}|j| |S )N)loader)	importlibutilspec_from_file_locationr'   module_from_specr(   exec_module)r%   pathspecmoduler   r   r   r$   -   s    c                       s,   e Zd Zdd Zdd Z fddZ  ZS )UnboundSymbolsc                 C   s   t | d  t | _d S r   )r	   __init__setunbound)selfr   r   r   r2   4   s    zUnboundSymbols.__init__c                 C   s"   |   |js| j|j |S r   )Zcurrent_envlookupr%   r4   addr5   noder   r   r   visit_NameNode7   s    zUnboundSymbols.visit_NameNodec                    s   t t| | | jS r   )superr1   __call__r4   r8   	__class__r   r   r<   ;   s    zUnboundSymbols.__call__)__name__
__module____qualname__r2   r:   r<   __classcell__r   r   r=   r   r1   3   s   r1   c                 C   s   t | } |d u rtg t}ddlm} td| }t|dD ]$}|d u rJq<||}t||r< qbq<zdd l	}W n t
y   dd l}Y n0 tt |tt| S )Nr   )AnalyseDeclarationsTransformz(tree fragment)Zpyxr   )r   r   r   Compiler.ParseTreeTransformsrC   r   r   Zcreate_pipeliner   builtinsImportError__builtin__tupler1   r3   dir)codecontextrC   treephaserE   r   r   r   unbound_symbols@   s     


rN   c                 C   s"   t | }|tu rdS t| |S d S )Nlong)typeint	safe_type)argrK   py_typer   r   r   unsafe_typeT   s    rU   c                 C   s   t | }|ttttfv r|jS |tu r*dS |tu r6dS |tu rBdS dt	j
v rpt| t	j
d jrpd| jj| jf S |jD ]N}|jdv r dS |j|jdd	}|rv||j}|jrvd
|j|jf   S qvdS d S )Nzdouble complexdoubleZbintnumpyz"numpy.ndarray[numpy.%s_t, ndim=%s])rG   rE   objectF)Zneed_pxdz%s.%s)rP   listrH   dictstrr?   complexfloatboolsysmodulesr   ZndarrayZdtyper%   ndim__mro__r@   find_moduler6   Zis_type)rS   rK   rT   Z	base_typer0   entryr   r   r   rR   \   s(    

rR   c                  C   s,   t  } |  }| | t| }|  |S r   )r   find_config_filesparse_config_filesr   finalize_options)distconfig_filesbuild_extensionr   r   r   _get_build_extensiont   s    
rk   c                 C   s   t t| tS r   )r   rY   r   )cython_include_dirsr   r   r   _create_context   s    rm   ).c                 C   s   |D ]~}|| vr|d u s |d u rJt  jjj}|d u r<|j}|d u rJ|j}||v r`|| | |< q||v rv|| | |< qtd|  qd S )NzCouldn't find %r)inspectcurrentframef_backf_locals	f_globalsprint)kwdsrN   localsglobalssymbolZcalling_framer   r   r   _populate_unbound   s    ry   c                 C   s.   | |t jt j|tjf}tt|d	 S )Nzutf-8)
r_   version_info
executableCython__version__hashlibsha1r   encode	hexdigest)	orig_codearg_sigslanguage_levelkeyr   r   r   _inline_key   s    r   inlineFc
           +         s  d u rdd |r t t|nt |r0t|ni }|	d u rHd|vrHd}	|	d urX|	|d< t| }|d urt||| t }t fdd|D }t	| ||	}t| ||f}|d urdd |D }|| S | }t
| } t| \} }t| } |d u rt jjj}|d u r&t jjj}z"t|  t|< }t||| W n" tyj   |sftd Y n0 g }t D ](\}}|tu r||d	|  |= q|t}t fd
d|D }t	|||	}d| }|tjv rtj| }nd }tjd u rt }|dt_tj ||tj }tj!|sDt"| |sXtj#|sg }g }t$%d}|D ]X\}}|&|} | rn|d| ' d   | ' d dkrndd l(}!||!)  qnt*| \}"}#d dd |D }$dd ||"|$|#d }%| D ]\}&}'|%+|&|'}%qtj ||d }(t,|(d})z|)-|% W |).  n
|).  0 t/||(g||d}*|d u rt }t0|*g|pdg||d|_1tj2|(|_3||_4|5  t6||}|j7t|||f< fdd|D }|j7| S )Nc                 S   s   dS )NrX   r   r   r   r   r   r       r!   zcython_inline.<locals>.<lambda>r   Z3strc                    s   g | ]\}}| |fqS r   r   ).0rS   value)ctxget_typer   r   
<listcomp>   r!   z!cython_inline.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )r   r   r   rS   r   r   r   r      r!   z>Could not parse code as a string (to extract unbound symbols).z
cimport cython as %sc                    s   g | ]}|  |fqS r   r   r   r   r   ru   r   r   r      r!   Z_cython_inline_ z([.\w]+)[.]z
cimport %sr   rW   z, c                 S   s   g | ]}d | qS )z%s %sr   )r   ar   r   r   r      r!   zf
%(module_body)s
%(cimports)s
def __invoke(%(params)s):
%(func_body)s
    return locals()
            
)cimportsmodule_bodyparams	func_bodyz.pyxw)r%   sourcesinclude_dirsextra_compile_argsrn   )Zinclude_pathZcompiler_directivesquietc                    s   g | ]} | qS r   r   r   )ru   r   r   r     r!   )8rm   rH   _cython_inline_default_contextrZ   _cython_inline_cachegetry   sorteditemsr   r   r   strip_common_indentro   rp   rq   rr   rs   rN   AssertionErrorrt   rY   cython_moduleappendr_   r`   cython_inlineso_extrk   Zget_ext_filenameosr.   joinexistsmakedirsisfilerecompilematchgroupsrW   Zget_includeextract_func_codereplaceopenwritecloser   r   
extensionsdirname
build_temp	build_librunr$   Z__invoke)+rJ   r   lib_dirrl   Zcython_compiler_directivesforcer   rv   rw   r   ru   Z_unbound_symbolsargsr   Zkey_hashZinvokearg_listr   literalsr   r%   rS   	arg_namesmodule_namer0   rj   r&   cflagsZc_include_dirsZ	qualifiedrP   _mrW   r   r   r   Zmodule_coder   r   Zpyx_filefh	extensionr   r   r   r      s    












r   z[^ ]c                 C   s   d }|   }|D ]<}t|}|s"q| }|| dkr8q|d u sH||kr|}qt|D ]>\}}t|}|rV|rV|||d  dkrqV||d  ||< qVd|S )N#r   r   )
splitlines_find_non_spacestart	enumerater   )rJ   Z
min_indentlinesliner   indentixr   r   r   r      s"    r   zI^((cdef +(extern|class))|cimport|(from .+ cimport)|(from .+ import +[*]))c                 C   sl   g }g }|}|  dd} | d}|D ],}|dsHt|rD|}n|}|| q&d|dd| fS )N	 r   z    z
    )r   split
startswithmodule_statementr   r   r   )rJ   r0   functioncurrentr   r   r   r   r   r   5  s    


r   )getcallargsc                 O   s  i }t | \}}}}|d ur2|t|d  ||< t||D ]\}}	|	||< q<t| D ]2\}}	||v rZ||v r~td| ||||< qZ|d ur|||< n|rtdt| |d u rd}t|t| }
t|D ]8\}}||vr||
kr|||
  ||< qtd| q|S )NzDuplicate argument %sz Unexpected keyword arguments: %sr   zMissing argument: %s)	ro   
getargspeclenziprY   r   	TypeErrorpopr   )funcZ
arg_valuesZ
kwd_valuesallr   varargsru   defaultsr%   r   Zfirst_defaultr   r   r   r   r   H  s0    


r   c                 C   sB   |  d}| d d dkr.d| |d d   S | |d d  S d S )N:r"   lambdaz	return %sr   )index)sourcer   r   r   r   get_bodyd  s    
r   c                   @   s   e Zd Zdd Zdd ZdS )RuntimeCompiledFunctionc                 C   s   || _ tt|| _d S r   )_fr   ro   	getsource_body)r5   fr   r   r   r2   p  s    z RuntimeCompiledFunction.__init__c                 O   s`   t | jg|R i |}tr<t| jf| jj| jjd|S t| jf| jj| jjd|S d S )N)rv   rw   )r   r   IS_PY3r   r   __globals__Zfunc_globals)r5   r   ru   r   r   r   r   r<   t  s     z RuntimeCompiledFunction.__call__N)r?   r@   rA   r2   r<   r   r   r   r   r   n  s   r   )N)N)N)NN)E
__future__r   r~   ro   r   r   r_   distutils.corer   r   Zdistutils.command.build_extr   r|   ZCompiler.Mainr   r   ZCompiler.Visitorr	   r
   rD   r   ZCompiler.TreeFragmentr   ZCompiler.StringEncodingr   ZDependenciesr   r   r   ZCompilerr   ZUtilsr   Zcythonr   rz   r   r   r#   r$   importlib.utilr)   Zimportlib.machineryr'   r1   rN   rU   rR   rk   rm   r   r   ry   r   r.   r   r   r   r   searchr   r   r   r   r   rF   r   rX   r   r   r   r   r   <module>   sn   








}

