U
    ÉZj…|  ã                   @   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dddddddg 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$   úd/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/numpy/distutils/command/build_ext.pyr   4   s    
zbuild_ext.initialize_optionsc              
   C   sÄ   | j rDzt| j ƒ| _ W n, tk
rB } ztdƒ|‚W 5 d }~X Y nX t| jtƒr`| j tj¡| _| jphg }| j	jd k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 k	�rZ|j/�püg D ]Z\}
}|
|	k�rN|	|
 |k�rNt d|
t0|	|
 ƒd d… t0|ƒd d… f ¡ ||	|
< �qþˆ jj/�pfg D ] \}
}|
|	k�r~�qh||	|
< �qht1ƒ }ˆ j D �]â}t1ƒ }g }g }g }|j/D ]†}
|
|	k�r|	|
 }|| dg ¡7 }|| dg ¡7 }| dg ¡D ]}||k�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|k�rþd}nd}d}d |k�rd }d!}nd|k�r,d}d!}|j9�r:|�rn|�rh||k�rh|j9�rht d"|j4||f ¡ ||_9| ;|¡ �q–d |k}d|k}d|k}|�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 k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 k	�rt#|dƒ�rô|j$�pög ng |_$t#|dƒ�r|j%�pg ng |_%| j&}|�r<|d k�r<t'd|j ƒ‚|�sH|�r`|d k�r`t'd|j ƒ‚|j dk�r†|d k�r†|  (d|j ¡ |j dk�r¬|d k�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 k�røt4d+ƒ}(|$| 5|&|'¡7 }$|%|j/|| j)||| j|$|jd,�7 }%|j3d k�rÒt4d+ƒD ]’})|)|(k�rP�q>tj |'|)¡}*tj 6|)¡tj 6|*¡k�r|�q>tj 7|*¡�r”t 8|*¡ z|  9|)|'¡ W n( t:k
�rÌ   t (d-|)|'f ¡ Y nX �q>|�rt d.¡ |%|j/|| j)||| j|$|jd,�7 }%|%�r"| ;| j¡�s"|%}+|#},ng }+|#|% },|j<�rB|, =|j<¡ |j>�pLg }|  ?|¡d d … }-|j@d d … }.| jjA}/| jjd/k�r”|  B||-|.¡ n|j dk�r°|d k	�r°|jA}/|j dk�rÌ|d k	�rÌ|jA}/|d k	�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 5 Q R X tj ||d ¡}
t|
dƒ�}	| |	 ¡  	¡ ¡ W 5 Q R X 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�   ‡  s     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,    
  þ
z&build_ext._process_unlinkable_fobjectsc              
   C   sÒ  |d k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|kr¼| | j¡ d} qÆqf|rÌqt 	d||f ¡ qg }	|j
D ]T}
|
  d¡�r4zt d	d
|
g¡}
W n ttjfk
�r*   Y n
X t|
ƒ}
|	 |
¡ qê| |	¡ |jD ]|}|  d¡�sP| |¡ t|	d| d ƒ}|�rPtj | j|d ¡}tj |¡�s²t|d |ƒ | j|k�rP| | j¡ �qPd 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    