o
    "gP                     @   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	d/ddZ		d0ddZd1ddZ			d2ddZ			d2ddZdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd3d*d+Z			d4d,d-ZdS )5r   )z
fcompiler=Nz!specify the Fortran compiler typec                 C   s   d | _ t|  d S N)	fcompiler
old_configinitialize_optionsself r   `/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/numpy/distutils/command/config.pyr   $   s   zconfig.initialize_optionsc              
   C   s@  t |  ddlm}m} tjdkrj| jjdv rj| jj	sJz| j
  W n& tyI } ztd|| jjjf }ttd tj||d }~ww ddlm} | dkrj| jj| jjfD ]}d	|vri|d	 q^t| j|s|| j| jd
| jd| _| jd ur| j| j | j r| j|  | j   d S d S d S d S )Nr   )	FCompilernew_fcompilerwin32)msvcintelwintelemwa>                          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 2015 as of this writing).

                        Original exception was: %s, and the Compiler class was %s
                        ============================================================================zd                        ============================================================================)msvc9compiler
   z	/MANIFEST   )compilerdry_runforce
c_compiler)!r   _check_compilernumpy.distutils.fcompilerr   r   sysplatformr$   compiler_typeinitialized
initializeOSErrortextwrapdedent	__class____name__print	distutilserrorsDistutilsPlatformErrorr!   get_build_versionldflags_sharedldflags_shared_debugappend
isinstancer   r%   	customizedistributionget_versioncustomize_cmdshow_customization)r   r   r   emsgr!   ldflagsr   r   r   r(   (   sJ   
	


zconfig._check_compilerc           	   
   C   s   ddl m} ddlm} | j}|dv r| j| _| jd u r#|d|f z	|| f|  }W n ||fy@ } z|| _||d }~ww || _|S )Nr   )r   )DistutilsExecErrorr   r   z%s compiler is not set)distutils.ccompilerr   distutils.errorsrE   r$   r   )	r   mthlangargsr   rE   save_compilerretrB   r   r   r   _wrap_methodX   s    
zconfig._wrap_methodc                 C   s4   |  tj|||||f\}}| j|d  ||fS )Nz.d)rN   r   _compile
temp_filesr;   )r   bodyheadersinclude_dirsrJ   srcobjr   r   r   rO   h   s
   

zconfig._compilec              
   C   s  | j jdkr|p	g d d  }|pg d d  }|dv r_d}| jr_| jjp$g D ]'}|drGz
tdd|g}W n ttjfyB   Y nw t	|}|
| q%| jjpRg D ]}||vr^|
| qS|D ]a}|driqad}	|png D ]}
tj|
d| }tj|rd	}	 nqo|	rqad}	|D ])}
tj|
d
| }tj|rtj|
d| }t|| | j
| d	}	 nq|	rqatd||f  qan
| j jdkrt|  | tj|||||||fS )Nr   rF   cz/usr/libcygpathz-wFz%s.libTzlib%s.az+could not find library %r in directories %smingw32)r$   r,   r   library_dirs
startswith
subprocesscheck_outputr/   CalledProcessErrorr   r;   	librariesospathjoinisfiler   rP   r   warnr	   rN   r   _link)r   rQ   rR   rS   r^   rY   rJ   dlibname
fileexistslibdirlibfilelibfile2r   r   r   rd   p   sj   




zconfig._linkNrV   c                 C   s   |    | d|g|S )Nz2/* we need a dummy line to make distutils happy */)r(   try_compile)r   headerrS   rY   rJ   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(   r0   r1   rk   r   symbolrR   rS   rQ   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;
            }rn   ro   r   r   r   check_macro_true   s
   	zconfig.check_macro_truec                 C   s   |    tdd|i }d}z,z| |d|i ||d d}W n tjjy-   d}Y nw W |   |S W |   |S |   w )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typerV   T)r(   r0   r1   rO   r5   r6   r   _clean)r   	type_namerR   rS   rY   rQ   str   r   r   
check_type   s*   	
zconfig.check_typec              	   C   sZ  |    td}| |d|i ||d |   |rDtd}|D ]!}z| |||d ||d |   |W   S  tyC   Y q"w td}d}d}		 z| |||	d ||d |   W n tyt   |	d	 }d
|	 d	 }	Y nw qN|	}
||
kr|
| d
 | }	z| |||	d ||d |   |	}
W n ty   |	d	 }Y nw ||
ks||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;
            }
            rt   rV   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;
                }
                )rt   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   Tr#      )r(   r0   r1   rO   ru   r   )r   rv   rR   rS   rY   expectedrQ   ry   lowmidhighr   r   r   check_type_size   s^   



	zconfig.check_type_sizeFc	           
      C   s   |    g }	|rt|tkr|	| n|	d|  |	d |	d|  |	d |	d |rC|d u r9d}|	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(   rt   strr;   ra   try_link)
r   funcrR   rS   r^   rY   declcall	call_argsrQ   r   r   r   
check_func;  s*   





zconfig.check_funcc	                 C   s  |    g }	|r| D ]\}
}|r|	d|
  q|	d |D ]	}|	d|  q!|	d |	d |rg|D ],}
|
|v r^||
 r^|rM|
|v rM||
 sPd}n||
 }|	d|
|f  q9|	d|
  q9n|D ]	}
|	d|
  qi|	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.
        r   r   r   r   r   r   r   r   r   r   r   )r(   itemsr;   ra   r   )r   funcsrR   rS   r^   rY   r   r   r   rQ   fvr   rK   r   r   r   check_funcs_once]  s:   






zconfig.check_funcs_oncec                 C      t | S )zUReturn the inline keyword recognized by the compiler, empty string
        otherwise.)r   r   r   r   r   r        zconfig.check_inlinec                 C   r   )zWReturn the restrict keyword recognized by the compiler, empty string
        otherwise.)r   r   r   r   r   r     r   zconfig.check_restrictc                 C   r   )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   	attributers   r   r   r   r
        z#config.check_gcc_function_attributec                 C   s   t | ||||S r   )r   )r   r   rs   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minor
patchlevelr   r   r   r     s   z!config.check_gcc_version_at_leastc              
   C   sl  t jdtdd |   d\}}	zt }
z| ||||||\}}}|
  W n ty6   |
j}	|
   w t	j
d|}z
tj|gdd}	W n$ tjy` } z|j}d}	W Y d}~nd}~w tyl   d	}d}	Y nw t|	}	tt	d
rt	|}t	|rt	|}td|f  |tjkrtn|}td W n ttfy   td Y nw |   ||	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.
+++++++++++++++++++++++++++++++++++++++++++++++++
rz   )
stacklevel)   r   .)cwdr   N   WEXITSTATUSz subprocess exited with signal %dzsuccess!zfailure.)warningsrc   DeprecationWarningr(   
GrabStdoutrd   restore	Exceptiondatar_   r`   ra   r[   r\   r]   
returncoder/   r   hasattrr   WIFSIGNALEDWTERMSIGr   errorsignalSIGINTKeyboardInterruptinfor   r   ru   )r   rQ   rR   rS   r^   rY   rJ   use_teeexitcodeoutputgrabberrT   rU   exeexc
exitstatussigr   r   r   
get_output  sX   






zconfig.get_output)NNrV   )NN)NNN)NNNN)NNNNFFN)r   r   )NNNNrV   N)r3   
__module____qualname__r   user_optionsr   r(   rN   rO   rd   rm   rq   rr   rx   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r      sJ    0
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 )Nr   )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     r   zGrabStdout.restoreN)r3   r   r   r   r   r   r   r   r   r   r   r     s
    r   )r_   r   r[   r*   r0   r   distutils.command.configr   r   r   r5   r   distutils.file_utilr   rG   r   r   numpy.distutils.exec_commandr    numpy.distutils.mingw32ccompilerr	    numpy.distutils.command.autodistr
   r   r   r   r   r   r   r   r   r   r   r   <module>   s,   $   Y