
    (ph+                        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rSSKJr  SSKJr  SSKJr  SSKJrJr  SSKJr  SqSq\R4                  S	:X  a=  \" \5      R8                  R8                  R8                  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q&S r'S r(S r)S r*\#S 5       r+ " S S5      r,S r-\R\                  S 5       r/g)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)asstr)	asunicode)temppathIS_WASM)import_modulei  cygwinz**/*.dllc                      [         bB   [        R                  R                  [         5         [
        R                  " [         5        S q g g ! [         a     N+f = f! [         a     N f = fN)_module_dirsyspathremove
ValueErrorshutilrmtreeOSError     H/var/www/html/venv/lib/python3.13/site-packages/numpy/f2py/tests/util.py_cleanupr   (   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   tempfilemkdtempatexitregisterr   r   r   insertr   r   r   get_module_dirr   6   sF    &&(!chh&HHOOA{+r   c                  |    [        5         S[        -  n [        S-  qU [        R                  ;   a  [	        S5      eU $ )Nz_test_ext_module_%d   z%Temporary module name already in use.)r   _module_numr   modulesRuntimeError)names    r   get_temp_module_namer&   @   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r   )repr	Exception
isinstance)akwkeyeretfuncmemos        r   wrapper_memoize.<locals>.wrapperO   sk    A7md? !NrNS	 3ic9%%I
  S	s   > 
AAA)__name__)r1   r3   r2   s   ` @r   _memoizer6   L   s     D }}GNr   c           
         S[         R                  < S3n[        5       n/ 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SSU/U-   U-   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R*                  S:w  a  [        SUSS < S[-        U5      < 35      e [        R                  " U5        U H  n	[        R.                  " U	5        M     [         R0                  S:X  au  [2        R5                  [6        R6                  " [        R                  R                  USR9                  U5      5      5      5        [         R:                  " / SQ[2        -   5        [=        U5      $ ! [        R                  " U5        U H  n	[        R.                  " 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()%s is not a file).f90.fz.c.pyfNz-cz-mzskip:zonly:stdoutstderrr   zRunning f2py failed:    
r	   z{:s}*)z/usr/bin/rebasez
--databasez--obliviousz	--verbose)r   r   r   osisfiler$   joinbasenamer   copyfileappendsplitextr&   getcwdchdir
executable
subprocessPopenPIPESTDOUTcommunicate
returncoder   unlinkplatform_module_listextendglobformat
check_callr   )source_filesoptionsskiponlymodule_namecodeddst_sourcesf2py_sourcesfndstbaseext	f2py_optscwdcmdpouterrs                      r   build_modulerk   e   sf    %SXXL0VWDA KLww~~b!!1B677ggll1bgg..r23 3GG$$S)	..$  < *,t[)G3lBI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 J> >7K5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:   )suffixwrY   rZ   r[   r\   )r   openwriterk   )source_coderY   rZ   r[   rm   r\   r   fs           r   
build_codert      sc     ~		 D$_GGK  TF$+!%!%(3	5 
!	 _ 
!	 s!   AAA
A	A
A,c            	         [         b  [         $ Sq [        (       a  [         $ [        R                  " S[	        [
        R                  5       S35      n U [        [	        [
        R                  5      S9-  n [        R                  " 5       n [        R                  R                  US5      n[        US5       nUR                  U 5        S S S 5        [
        R                  SS/n[        R                   " U[        R"                  [        R$                  US9nUR'                  5       u  pg[(        R*                  " U5        [,        R.                  " S	U5      nU(       ah  [1        [3        UR5                  S
5      5      5      [1        [3        UR5                  S5      5      5      [1        [3        UR5                  S5      5      5      4q [         $ ! , (       d  f       GN	= f! [(        R*                  " U5        f = f)N)FFFz8        import os
        import sys
        sys.path = a{  

        def configuration(parent_name='',top_path=None):
            global config
            from numpy.distutils.misc_util import Configuration
            config = Configuration('', parent_name, top_path)
            return config

        from numpy.distutils.core import setup
        setup(configuration=configuration)

        config_cmd = config.get_config_cmd()
        have_c = config_cmd.try_compile('void foo() {}')
        print('COMPILERS:%%d,%%d,%%d' %% (have_c,
                                          config.have_f77c(),
                                          config.have_f90c()))
        sys.exit(99)
        )syspathzsetup.pyrn   config)r=   r>   rf   s   COMPILERS:(\d+),(\d+),(\d+)r!         )_compiler_statusr   textwrapdedentr)   r   r   dictr   r   rA   rC   rp   rq   rJ   rK   rL   rM   rN   rO   r   r   researchboolintgroup)	r]   tmpdirscriptrs   rg   rh   ri   rj   ms	            r   _get_compiler_statusr      st   #,w ??   N# $	 D* $tCHH~..DFfj1&#!GGDM  ~~z84S$.OO$.$5$5!') ==?f
		137AQWWQZ!QWWQZ!QWWQZ!
 )  	fs%   ,G 7G	A G 
GG G5c                      [        5       S   $ r   r   r   r   r   has_c_compilerr         !!$$r   c                      [        5       S   $ )Nr!   r   r   r   r   has_f77_compilerr     r   r   c                      [        5       S   $ )Nrx   r   r   r   r   has_f90_compilerr     r   r   c                 l   [        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                  " Xg5        UR                  U5        M     [        R                  " U5      R                  SS5      nS[        [        R                  5       SU S3n[        R                  R                  U[        5       S-   5      n	UR                  U	5        [!        U	S5       n
U
R#                  UR%                  S	5      5        S
S
S
5        [        R&                  " 5       n [        R(                  " U5        [        R*                  U	SS/n[,        R.                  " U[,        R0                  [,        R2                  S9nUR5                  5       u  pUR6                  S:w  a  [	        SUSS
 < S[9        U5      < 35      e [        R(                  " U5        U H  n[        R:                  " U5        M     [=        U5        [        R>                  U   $ ! , (       d  f       GN= f! [        R(                  " U5        U H  n[        R:                  " U5        M     f = f)z.
Build a module via distutils and import it.

r8   r@   z
    z!
import os
import sys
sys.path = z

def configuration(parent_name='',top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('', parent_name, top_path)
    z
    return config

if __name__ == "__main__":
    from numpy.distutils.core import setup
    setup(configuration=configuration)
    z.pywblatin1N	build_extz-ir<   r   z Running distutils build failed: r?   ) r   rA   r   rB   r$   rC   rD   r   rE   rF   r{   r|   replacer)   r   r&   rp   rq   encoderH   rI   rJ   rK   rL   rM   rN   rO   rP   r   rQ   
__import__r#   )rX   config_coder\   r-   r^   r_   ra   rb   r]   r   rs   rf   rg   rh   ri   rj   s                   r   build_module_distutilsr     s    	A Kww~~b!!1B677ggll1bgg..r23 3  //+.66tXFK N 
 M D WW\\!13e;<Fv	fd	q	H%& 
 ))+C
~~v{D9S$.OO$.$5$57 ==?<<1 #ABs 5 6 6  	 BIIbM  {;;{##1 
	  	 BIIbM s   :!I*9BI< *
I9<7J3c                   F    \ rS rSrSrSr/ r/ r/ rSr	Sr
\S 5       rS rSrg)F2PyTestia  Nr:   c                 x    [        U 5      nSUR                  R                  SS5      S    SUR                   S3$ )N_.r!   _ext_module)type
__module__rsplitr5   )selfclss     r   r\   F2PyTest.module_namej  s;    4j3>>((Q/34Acll^;OOr   c           	         [         R                  S:X  a  [        R                  " S5        U R                  b  g [        5       (       d  [        R                  " S5        / nU R                  (       a  UR                  U R                  5        U R                  b  UR                  U R                  5        SnSnSnU Hl  n[        U5      R                  S5      (       a  SnM&  [        U5      R                  S5      (       a  SnMI  [        U5      R                  S5      (       d  Mj  SnMn     U(       a%  [        5       (       d  [        R                  " S	5        U(       a%  [        5       (       d  [        R                  " S
5        U(       a4  [        5       (       d%  [        5       (       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 )Nwin32z)Fails with MinGW64 Gfortran (Issue #9673)zNo C compiler availableFr:   Tr9   r;   z No Fortran 77 compiler availablez No Fortran 90 compiler availablezNo Fortran compiler available)rY   rZ   r[   rm   r\   ro   )r   rR   pytestrZ   moduler   sourcesrT   r]   rF   rm   strendswithr   r   rt   rY   r[   r\   rk   )r   codes	needs_f77	needs_f90	needs_pyfra   s         r   setup_methodF2PyTest.setup_methodo  s   <<7"KKCD;;" KK12<<LL&99 LL%			B2w%% 	R!!&)) 	R!!&)) 	  -//KK:;-//KK:;.004D4F4FKK78 99 $		YYYY{{ ,,DK <<#&YYYY ,,DK $r   )r   )r5   r   __qualname____firstlineno__r]   r   rY   rZ   r[   rm   r   propertyr\   r   __static_attributes__r   r   r   r   r   a  s>    DGGDDFFP P4r   r   c                      [        [        R                  R                  5      R                  R                  5       nUR                  " U 6 $ r   )r   numpyf2py__file__parentresolvejoinpath)r,   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r   )r   rf   rA   rI   )r   curpaths     r   	switchdirr     s;     hhjGHHTN
s   ,A%A
 A%
A""A%)0__doc__rU   rA   r   rK   r   r   r   r{   r~   r   
contextlibr   pathlibr   numpy.compatr   numpy._utilsr   numpy.testingr   r   	importlibr   r   r"   rR   r   r   NUMPY_INSTALL_ROOTlistrS   r   r   r&   r6   rk   rt   rz   r   r   r   r   r   r   r   contextmanagerr   r   r   r   <module>r      s>    	 
      	      " + # <<8h..55<<*//
;<L	2 
') F& 
F&R 
5 
54  ;|%%% 
<$ 
<$HB BT  r   