3
ßL]P  ã               @   s  d dl mZmZ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	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 d dl m!Z! ded< ded< G dd„ deƒZG dd„ de"ƒZ#dS )é    )ÚdivisionÚabsolute_importÚprint_functionN)Ú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_inlineÚcheck_restrictÚcheck_compiler_gcc4)Úget_exceptionz.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d3dd„Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd4d*d+„ZdS )5r   ú
fcompiler=Nú!specify the Fortran compiler typec             C   s   d | _ tj| ƒ d S )N)Ú	fcompilerÚ
old_configÚinitialize_options)Úself© r   úA/tmp/pip-install-q_7g0qgj/Numpy/numpy/distutils/command/config.pyr   %   s    zconfig.initialize_optionsc             C   s>  t j| ƒ ddlm}m} tjdkrØ| jjdkrØ| jj	s”y| jj
ƒ  W nL tk
r’   tƒ }tjdƒ|| jjjf }ttjdƒƒ tjj|ƒ‚Y nX dd	lm} |jƒ d
krØx*| jj| jjgD ]}d|kr¾|jdƒ q¾W t| j|ƒ�s:|| j| jd| jd�| _| jd k	�r:| jj| jƒ | jjƒ �r:| jj | ƒ | jj!ƒ  d S )Nr   )Ú	FCompilerÚnew_fcompilerÚwin32ÚmsvcÚintelwÚ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!   r"   r#   )"r   Ú_check_compilerZnumpy.distutils.fcompilerr   r   ÚsysÚplatformr'   Úcompiler_typeZinitializedZ
initializeÚIOErrorr   Ú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   sx   ddl m} ddlm} | j}|dkr.| j| _y|| f| Ž }W n, ||fk
rl   ttƒ ƒ || _|‚Y nX || _|S )Nr   )r	   )ÚDistutilsExecErrorr   r   )r   r   )Údistutils.ccompilerr	   Údistutils.errorsr=   r'   r   Ústrr   )r   ZmthÚlangÚargsr	   r=   Zsave_compilerÚretr   r   r   Ú_wrap_method[   s    

zconfig._wrap_methodc             C   s4   | j tj|||||fƒ\}}| jj|d ƒ ||fS )Nz.d)rD   r   Ú_compileÚ
temp_filesr7   )r   ÚbodyÚheadersÚinclude_dirsrA   ÚsrcÚobjr   r   r   rE   j   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Êx`| jjpLg D ]P}|jdƒr”ytjdd|gƒ}W n ttjfk
rŠ   Y n
X t	|ƒ}|j
|ƒ qNW x&| jjp®g D ]}||kr°|j
|ƒ q°W xî|D ]Î}|jdƒràqÐd}	x4|pìg D ](}
tjj|
d	| ƒ}tjj|ƒrîd
}	P qîW |	�r"qÐd}	x\|D ]T}
tjj|
d| ƒ}tjj|ƒ�r,tjj|
d	| ƒ}t||ƒ | jj
|ƒ d
}	P �q,W |	�rŒqÐtjd||f ƒ qÐW n| j jdk�rºt| ƒ | jtj|||||||fƒS )Nr!   r   r   Úcz/usr/libZcygpathz-wFz%s.libTzlib%s.az+could not find library %r in directories %sZmingw32)r   r   )r'   r-   r   Úlibrary_dirsÚ
startswithÚ
subprocessÚcheck_outputÚOSErrorÚCalledProcessErrorr   r7   Ú	librariesÚosÚpathÚjoinÚisfiler   rF   r   Úwarnr   rD   r   Ú_link)r   rG   rH   rI   rS   rM   rA   ÚdZlibnameZ
fileexistsZlibdirZlibfileZlibfile2r   r   r   rY   r   s^    


  

 
zconfig._linkrL   c             C   s   | j ƒ  | jd|g|ƒS )Nz2/* we need a dummy line to make distutils happy */)r*   Útry_compile)r   ÚheaderrI   rM   rA   r   r   r   Úcheck_header¨   s    zconfig.check_headerc             C   s(   | j ƒ  tjdƒ||f }| j|||ƒS )Nz¨
            int main(void)
            {
            #ifndef %s
                (void) %s;
            #endif
                ;
                return 0;
            })r*   r/   r0   r[   )r   ÚsymbolrH   rI   rG   r   r   r   Ú
check_decl®   s    zconfig.check_declc             C   s&   | j ƒ  tjdƒ|f }| j|||ƒS )NzÇ
            int main(void)
            {
            #if %s
            #else
            #error false or undefined macro
            #endif
                ;
                return 0;
            })r*   r/   r0   r[   )r   r^   rH   rI   rG   r   r   r   Úcheck_macro_true½   s    	zconfig.check_macro_truec             C   sp   | j ƒ  tjdƒd|i }d}zBy | j|d|i ||dƒ d}W n tjjk
r\   d}Y nX W d| jƒ  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ÚtyperL   TN)r*   r/   r0   rE   r4   r5   r	   Ú_clean)r   Ú	type_namerH   rI   rM   rG   Ústr   r   r   Ú
check_typeÍ   s    

zconfig.check_typec             C   sf  | j ƒ  tjdƒ}| j|d|i ||dƒ | jƒ  |rŠtjdƒ}xH|D ]@}y&| j|||dœ ||dƒ | jƒ  |S  tk
r„   Y qFX qFW tjdƒ}d}d}	xVy(| j|||	dœ ||dƒ | jƒ  P W qž tk
rî   |	d }d	|	 d }	Y qžX qžW |	}
xh||
k�r`|
| d	 | }	y*| j|||	dœ ||dƒ | jƒ  |	}
W qú tk
�r\   |	d }Y qúX qúW |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;
            }
            rb   rL   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;
                }
                )rb   Ú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/   r0   rE   rc   r	   )r   rd   rH   rI   rM   ÚexpectedrG   rg   ÚlowZmidÚhighr   r   r   Úcheck_type_sizeê   sR    








zconfig.check_type_sizeFc	       
      C   sÈ   | j ƒ  g }	|r6t|ƒtkr(|	j|ƒ n|	jd| ƒ |	jdƒ |	jd| ƒ |	jdƒ |	jdƒ |r†|d krrd}|	jd||f ƒ n|	jd| ƒ |	jd	ƒ |	jd
ƒ dj|	ƒd }	| j|	||||ƒS )Nzint %s (void);z#ifdef _MSC_VERz#pragma function(%s)z#endifzint main (void) {Ú z	  %s(%s);z  %s;z  return 0;Ú}Ú
)r*   rb   r@   r7   rV   Útry_link)
r   ÚfuncrH   rI   rS   rM   ÚdeclÚcallÚ	call_argsrG   r   r   r   Ú
check_func=  s(    





zconfig.check_funcc	             C   s*  | j ƒ  g }	|r8x&|jƒ D ]\}
}|r|	jd|
 ƒ qW |	jdƒ x|D ]}|	jd| ƒ qHW |	jdƒ |	jdƒ |rÚx~|D ]X}
|
|krÆ||
 rÆ|o¢|
|ko¢||
 sªd}n||
 }|	jd|
|f ƒ q||	jd|
 ƒ q|W nx|D ]}
|	jd|
 ƒ qàW |	jd	ƒ |	jd
ƒ dj|	ƒd }	| j|	||||ƒ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.
        zint %s (void);z#ifdef _MSC_VERz#pragma function(%s)z#endifzint main (void) {rm   z	  %s(%s);z  %s;z  return 0;rn   ro   )r*   Úitemsr7   rV   rp   )r   ÚfuncsrH   rI   rS   rM   rr   rs   rt   rG   ÚfÚvrq   rB   r   r   r   Úcheck_funcs_once_  s4    








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 >= 4.)r   )r   r   r   r   r   ¦  s    zconfig.check_compiler_gcc4c             C   s   t | ||ƒS )N)r   )r   Ú	attributera   r   r   r   r   ª  s    z#config.check_gcc_function_attributec             C   s   t | ||||ƒS )N)r   )r   r{   ra   ÚcodeÚincluder   r   r   r   ­  s    z3config.check_gcc_function_attribute_with_intrinsicsc             C   s
   t | |ƒS )N)r   )r   r{   r   r   r   r   ²  s    z#config.check_gcc_variable_attributec             C   s~  t jdtdd� | jƒ  d\}}	�y&tƒ }
y&| j||||||ƒ\}}}|
jƒ  W n$ tk
rt   |
j}	|
jƒ  ‚ Y nX t	j
jd|ƒ}ytj|gdd�}	W nH tjk
rÆ } z|j}d}	W Y dd}~X n$ tk
rà   d	}d}	Y n
X t|	ƒ}	tt	d
ƒ�r8t	j|ƒ}t	j|ƒ�r<t	j|ƒ}tjd|f ƒ |tjk�r<t‚n|}tjdƒ W n$ ttfk
�rl   tjdƒ Y nX | jƒ  ||	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.
+++++++++++++++++++++++++++++++++++++++++++++++++
rh   )Ú
stackleveléÿ   rm   Ú.)ÚcwdNé   ÚWEXITSTATUSz subprocess exited with signal %dzsuccess!zfailure.)r   rm   )ÚwarningsrX   ÚDeprecationWarningr*   Ú
GrabStdoutrY   ÚrestoreÚ	ExceptionÚdatarT   rU   rV   rO   rP   rR   Ú
returncoderQ   r   Úhasattrrƒ   ÚWIFSIGNALEDÚWTERMSIGr   ÚerrorÚsignalÚSIGINTÚKeyboardInterruptÚinfor	   r
   rc   )r   rG   rH   rI   rS   rM   rA   Zuse_teeÚexitcodeÚoutputZgrabberrJ   rK   ZexeÚexcZ
exitstatusÚsigr   r   r   Ú
get_outputµ  sJ    




zconfig.get_output)r   Nr   )NNrL   )NN)NN)NNN)NNNN)NNNNFFN)NNNNFFN)NNNNrL   N)r2   Ú
__module__Ú__qualname__r   Úuser_optionsr   r*   rD   rE   rY   r]   r_   r`   rf   rl   ru   rz   r   r   r   r   r   r   r—   r   r   r   r   r       s8   
2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 )Nrm   )r+   ÚstdoutÚ
sys_stdoutr‰   )r   r   r   r   Ú__init__ô  s    zGrabStdout.__init__c             C   s   | j j|ƒ |  j|7  _d S )N)rœ   Úwriter‰   )r   r‰   r   r   r   rž   ù  s    zGrabStdout.writec             C   s   | j jƒ  d S )N)rœ   Úflush)r   r   r   r   rŸ   ý  s    zGrabStdout.flushc             C   s   | j t_d S )N)rœ   r+   r›   )r   r   r   r   r‡      s    zGrabStdout.restoreN)r2   r˜   r™   r�   rž   rŸ   r‡   r   r   r   r   r†   ò  s   r†   )$Ú
__future__r   r   r   rT   r�   r„   r+   rO   r/   Zdistutils.command.configr   r   r   r4   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   Znumpy.distutils.compatr   Úobjectr†   r   r   r   r   Ú<module>   s,       U