
    G/Ph׀                         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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                       e Zd ZdZej        g dz   Zej        dddefgz   Zej        ddgz   Zd Z	d	 Z
d
 ZddZd Zd Zd Zd Zd Z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                     t          j        |            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)selfs    a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numpy/distutils/command/build_ext.pyr   zbuild_ext.initialize_options4   sK    (...  $(!    c           	      2   | j         r=	 t          | j                   | _         n"# t          $ r}t          d          |d }~ww xY wt          | j        t
                    r)| j                            t          j                  | _        | j        pg }| j	        j        g | j	        _        | j	        j        | _        | j        
                    |           t          j        |            |                     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_dirss      r&   r4   zbuild_ext.finalize_options>   s+   = 	UU #DM 2 2 U U U !LMMSTTU d'-- 	D $ 1 7 7
 C CD%+	)1-/D* -:  +++&t,,,""7(@(D(H(H(X(B	$ 	$ 	$ 8<~'444s   # 
A=Ac                      j         sd S                      d            j                                        r j        r j        j                            d          r/t          j        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                   _         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                    }tI           d          r j%        &                                 tO           j        | j(         j)        |           _%        d }dd l*}|+                    | j%                   t<          j                              j#        d           _,        t<          j        -                     j,                  st=          j.         j,                   i }	|r|j/        pg D ]h\  }
}|
|	v rZ|	|
         |k    rNt          j        d|
dta          |	|
                   d d         dta          |          d d         d           ||	|
<   i j        j/        pg D ]\  }
}|
|	v r
||	|
<   tc                      } j         D ]N}tc                      }g }g }g }|j/        D ]}
|
|	v rl|	|
         }||                    dg           z  }||                    dg           z  }|                    dg           D ]}||vr|                    |           |	                    |
i                               dg           D ]}|2                    |           |rG|j/        |z   }t          j3        d|j4        d|j/        d|           ||_/        |j        |z   |_        |r.t          j3        d|j4        d |           |j5        |z   |_5        tm          |j7                  r|2                    d!           tq          |j7                  r|2                    d"           |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|r2|r0||k    r*|j9        r#t          j        d'|j4        d(|d|d)           ||_9        |;                    |           Pd%|v }d!|v }d"|v }|r || j         j         j                   _<         j<        }|                     j        |*           |                                |                                 |=                                 _<        nd  _<        |r j>        } | j>         j         j         j        d$ j        +           _?         j?        }|r!|j@        }|                     j                   |r>|A                                r*|                                |                                 n'                     d,|z             d  _?        nd  _?        |r j>        } | j>         j         j         j        d& j        +           _B         jB        }|r!|j@        }|                     j                   |r>|A                                r*|                                |                                 n'                     d-|z             d  _B        nd  _B         C                                  fd. j         D             }|D ]}t<          j                             |d          }  j        s%t<          j                              jD        |           } t=          jE         j,                  D ]}!t<          j        -                    |           st=          j.        |            |!F                                G                    d/          s]t<          j                              j,        |!          }"t          |"|            d S )0N	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                 ~    t          j        d           t          j        |                     d                     d S )Nz2
########### EXT COMPILER OPTIMIZATION ###########T)full)r
   inforeport)copts    r&   rL   zbuild_ext.run.<locals>.report   s7    NOOO$//00000r'   z.libszlibrary z0 defined more than once, overwriting build_info
i,  z
... 
with
z...	librarieslibrary_dirsmacrossource_languageszupdating extension z libraries from  to zextending extension z defined_macros with f77c++cFf90Tzresetting extension z language from .)need_cxx)r?   r@   rA   rB   
requiref90
c_compilerz!f77_compiler=%s is not available.z!f90_compiler=%s is not available.c                 v    h | ]5}                     |j                                      d           d         6S )rW   r   )get_ext_fullnamenamer/   ).0extr%   s     r&   	<setcomp>z build_ext.run.<locals>.<setcomp>S  sL     
 
 
 !!#(++11#66q9
 
 
r'   z.dll)I
extensionsrun_commandr2   has_c_librariesinplacehave_rungetr
   warnget_command_objensure_finalizedrunget_finalized_commandrO   appendr;   distutils.ccompilerr=   numpy.distutils.fcompilerr>   r?   r@   rA   rB   	customizecustomize_cmdr    compiler_soshow_customizationr#   r0   pathjoinr:   abspath
build_temphasattrrF   cache_flushr   r!   r"   atexitregisterextra_dll_dirisdirmakedirsrN   reprsetaddrK   r]   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%   r;   r=   r>   r   rG   opt_cache_pathrL   ry   clibslibname
build_infoall_languagesr_   ext_languagesc_libs
c_lib_dirsrP   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_libs#   `                                  r&   rj   zbuild_ext.run`   s    	F 	%%%,,.. 	| F$-11,?? AH C D D D!%!2!B!B$"& "&JJ "&!2!B!B$"& "&J)*J&//111NN$$$?@D%.|<<   ...!77EE
$$Z%:;;;;J 	544444;;;;;;$m-1\-1\+/:7 7 7 	 1222##D)))? 	8M")))444M%,,Y777((***( 	7W\\';	KfggNW\\$*D*D[*Q*Q*[]kllNW__T_.JKK N t^,, 0 !--/// 1~!.T=N)! ! !D
1 1 1 MMMOOFD$5666  W\\$/7CCw}}T/00 	,K*+++ !'1';'Ar , ,#e##g*(D(DHH 'eGn)=)=dsd)C)C)CT*EUEUVZWZVZE[E[E[] ^ ^ ^ ",g#'#4#>#D" 	( 	(GZ%'E'NN ? B	0 B	0CEEMFJF= 
) 
)e##!'NEeiiR888F%))NB"?"??J"YYx44 - -F??"MM!,,,7B//334FKK ) )A!%%a(((() A ]V3
HHHcmmmZZA B B B *#&#3j#@  ?HHHff. / / /$'$5$>! S[)) )!!%(((s{++ )!!%(((J = =ck J JA %!!!$$$ %%$"K%%$"-''$"< :; : :l**s|*HH!hhh<<<9 : : : (CL   ////!]2!]2!]2  	&!-}6:l6:l48J"@ "@ "@D )Ht0;LMMM""4((('')))!)!6!6!8!8D!%D  	&NE!.7;|7;|59Z:?:>-"I "I "ID *I 7!/##D$5666 *Y2244 *''---,,....		= " # # #%)""!%D  	&NE!.7;|7;|59Z:>:>-"I "I "ID *I 7!/##D$5666 *Y2244 *''---,,....		= " # # #%)""!%D 	
 
 
 

 
 
	 " 
	7 
	7HW\\(G<<N< N!#dnn!M!Mj!344 7 7w}}^44 0K///xxzz**622  gll4+=rBB+~66667	
	7 
	7r'   c                     |S r    )r%   r   ra   s      r&   swig_sourceszbuild_ext.swig_sourcesc  s    r'   c                 ,  12 |j         }|t          |          st          d|j        z            t	          |          }|sd S |                     |j                  }| j        r|                    d          }d                    |dd                   }|d         }| 	                    d          }|
                    |          }t          j                            ||                     |                    }	n8t          j                            | j        |                     |                    }	||j        z   }
| j        }| j        s/| j                                        st)          j        d           d}|s-t-          |
|	d          st)          j        d	|j                   d S t)          j        d
|j                   |j        pg }t3          |dd           pg }t3          |dd           pg }|j        d d          }|j        D ]}|                    |f           t;          |j                   \  }}}}| j        j        dk    r#|r|                    d           ||z  }||z  }g }|j         dk    r| j!        }n!|j         dk    r| j"        }n| j!        p| j"        }|@tG          |d          r	|j$        pg ng |_$        tG          |d          r	|j%        pg ng |_%        | j&        }|r|tO          d|j        z            |s|r|tO          d|j        z            |j         dv r|| (                    d|j        z             |j         dk    r|| (                    d|j        z             d|j        i}| j)        }|j*        tW                      z   }g }g }g }g }| j        s| 	                    d          j,        }t          j                            ddd          }t          j                            ||          }|                    |           |} |f|df||f|dffD ]%\  }!}"1|!D ]2|"12fd 2d d          D             z  }"&| j        -                                }n|                    d!           g }#|r=t)          j        d"           |# | j        j.        |f|| ||z   || j        ||z   |d#|z  }#|r<t)          j        d$           |# | j        j.        |f|| ||z   || j        ||z   d%|z  }#|r>t)          j        d&           |# | j        j/        |f|||z   || j        ||z   |z   d'|z  }#|r9t)          j        d(           |# |j/        |f|||z   || j        ||z   |z   d'|z  }#g }$g }%|rt)          j        d)           |j0        d d          }&t          j                            | j)        t          j        1                    |                     |                              }'| 2                    |'           |j3        ti          d*          }(|$|5                    |&|'          z  }$|%|/                    || j)        ||| j        |$|j        +          z  }%|j3        ti          d*          D ]})|)|(v rt          j                            |'|)          }*t          j        6                    |)          t          j        6                    |*          k    rht          j        7                    |*          rt          j8        |*           	 | 9                    |)|'           # tt          $ r t)          j(        d,|)d-|'           Y w xY w|rBt)          j        d.           |%|/                    || j)        ||| j        |$|j        +          z  }%|%r|;                    | j                  s|%}+|#},ng }+|#|%z   },|j<        r|,=                    |j<                   |j>        pg }| ?                    |          d d          }-|j@        d d          }.| j        jA        }/| j        j        d/v rZ| B                    ||-|.           |jC        r;|jC        D ],}0ti          |0d0z             D ]})t          |)| jE                   -g |_C        n|j         dv r	||jA        }/|j         dk    r	||jA        }/|| F                    |,|-||.|+          \  },}- |/|,|	|-|.|jC        || G                    |          | j        | j)        |j         1
  
         d S )2Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesrW   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/Zm1000rV   rS   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)rS   rV   zTextension %r has Fortran libraries but no Fortran linker found, using default linkerrT   zLextension %r has C++ libraries but no C++ linker found, using default linkerdependsr:   rC   rD   rE   )z.dispatch.c)z.dispatch.cppz.dispatch.cxxc                     g | ]?}|                                                                       |                    @S r   )r   popindex)r^   s_ext_srcs     r&   
<listcomp>z-build_ext.build_extension.<locals>.<listcomp>  sP       AJJt,<,<A//  r'   )NPY_DISABLE_OPTIMIZATIONr<   z#compiling C++ dispatch-able sources)
output_dirsrc_dirrP   r-   debugextra_postargs	ccompilerz!compiling C dispatch-able sources)r   r   rP   r-   r   r   zcompiling C sources)r   rP   r-   r   r   zcompiling C++ sourcesz#compiling Fortran 90 module sourcesz*.mod)r   rP   r-   r   r   r   zfailed to move rR   zcompiling Fortran sources)r   intelwintelemwz/*.dll)rN   rO   runtime_library_dirsr   export_symbolsr   rv   target_lang)Hr   r   r   r]   listr\   rd   r/   rt   rk   get_package_dirr0   rs   get_ext_filenamer   r   rB   r#   rF   	is_cachedr
   r   r   rK   extra_compile_argsgetattrr   undef_macrosrl   r   r?   r   r   r   r   rw   r   r   r   r   rg   rv   r-   r   r:   cpu_baseline_flagstry_dispatchcompilemodule_dirsdirnamemkpathmodule_dir_switchr   module_optionsru   isfileremove	move_filer   can_ccompiler_linkextra_objectsr3   extra_link_argsget_librariesrO   link_shared_object_libs_with_msvc_and_fortranr   r	   r{   _process_unlinkable_fobjectsget_export_symbols)3r%   r_   r   fullnamemodpathpackagebaser   package_dirext_filenamer   force_rebuild
extra_argsextra_cflagsextra_cxxflagsrP   undef	c_sourcescxx_sources	f_sourcesfmodule_sourcesr   r   kwsr   r-   copt_c_sourcescopt_cxx_sourcescopt_baseline_flagscopt_macrosbsrc_dirrG   copt_build_src_srcs_dst	c_objectsr   	f_objectsr   module_build_direxisting_modulesftunlinkable_fobjectsobjectsrN   rO   linkerdr   r   s3                                                    @@r&   build_extensionzbuild_ext.build_extensiong  s   +?+g"6"6?%.14:; ; ; w-- 	F((22< 
	InnS))Ghhwqt}--G2;D11*==H"227;;K7<<(,(=(=d(C(CE ELL 7<<(,(=(=h(G(GI ILCK'
( 	!1B1L1L1N1N 	!IBCCC M 	:WlG!L!L 	:I<chGGGFH.999+1r
s$:DAAGR &>EEK"111%% 	$ 	$EMM5(#### 3;'' 	;	;	? =&&00 /!!),,,. $IK <5  *II\U""*II*@d.@I U\-V/ V/ 070J0Pb46 ,U\-V/ V/ 070J0Pb46 ,)  	K</  "=@C"J K K K 	O 	Oi.?  "ADGH"N O O O<>))i.?II JMPXW X X X<5  \%9II FILS T T T #+&_
'*@*B*BB  ( 	@11+>>HHW\\';	JJNW\\(NCCN/// &N~/?@[)+;68& 	 	!tT
 "  D     !%aaa   DD
 #'"3"F"F"H"H>???	 	H:;;;7*7 
%&+)j)N:&
 
 
 
 
I  
	H89997*7%&+)j)L8    I  
	H*+++..%+)j *-@ @ ,!-    I  
	H,-----%+)j *-@ @ .!/    I 	 !	8H:;;;/!!!,K!w||))(33"5 "5 6  6 KK()))*2#'== i66-/ / /N**?6:o288D15:H36; + @ @ @I *2g 8 8A,,, %5q99Awq))RW__Q-?-??? w~~a(( %	!8q*:;;;;- 8 8 8"#!!%5%5"7 8 8 8 8 88  	@H0111**96:o288D15:H36; + @ @ @I  	,Y99$-HH 	,"+GG"$)+G 	.NN3,---(.B
&&s++AAA.	'*1=&*HHH ,,9l4 4 4' . 1 9 9A!!h,// 9 9!!T%788889+-(\^++	0E1F<5  \%=!4F !%!B!BY|'") ")GY
 	w"($'$<("55c::Z/<	) 	) 	) 	) 	) 	)s   \44$]]c                 4   |                      d          j        }|                      d          j        }| j                            t
          j                            |d          g| j                  }| j        	                    |d|| j
                   d S )Nr:   r;   zgfortran_vs2003_hack.c)r   _gfortran_workaround)r   r   )rk   r:   r;   r?   r   r0   rs   rt   rv   create_static_libr   )r%   r   r:   r;   r   s        r&   _add_dummy_mingwex_symz build_ext._add_dummy_mingwex_symv  s    ..{;;E	//==H
-''i6N*P *P )Q37? ( D D 	''+
$* 	( 	V 	V 	V 	V 	Vr'   c                    t          |          }t          |          }t          |          }|d d          D ]D}|D ]=}t          j                            ||dz             }t          j                            |          r|                    |           t          |          5 }	|                    |	                                	                                           d d d            n# 1 swxY w Y   t          j                            ||dz             }
t          |
          5 }	|                    |	                                	                                           d d d            n# 1 swxY w Y   ?F|rCd |D             }|
                    || j        | j                  }|                    |           ||fS )Nz	.fobjectsz	.cobjectsc                 L    g | ]!}t           j                            |          "S r   )r0   rs   ru   )r^   objs     r&   r   z:build_ext._process_unlinkable_fobjects.<locals>.<listcomp>  s&    LLL,,LLLr'   )r   r{   )r   r0   rs   rt   r   r   openr3   read
splitlineswrap_unlinkable_objectsrv   r{   )r%   r   rN   r   rO   r   liblibdirfake_libr   c_libfobjectswrappeds                r&   r   z&build_ext._process_unlinkable_fobjects  s5    OO	w--"#677 QQQ< 	> 	>C& > >7<<k0ABB7>>(++ 	>$$S)))h J1+22166883F3F3H3HIIIJ J J J J J J J J J J J J J J GLL{1BCCEe >qvvxx':':'<'<===> > > > > > > > > > > > > > >>  	$LL8KLLLH77"&"4 8 6 6G NN7###	!!s$   &:C,,C03C0):E//E36E3c                 .   |d S |D ]1}|                     d          rd}|pg D ]H}t          j                            |d|z            }t          j                            |          rd} nI|rkd}|D ]}t          j                            |d|z            }t          j                            |          r_t          j                            | j        |dz             }t          ||           | j        |vr|                    | j                   d} n|rt          j	        d|d|           3g }	|j
        D ]p}
|
                     d	          rD	 t          j        d
d|
g          }
t          |
          }
n# t          t          j        f$ r Y nw xY w|	                    |
           q|                    |	           |j        D ]}|                     d          s|                    |           t%          |	d|z   dz             }|rt          j                            | j        |dz             }t          j                            |          st          |d         |           | j        |vr|                    | j                   d S )Nr   Fz%s.libTzlib%s.az.libzcould not find library z in directories z/usr/libcygpathz-wr  z.ar   )
startswithr0   rs   rt   r   rv   r	   rl   r
   rg   rO   
subprocesscheck_outputr   OSErrorCalledProcessErrorr3   rN   r   )r%   r   c_librariesc_library_dirsr   
fileexistsr  libfilelibfile2
f_lib_dirsdirr  pdst_names                 r&   r   z%build_ext._libs_with_msvc_and_fortran  s   F" 	2 	2G!!&)) J(.B  ',,vx7/CDD7>>'** !%JE  J( 
 
',,vyG/DEE7>>'**   "w||DOWv=MNNHgx000n<<&--do>>>!%JE  HH1 2 2 2 2 
) 
	# 
	#C ~~j)) ??$19dC2HIIC :#>>CC  !>?   D c""""j))) & 		? 		?C>>&)) ?""3'''!*eckD.@AA ?!w||DOS6\JJH7>>(33 2!!A$111n<<&--do>>>		? 		?s   FFFc                     |                      | j                   g }| j        D ]$}|                    t          |                     %|S r   )check_extensions_listra   r3   r   )r%   	filenamesr_   s      r&   get_source_fileszbuild_ext.get_source_files  sT    ""4?333	? 	8 	8C1#667777r'   c           	      ,   |                      | j                   g }| j        D ]o}|j        s
|                     |j                  }|                    t          j                            | j	        | 
                    |                               p|S r   )r&  ra   r   r\   r]   rl   r0   rs   rt   r   r   )r%   outputsr_   r   s       r&   get_outputszbuild_ext.get_outputs  s    ""4?333? 	J 	JC; ,,SX66HNN27<<(,(=(=h(G(GI I J J J Jr'   r   )__name__
__module____qualname__descriptionr   user_optionshelp_optionsr   boolean_optionsr   r4   rj   r   r  r  r   r   r(  r+  r   r'   r&   r   r      s       NK - 1 1 1 L" !-	4!C		!1 L
 $3|E[6\\O   F  F  FDA7 A7 A7F   M) M) M)^V V V!" !" !"F;? ;? ;?z  
 
 
 
 
r'   r   )!__doc__r0   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&   <module>r>     s    
			           * * * * * * B B B B B B          ) ) ) ) ) )       H H H H H H 5 5 5 5 5 5                K J J J J J I I I I I I I IX X X X X X X X X Xr'   