o
    U=ºib  ã                   @   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$   úgC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\numpy/distutils/command/build_ext.pyr   4   s   

zbuild_ext.initialize_optionsc              
   C   sº   | j rzt| j ƒ| _ W n ty } ztdƒ|‚d }~ww t| jtƒr+| j tj¡| _| jp/g }| 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   >   s0   
€ÿ


úzbuild_ext.finalize_optionsc           #   	      sž  ˆ j sd S ˆ  d¡ ˆ j ¡ rOˆ jr=ˆ jj d¡r%t d¡ ˆ j 	d¡}n"ˆ 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�r'|j/pùg D ],\}
}|
|	v �r"|	|
 |k�r"t d|
t0|	|
 ƒd d… t0|ƒd d… f ¡ ||	|
< qúˆ jj/�p-g D ]\}
}|
|	v �r9�q.||	|
< �q.t1ƒ }ˆ j D ]ñ}t1ƒ }g }g }g }|j/D ]C}
|
|	v �r‚|	|
 }|| dg ¡7 }|| dg ¡7 }| dg ¡D ]}||v�r€| |¡ �qt|	 |
i ¡ dg ¡D ]}| 2|¡ �qŒ�qS|�r´|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|�r0|�r-||k�r-|j9�r-t d"|j4||f ¡ ||_9| ;|¡ �qEd |v }d|v }d|v }|�rl||ˆ jˆ jˆ jd�ˆ _<ˆ j<}|jˆ j|d#� | ˆ ¡ | ¡  | =¡ ˆ _<nd ˆ _<|�r±ˆ j>}|ˆ j>ˆ jˆ jˆ jdˆ jd$�ˆ _?ˆ j?}|�r”|j@}| ˆ j¡ |�r¦| A¡ �r¦| ˆ ¡ | ¡  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 ]C}tj  |d¡} ˆ j�stj  ˆ jD| ¡} t Eˆ j,¡D ]&}!tj -| ¡�s2t .| ¡ |! F¡  Gd)¡�s<�q$tj  ˆ j,|!¡}"tH|"| ƒ �q$�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|ƒ}|sd S |  |j¡}| jrJ| d¡}d |dd… ¡}|d }|  	d¡}| 
|¡}tj ||  |¡¡}	ntj | j|  |¡¡}	||j }
| j}| jsl| j ¡ slt 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 ƒp˜g }|jd d … }|jD ]}| |f¡ q£t|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 ƒ‚|�s|�r"|d u �r"t'd|j ƒ‚|j dv �r5|d u �r5|  (d|j ¡ |j dk�rH|d u �rH|  (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 ]\}!}"‰ |!D ]‰|"‡ ‡fd d!„ˆd d … D ƒ7 }"�q˜�q‘| j -¡ }n| d"¡ g }#|�rÜt d#¡ |#| jj.|f|| || || j|| |d$œ|¤Ž7 }#|�rüt d%¡ |#| jj.|f|| || || j|| d&œ|¤Ž7 }#|�rt 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 �rnt4d+ƒ}(|$| 5|&|'¡7 }$|%|j/|| j)||| j|$|jd,�7 }%|j3d u �rÚt4d+ƒD ]H})|)|(v �rš�q‘tj |'|)¡}*tj 6|)¡tj 6|*¡k�r°�q‘tj 7|*¡�r¼t 8|*¡ z	|  9|)|'¡ W �q‘ t:�yÙ   t (d-|)|'f ¡ Y �q‘w |�rót d.¡ |%|j/|| j)||| j|$|jd,�7 }%|%�r| ;| j¡�s|%}+|#},ng }+|#|% },|j<�r|, =|j<¡ |j>�pg }|  ?|¡d d … }-|j@d d … }.| jjA}/| jjd/v �r;|  B||-|.¡ n|j dv �rI|d u�rI|jA}/|j dk�rW|d u�rW|jA}/|d u�rg|  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 |¡rq| |¡ t|dƒ�}	| |	 ¡  	¡ ¡ W d   ƒ n1 sEw   Y  tj ||d ¡}
t|
dƒ�}	| |	 ¡  	¡ ¡ W d   ƒ q1 slw   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�   ‡  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  s2   
ÿÿ€öþ
z&build_ext._process_unlinkable_fobjectsc              
   C   sÂ  |d u rd S |D ]g}|  d¡rqd}|pg D ]}tj |d| ¡}tj |¡r+d} q,q|r/qd}|D ]/}tj |d| ¡}tj |¡rbtj | j|d ¡}t||ƒ | j|vr^| | j¡ d} qcq3|rfqt 	d||f ¡ qg }	|j
D ]'}
|
  d¡r—z
t d	d
|
g¡}
W n ttjfy’   Y nw t|
ƒ}
|	 |
¡ qu| |	¡ |jD ]9}|  d¡sÞ| |¡ t|	d| d ƒ}|rÞtj | j|d ¡}tj |¡sÓt|d |ƒ | j|vrÞ| | j¡ q¥d 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¢   �  sj   
þ

ø	ÿ

ÿ




€÷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 ]}|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_outputsr   )Ú__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     