
    Kh/                     l   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKJr  SSKJr  SSKJrJr  SSKJr  SSKJr  S!S jrS	rS
r " S S5      r\(       d  \" 5       r\R;                  5         S rS rS r S r!Sq"Sq#\RH                  S:X  a=  \" \%5      RL                  RL                  RL                  r'\(" \'R                  S5      5      r)S r*S r+S r,S r-\-/ / / S4S j5       r.\-/ / / SS4S j5       r/ " S S\5      r0S!S jr1 " S S5      r2S r3\	Rh                  S  5       r5g)"z
Utility functions for

- building and importing modules on test time, using a temporary location
- detecting if compilers are present
- determining paths to tests

    N)Path)	asunicode)temppathIS_WASM)import_module)MesonBackendc                    [         R                  S:X  a  [        R                  " SSS9  [        R
                  " 5       n [        R                  R                  US5      n[        US5       nUR                  S5        UR                  SU  S	35        U(       aL  UR                  U  S
U  S	35        UR                  U  SU S35        UR                  SU  SU  SU  SU  S3	5        S S S 5         [        R                  " / SQSUSS9nWR                  S:H  [        R                   " U5        $ ! , (       d  f       NM= f! [        R                   a    [        R                  " SSS9   Naf = f! [        R                   " U5        f = f)Nwin32z*No Fortran tests on Windows (Issue #25134)T)allow_module_levelzmeson.buildwzproject('check_compilers')
zadd_languages('z')
z _compiler = meson.get_compiler('z_code = '''z'''
_have_z
_feature =z_compiler.compiles(z_code, name: 'z feature check')
)mesonsetupbtmpF)checkcwdcapture_outputz3meson not present, skipping compiler dependent testr   )sysplatformpytestskiptempfilemkdtempospathjoinopenwrite
subprocessrunCalledProcessError
returncodeshutilrmtree)langcode_snippettmpdir
meson_filefrunmesons         G/var/www/html/env/lib/python3.13/site-packages/numpy/f2py/tests/util.pycheck_languager,      s]   
||w@UYZFWW\\&-8
*c"aGG23GGodV4014& @dKL4&L>?@TF*f/v 6#f$68 #	h!~~*#	H ""a'f- #"$ ,, 	hKKMbfg	h 	fsI    ,E- ,A:D-&E- /D> E- -
D;7E- >)E*'E- )E**E- -Fz]
C Example Fortran 77 code
      PROGRAM HELLO
      PRINT *, 'Hello, Fortran 77!'
      END
z
! Example Fortran 90 code
program hello90
  type :: greeting
    character(len=20) :: text
  end type greeting

  type(greeting) :: greet
  greet%text = 'hello, fortran 90!'
  print *, greet%text
end program hello90
c                        \ rS rSrS rS rSrg)CompilerCheckerS   c                 <    SU l         SU l        SU l        SU l        g )NFcompilers_checkedhas_chas_f77has_f90selfs    r+   __init__CompilerChecker.__init__T   s    !&
    c                    U R                   (       d  [        R                  S:X  d  [        R                  R                  5        nUR                  [        S5      UR                  [        S[        5      UR                  [        S[        5      /nUS   R                  5       U l        US   R                  5       U l        US   R                  5       U l        S S S 5        SU l         g g g ! , (       d  f       N= f)Ncygwincfortranr         T)r2   r   r   
concurrentfuturesThreadPoolExecutorsubmitr,   fortran77_codefortran90_coderesultr3   r4   r5   )r7   executorrB   s      r+   check_compilersCompilerChecker.check_compilersZ   s    &&1I##668HOONC8OONI~NOONI~N %QZ..0
&qz002&qz002 9 &*D" 2J&88s   BC**
C8r1   N)__name__
__module____qualname____firstlineno__r8   rI   __static_attributes__ r:   r+   r.   r.   S   s    *r:   r.   c                  "    [         R                  $ N)checkerr3   rP   r:   r+   has_c_compilerrT   m   s    ==r:   c                  "    [         R                  $ rR   )rS   r4   rP   r:   r+   has_f77_compilerrV   p       ??r:   c                  "    [         R                  $ rR   )rS   r5   rP   r:   r+   has_f90_compilerrY   s   rW   r:   c                  P    [         R                  =(       a    [         R                  $ rR   )rS   r5   r4   rP   r:   r+   has_fortran_compilerr[   v   s    OO/0r:   i  r<   z**/*.dllc                      [         bB   [        R                  R                  [         5         [
        R                  " [         5        S q g g ! [         a     N+f = f! [         a     N f = frR   )_module_dirr   r   remove
ValueErrorr#   r$   OSErrorrP   r:   r+   _cleanupra      sa    	HHOOK(	MM+&    		  		s"   #A A 
AA
A('A(c                      [         ck  [        R                  " 5       q [        R                  " [
        5        [         [        R                  ;  a$  [        R                  R                  S[         5        [         $ )Nr   )	r]   r   r   atexitregisterra   r   r   insertrP   r:   r+   get_module_dirrf      sF    &&(!chh&HHOOA{+r:   c                  |    [        5         S[        -  n [        S-  qU [        R                  ;   a  [	        S5      eU $ )Nz_test_ext_module_%dr?   z%Temporary module name already in use.)rf   _module_numr   modulesRuntimeError)names    r+   get_temp_module_namerl      s;      ;.D1Ks{{BCCKr:   c                 >   ^ ^ 0 mU U4S jnT R                   Ul         U$ )Nc                     > [        X45      nUT;  a   T" U 0 UD6TU'   TU   n[        U[        5      (       a  UeU$ ! [         a  nUTU'   e S nAff = frR   )repr	Exception
isinstance)akwkeyeretfuncmemos        r+   wrapper_memoize.<locals>.wrapper   sk    A7md? !NrNS	 3ic9%%I
  S	s   > 
AAA)rK   )rw   ry   rx   s   ` @r+   _memoizer{      s     D }}GNr:   c           
      p   S[         R                  < S3n[        5       n[        5       (       d  [        R
                  " S5        / n/ nU  H  n	[        R                  R                  U	5      (       d  [        SU	-  5      e[        R                  R                  U[        R                  R                  U	5      5      n
[        R                  " X5        UR                  U
5        [        R                  R                  U
5      u  pUS;   d  M  UR                  U
5        M     U(       d   eUc
  [        5       n/ nSU;  a	  SU;  a  S/nS	S
U/U-   U-   U-   nUSS/-  nU(       a	  US/U-   -  nU(       a	  US/U-   -  n[        R                   " 5       n [        R"                  " U5        [         R$                  S	U/U-   n[&        R(                  " U[&        R*                  [&        R,                  S9nUR/                  5       u  nnUR0                  S:w  a  [        SUSS < S[3        U5      < 35      e [        R"                  " U5        U H  n	[        R4                  " U	5        M     [         R6                  S:X  au  [8        R;                  [<        R<                  " [        R                  R                  USR?                  U5      5      5      5        [&        R@                  " / SQ[8        -   5        [C        U5      $ ! [        R"                  " U5        U H  n	[        R4                  " U	5        M     f = f)z@
Compile and import a f2py module, built from the given files.

zimport sys; sys.path = z&; import numpy.f2py; numpy.f2py.main()No Fortran compiler availablez%s is not a file).f90z.f95.fz.c.pyfNz--freethreading-compatiblez--no-freethreading-compatiblez-cz-mz	--backendr   zskip:zonly:)stdoutstderrr   zRunning f2py failed:    
r<   z{:s}*)z/usr/bin/rebasez
--databasez--obliviousz	--verbose)"r   r   rf   r[   r   r   r   isfilerj   r   basenamer#   copyfileappendsplitextrl   getcwdchdir
executabler   PopenPIPESTDOUTcommunicater"   r   unlinkr   _module_listextendglobformat
check_callr   )source_filesoptionsr   onlymodule_namecodeddst_sourcesf2py_sourcesfndstbaseextgil_options	f2py_optsr   cmdpouterrs                       r+   build_moduler      s    %SXXL0VWDA!!34 KLww~~b!!1B677ggll1bgg..r23 3GG$$S)	66$  < *,K#727V^e7e34t[)G3kALPI+w''IgY%%	gY%%	 ))+C
~~tT*Y6S$.OO$.$5$57 ==?S<<1 #AB3 9 : :  	 BIIbM  ||x 	IIbggll1gnn[&ABC	
 	I	
 %%) 	 BIIbM s   B K> >7L5c           	          Uc  Sn[        US9 n[        US5       nUR                  U 5        SSS5        [        U/UUUUS9sSSS5        $ ! , (       d  f       N%= f! , (       d  f       g= f)z.
Compile and import Fortran code using f2py.

Nr   )suffixr   r   r   r   r   )r   r   r   r   )source_coder   r   r   r   r   r   r)   s           r+   
build_coder     sc     ~		 D$_GGK  TF$+!%!%(3	5 
!	 _ 
!	 s!   AAA
A	A
A,c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )SimplifiedMesonBackendi/  c                 &   > [         TU ]  " U0 UD6  g rR   )superr8   )r7   argskwargs	__class__s      r+   r8   SimplifiedMesonBackend.__init__0  s    $)&)r:   c                 p    U R                  U R                  5        U R                  U R                  5        g rR   )write_meson_build	build_dir	run_mesonr6   s    r+   compileSimplifiedMesonBackend.compile3  s$    t~~.t~~&r:   rP   )rK   rL   rM   rN   r8   r   rO   __classcell__)r   s   @r+   r   r   /  s    *' 'r:   r   c           	          [        5       (       d  [        R                  " S5        [        5       nUc
  [	        5       n[        S0 SU_SU _SUR                  S/ 5      _SU_SUR                  S/ 5      _SUR                  S/ 5      _SUR                  S/ 5      _S	UR                  S	/ 5      _S
UR                  S
/ 5      _SUR                  S/ 5      _SUR                  S/ 5      _SUR                  S/ 5      _SUR                  S/ 5      _SUR                  S/ 5      _SUR                  SS5      _SUR                  S0 5      _6nUR                  5         [        R                  R                  SU SUR                   35        [        U5      $ )z)
Build a module via Meson and import it.
r}   
modulenamesourcesextra_objectsr   include_dirslibrary_dirs	librariesdefine_macrosundef_macros
f2py_flagssysinfo_flagsfc_flags
flib_flagssetup_flagsremove_build_dirF	extra_datr   /rP   )r[   r   r   rf   rl   r   getr   r   r   re   meson_build_dirr   )r   r   r   r   backends        r+   build_mesonr   8  s     !!34 I*, %  jj"5 	
 ZZ3 ZZ3 **["- jj"5 ZZ3 ::lB/ jj"5 J+ ::lB/ JJ}b1  $6>  **["-!G& OO HHOOA)Ag&=&=%>?@%%r:   c                   b    \ rS rSrSrSr/ r/ r/ rSr	Sr
SrSrSr\S 5       r\S 5       rS rSrg)F2PyTestie  Nr   c                 x    [        U 5      nSUR                  R                  SS5      S    SUR                   S3$ )N_.r?   _ext_module)typerL   rsplitrK   )r7   clss     r+   r   F2PyTest.module_nameq  s;    4j3>>((Q/34Acll^;OOr:   c                     [         R                  S:X  a  [        R                  " S5        [	        5       [
        l        [        5       [
        l        [        5       [
        l
        [        5       [
        l        g )Nr
   z)Fails with MinGW64 Gfortran (Issue #9673))r   r   r   r   rT   r   _has_c_compilerrV   _has_f77_compilerrY   _has_f90_compilerr[   _has_fortran_compiler)r   s    r+   setup_classF2PyTest.setup_classv  sG    <<7"KKCD#1#3 %5%7"%5%7")=)?&r:   c           	         U R                   b  g U R                  (       a  U R                  O/ nU R                  (       a  UR                  U R                  5        [        S U 5       5      n[        S U 5       5      n[        S U 5       5      nU(       a'  U R                  (       d  [        R                  " S5        U(       a'  U R                  (       d  [        R                  " S5        U(       a'  U R                  (       d  [        R                  " S5        U R                  bO  [        U R                  U R                  U R                  U R                  U R                  U R                  S9U l         U R                  bE  [        U R                  U R                  U R                  U R                  U R                  S9U l         g g )	Nc              3   V   #    U  H  n[        U5      R                  S 5      v   M!     g7f)r   Nstrendswith.0r   s     r+   	<genexpr>(F2PyTest.setup_method.<locals>.<genexpr>  s"     ?2B((..   ')c              3   V   #    U  H  n[        U5      R                  S 5      v   M!     g7f)r~   Nr   r   s     r+   r   r     "     A5RB((005r   c              3   V   #    U  H  n[        U5      R                  S 5      v   M!     g7f)r   Nr   r   s     r+   r   r     r   r   z No Fortran 77 compiler availablez No Fortran 90 compiler availabler}   )r   r   r   r   r   r   )moduler   r   r   r   anyr   r   r   r   r   r   r   r   r   r   )r7   codes	needs_f77	needs_f90	needs_pyfs        r+   setup_methodF2PyTest.setup_method  s5   ;;" $"99LL%???	A5AA	A5AA	T33KK:;T33KK:;T77KK78 99 $		YYYY{{ ,,DK <<#&YYYY ,,DK $r:   )r   )rK   rL   rM   rN   r   r   r   r   r   r   r   r   r   r   propertyr   classmethodr   r   rO   rP   r:   r+   r   r   e  se    DGGDDFFOP P @ @%r:   r   c                      [        [        R                  R                  5      R                  R                  5       nUR                  " U 6 $ rR   )r   numpyf2py__file__parentresolvejoinpath)rr   r   s     r+   getpathr    s3    UZZ  !((002A::q>r:   c              #      #    [         R                  " 5       n[        R                  " U 5         S v   [        R                  " U5        g ! [        R                  " U5        f = f7frR   )r   r   r   r   )r   curpaths     r+   	switchdirr    s;     hhjGHHTN
s   ,A%A
 A%
A""A%rR   )6__doc__r   r   r   r   r   r#   rc   r   
contextlibr   concurrent.futuresrA   pathlibr   numpy._utilsr   numpy.testingr   r   	importlibr   numpy.f2py._backends._mesonr   r,   rE   rF   r.   rS   rI   rT   rV   rY   r[   r]   rh   r   r   r   NUMPY_INSTALL_ROOTlistr   ra   rf   rl   r{   r   r   r   r   r   r  contextmanagerr  rP   r:   r+   <module>r     sc    	 
          " + # 4>* *, G1 <<8h..55<<*//
;<L	2 
') L& 
L&^ 
5 
56'\ '%&Z? ?N  r:   