o
    U=ºi÷L  ã                   @   sæ   d Z ddlZddlmZ ddl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mZmZmZmZmZ dd	lmZ ejZeeeƒƒD ]Zee d d
v rhee d d fee dd…  ee< qKG dd„ deƒZdS )zC Modified version of build_clib that handles fortran source files.
é    N)Úglob)Ú
build_clib)ÚDistutilsSetupErrorÚDistutilsErrorÚDistutilsFileError)Úlog)Únewer_group)Úfilter_sourcesÚget_lib_source_filesÚget_numpy_include_dirsÚhas_cxx_sourcesÚhas_f_sourcesÚis_sequence)Únew_ccompiler_opt)z
build-clibz
build-tempú=é   c                   @   st   e Zd ZdZejg d¢ Zejg d¢ Zdd„ Zdd„ Zdd	„ Z	d
d„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r   z1build C/C++/F libraries used by Python extensions))z
fcompiler=Nz!specify the Fortran compiler type)ÚinplaceÚizBuild in-place)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...))r   r   r   c                 C   s8   t  | ¡ d | _d| _d | _d | _d | _d | _d | _d S )Nr   )	Úold_build_clibÚinitialize_optionsÚ	fcompilerr   ÚparallelÚ
warn_errorÚcpu_baselineÚcpu_dispatchÚdisable_optimization)Úself© r    úhC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\numpy/distutils/command/build_clib.pyr   1   s   

zbuild_clib.initialize_optionsc              
   C   s\   | j rzt| j ƒ| _ W n ty } ztdƒ|‚d }~ww t | ¡ |  dddddd¡ d S )Nz)--parallel/-j argument must be an integerÚbuild)r   r   )r   r   )r   r   )r   r   )r   r   )r   ÚintÚ
ValueErrorr   Úfinalize_optionsÚset_undefined_options)r   Úer    r    r!   r%   <   s   
€ÿ
ûzbuild_clib.finalize_optionsc                 C   ó*   | j D ]\}}t| dg ¡ƒr dS qdS ©NÚsourcesTF)Ú	librariesr   Úget©r   Úlib_nameÚ
build_infor    r    r!   Úhave_f_sourcesK   ó
   ÿzbuild_clib.have_f_sourcesc                 C   r(   r)   )r+   r   r,   r-   r    r    r!   Úhave_cxx_sourcesQ   r1   zbuild_clib.have_cxx_sourcesc                 C   sN  | j sd S g }|  d¡ | j D ]\}}| dd ¡}|r$||vr$| |¡ qddlm} || j| j| jd�| _| jj	| j
|  ¡ d� | jrR| jj d¡ | jj d¡ | j }d | _ | j | ¡ || _ | 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¡ |   ¡ rìddl!m"} || j#| j$| j| jd|v | jd�| _%| j%d urë| j% 	| j
¡ | j }d | _ | j% | ¡ || _ | j% ¡  nd | _%|  &| j ¡ | j'�r#| j
j(D ]'}| j )|j*¡}tj | j+|¡}tj |j,|¡}|  -|j,¡ t. /||¡ qýd S d S )NÚ	build_srcÚlanguager   )Únew_compiler)ÚcompilerÚdry_runÚforce)Zneed_cxxz-WerrorÚnumpyÚ	distutilsÚincludeznpy_cpu_dispatch_config.hzccompiler_opt_cache_clib.pyÚcompiler_opt)r6   Údispatch_hpathr   r   Ú
cache_pathc                 S   s    t  d¡ t  | jdd�¡ d S )Nz3
########### CLIB COMPILER OPTIMIZATION ###########T)Úfull)r   ÚinfoÚreport)Zcoptr    r    r!   rA   Œ   s   
zbuild_clib.run.<locals>.report©Únew_fcompilerÚf90©r6   Úverboser7   r8   Ú
requiref90Z
c_compiler)0r+   Úrun_commandr,   ÚappendÚdistutils.ccompilerr5   r6   r7   r8   Ú	customizeÚdistributionr2   r   Úcompiler_soZcustomize_cmdZshow_customizationr   ÚosÚpathÚjoinÚget_finalized_commandr3   ÚabspathÚ
build_tempÚhasattrr<   Zcache_flushr   r   r   ÚatexitÚregisterr0   Únumpy.distutils.fcompilerrC   r   rF   Ú_f_compilerÚbuild_librariesr   Zinstalled_librariesÚlibrary_filenameÚnamer   Ú
target_dirÚmkpathÚshutilÚcopy)r   Ú	languagesr.   r/   Úlr5   r+   r=   Zopt_cache_pathrA   rU   rC   ZlibnameÚsourceÚtargetr    r    r!   ÚrunW   sŠ   

€þ
ÿ
ÿ

ýû

€úzbuild_clib.runc                 C   s.   |   | j¡ g }| jD ]	}| t|ƒ¡ q|S ©N)Zcheck_library_listr+   Úextendr
   )r   Ú	filenamesÚlibr    r    r!   Úget_source_files±   s
   
zbuild_clib.get_source_filesc                 C   s    |D ]\}}|   |||¡ qd S re   )Úbuild_a_library)r   r+   r.   r/   r    r    r!   rY   ¸   s   ÿzbuild_clib.build_librariesc                 C   s>   |du rg S g }|D ]}t |ƒr||| ƒ7 }q
| |¡ q
|S )ah   Assemble flags from flag list

        Parameters
        ----------
        in_flags : None or sequence
            None corresponds to empty list.  Sequence elements can be strings
            or callables that return lists of strings. Callable takes `self` as
            single parameter.

        Returns
        -------
        out_flags : list
        N)ÚcallablerI   )r   Zin_flagsZ	out_flagsZin_flagr    r    r!   Úassemble_flags¼   s   zbuild_clib.assemble_flagsc           0         s  | j }| j}| d¡}|d u st|ƒstd| ƒ‚t|ƒ}t|ƒ\}}}	}
|
  p0| dd¡dk}g }|r:| d¡ |rA| d¡ |rI| d¡ n|	rP| d¡ ||d< |j|| j	d	�}|| d
g ¡ }| j
}| jsv| j ¡ svt d¡ d}|s†t||dƒs†t d|¡ d S t d|¡ | di ¡}|d urÍ|rÍt d|f ¡ ddlm} ||j| j| j| j
|| j d�}|d urÍ| j}| d¡ ¡ }| |¡ | |¡ |	sÑ|
rÛ|d u rÛtd| ƒ‚|d urï| d¡påg |_| d¡píg |_| d¡}|d u rúg }| d¡}|d u �rg }|  | d¡¡}|  | d¡¡}|  | d¡¡}|  t!ƒ ¡ | d¡�p+g }t"j# $|¡}|�r:|  %|¡ |jdk�rF||7 }g }g }g }g }g }| j�s¤|  &d¡j'}t"j# (d d!d"¡} t"j# (|| ¡} | | ¡ | j)�rrd 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+|| j,|!|| || j|| |%d)�7 }$|�ræt d*¡ |$| jj+|| j,|!|| || j|| d+�7 }$|�rt d,¡ |$|j-|| j,|| || j|| | d-�7 }$|�r't d.¡ | .¡ }%|%j-|| j,|| || j|| | d-�}&|$  |&¡ |	�s-|
�rÌg }g }'|�rF|j/d u �r>t0d/ƒ}(|| 1||¡7 }|
�r]t d0¡ |'|j-|
| j,||| j|d-�7 }'|�r´| jj/d u �r´t0d/ƒD ]H})|)|(v �rt�qkt"j# (||)¡}*t"j# 2|)¡t"j# 2|*¡k�rŠ�qkt"j# 3|*¡�r–t" 4|*¡ z	|  5|)|¡ W �qk t6�y³   t 7d1|)|f ¡ Y �qkw |	�rËt d2¡ |'|j-|	| j,||| j|d-�7 }'ng }'|'�rS| 8|¡�sSt"j# (| j	|d3 ¡}+t9|+d4ƒ�})|) :d5 (d6d7„ |'D ƒ¡¡ W d   ƒ n	1 �sÿw   Y  t"j# (| j	|d8 ¡}+t9|+d4ƒ�})|) :d5 (d9d7„ |$D ƒ¡¡ W d   ƒ n	1 �s,w   Y  t"j# (| j	||j; ¡},t9|,d:ƒ�})W d   ƒ n1 �sMw   Y  n|$  |'¡ |j<|$|| j	| jd;� | d<g ¡}-|D ]\}.}/|.|-v �r}|-  |/ d<g ¡¡ �qk|-�rˆ|-|d<< d S d S )=Nr*   zfin 'libraries' option (library '%s'), 'sources' must be present and must be a list of source filenamesr4   ÚcrD   zc++Zf77Úsource_languages)Ú
output_dirÚdependsz*Detected changes on compiler optimizationsTÚnewerz"skipping '%s' library (up-to-date)zbuilding '%s' libraryÚ	config_fczEusing additional config_fc from setup script for fortran compiler: %sr   rB   rE   z<library %s has Fortran sources but no Fortran compiler foundÚextra_f77_compile_argsÚextra_f90_compile_argsÚmacrosÚinclude_dirsZextra_compiler_argsÚextra_cflagsÚextra_cxxflagsÚmodule_dirsZmsvcr3   r9   r:   r;   )z.dispatch.c)z.dispatch.cppz.dispatch.cxxc                    s&   g | ]}|  ˆ ¡rˆ ˆ |¡¡‘qS r    )ÚendswithÚpopÚindex)Ú.0Ús©Z_extZ_srcr    r!   Ú
<listcomp>J  s
    
þÿz.build_clib.build_a_library.<locals>.<listcomp>)ZNPY_DISABLE_OPTIMIZATIONr   z#compiling C++ dispatch-able sources)ro   Úsrc_dirru   rv   ÚdebugÚextra_postargsZ	ccompilerz!compiling C dispatch-able sources)ro   r�   ru   rv   r‚   rƒ   zcompiling C sources)ro   ru   rv   r‚   rƒ   zcompiling C++ sourcesz*.modz#compiling Fortran 90 module sourceszfailed to move %r to %rzcompiling Fortran sourcesz	.fobjectsÚwÚ
c                 s   ó   � | ]	}t j |¡V  qd S re   ©rN   rO   rR   ©r}   Úobjr    r    r!   Ú	<genexpr>º  ó   € z-build_clib.build_a_library.<locals>.<genexpr>z	.cobjectsc                 s   r†   re   r‡   rˆ   r    r    r!   rŠ   ¿  r‹   Úwb)ro   r‚   r+   )=r6   rX   r,   r   r   Úlistr	   rI   rZ   r   r8   r   r<   Z	is_cachedr   r‚   r   r@   rW   rC   Úcompiler_typerF   r7   rL   Úget_option_dictr_   ÚupdaterK   r   rs   rt   rl   rf   r   rN   rO   Údirnamer]   rQ   r3   rP   r   Zcpu_baseline_flagsZtry_dispatchrS   ÚcompileÚcxx_compilerZmodule_dir_switchr   Zmodule_optionsrR   ÚisfileÚremoveÚ	move_filer   ÚwarnZcan_ccompiler_linkÚopenÚwriteZstatic_lib_extensionZcreate_static_lib)0r   r/   r.   r+   r6   r   r*   Z	c_sourcesZcxx_sourcesZ	f_sourcesZfmodule_sourcesrG   rn   Zlib_filerp   Zforce_rebuildrr   rC   ÚdistZbase_config_fcru   rv   rƒ   rw   rx   ry   Zmodule_build_dirZcopt_c_sourcesZcopt_cxx_sourcesZcopt_baseline_flagsZcopt_macrosZbsrc_dirr=   Zcopt_build_srcZ_srcsZ_dstZobjectsr“   Zcxx_objectsZ	f_objectsZexisting_modulesÚfÚtZlistfnZ	lib_fnameZclib_librariesÚlnameZbinfor    r   r!   rj   Ô   sè  
þ
ÿÿ


ÿ
þû

ÿÿÿÿÿ


ÿÿÿ


ÿþ
þÿ

ø
ù	
ÿþú

ÿþú
	ÿ
û

ÿÿ
û€
ÿÿ
ÿÿ
ÿ ÿ
þ
€ÿzbuild_clib.build_a_libraryN)Ú__name__Ú
__module__Ú__qualname__Údescriptionr   Úuser_optionsÚboolean_optionsr   r%   r0   r2   rd   ri   rY   rl   rj   r    r    r    r!   r      s    ÿZr   )Ú__doc__rN   r   r^   Zdistutils.command.build_clibr   r   Údistutils.errorsr   r   r   Znumpy.distutilsr   Údistutils.dep_utilr   Znumpy.distutils.misc_utilr	   r
   r   r   r   r   Znumpy.distutils.ccompiler_optr   r¢   Z_lÚrangeÚlenZ_ir    r    r    r!   Ú<module>   s      &€