o
    Ô­j×€  ã                   @   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$   ú^/var/www/html/CropPilot/venv/lib/python3.10/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   Úconf_target_groups)r#   ÚeÚ	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|�r-|�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)r;   Údispatch_hpathr   r   Ú
cache_pathc                 S   s    t  d¡ t  | jdd�¡ d S )Nz2
########### EXT COMPILER OPTIMIZATION ###########T)Úfull)r	   ÚinfoÚreport)Úcoptr$   r$   r%   rG   ¨   s   
zbuild_ext.run.<locals>.reportz.libszKlibrary %r defined more than once, overwriting build_info
%s... 
with
%s...i,  Ú	librariesÚlibrary_dirsÚmacrosÚ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.)Úneed_cxx)r;   r<   r=   r>   Ú
requiref90Ú
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_commandrJ   Úappendr7   Údistutils.ccompilerr9   Únumpy.distutils.fcompilerr:   r;   r<   r=   r>   Ú	customizeÚcustomize_cmdr   Úcompiler_soÚshow_customizationr    r-   ÚpathÚjoinr6   ÚabspathÚ
build_tempÚhasattrrB   Úcache_flushr   r   r   ÚatexitÚregisterÚextra_dll_dirÚisdirÚmakedirsrI   ÚreprÚsetÚaddrF   rV   Údefine_macrosr   Úsourcesr   ÚlanguageÚdetect_languageÚupdateÚ_cxx_compilerÚcxx_compilerr   Ú_f77_compilerÚcompiler_typeÚget_versionÚ_f90_compilerÚbuild_extensionsÚ	build_libÚlistdirÚlowerÚendswithr   )#r#   r7   r9   r:   r‚   rC   Úopt_cache_pathrG   rr   ÚclibsÚlibnameÚ
build_infoÚall_languagesrX   Úext_languagesÚc_libsÚ
c_lib_dirsrK   ÚbinfoÚmÚlÚ
new_c_libsÚext_languageÚhas_fortranÚneed_f90_compilerÚneed_f77_compilerÚneed_cxx_compilerr;   Úctyper   Ú	pkg_rootsÚpkg_rootÚshared_lib_dirÚfnÚruntime_libr$   r"   r%   rc   `   s„  


ÿÿ

ý
ÿ

ý
$þ






€ÿ
ÿÿ






ÿý
û

ÿû

ÿ
þ
úüzbuild_ext.runc                 C   s   |S r   r$   )r#   r{   rZ   r$   r$   r%   Úswig_sourcesc  s   zbuild_ext.swig_sourcesc           1         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 }||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 �r<|d u �r<|  (d|j ¡ |j dk�rO|d u �rO|  (d|j ¡ d|ji}| j)}|j*t+ƒ  }g }g }g }g }| j�sµ|  	d¡j,}tj ddd¡}tj ||¡}| |¡ |} |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 �rot4d+ƒ}(|$| 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 �rZ|  B||-|.¡ |jC�rY|jCD ]}0t4|0d0 ƒD ]	})tD|)| jEƒ �qJ�qBg |_Cn|j dv �rh|d u�rh|jA}/|j dk�rv|d u�rv|jA}/|d u�r†|  F|,|-||.|+¡\},}-|/|,|	|-|.|jC||  G|¡| j| j)|j d1�
 d S )2Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesrT   r   éÿÿÿÿÚbuild_pyz*Detected changes on compiler optimizationsTÚnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extensionÚextra_c_compile_argsÚextra_cxx_compile_argsÚmsvcz/Zm1000rP   rM   Ú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)rM   rP   zTextension %r has Fortran libraries but no Fortran linker found, using default linkerrN   zLextension %r has C++ libraries but no C++ linker found, using default linkerÚdependsr6   r?   r@   rA   )z.dispatch.c)z.dispatch.cppz.dispatch.cxxc                    s&   g | ]}|  ˆ ¡rˆ ˆ |¡¡‘qS r$   )r‰   ÚpopÚindex)rW   Ús©Ú_extÚ_srcr$   r%   Ú
<listcomp>ß  s
    
þÿz-build_ext.build_extension.<locals>.<listcomp>)ÚNPY_DISABLE_OPTIMIZATIONr8   z#compiling C++ dispatch-able sources)Ú
output_dirÚsrc_dirrK   r*   ÚdebugÚextra_postargsÚ	ccompilerz!compiling C dispatch-able sources)r³   r´   rK   r*   rµ   r¶   zcompiling C sources)r³   rK   r*   rµ   r¶   zcompiling C++ sourcesz#compiling Fortran 90 module sourcesz*.mod)r³   rK   r*   rµ   r¶   rª   zfailed to move %r to %rzcompiling Fortran sources)r§   ÚintelwÚintelemwz/*.dll)rI   rJ   Úruntime_library_dirsr¶   Úexport_symbolsrµ   ro   Útarget_lang)Hr{   r   r   rV   ÚlistrU   r]   r,   rm   rd   Úget_package_dirr-   rl   Úget_ext_filenamer†   rª   r>   r    rB   Ú	is_cachedr	   rµ   r   rF   Úextra_compile_argsÚgetattrrz   Úundef_macrosre   r   r;   r‚   r|   r„   r�   rp   r¨   r©   r   r   r`   ro   r*   r   r6   Úcpu_baseline_flagsÚtry_dispatchÚcompileÚmodule_dirsÚdirnameÚmkpathÚmodule_dir_switchr   Úmodule_optionsrn   ÚisfileÚremoveÚ	move_filer   Úcan_ccompiler_linkÚextra_objectsr0   Úextra_link_argsÚget_librariesrJ   Úlink_shared_objectÚ_libs_with_msvc_and_fortranrº   r   rt   Ú_process_unlinkable_fobjectsÚget_export_symbols)1r#   rX   r{   ÚfullnameÚmodpathÚpackageÚbaser£   Úpackage_dirÚext_filenamerª   Úforce_rebuildÚ
extra_argsÚextra_cflagsÚextra_cxxflagsrK   ÚundefÚ	c_sourcesÚcxx_sourcesÚ	f_sourcesÚfmodule_sourcesr   r€   Úkwsr³   r*   Úcopt_c_sourcesÚcopt_cxx_sourcesÚcopt_baseline_flagsÚcopt_macrosÚbsrc_dirrC   Úcopt_build_srcÚ_srcsÚ_dstÚ	c_objectsr¶   Ú	f_objectsrÇ   Úmodule_build_dirÚexisting_modulesÚfÚtÚunlinkable_fobjectsÚobjectsrI   rJ   ÚlinkerÚdr$   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 )Nr6   r7   zgfortran_vs2003_hack.c)r³   Ú_gfortran_workaround)r³   rµ   )rd   r6   r7   r;   rÆ   r-   rl   rm   ro   Úcreate_static_librµ   )r#   râ   r6   r7   rö   r$   r$   r%   Ú_add_dummy_mingwex_symv  s   ÿþ

ÿz build_ext._add_dummy_mingwex_symc              
   C   s  t |ƒ}t |ƒ}t |ƒ}|d d … D ]^}|D ]Y}tj ||d ¡}tj |¡ro| |¡ t|ƒ�}	| |	 ¡  	¡ ¡ W d   ƒ n1 sDw   Y  tj ||d ¡}
t|
ƒ�}	| |	 ¡  	¡ ¡ W d   ƒ n1 sjw   Y  qq|r‰dd„ |D ƒ}|j
|| j| jd�}| |¡ ||fS )Nz	.fobjectsz	.cobjectsc                 S   s   g | ]}t j |¡‘qS r$   )r-   rl   rn   )rW   Úobjr$   r$   r%   r±   š  s    z:build_ext._process_unlinkable_fobjects.<locals>.<listcomp>)r³   rt   )r½   r-   rl   rm   rÌ   rÍ   Úopenr0   ÚreadÚ
splitlinesÚwrap_unlinkable_objectsro   rt   )r#   rö   rI   r   rJ   rõ   ÚlibÚlibdirÚfake_libró   Úc_libÚfobjectsÚwrappedr$   r$   r%   rÕ     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} nq|r/qd}|D ]/}tj |d| ¡}tj |¡rbtj | j|d ¡}t||ƒ | j|vr^| | j¡ d} nq3|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/libÚcygpathz-wr  z.ar   )Ú
startswithr-   rl   rm   rÌ   ro   r   re   r	   r`   rJ   Ú
subprocessÚcheck_outputÚOSErrorÚCalledProcessErrorr
   r0   rI   r   )r#   r   Úc_librariesÚc_library_dirsrŒ   Ú
fileexistsr  ÚlibfileÚlibfile2Ú
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_listrZ   r0   r   )r#   Ú	filenamesrX   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  rZ   r{   rU   rV   re   r-   rl   rm   r†   r¿   )r#   ÚoutputsrX   r×   r$   r$   r%   Úget_outputsæ  s   
ÿzbuild_ext.get_outputsr   )Ú__name__Ú
__module__Ú__qualname__Údescriptionr   Úuser_optionsÚhelp_optionsr   Úboolean_optionsr   r1   rc   r¡   rù   rü   rÕ   rÔ   r  r  r$   r$   r$   r%   r      s.    ÿÿ
"  
  	#=r   )!Ú__doc__r-   r
  r   Údistutils.dep_utilr   Údistutils.command.build_extr   r   Údistutils.errorsr   r   r   Údistutils.file_utilr   Únumpy.distutilsr	   Únumpy.distutils.exec_commandr
   Únumpy.distutils.system_infor   Únumpy.distutils.misc_utilr   r   r   r   r   r   Ú'numpy.distutils.command.config_compilerr   Únumpy.distutils.ccompiler_optr   r   r$   r$   r$   r%   Ú<module>   s     