a
    p=icP                     @   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   o/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/numpy/distutils/command/config.pyr   $   s    zconfig.initialize_optionsc              
   C   sF  t |  ddlm}m} tjdkr| jjdv r| jj	sz| j
  W nX ty } z@td|| jjjf }ttd tj||W Y d }~n
d }~0 0 ddlm} | dkr| jj| jjfD ]}d	|vr|d	 qt| j|sB|| j| jd
| jd| _| jd urB| j| j | j rB| 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v r.| j| _| jd u rF|d|f z|| f|  }W n4 ||fy } z|| _||W Y d }~n
d }~0 0 || _|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v rd}| jr| jjpJg D ]N}|drztdd|g}W n ttjfy   Y n
0 t	|}|
| qL| jjpg D ]}||vr|
| q|D ]}|drqd}	|pg D ],}
tj|
d| }tj|rd	}	 qq|	rqd}	|D ]X}
tj|
d
| }tj|rtj|
d| }t|| | j
| d	}	 qxq|	rqtd||f  qn| j jdkrt|  | 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<   dZlibnameZ
fileexistslibdirZlibfileZlibfile2r   r   r   rT   q   s`    





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   sv   |    tdd|i }d}zHz | |d|i ||d d}W n tjjyZ   d}Y n0 W |   n
|   0 |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+   r@   r/   r0   r   _clean)r   	type_namerC   rD   rH   rB   str   r   r   
check_type   s    	zconfig.check_typec              	   C   s\  |    td}| |d|i ||d |   |rtd}|D ]D}z,| |||d ||d |   |W   S  ty   Y qD0 qDtd}d}d}	z*| |||	d ||d |   W qW q ty   |	d }d	|	 d }	Y q0 q|	}
||
krX|
| d	 | }	z*| |||	d ||d |   |	}
W q tyT   |	d }Y q0 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   sR    




zconfig.check_type_sizeFc	           
      C   s   |    g }	|r6t|tkr(|	| n|	d|  |	d |	d|  |	d |	d |r|d u 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}
|
|v r||
 r|r|
|v r||
 sd}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^  s6    





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   sz  t jdtdd |   d\}}	z$t }
z&| ||||||\}}}|
  W n" tyr   |
j}	|
   Y n0 t	j
d|}ztj|gdd}	W nH tjy } z|j}d}	W Y d}~n*d}~0  ty   d	}d}	Y n
0 t|	}	tt	d
r6t	|}t	|r:t	|}td|f  |tjkr:tn|}td W n" ttfyh   td Y n0 |   ||	fS )zTry 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  sN    




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      sH   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