a
    iÝEb…|  ã                   @   sÌ   d 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
mZm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mZmZmZmZ ddlmZ ddlmZm Z  G dd„ deƒZdS )zC Modified version of build_ext that handles fortran source files.

é    N)Úglob)Únewer_group)Ú	build_ext)ÚDistutilsFileErrorÚDistutilsSetupErrorÚDistutilsError)Ú	copy_file)Úlog)Úfilepath_from_subprocess_output)Úcombine_paths)Úfilter_sourcesÚget_ext_source_filesÚget_numpy_include_dirsÚhas_cxx_sourcesÚhas_f_sourcesÚis_sequence)Úshow_fortran_compilers)Únew_ccompiler_optÚCCompilerOptc                   @   s’   e Zd ZdZejg d¢ Zejdddefg Zejddg Zdd	„ Z	d
d„ Z
dd„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r   z:build C/C++/F extensions (compile/link to build directory)))z
fcompiler=Nz!specify the Fortran compiler type)z	parallel=Újznumber of parallel jobs)ú
warn-errorNz'turn all warnings into errors (-Werror))zcpu-baseline=Nz4specify a list of enabled baseline CPU optimizations)zcpu-dispatch=Nz.specify a list of dispatched CPU optimizations)údisable-optimizationNz1disable CPU optimized code(dispatch,simd,fast...))z
simd-test=NzMspecify a list of CPU optimizations to be tested against NumPy SIMD interfacezhelp-fcompilerNz list available Fortran compilersr   r   c                 C   s8   t  | ¡ d | _d | _d | _d | _d | _d | _d | _d S ©N)	Úold_build_extÚinitialize_optionsÚ	fcompilerÚparallelÚ
warn_errorÚcpu_baselineÚcpu_dispatchÚdisable_optimizationÚ	simd_test©Úself© r$   úa/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/numpy/distutils/command/build_ext.pyr   4   s    
zbuild_ext.initialize_optionsc              
   C   sÆ   | j rFzt| j ƒ| _ W n. tyD } ztdƒ|‚W Y d }~n
d }~0 0 t| jtƒrb| j tj¡| _| jpjg }| j	jd u r€g | j	_| j	j| _| j 
|¡ t | ¡ |  ddddddd¡ | jtjd	< d S )
Nz)--parallel/-j argument must be an integerÚbuild)r   r   )r   r   )r   r   )r   r   )r    r    )r!   r!   r!   )r   ÚintÚ
ValueErrorÚ
isinstanceÚinclude_dirsÚstrÚsplitÚosÚpathsepÚdistributionÚextendr   Úfinalize_optionsÚset_undefined_optionsr!   r   Zconf_target_groups)r#   ÚeZ	incl_dirsr$   r$   r%   r1   >   s,     



úzbuild_ext.finalize_optionsc           #   	      s¬  ˆ j s
d S ˆ  d¡ ˆ j ¡ ržˆ jrzˆ jj d¡rJt d¡ ˆ j 	d¡}qŽˆ j 	d¡}d|_| 
¡  | ¡  dˆ jjd< nˆ  d¡ ˆ  d¡}ˆ j |j¡ nd }ddlm} ddlm} ˆ j}||ˆ jˆ jˆ jd�ˆ _ˆ j ˆ j¡ ˆ j ˆ ¡ ˆ j�rˆ jj d	¡ ˆ jj d	¡ ˆ j ¡  ˆ j�s¶tj  d
ddd¡}tj  ˆ  d¡j!|¡}tj "tj  ˆ j#d¡¡}t$ˆ dƒ�r~ˆ j% &¡  t'ˆ j|ˆ j(ˆ j)|d�ˆ _%dd„ }dd l*}| +|ˆ j%¡ tj  ˆ j#d¡ˆ _,tj -ˆ j,¡�sät .ˆ j,¡ i }	|d u�rZ|j/�püg D ]Z\}
}|
|	v �rN|	|
 |k�rNt d|
t0|	|
 ƒd d… t0|ƒd d… f ¡ ||	|
< �qþˆ jj/�pfg D ] \}
}|
|	v �r~�qh||	|
< �qht1ƒ }ˆ j D �]â}t1ƒ }g }g }g }|j/D ]†}
|
|	v �r|	|
 }|| dg ¡7 }|| dg ¡7 }| dg ¡D ]}||v�rö| |¡ �qö|	 |
i ¡ dg ¡D ]}| 2|¡ �q&�q´|�rv|j/| }t 3d|j4|j/|f ¡ ||_/|j| |_|�rœt 3d|j4|f ¡ |j5| |_5t6|j7ƒ�r²| 2d¡ t8|j7ƒ�rÈ| 2d¡ |j9�pÜˆ j :|j7¡}|�rî| 2|¡ d|v �rþd}nd}d}d |v �rd }d!}nd|v �r,d}d!}|j9�r:|�rn|�rh||k�rh|j9�rht d"|j4||f ¡ ||_9| ;|¡ �q–d |v }d|v }d|v }|�ræ||ˆ jˆ jˆ jd�ˆ _<ˆ j<}|jˆ j|d#� | ˆ ¡ | ¡  | =¡ ˆ _<nd ˆ _<|�rpˆ j>}|ˆ j>ˆ jˆ jˆ jdˆ jd$�ˆ _?ˆ j?}|�r6|j@}| ˆ j¡ |�rZ| A¡ �rZ| ˆ ¡ | ¡  nˆ  d%| ¡ d ˆ _?nd ˆ _?|�rúˆ j>}|ˆ j>ˆ jˆ jˆ jd!ˆ jd$�ˆ _Bˆ jB}|�rÀ|j@}| ˆ j¡ |�rä| A¡ �rä| ˆ ¡ | ¡  nˆ  d&| ¡ d ˆ _Bnd ˆ _Bˆ  C¡  ‡ fd'd(„ˆ j D ƒ}|D ]†}tj  |d¡} ˆ j�sJtj  ˆ jD| ¡} t Eˆ j,¡D ]L}!tj -| ¡�srt .| ¡ |! F¡  Gd)¡�s†�qVtj  ˆ j,|!¡}"tH|"| ƒ �qV�q d S )*NÚ	build_srcÚ
build_clibzMbuild_clib already run, it is too late to ensure in-place build of build_clibé   r   )Únew_compiler)Únew_fcompiler)ÚcompilerÚverboseÚdry_runÚforcez-WerrorÚnumpyÚ	distutilsÚincludeznpy_cpu_dispatch_config.hzccompiler_opt_cache_ext.pyÚcompiler_opt)r9   Údispatch_hpathr   r   Ú
cache_pathc                 S   s    t  d¡ t  | jdd�¡ d S )Nz2
########### EXT COMPILER OPTIMIZATION ###########T)Úfull)r	   ÚinfoÚreport)Zcoptr$   r$   r%   rE   ¨   s    
zbuild_ext.run.<locals>.reportz.libszKlibrary %r defined more than once, overwriting build_info
%s... 
with
%s...i,  Ú	librariesÚlibrary_dirsÚmacrosZsource_languagesz-updating extension %r libraries from %r to %rz-extending extension %r defined_macros with %rÚf77úc++ÚcFÚf90Tz.resetting extension %r language from %r to %r.)Zneed_cxx)r9   r:   r;   r<   Z
requiref90Z
c_compilerz!f77_compiler=%s is not available.z!f90_compiler=%s is not available.c                    s"   h | ]}ˆ   |j¡ d ¡d ’qS )Ú.r   )Úget_ext_fullnameÚnamer,   )Ú.0Úextr"   r$   r%   Ú	<setcomp>S  s   ÿz build_ext.run.<locals>.<setcomp>z.dll)IÚ
extensionsÚrun_commandr/   Úhas_c_librariesÚinplaceÚhave_runÚgetr	   ÚwarnÚget_command_objÚensure_finalizedÚrunÚget_finalized_commandrG   Úappendr5   Údistutils.ccompilerr7   Znumpy.distutils.fcompilerr8   r9   r:   r;   r<   Z	customizeZcustomize_cmdr   Úcompiler_soZshow_customizationr    r-   ÚpathÚjoinr4   ÚabspathÚ
build_tempÚhasattrr@   Zcache_flushr   r   r   ÚatexitÚregisterÚextra_dll_dirÚisdirÚmakedirsrF   ÚreprÚsetÚaddrD   rO   Údefine_macrosr   Úsourcesr   ÚlanguageZdetect_languageÚupdateÚ_cxx_compilerÚcxx_compilerr   Ú_f77_compilerÚcompiler_typeÚget_versionÚ_f90_compilerZbuild_extensionsÚ	build_libÚlistdirÚlowerÚendswithr   )#r#   r5   r7   r8   ru   rA   Zopt_cache_pathrE   rf   ZclibsÚlibnameZ
build_infoZall_languagesrQ   Zext_languagesZc_libsZ
c_lib_dirsrH   ZbinfoÚmÚlZ
new_c_libsZext_languageZhas_fortranZneed_f90_compilerZneed_f77_compilerZneed_cxx_compilerr9   Úctyper   Z	pkg_rootsZpkg_rootZshared_lib_dirÚfnZruntime_libr$   r"   r%   r\   `   s|   


ÿÿ

ý
ÿ
ý
$þ




ÿÿ






ÿý
û

ÿû

ÿ
þ
zbuild_ext.runc                 C   s   |S r   r$   )r#   ro   rS   r$   r$   r%   Úswig_sourcesc  s    zbuild_ext.swig_sourcesc           0         s  |j }|d u st|ƒs$td|j ƒ‚t|ƒ}|s4d S |  |j¡}| jr”| d¡}d |dd… ¡}|d }|  	d¡}| 
|¡}tj ||  |¡¡}	ntj | j|  |¡¡}	||j }
| j}| jsØ| j ¡ sØt d¡ d}|sút|
|	dƒsút d	|j¡ d S t d
|j¡ |j�pg }t|dd ƒ�p$g }t|dd ƒ�p6g }|jd d … }|jD ]}| |f¡ �qLt|j ƒ\}}}}| jjdk�rœ|�r�| d¡ ||7 }g }|j dk�r°| j!}n"|j dk�rÄ| j"}n| j!�pÐ| j"}|d u�rt#|dƒ�rô|j$�pög ng |_$t#|dƒ�r|j%�pg ng |_%| j&}|�r<|d u �r<t'd|j ƒ‚|�sH|�r`|d u �r`t'd|j ƒ‚|j dv �r†|d u �r†|  (d|j ¡ |j dk�r¬|d u �r¬|  (d|j ¡ d|ji}| j)}|j*t+ƒ  }g }g }g }g }| j�s„|  	d¡j,}tj ddd¡}tj ||¡}| |¡ | j�r d n|} |f|df||f|dffD ]8\}!}"‰ |!D ]&‰|"‡ ‡fd d!„ˆd d … D ƒ7 }"�qL�q>| j -¡ }n
| d"¡ g }#|�rÔt d#¡ |#| jj.|f|| || || j|| |d$œ|¤Ž7 }#|�rt d%¡ |#| jj.|f|| || || j|| d&œ|¤Ž7 }#|�rVt d'¡ |#| jj/|f||| || j|| | d(œ|¤Ž7 }#|�r–t d)¡ |#|j/|f||| || j|| | d(œ|¤Ž7 }#g }$g }%|�rÐt d*¡ |j0d d … }&tj | j)tj 1|  |¡¡¡}'|  2|'¡ |j3d u �røt4d+ƒ}(|$| 5|&|'¡7 }$|%|j/|| j)||| j|$|jd,�7 }%|j3d u �rÐt4d+ƒD ]�})|)|(v �rP�q>tj |'|)¡}*tj 6|)¡tj 6|*¡k�r|�q>tj 7|*¡�r”t 8|*¡ z|  9|)|'¡ W n& t:�yÊ   t (d-|)|'f ¡ Y n0 �q>|�rt d.¡ |%|j/|| j)||| j|$|jd,�7 }%|%�r | ;| j¡�s |%}+|#},ng }+|#|% },|j<�r@|, =|j<¡ |j>�pJg }|  ?|¡d d … }-|j@d d … }.| jjA}/| jjd/v �r’|  B||-|.¡ n|j dv �r®|d u�r®|jA}/|j dk�rÊ|d u�rÊ|jA}/|d u�rê|  C|,|-||.|+¡\},}-|/|,|	|-|.|jD||  E|¡| j| j)|j d0�
 d S )1Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesrM   r   éÿÿÿÿÚbuild_pyz*Detected changes on compiler optimizationsTÚnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extensionZextra_c_compile_argsZextra_cxx_compile_argsÚmsvcz/Zm1000rL   rI   Úextra_f77_compile_argsÚextra_f90_compile_argsz5extension %r has C++ sourcesbut no C++ compiler foundz>extension %r has Fortran sources but no Fortran compiler found)rI   rL   zTextension %r has Fortran libraries but no Fortran linker found, using default linkerrJ   zLextension %r has C++ libraries but no C++ linker found, using default linkerÚdependsr4   r=   r>   r?   )z.dispatch.c)z.dispatch.cppz.dispatch.cxxc                    s&   g | ]}|  ˆ ¡rˆ ˆ |¡¡‘qS r$   )r{   ÚpopÚindex)rP   Ús©Z_extZ_srcr$   r%   Ú
<listcomp>Ó  s   ÿz-build_ext.build_extension.<locals>.<listcomp>)ZNPY_DISABLE_OPTIMIZATIONr6   z#compiling C++ dispatch-able sources)Ú
output_dirÚsrc_dirrH   r*   ÚdebugÚextra_postargsZ	ccompilerz!compiling C dispatch-able sources)rŽ   r�   rH   r*   r�   r‘   zcompiling C sources)rŽ   rH   r*   r�   r‘   zcompiling C++ sourcesz#compiling Fortran 90 module sourcesz*.mod)rŽ   rH   r*   r�   r‘   rˆ   zfailed to move %r to %rzcompiling Fortran sources)r…   ZintelwZintelemw)rF   rG   Úruntime_library_dirsr‘   Úexport_symbolsr�   rd   Ztarget_lang)Fro   r   r   rO   ÚlistrN   rV   r,   rb   r]   Zget_package_dirr-   ra   Úget_ext_filenamerx   rˆ   r<   r    r@   Z	is_cachedr	   r�   r   rD   Úextra_compile_argsÚgetattrrn   Úundef_macrosr^   r   r9   ru   rp   rw   rt   re   r†   r‡   rr   r   rY   rd   r*   r   r4   Zcpu_baseline_flagsZtry_dispatchÚcompileÚmodule_dirsÚdirnameÚmkpathZmodule_dir_switchr   Zmodule_optionsrc   ÚisfileÚremoveÚ	move_filer   Zcan_ccompiler_linkÚextra_objectsr0   Úextra_link_argsZget_librariesrG   Zlink_shared_objectÚ_libs_with_msvc_and_fortranÚ_process_unlinkable_fobjectsr’   Zget_export_symbols)0r#   rQ   ro   ÚfullnameÚmodpathÚpackageÚbaserƒ   Úpackage_dirZext_filenamerˆ   Zforce_rebuildÚ
extra_argsZextra_cflagsZextra_cxxflagsrH   ZundefÚ	c_sourcesZcxx_sourcesZ	f_sourcesZfmodule_sourcesr   rs   ÚkwsrŽ   r*   Zcopt_c_sourcesZcopt_cxx_sourcesZcopt_baseline_flagsZcopt_macrosZbsrc_dirrA   Zcopt_build_srcZ_srcsZ_dstZ	c_objectsr‘   Z	f_objectsrš   Zmodule_build_dirZexisting_modulesÚfÚtÚunlinkable_fobjectsÚobjectsrF   rG   Zlinkerr$   rŒ   r%   Úbuild_extensiong  sì   þÿ


ÿ
ÿ


ÿ


ÿÿÿÿÿÿÿÿ


ÿþ
þ

ÿø	÷
ÿùø	
ÿÿúø	
ÿÿúø


ÿÿ
ÿú

ÿ
úÿ
ýøzbuild_ext.build_extensionc                 C   sP   |   d¡j}|   d¡j}| jjtj |d¡g| jd�}| jj	|d|| j
d� d S )Nr4   r5   zgfortran_vs2003_hack.c)rŽ   Z_gfortran_workaround)rŽ   r�   )r]   r4   r5   r9   r™   r-   ra   rb   rd   Zcreate_static_libr�   )r#   rª   r4   r5   r¯   r$   r$   r%   Ú_add_dummy_mingwex_symc  s    ÿþ
ÿz build_ext._add_dummy_mingwex_symc              
   C   s   t |ƒ}t |ƒ}t |ƒ}|d d … D ]À}|D ]¶}tj ||d ¡}tj |¡r,| |¡ t|dƒ�"}	| |	 ¡  	¡ ¡ W d   ƒ n1 sŠ0    Y  tj ||d ¡}
t|
dƒ�"}	| |	 ¡  	¡ ¡ W d   ƒ q,1 sØ0    Y  q,q$|�rdd„ |D ƒ}|j
|| j| jd�}| |¡ ||fS )Nz	.fobjectsÚrz	.cobjectsc                 S   s   g | ]}t j |¡‘qS r$   )r-   ra   rc   )rP   Úobjr$   r$   r%   r�   ‡  ó    z:build_ext._process_unlinkable_fobjects.<locals>.<listcomp>)rŽ   rh   )r”   r-   ra   rb   r�   rž   Úopenr0   ÚreadÚ
splitlinesZwrap_unlinkable_objectsrd   rh   )r#   r¯   rF   r   rG   r®   ÚlibÚlibdirZfake_libr¬   Zc_libZfobjectsÚwrappedr$   r$   r%   r£   l  s*    
04þ
z&build_ext._process_unlinkable_fobjectsc              
   C   sÐ  |d u rd S |D ]Î}|  d¡r qd}|p*g D ]*}tj |d| ¡}tj |¡r,d} qXq,|r^qd}|D ]^}tj |d| ¡}tj |¡rftj | j|d ¡}t||ƒ | j|vr¼| | j¡ d} qÆqf|rÌqt 	d||f ¡ qg }	|j
D ]R}
|
  d¡�r2zt d	d
|
g¡}
W n ttjf�y(   Y n
0 t|
ƒ}
|	 |
¡ qê| |	¡ |jD ]|}|  d¡�sN| |¡ t|	d| d ƒ}|�rNtj | j|d ¡}tj |¡�s°t|d |ƒ | j|v�rN| | j¡ �qNd S )Nr…   Fz%s.libTzlib%s.az.libz+could not find library %r in directories %sz/usr/libZcygpathz-wr¸   z.ar   )Ú
startswithr-   ra   rb   r�   rd   r   r^   r	   rY   rG   Ú
subprocessÚcheck_outputÚOSErrorÚCalledProcessErrorr
   r0   rF   r   )r#   r   Zc_librariesZc_library_dirsr|   Z
fileexistsr¹   ZlibfileZlibfile2Z
f_lib_dirsÚdirr¸   ÚpÚdst_namer$   r$   r%   r¢   �  s`    


ÿ



z%build_ext._libs_with_msvc_and_fortranc                 C   s.   |   | j¡ g }| jD ]}| t|ƒ¡ q|S r   )Úcheck_extensions_listrS   r0   r   )r#   Ú	filenamesrQ   r$   r$   r%   Úget_source_filesÌ  s
    
zbuild_ext.get_source_filesc              	   C   sP   |   | j¡ g }| jD ]4}|js"q|  |j¡}| tj | j	|  
|¡¡¡ q|S r   )rÃ   rS   ro   rN   rO   r^   r-   ra   rb   rx   r•   )r#   ÚoutputsrQ   r¤   r$   r$   r%   Úget_outputsÓ  s    
ÿzbuild_ext.get_outputs)N)Ú__name__Ú
__module__Ú__qualname__Údescriptionr   Úuser_optionsÚhelp_optionsr   Úboolean_optionsr   r1   r\   r�   r°   r±   r£   r¢   rÅ   rÇ   r$   r$   r$   r%   r      s*   ÿÿ
"  
 }	#=r   )!Ú__doc__r-   r¼   r   Údistutils.dep_utilr   Zdistutils.command.build_extr   r   Údistutils.errorsr   r   r   Údistutils.file_utilr   Znumpy.distutilsr	   Znumpy.distutils.exec_commandr
   Znumpy.distutils.system_infor   Znumpy.distutils.misc_utilr   r   r   r   r   r   Z'numpy.distutils.command.config_compilerr   Znumpy.distutils.ccompiler_optr   r   r$   r$   r$   r%   Ú<module>   s    