o
    ðT·jÜl  ã                   @   s`  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d	„ Zed
dƒZd�dd„Ze
jdd�dd„ ƒZe
jdd�dd„ ƒZe
jdd�dd„ ƒZe
jdd�dd„ ƒZe
jdd�dd„ ƒZe
jdd�dd„ ƒZdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Z d'd(„ Z!e
j"j#ej$d)kd*d+�d,d-„ ƒZ%e
j"j#e	 &¡ d.kp¸ej$d)kd/d+�d0d1„ ƒZ'e
j"j(d2d3„ ƒZ)d4d5„ Z*d6d7„ Z+d8d9„ Z,d:d;„ Z-d<d=„ Z.d>d?„ Z/d@dA„ Z0dBdC„ Z1dDdE„ Z2dFdG„ Z3dHdI„ Z4dJdK„ Z5dLdM„ Z6dNdO„ Z7e
j"j8dPd+�dQdR„ ƒZ9dSdT„ Z:dUdV„ Z;dWdX„ Z<dYdZ„ Z=d[d\„ Z>d]d^„ Z?d_d`„ Z@dadb„ ZAdcdd„ ZBe
j"j8dPd+�dedf„ ƒZCe
j"j#e	 &¡ d.k�pHej$d)kdgd+�dhdi„ ƒZDe
j"j#e	 &¡ d.k�p^ej$d)kdgd+�djdk„ ƒZEdldm„ ZFdndo„ ZGdpdq„ ZHdrds„ ZIdtdu„ ZJdvdw„ ZKdxdy„ ZLdzd{„ ZMd|d}„ ZNd~d„ ZOd€d�„ ZPd‚dƒ„ ZQd„d…„ ZRd†d‡„ ZSdˆd‰„ ZTdŠd‹„ ZUdŒd�„ ZVdŽd�„ ZWdS )‘é    N)ÚPath)Ú
namedtupleé   )Úutil)Úmain)ÚNOGIL_BUILDc                   C   s    t  ¡ st d¡ d S tƒ  d S )Nz$CLI command needs a Fortran compiler)r   Úhas_fortran_compilerÚpytestÚskipÚf2pycli© r   r   ú_/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/numpy/f2py/tests/test_f2py2e.pyÚcompiler_check_f2pycli   s   
r   ÚPPathsz(finp, f90inp, pyf, wrap77, wrap90, cmodfÚuntitledc              
   C   sR   t | ƒ}t| d¡| d¡| d¡| |› d�¡| |› d�¡| |› d�¡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Úbpathr   r   r   Úget_io_paths$   s   úr   Úsession)Úscopec                 C   ó2   t  dddd¡ ¡ }|  ¡ d }|j|d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Úfnr   r   r   Úhello_world_f90K   ó   r2   c                 C   ó2   t  dddd¡ ¡ }|  ¡ d }|j|dd� |S )z(F90 file for testing warnings in gh23598r#   r$   Úcrackfortranzgh23598Warn.f90r&   r'   r)   r.   r   r   r   Úgh23598_warnT   r3   r6   c                 C   r4   )z8F90 file for testing disallowed CLI arguments in ghff819r#   r$   r%   zgh_22819.pyfr&   r'   r)   r.   r   r   r   Úgh22819_cli]   r3   r7   c                 C   r!   )ú'Generates a single f77 file for testingr#   r$   r%   zhi77.fzhello.fr&   r'   r)   r.   r   r   r   Úhello_world_f77f   r3   r9   c                 C   r!   )r8   r#   r$   Úreturn_realzfoo77.fzfoo.fr&   r'   r)   r.   r   r   r   Úretreal_f77o   r3   r;   c                 C   s`   t  dddd¡ ¡ }t  dddd¡ ¡ }|  ¡ d }|  ¡ d }|j|dd	� |j|dd	� |S )
r"   r#   r$   Úf2cmapzisoFortranEnvMap.f90z.f2py_f2cmapz
f2cmap.f90Úmapfiler&   r'   r)   )r/   r0   r<   r1   Úfmapr   r   r   Ú
f2cmap_f90w   s   r?   c                 C   s    t |ƒ}| tdd|› � ¡ ¡ t |j¡�0 tƒ  dd„ |j d¡D ƒ}d|vs+J ‚d|vs1J ‚d|v s7J ‚d	|v s=J ‚	 W d  ƒ dS 1 sIw   Y  dS )zÝCheck 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 c                 S   s   g | ]	}|  ¡ r|j‘qS r   )Úis_fileÚname)Ú.0Úitemr   r   r   Ú
<listcomp>’   s    z$test_gh22819_cli.<locals>.<listcomp>Ú*zblahmodule.czblah-f2pywrappers.fztest_22819-f2pywrappers.fztest_22819module.czIgnoring blahN)	r   ÚsetattrÚsysÚsplitr   Ú	switchdirÚparentr   Úrglob)Úcapfdr7   ÚmonkeypatchÚipathÚ	gen_pathsr   r   r   Útest_gh22819_cli†   s   "ùrR   c              	   C   s˜   t |ƒ}| tdd|› d� ¡ ¡ t |j¡�+ tjt	dd�� t
ƒ  W d  ƒ n1 s-w   Y  W d  ƒ dS W d  ƒ dS 1 sEw   Y  dS )zBOnly one .pyf file allowed
    gh-22819
    CLI :: .pyf files
    r@   rA   z
 hello.pyfzOnly one .pyf file per call)ÚmatchN)r   rH   rI   rJ   r   rK   rL   r	   ÚraisesÚ
ValueErrorr   )rN   r7   rO   rP   r   r   r   Útest_gh22819_many_pyfš   s   ÿÿ"ÿrV   c                 C   sz   t |dd�}|j}| tdd|› d� ¡ ¡ t |j¡� tƒ  |j	 
¡ }d|vs+J ‚W d   ƒ d S 1 s6w   Y  d S )NÚtest©r   r@   úf2py z -m testzintproductf2pywrap, intpr)r   r   rH   rI   rJ   r   rK   rL   r   r   r+   )rN   r6   rO   ÚfoutlrP   Úwrapperr   r   r   Útest_gh23598_warn¦   s   þ
"ýr\   c                 C   s–   t |ƒ}t |ƒjd }| tdd|› d|› � ¡ ¡ t |j¡�! tƒ  |  	¡ \}}d|v s0J ‚t |› ƒ 
¡ s9J ‚W d  ƒ dS 1 sDw   Y  dS )zIEnsures that a signature file is generated via the CLI
    CLI :: -h
    r   r@   zf2py -h ú úSaving signatures to fileN)r   ÚstemrH   rI   rJ   r   rK   rL   r   Ú
readouterrÚexists)rN   r2   rO   rP   ÚopathÚoutÚ_r   r   r   Útest_gen_pyf³   s   "üre   c                 C   s|   t |ƒ}| tdd|› � ¡ ¡ t |j¡� tƒ  |  ¡ \}}d|v s&J ‚d|v s,J ‚W d  ƒ dS 1 s7w   Y  dS )zHEnsures that a signature file can be dumped to stdout
    CLI :: -h
    r@   zf2py -h stdout r^   zfunction hi() ! in N©	r   rH   rI   rJ   r   rK   rL   r   r`   ©rN   r2   rO   rP   rc   rd   r   r   r   Útest_gen_pyf_stdoutÂ   s   "ürh   c              	   C   s¼   t |ƒ}| tdd|› � ¡ ¡ t |j¡�> t dƒjddd� t 	t
¡� tƒ  |  ¡ \}}d|v s5J ‚W d  ƒ n1 s?w   Y  W d  ƒ dS W d  ƒ dS 1 sWw   Y  dS )	zjEnsures that the CLI refuses to overwrite signature files
    CLI :: -h without --overwrite-signature
    r@   úf2py -h faker.pyf ú	faker.pyfú	Fake newsr&   r'   z&Use --overwrite-signature to overwriteN)r   rH   rI   rJ   r   rK   rL   r-   r	   rT   Ú
SystemExitr   r`   )rN   r2   rO   rP   rd   Úerrr   r   r   Útest_gen_pyf_no_overwriteÏ   s   ýþ"þrn   )é   é   zPython 3.12 required)Úreasonc                 C   sp   t |ƒ}| tdd|› � ¡ ¡ t |j¡� tƒ  |  ¡ \}}d|v s&J ‚W d  ƒ dS 1 s1w   Y  dS )z@Check that modules are named correctly

    CLI :: defaults
    r@   zf2py --backend meson -c zuntitledmodule.cN)	r   rH   rI   rJ   r   rK   rL   r   r`   rg   r   r   r   Útest_untitled_cliÞ   s   "ýrr   ÚLinuxzCompiler and 3.12 requiredc              	   C   sN  d}t ||d�}|j}| tdd|› d|› � ¡ ¡ t |j¡� tƒ  |  	¡ \}}d|v s0J ‚W d  ƒ n1 s:w   Y  | tdd ¡ ¡ t |j¡� t
ƒ  |  	¡ \}}d	|v s^J ‚W d  ƒ n1 shw   Y  d
}| tdd|› d|› d� ¡ ¡ t |j¡� t
ƒ  |  	¡ \}}d|v s•J ‚W d  ƒ dS 1 s w   Y  dS )zqCheck that no distutils imports are performed on 3.12
    CLI :: --fcompiler --help-link --backend distutils
    ÚhirX   r@   rY   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   rH   rI   rJ   r   rK   rL   r   r`   r   )rN   r2   rO   ÚMNAMErZ   rP   rc   rd   r   r   r   Ú!test_no_py312_distutils_fcompilerì   s8   ÿý
ÿýÿ"ýrw   c                 C   sÀ   t |dd�}|j}d}d}| tdd|› d|› � ¡ ¡ t |j¡�4 tƒ  |  	¡ \}}| ¡ D ]}	d|	› d	�|v s<J ‚q0| ¡ D ]}
d
|
› d�|v sMJ ‚qAW d  ƒ dS 1 sYw   Y  dS )z9Tests that functions can be skipped
    CLI :: skip:
    rW   rX   út0 t4 t8 sd s8 s4útd s0r@   rY   z -m test skip: z=buildmodule: Could not found the body of interfaced routine "ú". Skipping.úConstructing wrapper function "ú"N©
r   r   rH   rI   rJ   r   rK   rL   r   r`   )rN   r;   rO   rZ   rP   ÚtoskipÚ	remainingrc   rm   ÚskeyÚrkeyr   r   r   Útest_f2py_skip  s&   þ

ÿÿ"ùr‚   c                 C   sÀ   t |dd�}|j}d}d}| tdd|› d|› � ¡ ¡ t |j¡�4 tƒ  |  	¡ \}}| ¡ D ]}	d|	› d	�|v s<J ‚q0| ¡ D ]}
d
|
› d�|v sMJ ‚qAW d  ƒ dS 1 sYw   Y  dS )z>Test that functions can be kept by only:
    CLI :: only:
    rW   rX   rx   ry   r@   rY   z -m test only: ú<buildmodule: Could not find the body of interfaced routine "rz   r{   r|   Nr}   )rN   r;   rO   rZ   rP   r~   Útokeeprc   rm   r€   r�   r   r   r   Útest_f2py_only$  s&   þ

ÿÿ"ùr…   c                 C   sØ   t |dd�}|j}d}t|ƒ}d}d}	| tdd|› d|	› d	|› d
|› � ¡ ¡ t |j¡�4 t	ƒ  |  
¡ \}
}| ¡ D ]}d|› d�|v sHJ ‚q<| ¡ D ]}d|› d�|
v sYJ ‚qMW d  ƒ dS 1 sew   Y  dS )zfTests that it is possible to return to file processing mode
    CLI :: :
    BUG: numpy-gh #20520
    rW   rX   rx   ztd s0 hiÚblahr@   rY   ú -m z only: z : rƒ   rz   r{   r|   N)r   r   r   rH   rI   rJ   r   rK   rL   r   r`   )rN   r2   r;   rO   rZ   rP   r~   Úipath2r„   r   rc   rm   r€   r�   r   r   r   Útest_file_processing_switch;  s,   ý

ÿÿ"ùr‰   c                 C   sŠ   d}t ||d�}|j}| tdd|› d|› � ¡ ¡ t |j¡� tƒ  W d  ƒ n1 s.w   Y  t	 
|j¡s;J ‚t	 
|j¡sCJ ‚dS )zHChecks the generation of files based on a module name
    CLI :: -m
    rt   rX   r@   rY   r‡   N)r   r   rH   rI   rJ   r   rK   rL   r   r   ra   r   r   )rN   r2   rO   rv   rZ   rP   r   r   r   Útest_mod_gen_f77Y  s   ÿrŠ   c              	   C   s¾   d}t ||d�}|j}| tdd|› d|› d� ¡ ¡ t |j¡�4 tƒ  t	dƒ 
¡ �}| ¡ }d|v s6J ‚W d	  ƒ n1 s@w   Y  W d	  ƒ d	S W d	  ƒ d	S 1 sXw   Y  d	S )
z�Check that pyf files are correctly generated with module structure
    CLI :: -m <name> -h pyf_file
    BUG: numpy-gh #20520
    rt   rX   r@   rY   r‡   z
 -h hi.pyfzhi.pyfzpython module hiN)r   r   rH   rI   rJ   r   rK   rL   r   r   ÚopenÚread)rN   r9   rO   rv   rZ   rP   ÚhipyfÚpyfdatr   r   r   Útest_mod_gen_gh25263j  s    þþ"þr�   c           	      C   s$  t |dd�}|j}t d¡}t d¡}| tdd|› d� ¡ ¡ t |j	¡�# t
ƒ  |  ¡ \}}| |¡dus9J ‚| |¡du sBJ ‚W d  ƒ n1 sLw   Y  | tdd|› d	� ¡ ¡ t |j	¡�$ t
ƒ  |  ¡ \}}| |¡du swJ ‚| |¡dus€J ‚W d  ƒ dS 1 s‹w   Y  dS )
zHLowers cases by flag or when -h is present

    CLI :: --[no-]lower
    rW   rX   zHI\(\)zhi\(\)r@   rY   z -m test --lowerNz -m test --no-lower)r   r   ÚreÚcompilerH   rI   rJ   r   rK   rL   r   r`   Úsearch©	rN   r9   rO   rZ   rP   ÚcapshiÚcapslorc   rd   r   r   r   Útest_lower_cmodz  s(   

üÿ"ür–   c           	   	   C   s4  t |dd�}|j}t d¡}t d¡}| tdd|› d|j› d� ¡ ¡ t 	|j
¡�# tƒ  |  ¡ \}}| |¡d	us=J ‚| |¡d	u sFJ ‚W d	  ƒ n1 sPw   Y  | tdd|› d|j› d
� ¡ ¡ t 	|j
¡�$ tƒ  |  ¡ \}}| |¡d	u sJ ‚| |¡d	usˆJ ‚W d	  ƒ d	S 1 s“w   Y  d	S )z^Lowers cases in signature files by flag or when -h is present

    CLI :: --[no-]lower -h
    rW   rX   z	Block: HIz	Block: hir@   rY   z -h z -m test --overwrite-signatureNz) -m test --overwrite-signature --no-lower)r   r   r�   r‘   rH   rI   r   rJ   r   rK   rL   r   r`   r’   r“   r   r   r   Útest_lower_sig”  s6   

ýüü"ür—   c              
   C   sŒ   t |ƒ}d}d}| tdd|› d|› d|› � ¡ ¡ t |j¡� tƒ  |  ¡ \}}d|› d�|v s4J ‚W d	  ƒ d	S 1 s?w   Y  d	S )
zNEnsures that the build directory can be specified

    CLI :: --build-dir
    r†   Útttmpr@   úf2py -m r]   z --build-dir zWrote C/API module "r|   Nrf   )rN   r2   rO   rP   r   Úodirrc   rd   r   r   r   Útest_build_dir»  s   ÿ"ýr›   c                 C   s„   t |ƒ}| tdd|› d� ¡ ¡ t |j¡�! t dƒjddd� tƒ  |  	¡ \}}d|v s0J ‚W d	  ƒ d	S 1 s;w   Y  d	S )
zXEnsures that the build directory can be specified

    CLI :: --overwrite-signature
    r@   ri   z --overwrite-signaturerj   rk   r&   r'   r^   N)
r   rH   rI   rJ   r   rK   rL   r-   r   r`   rg   r   r   r   Útest_overwriteÌ  s   þ"ürœ   c              	   C   sÎ   t |ƒ}d}| tdd|› d|› d� ¡ ¡ t |j¡�A tƒ  |  ¡ \}}d|v s,J ‚t |› d�ƒ 	¡ �}d| 
¡ v s>J ‚W d	  ƒ n1 sHw   Y  W d	  ƒ d	S W d	  ƒ d	S 1 s`w   Y  d	S )
zJEnsures that TeX documentation is written out

    CLI :: --latex-doc
    r†   r@   r™   r]   z --latex-docúDocumentation is saved to fileú
module.texú\documentclassN©r   rH   rI   rJ   r   rK   rL   r   r`   r‹   rŒ   ©rN   r2   rO   rP   r   rc   rd   Úotexr   r   r   Útest_latexdocÝ  s   ÿÿü"ür£   c              	   C   ó|   t |ƒ}d}| tdd|› d|› d� ¡ ¡ t |j¡� tƒ  |  ¡ \}}d|vs,J ‚W d  ƒ dS 1 s7w   Y  dS )zMEnsures that TeX documentation is written out

    CLI :: --no-latex-doc
    r†   r@   r™   r]   z --no-latex-docr�   Nrf   ©rN   r2   rO   rP   r   rc   rd   r   r   r   Útest_nolatexdocï  ó   ÿ"ýr¦   c              	   C   sÐ   t |ƒ}d}| tdd|› d|› d� ¡ ¡ t |j¡�B tƒ  |  ¡ \}}d|v s,J ‚t d|› d�ƒ 	¡ �}d	| 
¡ vs?J ‚W d
  ƒ n1 sIw   Y  W d
  ƒ d
S W d
  ƒ d
S 1 saw   Y  d
S )zžEnsures that truncated documentation is written out

    TODO: Test to ensure this has no effect without --latex-doc
    CLI :: --latex-doc --short-latex
    r†   r@   r™   r]   z --latex-doc --short-latexr�   ú./rž   rŸ   Nr    r¡   r   r   r   Útest_shortlatexÿ  s"   ýÿü"ür©   c              	   C   sÐ   t |ƒ}d}| tdd|› d|› d� ¡ ¡ t |j¡�B tƒ  |  ¡ \}}d|v s,J ‚t d|› d�ƒ 	¡ �}d	| 
¡ v s?J ‚W d
  ƒ n1 sIw   Y  W d
  ƒ d
S W d
  ƒ d
S 1 saw   Y  d
S )zIEnsures that RsT documentation is written out

    CLI :: --rest-doc
    r†   r@   r™   r]   z --rest-docú#ReST Documentation is saved to filer¨   zmodule.restz.. -*- rest -*-Nr    )rN   r2   rO   rP   r   rc   rd   Úorstr   r   r   Útest_restdoc  s   ÿÿü"ür¬   c              	   C   r¤   )zLEnsures that TeX documentation is written out

    CLI :: --no-rest-doc
    r†   r@   r™   r]   z --no-rest-docrª   Nrf   r¥   r   r   r   Útest_norestexdoc'  r§   r­   c              	   C   s¸   t |ƒ}d}| tdd|› d|› d� ¡ ¡ t |j¡�6 tƒ  t d|› d�ƒ ¡ �}d| 	¡ v s3J ‚W d	  ƒ n1 s=w   Y  W d	  ƒ d	S W d	  ƒ d	S 1 sUw   Y  d	S )
zIEnsures that debugging wrappers are written

    CLI :: --debug-capi
    r†   r@   r™   r]   z --debug-capir¨   r   z#define DEBUGCFUNCSN©
r   rH   rI   rJ   r   rK   rL   r   r‹   rŒ   )rN   r2   rO   rP   r   Úocmodr   r   r   Útest_debugcapi7  s   ÿÿþ"þr°   z2Consistently fails on CI; noisy so skip not xfail.c              	   C   s°   t | ƒ}d}| tdd|› d|› d� ¡ ¡ t |j¡�2 tƒ  t tj	› d�¡}t
j|ddd	�}d
}t d¡}|j|ks?J ‚|j|ksFJ ‚W d  ƒ dS 1 sQw   Y  dS )zEEnsures that debugging wrappers work

    CLI :: --debug-capi -c
    r†   r@   r™   r]   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   rH   rI   rJ   r   rK   rL   r   ÚshlexÚ
executableÚ
subprocessÚrunÚtextwrapÚdedentÚstdoutÚstderr)r2   rO   rP   r   Úcmd_runÚroutÚeoutÚeerrr   r   r   Útest_debugcapi_bldG  s   ÿ

"ðrÂ   c              	   C   sä   t |ƒ}d}| tdd|› d|› � ¡ ¡ t |j¡� tƒ  W d  ƒ n1 s)w   Y  |  ¡ \}}d|v s:J ‚| tdd|› d|› d� ¡ ¡ t |j¡� tƒ  |  ¡ \}}d|v s`J ‚W d  ƒ dS 1 skw   Y  dS )zoEnsures that fortran subroutine wrappers for F77 are included by default

    CLI :: --[no]-wrap-functions
    r†   r@   r™   r]   Nú Fortran 77 wrappers are saved toz --wrap-functionsrf   r¥   r   r   r   Útest_wrapfunc_defe  s    ÿÿ"ýrÄ   c              	   C   r¤   )zeEnsures that fortran subroutine wrappers for F77 can be disabled

    CLI :: --no-wrap-functions
    r†   r@   r™   r]   z --no-wrap-functionsrÃ   Nrf   r¥   r   r   r   Útest_nowrapfunc~  r§   rÅ   c              	   C   sÈ   t |ƒ}d}| tdd|› d|› d� ¡ ¡ t |j¡�> tƒ  t d|› d�ƒ ¡ �}| 	¡ }d|v s5J ‚d	|v s;J ‚W d
  ƒ n1 sEw   Y  W d
  ƒ d
S W d
  ƒ d
S 1 s]w   Y  d
S )zcAdd to the include directories

    CLI :: -include
    TODO: Document this in the help string
    r†   r@   r™   r]   z' -include<stdbool.h> -include<stdio.h> r¨   r   z#include <stdbool.h>z#include <stdio.h>Nr®   )rN   r2   rO   rP   r   r¯   Úocmrr   r   r   Útest_inclheaderŽ  s$   üýþ"þrÇ   c                   C   ó   dS )z?Add to the include directories

    CLI :: --include-paths
    Nr   r   r   r   r   Útest_inclpath¥  ó   rÉ   c                   C   rÈ   )z;Add to the include directories

    CLI :: --help-link
    Nr   r   r   r   r   Ú
test_hlink®  rÊ   rË   c                 C   s¢   t |ƒ}| tdd|› d� ¡ ¡ t |j¡�0 tƒ  |  ¡ \}}d|v s'J ‚d|v s-J ‚d|v s3J ‚d|v s9J ‚d|v s?J ‚W d	  ƒ d	S 1 sJw   Y  d	S )
zOCheck that Fortran-to-Python KIND specs can be passed

    CLI :: --f2cmap
    r@   rA   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 changesNrf   )rN   r?   rO   rP   rc   rd   r   r   r   Útest_f2cmap·  s   "ùrÌ   c                 C   sv   t |ƒ}| tdd|› d� ¡ ¡ t |j¡� tƒ  |  ¡ \}}t	|ƒdks)J ‚W d  ƒ dS 1 s4w   Y  dS )z)Reduce verbosity

    CLI :: --quiet
    r@   rA   z --quietr   N)
r   rH   rI   rJ   r   rK   rL   r   r`   Úlenrg   r   r   r   Ú
test_quietÉ  s   "ýrÎ   c                 C   sr   t |ƒ}| tdd|› d� ¡ ¡ t |j¡� tƒ  |  ¡ \}}d|v s'J ‚W d  ƒ dS 1 s2w   Y  dS )z-Increase verbosity

    CLI :: --verbose
    r@   rA   z
 --verboseÚanalyzelineNrf   rg   r   r   r   Útest_verbose×  s   "ýrÐ   c                 C   sn   |  tdd ¡ ¡ t t¡� tƒ  |  ¡ \}}ddl}|j	| 
¡ ks%J ‚W d  ƒ dS 1 s0w   Y  dS )z"Ensure version

    CLI :: -v
    r@   zf2py -vr   N)rH   rI   rJ   r	   rT   rl   r   r`   ÚnumpyÚ__version__Ústrip)rN   rO   rc   rd   Únpr   r   r   Útest_versionå  s   "ürÕ   c                 C   sŽ   t | ƒ}| tdd|› d� ¡ ¡ t |j¡�& tƒ  t tj	› d�¡}t
j|ddd�}d}|j|ks5J ‚W d	  ƒ d	S 1 s@w   Y  d	S )
z
    CLI :: -c
    r@   rA   z -cr±   Tr²   r³   rµ   N)r   rH   rI   rJ   r   rK   rL   r   r¶   r·   r¸   r¹   r¼   )r2   rO   rP   r¾   r¿   rÀ   r   r   r   Útest_npdistopó  s   "ûrÖ   z*Compiler and Python 3.12 or newer requiredc                 C   sÈ   t | ƒ}| tdd|› d� ¡ ¡ t |j¡�C tƒ  tj› d�}t	r(|d7 }n|d7 }t
 |¡}tj|ddd	�}d
}|j|ksBJ ‚t	rKd|jv sKJ ‚|jdksRJ ‚W d  ƒ dS 1 s]w   Y  dS )z.
    CLI :: --no-freethreading-compatible
    r@   rA   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   rH   rI   rJ   r   rK   rL   r   r·   r   r¶   r¸   r¹   r¼   r½   Ú
returncode©r2   rO   rP   Úcmdr¾   r¿   rÀ   r   r   r   Ú test_no_freethreading_compatible  s    

"órÜ   c                 C   sÄ   t | ƒ}| tdd|› d� ¡ ¡ t |j¡�A tƒ  tj› d�}t	r(|d7 }n|d7 }t
 |¡}tj|ddd	�}d
}|j|ksBJ ‚|jdksIJ ‚|jdksPJ ‚W d  ƒ dS 1 s[w   Y  dS )z+
    CLI :: --freethreading_compatible
    r@   rA   z -c --freethreading-compatibler×   z2import sys; assert sys._is_gil_enabled() is False"r|   Tr²   r³   rµ   Ú r   NrØ   rÚ   r   r   r   Útest_freethreading_compatible  s   

"ôrÞ   c                   C   rÈ   )z
    CLI :: -c --fcompiler
    Nr   r   r   r   r   Útest_npd_fcompiler7  ó   rß   c                   C   rÈ   )z
    CLI :: -c --compiler
    Nr   r   r   r   r   Útest_npd_compiler?  rà   rá   c                   C   rÈ   )z$
    CLI :: -c --help-fcompiler
    Nr   r   r   r   r   Útest_npd_help_fcompilerG  rà   râ   c                   C   rÈ   )z
    CLI :: -c --f77exec
    Nr   r   r   r   r   Útest_npd_f77execO  rà   rã   c                   C   rÈ   )z
    CLI :: -c --f90exec
    Nr   r   r   r   r   Útest_npd_f90execW  rà   rä   c                   C   rÈ   )z
    CLI :: -c --f77flags
    Nr   r   r   r   r   Útest_npd_f77flags_  rà   rå   c                   C   rÈ   )z
    CLI :: -c --f90flags
    Nr   r   r   r   r   Útest_npd_f90flagsg  rà   ræ   c                   C   rÈ   )z
    CLI :: -c --opt
    Nr   r   r   r   r   Útest_npd_opto  rà   rç   c                   C   rÈ   )z
    CLI :: -c --arch
    Nr   r   r   r   r   Útest_npd_archw  rà   rè   c                   C   rÈ   )z
    CLI :: -c --noopt
    Nr   r   r   r   r   Útest_npd_noopt  rà   ré   c                   C   rÈ   )z
    CLI :: -c --noarch
    Nr   r   r   r   r   Útest_npd_noarch‡  rà   rê   c                   C   rÈ   )z
    CLI :: -c --debug
    Nr   r   r   r   r   Útest_npd_debug�  rà   rë   c                   C   rÈ   )z%
    CLI :: -c --link-<resource>
    Nr   r   r   r   r   Útest_npd_link_auto—  rà   rì   c                   C   rÈ   )z/
    CLI :: -c -L/path/to/lib/ -l<libname>
    Nr   r   r   r   r   Útest_npd_libŸ  rà   rí   c                   C   rÈ   )z
    CLI :: -D<define>
    Nr   r   r   r   r   Útest_npd_define§  rà   rî   c                   C   rÈ   )z
    CLI :: -U<name>
    Nr   r   r   r   r   Útest_npd_undefine¯  rà   rï   c                   C   rÈ   )z$
    CLI :: -I/path/to/include/
    Nr   r   r   r   r   Útest_npd_incl·  rà   rð   c                   C   rÈ   )z8
    CLI :: <filename>.o <filename>.so <filename>.a
    Nr   r   r   r   r   Útest_npd_linker¿  rà   rñ   )r   )Xr�   r¶   r¸   rI   rº   Úpathlibr   Úcollectionsr   Úplatformr	   rÝ   r   Únumpy.f2py.f2py2er   r   Únumpy.testing._private.utilsr   r   r   r   Úfixturer2   r6   r7   r9   r;   r?   rR   rV   r\   re   rh   rn   ÚmarkÚskipifÚversion_inforr   Úsystemrw   Ú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   r   Ú<module>   s¸    



'











 

'
		
ÿ
ÿ
