
    Bwgl                        d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlm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 Z ed	d
      ZdQdZ e
j*                  d      d        Z e
j*                  d      d        Z e
j*                  d      d        Z e
j*                  d      d        Z e
j*                  d      d        Z e
j*                  d      d        Zd Zd Zd Zd Zd Z d Z!e
jD                  jG                  ejH                  dk  d      d        Z%e
jD                  jG                   e	jL                         dk7  xs ejH                  dk  d      d         Z'e
jD                  jP                  d!        Z)d" Z*d# Z+d$ Z,d% Z-d& Z.d' Z/d( Z0d) Z1d* Z2d+ Z3d, Z4d- Z5d. Z6d/ Z7e
jD                  jq                  d0      d1        Z9d2 Z:d3 Z;d4 Z<d5 Z=d6 Z>d7 Z?d8 Z@d9 ZAd: ZBe
jD                  jq                  d0      d;        ZCe
jD                  jG                   e	jL                         dk7  xs ejH                  dk  d<      d=        ZDe
jD                  jG                   e	jL                         dk7  xs ejH                  dk  d<      d>        ZEd? ZFd@ ZGdA ZHdB ZIdC ZJdD ZKdE ZLdF ZMdG ZNdH ZOdI ZPdJ ZQdK ZRdL ZSdM ZTdN ZUdO ZVdP ZWy)R    N)Path)
namedtuple   )util)main)NOGIL_BUILDc                  l    t        j                         st        j                  d       y t	                y )Nz$CLI command needs a Fortran compiler)r   has_fortran_compilerpytestskipf2pycli     S/var/www/horilla/myenv/lib/python3.12/site-packages/numpy/f2py/tests/test_f2py2e.pycompiler_check_f2pyclir      s     $$&:;	r   PPathsz(finp, f90inp, pyf, wrap77, wrap90, cmodfc                     t        |       }t        |j                  d      |j                  d      |j                  d      |j                  | d      |j                  | d      |j                  | d            S )ax  Takes in a temporary file for testing and returns the expected output and input paths

    Here expected output is essentially one of any of the possible generated
    files.

    ..note::

         Since this does not actually run f2py, none of these are guaranteed to
         exist, and module names are typically incorrect

    Parameters
    ----------
    fname_inp : str
                The input filename
    mname : str, optional
                The name of the module, untitled by default

    Returns
    -------
    genp : NamedTuple PPaths
            The possible paths which are generated, not all of which exist
    z.fz.f90.pyfz-f2pywrappers.fz-f2pywrappers2.f90module.c)finpf90inppyfwrap77wrap90cmodf)r   r   with_suffix	with_name)	fname_inpmnamebpaths      r   get_io_pathsr!   $   s~    . OEt$  (f%%89%(:;<oox01 r   session)scopec                     t        j                  dddd      j                         }| j                         dz  }|j	                  |d       |S )'Generates a single f90 file for testingtestssrcclizhiworld.f90z	hello.f90asciiencodingr   getpath	read_textgetbasetemp
write_texttmpdir_factoryfdatfns      r   hello_world_f90r5   K   sI     <<}=GGID		#	#	%	3BMM$M)Ir   c                     t        j                  dddd      j                         }| j                         dz  }|j	                  |d       |S )z(F90 file for testing warnings in gh23598r&   r'   crackfortranzgh23598Warn.f90r)   r*   r,   r1   s      r   gh23598_warnr8   T   sK     <<8IJTTVD		#	#	%(9	9BMM$M)Ir   c                     t        j                  dddd      j                         }| j                         dz  }|j	                  |d       |S )z8F90 file for testing disallowed CLI arguments in ghff819r&   r'   r(   zgh_22819.pyfr)   r*   r,   r1   s      r   gh22819_clir:   ]   sI     <<~>HHJD		#	#	%	6BMM$M)Ir   c                     t        j                  dddd      j                         }| j                         dz  }|j	                  |d       |S )'Generates a single f77 file for testingr&   r'   r(   zhi77.fzhello.fr)   r*   r,   r1   s      r   hello_world_f77r=   f   sI     <<x8BBDD		#	#	%		1BMM$M)Ir   c                     t        j                  dddd      j                         }| j                         dz  }|j	                  |d       |S )r<   r&   r'   return_realzfoo77.fzfoo.fr)   r*   r,   r1   s      r   retreal_f77r@   o   sI     <<yAKKMD		#	#	%	/BMM$M)Ir   c                 6   t        j                  dddd      j                         }t        j                  dddd      j                         }| j                         dz  }| j                         dz  }|j	                  |d	       |j	                  |d	       |S )
r%   r&   r'   f2cmapzisoFortranEnvMap.f90z.f2py_f2cmapz
f2cmap.f90mapfiler)   r*   r,   )r2   r3   rB   r4   fmaps        r   
f2cmap_f90rE   w   s     <<2HISSUD\\'5(NCMMOF		#	#	%	4B%%')3DMM$M)OOFWO-Ir   c                    t        |      }|j                  t        dd| j                                t	        j
                  |j                        5  t                |j                  j                  d      D cg c]  }|j                         s|j                  ! }}d|vsJ d|vsJ d|v sJ d|v sJ 	 ddd       yc c}w # 1 sw Y   yxY w)	zCheck that module names are handled correctly
    gh-22819
    Essentially, the -m name cannot be used to import the module, so the module
    named in the .pyf needs to be used instead

    CLI :: -m and a .pyf file
    argvf2py -m blah *zblahmodule.czblah-f2pywrappers.fztest_22819-f2pywrappers.fztest_22819module.cN)r   setattrsyssplitr   	switchdirparentr   rglobis_filename)capfdr:   monkeypatchipathitem	gen_pathss         r   test_gh22819_clirW      s     EV}UG%<%B%B%DE		% 	+0<<+=+=c+BU4dllnTYYU	UY...$I555*i777#y000 U s$   (C;CCCCCc                 H   t        |      }|j                  t        dd| dj                                t	        j
                  |j                        5  t        j                  t        d      5  t                ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)zBOnly one .pyf file allowed
    gh-22819
    CLI :: .pyf files
    rG   rH   z
 hello.pyfzOnly one .pyf file per call)matchN)r   rJ   rK   rL   r   rM   rN   r   raises
ValueErrorr   )rR   r:   rS   rT   s       r   test_gh22819_many_pyfr\      s    
 EV}UG:%F%L%L%NO		% ]]:-JK 	I	 	 	 s$   B0B;BB	BB!c                 F   t        |d      }|j                  }|j                  t        dd| dj	                                t        j                  |j                        5  t                |j                  j                         }d|vsJ 	 d d d        y # 1 sw Y   y xY w)Ntestr   rG   f2py z -m testzintproductf2pywrap, intpr)r!   r   rJ   rK   rL   r   rM   rN   r   r   r.   )rR   r8   rS   foutlrT   wrappers         r   test_gh23598_warnrc      s    V4ELLEV
wh%%') 
	% :	,,((**'999: : :s   "+BB c                    t        |      }t        |      j                  dz   }|j                  t        dd| d| j	                                t        j                  |j                        5  t                | j                         \  }}d|v sJ t        |       j                         sJ 	 ddd       y# 1 sw Y   yxY w)zIEnsures that a signature file is generated via the CLI
    CLI :: -h
    r   rG   zf2py -h  Saving signatures to fileN)r   stemrJ   rK   rL   r   rM   rN   r   
readouterrexists)rR   r5   rS   rT   opathout_s          r   test_gen_pyfrm      s     !E!&&/EVxwaw%?%E%E%GH		% )	!!#Q*c111ug&&(((	) ) )s   .A B88Cc                 &   t        |      }|j                  t        dd| j                                t	        j
                  |j                        5  t                | j                         \  }}d|v sJ d|v sJ 	 ddd       y# 1 sw Y   yxY w)zHEnsures that a signature file can be dumped to stdout
    CLI :: -h
    rG   zf2py -h stdout rf   zfunction hi() ! in N	r   rJ   rK   rL   r   rM   rN   r   rh   rR   r5   rS   rT   rk   rl   s         r   test_gen_pyf_stdoutrq      s     !EVug%>%D%D%FG		% ,	!!#Q*c111$+++	, , ,s   *BBc                    t        |      }|j                  t        dd| j                                t	        j
                  |j                        5  t        d      j                  dd       t        j                  t              5  t                | j                         \  }}d|v sJ 	 ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)	zjEnsures that the CLI refuses to overwrite signature files
    CLI :: -h without --overwrite-signature
    rG   f2py -h faker.pyf 	faker.pyf	Fake newsr)   r*   z&Use --overwrite-signature to overwriteN)r   rJ   rK   rL   r   rM   rN   r0   r   rZ   
SystemExitr   rh   )rR   r5   rS   rT   rl   errs         r   test_gen_pyf_no_overwriterx      s     !EV'9%%A%G%G%IJ		% C[$$[7$C]]:& 	CI%%'FAs;sBBB	CC C	C 	CC Cs$   6C	$B?.C?C	CC)      zPython 3.12 required)reasonc                    t        |      }|j                  t        dd| j                                t	        j
                  |j                        5  t                | j                         \  }}d|v sJ 	 ddd       y# 1 sw Y   yxY w)z@Check that modules are named correctly

    CLI :: defaults
    rG   zf2py --backend meson -c zuntitledmodule.cN)	r   rJ   rK   rL   r   rM   rN   r   rh   rp   s         r   test_untitled_clir}      s|     !EV'?w%G%M%M%OP		% ) !!#Q!S((() ) )s   $BB
LinuxzCompiler and 3.12 requiredc           	      F   d}t        ||      }|j                  }|j                  t        dd| d| j	                                t        j                  |j                        5  t                | j                         \  }}d|v sJ 	 ddd       |j                  t        ddj	                                t        j                  |j                        5  t                | j                         \  }}d	|v sJ 	 ddd       d
}|j                  t        dd| d| dj	                                t        j                  |j                        5  t                | j                         \  }}d|v sJ 	 ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)zqCheck that no distutils imports are performed on 3.12
    CLI :: --fcompiler --help-link --backend distutils
    hir_   rG   r`   z -c --fcompiler=gfortran -m z%--fcompiler cannot be used with mesonNzf2py --help-linkzUse --dep for meson buildshi2z -c -m z --backend distutilsz.Cannot use distutils backend with Python>=3.12)r!   r   rJ   rK   rL   r   rM   rN   r   rh   r   )rR   r5   rS   MNAMEra   rT   rk   rl   s           r   !test_no_py312_distutils_fcompilerr      s   
 E6ELLEVuUG#?wGMMO 
	% > !!#Q6#===> V'--/ 
	% 3	!!#Q+s2223 EVuUG75'1EFLLN 
	% G	!!#Q?3FFFG G> >3 3G Gs$   &$E?$F$F?FFF c                    t        |d      }|j                  }d}d}|j                  t        dd| d| j	                                t        j                  |j                        5  t                | j                         \  }}|j	                         D ]  }	d|	 d	|v rJ  |j	                         D ]  }
d
|
 d|v rJ  	 ddd       y# 1 sw Y   yxY w)z9Tests that functions can be skipped
    CLI :: skip:
    r^   r_   t0 t4 t8 sd s8 s4td s0rG   r`   z -m test skip: z=buildmodule: Could not found the body of interfaced routine "". Skipping.Constructing wrapper function ""N
r!   r   rJ   rK   rL   r   rM   rN   r   rh   )rR   r@   rS   ra   rT   toskip	remainingrk   rw   skeyrkeys              r   test_f2py_skipr     s    
 F3EJJE FIV
wofX.4468 
	% D	##%SLLN 	DOPTvUab	 OO% 	DD4TF!<CCC	DD D D   (9C"CCCc                    t        |d      }|j                  }d}d}|j                  t        dd| d| j	                                t        j                  |j                        5  t                | j                         \  }}|j	                         D ]  }	d|	 d	|v rJ  |j	                         D ]  }
d
|
 d|v rJ  	 ddd       y# 1 sw Y   yxY w)z>Test that functions can be kept by only:
    CLI :: only:
    r^   r_   r   r   rG   r`   z -m test only: <buildmodule: Could not find the body of interfaced routine "r   r   r   Nr   )rR   r@   rS   ra   rT   r   tokeeprk   rw   r   r   s              r   test_f2py_onlyr   $  s     F3EJJE FFV
wofX.4468 
	% D	##%SLLN 	DNtfT`a	 LLN 	DD4TF!<CCC	DD D Dr   c                    t        |d      }|j                  }d}t        |      }d}d}	|j                  t        dd| d|	 d	| d
| j                                t        j                  |j                        5  t                | j                         \  }
}|j                         D ]  }d| d|v rJ  |j                         D ]  }d| d|
v rJ  	 ddd       y# 1 sw Y   yxY w)zfTests that it is possible to return to file processing mode
    CLI :: :
    BUG: numpy-gh #20520
    r^   r_   r   ztd s0 hiblahrG   r`    -m z only: z : r   r   r   r   N)r!   r   r   rJ   rK   rL   r   rM   rN   r   rh   )rR   r5   r@   rS   ra   rT   r   ipath2r   r   rk   rw   r   r   s                 r   test_file_processing_switchr   ;  s    F3EJJE F/"FFE
wd5'F8<BB 	
 
	% D	##%SLLN 	DNtfT`a	 LLN 	DD4TF!<CCC	DD D Ds   ;9C!5C!C!!C*c                    d}t        ||      }|j                  }|j                  t        dd| d| j	                                t        j                  |j                        5  t                ddd       t        j                  |j                        sJ t        j                  |j                        sJ y# 1 sw Y   LxY w)zHChecks the generation of files based on a module name
    CLI :: -m
    r   r_   rG   r`   r   N)r!   r   rJ   rK   rL   r   rM   rN   r   r   ri   r   r   )rR   r5   rS   r   ra   rT   s         r   test_mod_gen_f77r   Y  s     E6ELLEVuUG4w%?%E%E%GH		% 	 ;;u{{###;;u||$$$ s   &B<<Cc           	         d}t        ||      }|j                  }|j                  t        dd| d| dj	                                t        j                  |j                        5  t                t        d      j                         5 }|j                         }d|v sJ 	 d	d	d	       d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   y	xY w)
zCheck that pyf files are correctly generated with module structure
    CLI :: -m <name> -h pyf_file
    BUG: numpy-gh #20520
    r   r_   rG   r`   r   z
 -h hi.pyfzhi.pyfzpython module hiN)r!   r   rJ   rK   rL   r   rM   rN   r   r   openread)rR   r=   rS   r   ra   rT   hipyfpyfdats           r   test_mod_gen_gh25263r   j  s    
 E6EJJEVuUG4wj%I%O%O%QR		% 0	(^  " 	0eZZ\F%///	00 0	0 	00 0s$   '$C B4#C 4B=	9C  C	c                    t        |d      }|j                  }t        j                  d      }t        j                  d      }|j	                  t
        dd| dj                                t        j                  |j                        5  t                | j                         \  }}|j                  |      J |j                  |      J 	 ddd       |j	                  t
        dd| d	j                                t        j                  |j                        5  t                | j                         \  }}|j                  |      J |j                  |      J 	 ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)
zHLowers cases by flag or when -h is present

    CLI :: --[no-]lower
    r^   r_   zHI\(\)zhi\(\)rG   r`   z -m test --lowerNz -m test --no-lower)r!   r   recompilerJ   rK   rL   r   rM   rN   r   rh   search	rR   r=   rS   ra   rT   capshicapslork   rl   s	            r   test_lower_cmodr   z  sV   
 7EJJEZZ	"FZZ	"FVuUG3C%D%J%J%LM		% *	!!#Q}}S!---}}S!)))	* Vw&9:@@BD		% .	!!#Q}}S!)))}}S!---	. .* *. .s   AE/!AE;/E8;Fc           	      B   t        |d      }|j                  }t        j                  d      }t        j                  d      }|j	                  t
        dd| d|j                   dj                                t        j                  |j                        5  t                | j                         \  }}|j                  |      J |j                  |      J 	 d	d	d	       |j	                  t
        dd| d|j                   d
j                                t        j                  |j                        5  t                | j                         \  }}|j                  |      J |j                  |      J 	 d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   y	xY w)z^Lowers cases in signature files by flag or when -h is present

    CLI :: --[no-]lower -h
    r^   r_   z	Block: HIz	Block: hirG   r`   z -h z -m test --overwrite-signatureNz) -m test --overwrite-signature --no-lower)r!   r   r   r   rJ   rK   r   rL   r   rM   rN   r   rh   r   r   s	            r   test_lower_sigr     st   
 7EJJEZZ%FZZ%F 
wd599+%CDJJL 
	% *	!!#Q}}S!---}}S!)))	* 
wd599+%NO		 
	% .	!!#Q}}S!)))}}S!---	. .* *. .s   AF	;AF	FFc           
      6   t        |      }d}d}|j                  t        dd| d| d| j                                t	        j
                  |j                        5  t                | j                         \  }}d| d|v sJ 	 d	d	d	       y	# 1 sw Y   y	xY w)
zNEnsures that the build directory can be specified

    CLI :: --build-dir
    r   tttmprG   f2py -m re   z --build-dir zWrote C/API module "r   Nro   )rR   r5   rS   rT   r   odirrk   rl   s           r   test_build_dirr     s    
 !EEDV"5'5'tfEKKMO 
	% 8	!!#Q&ugR0C7778 8 8s   (BBc                 T   t        |      }|j                  t        dd| dj                                t	        j
                  |j                        5  t        d      j                  dd       t                | j                         \  }}d|v sJ 	 d	d	d	       y	# 1 sw Y   y	xY w)
zXEnsures that the build directory can be specified

    CLI :: --overwrite-signature
    rG   rs   z --overwrite-signaturert   ru   r)   r*   rf   N)
r   rJ   rK   rL   r   rM   rN   r0   r   rh   rp   s         r   test_overwriter     s    
 !EV
UG#9:@@BD 
	% 2[$$[7$C	!!#Q*c111	2 2 2s   A BB'c           	         t        |      }d}|j                  t        dd| d| dj                                t	        j
                  |j                        5  t                | j                         \  }}d|v sJ t        | d      j                         5 }d|j                         v sJ 	 d	d	d	       d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   y	xY w)
zJEnsures that TeX documentation is written out

    CLI :: --latex-doc
    r   rG   r   re   z --latex-docDocumentation is saved to file
module.tex\documentclassNr   rJ   rK   rL   r   rM   rN   r   rh   r   r   rR   r5   rS   rT   r   rk   rl   otexs           r   test_latexdocr     s    
 !EEV"5'5'>DDFH 
	% 4	!!#Q/3666UG:&',,. 	4$$		333	4	4 4	4 	4	4 4s%   A CC /C C		CCc           	      &   t        |      }d}|j                  t        dd| d| dj                                t	        j
                  |j                        5  t                | j                         \  }}d|vsJ 	 ddd       y# 1 sw Y   yxY w)zMEnsures that TeX documentation is written out

    CLI :: --no-latex-doc
    r   rG   r   re   z --no-latex-docr   Nro   rR   r5   rS   rT   r   rk   rl   s          r   test_nolatexdocr     s    
 !EEV"5'5'AGGIK 
	% ;	!!#Q/s:::; ; ;   $BBc           	         t        |      }d}|j                  t        dd| d| dj                                t	        j
                  |j                        5  t                | j                         \  }}d|v sJ t        d| d      j                         5 }d	|j                         vsJ 	 d
d
d
       d
d
d
       y
# 1 sw Y   xY w# 1 sw Y   y
xY w)zEnsures that truncated documentation is written out

    TODO: Test to ensure this has no effect without --latex-doc
    CLI :: --latex-doc --short-latex
    r   rG   r   re   z --latex-doc --short-latexr   ./r   r   Nr   r   s           r   test_shortlatexr     s     !EE
5'5'!;<BBD 
	% 8	!!#Q/3666BugZ()..0 	8D$DIIK777	8	8 8	8 	8	8 8%   ACC0CC
	CCc           	         t        |      }d}|j                  t        dd| d| dj                                t	        j
                  |j                        5  t                | j                         \  }}d|v sJ t        d| d      j                         5 }d	|j                         v sJ 	 d
d
d
       d
d
d
       y
# 1 sw Y   xY w# 1 sw Y   y
xY w)zIEnsures that RsT documentation is written out

    CLI :: --rest-doc
    r   rG   r   re   z --rest-doc#ReST Documentation is saved to filer   zmodule.restz.. -*- rest -*-Nr   )rR   r5   rS   rT   r   rk   rl   orsts           r   test_restdocr     s    
 !EEV"5'5'=CCEG 
	% 5	!!#Q4;;;Bug[)*//1 	5T%444	5	5 5	5 	5	5 5r   c           	      &   t        |      }d}|j                  t        dd| d| dj                                t	        j
                  |j                        5  t                | j                         \  }}d|vsJ 	 ddd       y# 1 sw Y   yxY w)zLEnsures that TeX documentation is written out

    CLI :: --no-rest-doc
    r   rG   r   re   z --no-rest-docr   Nro   r   s          r   test_norestexdocr   '  s    
 !EEV"5'5'@FFHJ 
	% @	!!#Q4C???@ @ @r   c           	         t        |      }d}|j                  t        dd| d| dj                                t	        j
                  |j                        5  t                t        d| d      j                         5 }d|j                         v sJ 	 d	d	d	       d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   y	xY w)
zIEnsures that debugging wrappers are written

    CLI :: --debug-capi
    r   rG   r   re   z --debug-capir   r   z#define DEBUGCFUNCSN
r   rJ   rK   rL   r   rM   rN   r   r   r   )rR   r5   rS   rT   r   ocmods         r   test_debugcapir   7  s    
 !EEV"5'5'?EEGI 
	% :	BugX&',,. 	:%)UZZ\999	:: :	: 	:: :s$   (B4B(B4(B1	-B44B=z2Consistently fails on CI; noisy so skip not xfail.c           	         t        |       }d}|j                  t        dd| d| dj                                t	        j
                  |j                        5  t                t        j                  t        j                   d      }t        j                  |dd	      }d
}t        j                  d      }|j                  |k(  sJ |j                  |k(  sJ 	 ddd       y# 1 sw Y   yxY w)zEEnsures that debugging wrappers work

    CLI :: --debug-capi -c
    r   rG   r   re   z -c --debug-capi -c "import blah; blah.hi()"TUTF-8capture_outputr+    Hello World
a   debug-capi:Python C/API function blah.hi()
debug-capi:float hi=:output,hidden,scalar
debug-capi:hi=0
debug-capi:Fortran subroutine `f2pywraphi(&hi)'
debug-capi:hi=0
debug-capi:Building return value.
debug-capi:Python C/API function blah.hi: successful.
debug-capi:Freeing memory.
        N)r   rJ   rK   rL   r   rM   rN   r   shlex
executable
subprocessruntextwrapdedentstdoutstderr)r5   rS   rT   r   cmd_runrouteouteerrs           r   test_debugcapi_bldr   G  s     !EEV"5'5'1ABHHJL 
	% #	++ 00NOP~~gdWM 	  	 {{d"""{{d"""!# # #s   BC%%C.c           	      *   t        |      }d}|j                  t        dd| d| j                                t	        j
                  |j                        5  t                ddd       | j                         \  }}d|v sJ |j                  t        dd| d| dj                                t	        j
                  |j                        5  t                | j                         \  }}d|v sJ 	 ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)zoEnsures that fortran subroutine wrappers for F77 are included by default

    CLI :: --[no]-wrap-functions
    r   rG   r   re   N Fortran 77 wrappers are saved toz --wrap-functionsro   r   s          r   test_wrapfunc_defr   e  s    !EEVxwaw%?%E%E%GH		% 	FC.#555 V"5'5'1BCIIKM 
	% :	!!#Q2c999: : : :s   C=$D	=D	Dc           	      &   t        |      }d}|j                  t        dd| d| dj                                t	        j
                  |j                        5  t                | j                         \  }}d|vsJ 	 ddd       y# 1 sw Y   yxY w)zeEnsures that fortran subroutine wrappers for F77 can be disabled

    CLI :: --no-wrap-functions
    r   rG   r   re   z --no-wrap-functionsr   Nro   r   s          r   test_nowrapfuncr   ~  s    
 !EEV"5'5'1EFLLNP 
	% >	!!#Q2#===> > >r   c           	         t        |      }d}|j                  t        dd| d| dj                                t	        j
                  |j                        5  t                t        d| d      j                         5 }|j                         }d|v sJ d	|v sJ 	 d
d
d
       d
d
d
       y
# 1 sw Y   xY w# 1 sw Y   y
xY w)zcAdd to the include directories

    CLI :: -include
    TODO: Document this in the help string
    r   rG   r   re   z' -include<stdbool.h> -include<stdio.h> r   r   z#include <stdbool.h>z#include <stdio.h>Nr   )rR   r5   rS   rT   r   r   ocmrs          r   test_inclheaderr     s     !EE
5'5'!HI	 
	% 0	BugX&',,. 	0%::<D)T111'4///	00 0	0 	00 0s$   (B<B0B<0B9	5B<<Cc                       y)z?Add to the include directories

    CLI :: --include-paths
    Nr   r   r   r   test_inclpathr          	r   c                       y)z;Add to the include directories

    CLI :: --help-link
    Nr   r   r   r   
test_hlinkr     r   r   c                 L   t        |      }|j                  t        dd| dj                                t	        j
                  |j                        5  t                | j                         \  }}d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ 	 d	d	d	       y	# 1 sw Y   y	xY w)
zOCheck that Fortran-to-Python KIND specs can be passed

    CLI :: --f2cmap
    rG   rH   z --f2cmap mapfilez!Reading f2cmap from 'mapfile' ...z&Mapping "real(kind=real32)" to "float"z'Mapping "real(kind=real64)" to "double"z,Mapping "integer(kind=int64)" to "long_long"z0Successfully applied user defined f2cmap changesNro   )rR   rE   rS   rT   rk   rl   s         r   test_f2cmapr     s    
 EV}UG;L%M%S%S%UV		% I	!!#Q2c999;sBBB<CCCASHHHASHHHI I Is   <BB#c                 0   t        |      }|j                  t        dd| dj                                t	        j
                  |j                        5  t                | j                         \  }}t        |      dk(  sJ 	 ddd       y# 1 sw Y   yxY w)z)Reduce verbosity

    CLI :: --quiet
    rG   rH   z --quietr   N)
r   rJ   rK   rL   r   rM   rN   r   rh   lenrp   s         r   
test_quietr     s~    
 !EV}UG8%D%J%J%LM		% 	!!#Q3x1}}  s   .BBc                    t        |      }|j                  t        dd| dj                                t	        j
                  |j                        5  t                | j                         \  }}d|v sJ 	 ddd       y# 1 sw Y   yxY w)z-Increase verbosity

    CLI :: --verbose
    rG   rH   z
 --verboseanalyzelineNro   rp   s         r   test_verboser     s|    
 !EV}UG:%F%L%L%NO		% $	!!#Q###$ $ $s   $BBc                 ,   |j                  t        ddj                                t        j                  t
              5  t                | j                         \  }}ddl}|j                  |j                         k(  sJ 	 ddd       y# 1 sw Y   yxY w)z"Ensure version

    CLI :: -v
    rG   zf2py -vr   N)rJ   rK   rL   r   rZ   rv   r   rh   numpy__version__strip)rR   rS   rk   rl   nps        r   test_versionr     sp    
 VY__%67	z	" -	!!#Q~~,,,	- - -s   AB

Bc                    t        |       }|j                  t        dd| dj                                t	        j
                  |j                        5  t                t        j                  t        j                   d      }t        j                  |dd      }d}|j                  |k(  sJ 	 d	d	d	       y	# 1 sw Y   y	xY w)
z
    CLI :: -c
    rG   rH   z -cr   Tr   r   r   N)r   rJ   rK   rL   r   rM   rN   r   r   r   r   r   r   )r5   rS   rT   r   r   r   s         r   test_npdistopr     s    
 !EV}UG3%?%E%E%GH		% #	++ 00NOP~~gdWM{{d"""# # #s   AB::Cz*Compiler and Python 3.12 or newer requiredc                     t        |       }|j                  t        dd| dj                                t	        j
                  |j                        5  t                t        j                   d}t        r|dz  }n|dz  }t        j                  |      }t        j                  |dd	      }d
}|j                  |k(  sJ t        rd|j                  v sJ |j                  dk(  sJ 	 ddd       y# 1 sw Y   yxY w)z.
    CLI :: --no-freethreading-compatible
    rG   rH   z! -c --no-freethreading-compatible -c "import blah; blah.hi();z1import sys; assert sys._is_gil_enabled() is True"r   Tr   r   r   zHThe global interpreter lock (GIL) has been enabled to load module 'blah'r   Nr   rJ   rK   rL   r   rM   rN   r   r   r   r   r   r   r   r   
returncoder5   rS   rT   cmdr   r   r   s          r    test_no_freethreading_compatibler    s     !EV}UG;\%]%c%c%ef		% $   =>GGC4KC++c"~~gdWM{{d"""]aealallll!###$ $ $s   BC44C=c                    t        |       }|j                  t        dd| dj                                t	        j
                  |j                        5  t                t        j                   d}t        r|dz  }n|dz  }t        j                  |      }t        j                  |dd	      }d
}|j                  |k(  sJ |j                  dk(  sJ |j                  dk(  sJ 	 ddd       y# 1 sw Y   yxY w)z+
    CLI :: --freethreading_compatible
    rG   rH   z -c --freethreading-compatibler   z2import sys; assert sys._is_gil_enabled() is False"r   Tr   r   r    r   Nr   r  s          r   test_freethreading_compatibler    s     !EV}UG;Y%Z%`%`%bc		% $   =>HHC4KC++c"~~gdWM{{d"""{{b   !###$ $ $s   BC//C8c                       y)z
    CLI :: -c --fcompiler
    Nr   r   r   r   test_npd_fcompilerr  7      
 	r   c                       y)z
    CLI :: -c --compiler
    Nr   r   r   r   test_npd_compilerr  ?  r	  r   c                       y)z$
    CLI :: -c --help-fcompiler
    Nr   r   r   r   test_npd_help_fcompilerr  G  r	  r   c                       y)z
    CLI :: -c --f77exec
    Nr   r   r   r   test_npd_f77execr  O  r	  r   c                       y)z
    CLI :: -c --f90exec
    Nr   r   r   r   test_npd_f90execr  W  r	  r   c                       y)z
    CLI :: -c --f77flags
    Nr   r   r   r   test_npd_f77flagsr  _  r	  r   c                       y)z
    CLI :: -c --f90flags
    Nr   r   r   r   test_npd_f90flagsr  g  r	  r   c                       y)z
    CLI :: -c --opt
    Nr   r   r   r   test_npd_optr  o  r	  r   c                       y)z
    CLI :: -c --arch
    Nr   r   r   r   test_npd_archr  w  r	  r   c                       y)z
    CLI :: -c --noopt
    Nr   r   r   r   test_npd_nooptr    r	  r   c                       y)z
    CLI :: -c --noarch
    Nr   r   r   r   test_npd_noarchr    r	  r   c                       y)z
    CLI :: -c --debug
    Nr   r   r   r   test_npd_debugr    r	  r   c                       y)z%
    CLI :: -c --link-<resource>
    Nr   r   r   r   test_npd_link_autor!    r	  r   c                       y)z/
    CLI :: -c -L/path/to/lib/ -l<libname>
    Nr   r   r   r   test_npd_libr#    r	  r   c                       y)z
    CLI :: -D<define>
    Nr   r   r   r   test_npd_definer%    r	  r   c                       y)z
    CLI :: -U<name>
    Nr   r   r   r   test_npd_undefiner'    r	  r   c                       y)z$
    CLI :: -I/path/to/include/
    Nr   r   r   r   test_npd_inclr)    r	  r   c                       y)z8
    CLI :: <filename>.o <filename>.so <filename>.a
    Nr   r   r   r   test_npd_linkerr+    r	  r   )untitled)Xr   r   r   rK   r   pathlibr   collectionsr   platformr   r  r   numpy.f2py.f2py2er   r   numpy.testing._private.utilsr   r   r   r!   fixturer5   r8   r:   r=   r@   rE   rW   r\   rc   rm   rq   rx   markskipifversion_infor}   systemr   xfailr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r#  r%  r'  r)  r+  r   r   r   <module>r8     sw   	   
   "    - 4 
HH	IN i  ! i  ! i  ! i  ! i  ! i  !(	
:)
,C C$$/8NO
) P
) _X__&'1Ss7G7G77R\xyG zG> D D.D.D<%"0 .4$.N8"2"4$; 8,5$@ :  MN# O#::2> 0.		I$$- MN# O# _X__&'1Qc6F6F'6QG  I$I$. _X__&'1Qc6F6F'6QG  I$I$2																		r   