U
    b»{jý  ã                   @   s  d dl Z d dlm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mZ d dlmZ d dlmZ e jjjZe jjjZe jjjZe jjZddd	œZd
d„ Ze ed ¡Ze ed¡Zedd„ ƒZejdd�dd„ ƒZG dd„ de ƒZ!G dd„ de ƒZ"dd„ Z#dd„ Z$dS )é    N)Ú	build_ext)ÚDistribution)Úmkdtemp)Úcontextmanager)ÚPath)z.dllz.pyd)ú.sor   )ÚwinÚdefaultc                 C   s   t  tjd d… t d ¡|  S )Né   r	   )Ú_configsÚgetÚsysÚplatform©Úarg© r   úR/var/www/html/bwave/python/venv/lib/python3.8/site-packages/numba/pycc/platform.pyÚget_configs   s    r   é   c                 c   s^   z(tƒ }ttj |d|  ¡dƒ}|V  W 5 z|  ¡  t |¡ W n   Y nX t |¡ X d S )Nztemp%sZwt)ÚcloseÚosÚremoveÚrmdirr   ÚopenÚpathÚjoin)ÚsuffixÚntfZtmpdirr   r   r   Ú_gentmpfile#   s    
r   )Úmaxsizec               
   C   s†   t ƒ } t| ƒ dD ]n}zPt|ƒ�>}d}| |¡ | ¡  | ¡  | j|jgt|jƒj	d� W 5 Q R X W q t
k
r~   Y  dS X qdS )zv
    Returns True if the "external compiler" bound in numpy.distutil is present
    and working, False otherwise.
    )z.cz.cxxzint main(void) { return 0; })Ú
output_dirFT)Únew_compilerÚcustomize_compilerr   ÚwriteÚflushr   ÚcompileÚnamer   ÚanchorÚ	Exception)Úcompilerr   r   Zsimple_cr   r   r   Úexternal_compiler_works5   s    

(r*   c                   @   s   e Zd Zg ZdS )Ú_DummyExtensionN)Ú__name__Ú
__module__Ú__qualname__Ú	librariesr   r   r   r   r+   L   s   r+   c                   @   sj   e Zd Zdd„ Zedd„ ƒZejdd„ ƒZdd„ Zdd
d„Zddd„Z	dd„ Z
dd„ Zdd„ Zdd„ Zd	S )Ú	Toolchainc                 C   s†   t ƒ s|  ¡  d| _tƒ | _t| jƒ ttƒ ƒ| _| j 	¡  | jj
| _| jj| _dt ¡ gi}tjdkrrg |d< n
dg|d< || _d S )NFÚinclude_dirsÚwin32r/   Úm)r*   Ú_raise_external_compiler_errorÚ_verboser!   Ú	_compilerr"   r   r   Ú
_build_extÚfinalize_optionsÚlibrary_dirsÚ_py_lib_dirsr1   Ú_py_include_dirsÚnpZget_includer   r   Ú
_math_info)ÚselfZnp_compile_argsr   r   r   Ú__init__R   s    






zToolchain.__init__c                 C   s   | j S ©N)r5   ©r>   r   r   r   Úverbosed   s    zToolchain.verbosec                 C   s    || _ t |rtjntj¡ d S r@   )r5   ÚlogÚset_thresholdÚINFOÚWARN)r>   Úvaluer   r   r   rB   h   s    c                 C   s¦   d}d}t j}| d¡rLt jdkr,ddg}nddg}d	||d
 |¡ f }nN| d¡rvddg}d	||d
 |¡ f }n$| d¡r’d}d	||f }nd| }t|ƒ‚d S )NzYAttempted to compile AOT function without the compiler used by `numpy.distutils` present.z(If using conda try:

#> conda install %sÚlinuxl        zgcc_linux-32zgxx_linux-32zgcc_linux-64zgxx_linux-64z%s %sú Údarwinzclang_osx-64zclangxx_osx-64r2   zCannot find suitable msvc.zUnknown platform %s)r   r   Ú
startswithr   r   ÚRuntimeError)r>   ZbasemsgZ	conda_msgZpltZ	compilersÚmsgZwinmsgr   r   r   r4   o   s     




z(Toolchain._raise_external_compiler_errorr   Nc                 C   s    | j j|||||pg |d�}|S )aÖ  
        Compile the given source files into a separate object file each,
        all beneath the *output_dir*.  A list of paths to object files
        is returned.

        *macros* has the same format as in distutils: a list of 1- or 2-tuples.
        If a 1-tuple (name,), the given name is considered undefined by
        the C preprocessor.
        If a 2-tuple (name, value), the given name is expanded into the
        given value by the C preprocessor.
        )r    r1   ÚdependsÚmacrosÚextra_preargs)r6   r%   )r>   Úsourcesr    r1   rN   rO   Zextra_cflagsÚobjectsr   r   r   Úcompile_objects„   s    ûzToolchain.compile_objectsc           	   
   C   s2   t j |¡\}}| jjtj|||||||d� dS )zu
        Create a shared library *output* linking the given *objects*
        and *libraries* (all strings).
        )Úexport_symbolsrP   N)r   r   Úsplitr6   ÚlinkÚ	CCompilerZSHARED_OBJECT)	r>   ÚoutputrR   r/   r9   rT   Zextra_ldflagsr    Zoutput_filenamer   r   r   Úlink_sharedš   s      üzToolchain.link_sharedc                 C   s0   | j  tƒ ¡}tjdkr"|dg }|| jd  S )zJ
        Get the library arguments necessary to link with Python.
        r2   Úmsvcrtr/   )r7   Zget_librariesr+   r   r   r=   )r>   Zlibsr   r   r   Úget_python_libraries¨   s    

zToolchain.get_python_librariesc                 C   s
   t | jƒS )zL
        Get the library directories necessary to link with Python.
        )Úlistr:   rA   r   r   r   Úget_python_library_dirs´   s    z!Toolchain.get_python_library_dirsc                 C   s   t | jƒ| jd  S )zo
        Get the include directories necessary to compile against the Python
        and Numpy C APIs.
        r1   )r\   r;   r=   rA   r   r   r   Úget_python_include_dirsº   s    z!Toolchain.get_python_include_dirsc                 C   s   | j  |¡S )zR
        Given a C extension's module name, return its intended filename.
        )r7   Úget_ext_filename)r>   Zext_namer   r   r   r_   Á   s    zToolchain.get_ext_filename)r   r   r   N)r   r   r   N)r,   r-   r.   r?   ÚpropertyrB   Úsetterr4   rS   rY   r[   r]   r^   r_   r   r   r   r   r0   P   s(   

      þ
     þ
r0   c                 C   s   d| krd| krd|  S | S )zB
    Quote the argument for safe use in a shell command line.
    ú"rI   z"%s"r   r   r   r   r   Ú
_quote_argÈ   s    rc   c                 C   s<   t | ttfƒrdS zt| ƒ W dS  tk
r6   Y dS X d S )NFT)Ú
isinstanceÚstrÚbytesÚlenr(   r   r   r   r   Ú_is_sequenceÓ   s    rh   )%Ú
setuptoolsZsetuptools.command.build_extr   Zsetuptools.distr   Únumpyr<   Ú	functoolsr   Ú
subprocessr   Útempfiler   Ú
contextlibr   Úpathlibr   Ú	distutilsZ	ccompilerrW   r!   Ú	sysconfigr"   rC   r   r   ÚpartialZfind_shared_endingZfind_pyext_endingr   Ú	lru_cacher*   Úobjectr+   r0   rc   rh   r   r   r   r   Ú<module>   s8   


ý


x