U
    ÉZjôP  ã                   @   sæ   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mZ d dlmZmZ d dl
Z
d dlmZ d dlmZ d d	lmZmZmZmZmZmZmZ d
e	d< de	d< G dd„ deƒZG dd„ dƒZdS )é    N)Úconfig)ÚLANG_EXT)Úlog)Ú	copy_file)ÚCompileErrorÚ	LinkError)Úfilepath_from_subprocess_output)Úgenerate_manifest)Úcheck_gcc_function_attributeÚ,check_gcc_function_attribute_with_intrinsicsÚcheck_gcc_variable_attributeÚcheck_gcc_version_at_leastÚcheck_inlineÚcheck_restrictÚcheck_compiler_gccz.fÚf77z.f90Úf90c                   @   sÎ   e Zd Ze jdg7  _dd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Z	d.dd„Z
d/dd„Zd0dd„Zd1dd„Zd2dd„Zd3dd„Zd4dd„Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd5d*d+„Zd6d,d-„ZdS )7r   )z
fcompiler=Nz!specify the Fortran compiler typec                 C   s   d | _ t | ¡ d S ©N)Ú	fcompilerÚ
old_configÚinitialize_options©Úself© r   úa/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/numpy/distutils/command/config.pyr   $   s    zconfig.initialize_optionsc              
   C   sD  t  | ¡ ddlm}m} tjdkrÞ| jjdkrÞ| jj	sžz| j 
¡  W nV tk
rœ } z8t d¡|| jjjf }tt d¡ƒ tj |¡|‚W 5 d }~X Y nX ddlm} | ¡ dkrÞ| jj| jjfD ]}d	|krÆ| d	¡ qÆt| j|ƒ�s@|| j| jd
| jd�| _| jd k	�r@| j | j¡ | j ¡ �r@| j | ¡ | j  ¡  d S )Nr   )Ú	FCompilerÚnew_fcompilerÚwin32)ÚmsvcZintelwZintelemwas                          Could not initialize compiler instance: do you have Visual Studio
                        installed?  If you are trying to build with MinGW, please use "python setup.py
                        build -c mingw32" instead.  If you have Visual Studio installed, check it is
                        correctly installed, and the right version (VS 2008 for python 2.6, 2.7 and 3.2,
                        VS 2010 for >= 3.3).

                        Original exception was: %s, and the Compiler class was %s
                        ============================================================================zd                        ============================================================================)Úmsvc9compileré
   z	/MANIFESTé   )ÚcompilerÚdry_runÚforceZ
c_compiler)!r   Ú_check_compilerZnumpy.distutils.fcompilerr   r   ÚsysÚplatformr"   Úcompiler_typeZinitializedZ
initializeÚIOErrorÚtextwrapÚdedentÚ	__class__Ú__name__ÚprintÚ	distutilsÚerrorsÚDistutilsPlatformErrorr   Zget_build_versionZldflags_sharedZldflags_shared_debugÚappendÚ
isinstancer   r#   Z	customizeÚdistributionÚget_versionZcustomize_cmdZshow_customization)r   r   r   ÚeÚmsgr   Zldflagsr   r   r   r%   (   s@    
ÿ	÷
 ÿ þzconfig._check_compilerc           	   
   C   s–   ddl m} ddlm} | j}|dkr.| j| _| jd krF|d|f ƒ‚z|| f| Ž }W n2 ||fk
rŠ } z|| _||‚W 5 d }~X Y nX || _|S )Nr   )r   )ÚDistutilsExecError©r   r   z%s compiler is not set)Údistutils.ccompilerr   Údistutils.errorsr8   r"   r   )	r   ZmthÚlangÚargsr   r8   Zsave_compilerÚretr6   r   r   r   Ú_wrap_methodY   s    
zconfig._wrap_methodc                 C   s4   |   tj|||||f¡\}}| j |d ¡ ||fS )Nz.d)r?   r   Ú_compileÚ
temp_filesr2   )r   ÚbodyÚheadersÚinclude_dirsr<   ÚsrcÚobjr   r   r   r@   i   s
    

ÿzconfig._compilec              
   C   sÊ  | j jdk�r˜|pg d d … }|p$g d d … }|dkrÂd}| jrÂ| jjpJg D ]P}| d¡r’zt dd|g¡}W n ttjfk
rˆ   Y n
X t	|ƒ}| 
|¡ qL| jjp¨g D ]}||krª| 
|¡ qª|D ]Î}| d¡rÖqÆd}	|pàg D ],}
tj |
d| ¡}tj |¡râd	}	 �qqâ|	�rqÆd}	|D ]X}
tj |
d
| ¡}tj |¡�r tj |
d| ¡}t||ƒ | j 
|¡ d	}	 �qz�q |	�r‚qÆt d||f ¡ qÆn| j jdk�r®t| ƒ |  tj|||||||f¡S )Nr   r9   Úcz/usr/libZcygpathz-wFz%s.libTzlib%s.az+could not find library %r in directories %sZmingw32)r"   r(   r   Úlibrary_dirsÚ
startswithÚ
subprocessÚcheck_outputÚOSErrorÚCalledProcessErrorr   r2   Ú	librariesÚosÚpathÚjoinÚisfiler   rA   r   Úwarnr	   r?   r   Ú_link)r   rB   rC   rD   rN   rH   r<   ÚdÚlibnameZ
fileexistsZlibdirZlibfileZlibfile2r   r   r   rT   q   sl    
 ÿ

  

 ÿ

  ÿÿzconfig._linkNrG   c                 C   s   |   ¡  |  d|g|¡S )Nz2/* we need a dummy line to make distutils happy */)r%   Útry_compile)r   ÚheaderrD   rH   r<   r   r   r   Úcheck_header§   s     þzconfig.check_headerc                 C   s(   |   ¡  t d¡||f }|  |||¡S )Nz¨
            int main(void)
            {
            #ifndef %s
                (void) %s;
            #endif
                ;
                return 0;
            }©r%   r*   r+   rW   ©r   ÚsymbolrC   rD   rB   r   r   r   Ú
check_decl­   s
    ø
zconfig.check_declc                 C   s&   |   ¡  t d¡|f }|  |||¡S )NzÇ
            int main(void)
            {
            #if %s
            #else
            #error false or undefined macro
            #endif
                ;
                return 0;
            }rZ   r[   r   r   r   Úcheck_macro_true¼   s
    	÷zconfig.check_macro_truec                 C   sp   |   ¡  t d¡d|i }d}zBz |  |d|i ||d¡ d}W n tjjk
r\   d}Y nX W 5 |  ¡  X |S )zYCheck type availability. Return True if the type can be compiled,
        False otherwisez³
            int main(void) {
              if ((%(name)s *) 0)
                return 0;
              if (sizeof (%(name)s))
                return 0;
            }
            ÚnameFÚtyperG   T)r%   r*   r+   Ú_cleanr@   r/   r0   r   )r   Ú	type_namerC   rD   rH   rB   Ústr   r   r   Ú
check_typeÌ   s"    ù	  ÿ
zconfig.check_typec              	   C   sb  |   ¡  t d¡}|  |d|i ||d¡ |  ¡  |rŒt d¡}|D ]F}z,|  |||dœ ||d¡ |  ¡  |W   S  tk
rˆ   Y qDX qDt d¡}d}d}	z*|  |||	dœ ||d¡ |  ¡  W qôW qž tk
rð   |	d }d	|	 d }	Y qžX qž|	}
||
k�r^|
| d	 | }	z*|  |||	dœ ||d¡ |  ¡  |	}
W qø tk
�rZ   |	d }Y qøX qø|S )
zCheck size of a given type.a,  
            typedef %(type)s npy_check_sizeof_type;
            int main (void)
            {
                static int test_array [1 - 2 * !(((long) (sizeof (npy_check_sizeof_type))) >= 0)];
                test_array [0] = 0

                ;
                return 0;
            }
            r`   rG   aW  
                typedef %(type)s npy_check_sizeof_type;
                int main (void)
                {
                    static int test_array [1 - 2 * !(((long) (sizeof (npy_check_sizeof_type))) == %(size)s)];
                    test_array [0] = 0

                    ;
                    return 0;
                }
                )r`   Úsizea3  
            typedef %(type)s npy_check_sizeof_type;
            int main (void)
            {
                static int test_array [1 - 2 * !(((long) (sizeof (npy_check_sizeof_type))) <= %(size)s)];
                test_array [0] = 0

                ;
                return 0;
            }
            r   r!   é   )r%   r*   r+   r@   ra   r   )r   rb   rC   rD   rH   ÚexpectedrB   re   ÚlowÚmidÚhighr   r   r   Úcheck_type_sizeé   sb    
  ÿ
  ÿ

  ÿ
  ÿzconfig.check_type_sizeFc	           
      C   sÈ   |   ¡  g }	|r6t|ƒtkr(|	 |¡ n|	 d| ¡ |	 d¡ |	 d| ¡ |	 d¡ |	 d¡ |r†|d krrd}|	 d||f ¡ n|	 d| ¡ |	 d	¡ |	 d
¡ d |	¡d }	|  |	||||¡S )Núint %s (void);ú#ifdef _MSC_VERú#pragma function(%s)ú#endifúint main (void) {Ú ú	  %s(%s);ú  %s;ú  return 0;Ú}Ú
)r%   r`   Ústrr2   rQ   Útry_link)
r   ÚfuncrC   rD   rN   rH   ÚdeclÚcallÚ	call_argsrB   r   r   r   Ú
check_func<  s,    





 ÿzconfig.check_funcc	                 C   s  |   ¡  g }	|r4| ¡ D ]\}
}|r|	 d|
 ¡ q|	 d¡ |D ]}|	 d| ¡ qB|	 d¡ |	 d¡ |rÎ|D ]X}
|
|kr¼||
 r¼|rš|
|krš||
 s d}n||
 }|	 d|
|f ¡ qr|	 d|
 ¡ qrn|D ]}
|	 d|
 ¡ qÒ|	 d	¡ |	 d
¡ d |	¡d }	|  |	||||¡S )a0  Check a list of functions at once.

        This is useful to speed up things, since all the functions in the funcs
        list will be put in one compilation unit.

        Arguments
        ---------
        funcs : seq
            list of functions to test
        include_dirs : seq
            list of header paths
        libraries : seq
            list of libraries to link the code snippet to
        library_dirs : seq
            list of library paths
        decl : dict
            for every (key, value), the declaration in the value will be
            used for function in key. If a function is not in the
            dictionary, no declaration will be used.
        call : dict
            for every item (f, value), if the value is True, a call will be
            done to the function f.
        rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   )r%   Úitemsr2   rQ   rx   )r   ÚfuncsrC   rD   rN   rH   rz   r{   r|   rB   ÚfÚvry   r=   r   r   r   Úcheck_funcs_once^  s8    





 ÿzconfig.check_funcs_oncec                 C   s   t | ƒS )zUReturn the inline keyword recognized by the compiler, empty string
        otherwise.)r   r   r   r   r   r   ›  s    zconfig.check_inlinec                 C   s   t | ƒS )zWReturn the restrict keyword recognized by the compiler, empty string
        otherwise.)r   r   r   r   r   r      s    zconfig.check_restrictc                 C   s   t | ƒS )z$Return True if the C compiler is gcc)r   r   r   r   r   r   ¥  s    zconfig.check_compiler_gccc                 C   s   t | ||ƒS r   )r
   )r   Ú	attributer_   r   r   r   r
   ©  s    z#config.check_gcc_function_attributec                 C   s   t | ||||ƒS r   )r   )r   rƒ   r_   ÚcodeÚincluder   r   r   r   ¬  s
      ÿz3config.check_gcc_function_attribute_with_intrinsicsc                 C   s
   t | |ƒS r   )r   )r   rƒ   r   r   r   r   ±  s    z#config.check_gcc_variable_attributer   c                 C   s   t | |||ƒS )zYReturn True if the GCC version is greater than or equal to the
        specified version.)r   )r   ÚmajorÚminorZ
patchlevelr   r   r   r   ´  s    z!config.check_gcc_version_at_leastc              
   C   s~  t jdtdd� |  ¡  d\}}	�z&tƒ }
z&|  ||||||¡\}}}|
 ¡  W n$ tk
rt   |
j}	|
 ¡  ‚ Y nX t	j
 d|¡}ztj|gdd�}	W nH tjk
rÆ } z|j}d}	W 5 d}~X Y n$ tk
rà   d	}d}	Y n
X t|	ƒ}	tt	d
ƒ�r8t	 |¡}t	 |¡�r<t	 |¡}t d|f ¡ |tjk�r<t‚n|}t d¡ W n$ ttfk
�rl   t d¡ Y nX |  ¡  ||	fS )z®Try to compile, link to an executable, and run a program
        built from 'body' and 'headers'. Returns the exit status code
        of the program and its output.
        zû
+++++++++++++++++++++++++++++++++++++++++++++++++
Usage of get_output is deprecated: please do not 
use it anymore, and avoid configuration checks 
involving running executable on the target machine.
+++++++++++++++++++++++++++++++++++++++++++++++++
rf   )Ú
stacklevel)éÿ   rq   Ú.)Úcwdrq   Né   ÚWEXITSTATUSz subprocess exited with signal %dzsuccess!zfailure.)ÚwarningsrS   ÚDeprecationWarningr%   Ú
GrabStdoutrT   ÚrestoreÚ	ExceptionÚdatarO   rP   rQ   rJ   rK   rM   Ú
returncoderL   r   Úhasattrr�   ÚWIFSIGNALEDÚWTERMSIGr   ÚerrorÚsignalÚSIGINTÚKeyboardInterruptÚinfor   r   ra   )r   rB   rC   rD   rN   rH   r<   Zuse_teeÚexitcodeÚoutputZgrabberrE   rF   ÚexeÚexcZ
exitstatusÚsigr   r   r   Ú
get_output¹  sT     û
  ÿ



zconfig.get_output)NNrG   )NN)NN)NNN)NNNN)NNNNFFN)NNNNFFN)r   r   )NNNNrG   N)r-   Ú
__module__Ú__qualname__r   Úuser_optionsr   r%   r?   r@   rT   rY   r]   r^   rd   rk   r}   r‚   r   r   r   r
   r   r   r   r¢   r   r   r   r   r      s`   ÿ16
   ÿ
   ÿ
  ÿ

T           ý
#           ý
=
       þr   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
r�   c                 C   s   t j| _d| _| t _d S )Nrq   )r&   ÚstdoutÚ
sys_stdoutr“   r   r   r   r   Ú__init__ø  s    zGrabStdout.__init__c                 C   s   | j  |¡ |  j|7  _d S r   )r§   Úwriter“   )r   r“   r   r   r   r©   ý  s    zGrabStdout.writec                 C   s   | j  ¡  d S r   )r§   Úflushr   r   r   r   rª     s    zGrabStdout.flushc                 C   s   | j t_d S r   )r§   r&   r¦   r   r   r   r   r‘     s    zGrabStdout.restoreN)r-   r£   r¤   r¨   r©   rª   r‘   r   r   r   r   r�   ö  s   r�   )rO   r™   rJ   r&   r*   rŽ   Zdistutils.command.configr   r   r   r/   r   Údistutils.file_utilr   r:   r   r   Znumpy.distutils.exec_commandr   Z numpy.distutils.mingw32ccompilerr	   Z numpy.distutils.command.autodistr
   r   r   r   r   r   r   r�   r   r   r   r   Ú<module>   s*   $   Z