HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/.local/lib/python3.10/site-packages/numpy/f2py/tests/__pycache__/util.cpython-310.pyc
o

���g�+�@sxdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZddlmZddlmZmZddlmZdadaejd	kriee�jjjZee�d
��Zdd�Z d
d�Z!dd�Z"dd�Z#e#gggdfdd��Z$e#gggddfdd��Z%da&dd�Z'dd�Z(dd�Z)dd�Z*e#dd ��Z+Gd!d"�d"�Z,d#d$�Z-ej.d%d&��Z/dS)'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**/*.dllcCsZtdur+ztj�t�Wn	tyYnwzt�t�Wn	ty&YnwdadSdS�N)�_module_dir�sys�path�remove�
ValueError�shutil�rmtree�OSError�rr�H/home/arjun/.local/lib/python3.10/site-packages/numpy/f2py/tests/util.py�_cleanup(s���rcCs6tdurt��at�t�ttjvrtj�dt�tS�Nr)	r
�tempfile�mkdtemp�atexit�registerrrr�insertrrrr�get_module_dir6s

rcCs,t�dt}td7a|tjvrtd��|S)Nz_test_ext_module_%d�z%Temporary module name already in use.)r�_module_numr�modules�RuntimeError)�namerrr�get_temp_module_name@s
r!csi���fdd�}�j|_|S)Nc
sht||f�}|�vr'z�|i|���|<Wnty&}z|�|<�d}~ww�|}t|t�r2|�|Sr	)�repr�	Exception�
isinstance)�a�kw�key�e�ret��func�memorr�wrapperOs��
z_memoize.<locals>.wrapper)�__name__)r+r-rr*r�_memoizeLs
r/c
Cs�dtj�d�}t�}g}g}|D]5}	tj�|	�std|	��tj�|tj�|	��}
t�	|	|
�|�
|
�tj�|
�\}}|dvrE|�
|
�q|sJJ�|durQt�}dd|g||}
|rc|
dg|7}
|rl|
d	g|7}
t�
�}zAt�|�tjd|g|
}tj|tjtjd
�}|��\}}|jdkr�td|d
d�t|�f��Wt�|�|D]}	t�|	�q�nt�|�|D]}	t�|	�q�wtjdkr�t�t�tj�|d�|����t�gd�t�t|�S)zH
    Compile and import a f2py module, built from the given files.

    zimport sys; sys.path = z&; import numpy.f2py; numpy.f2py.main()�%s is not a file)�.f90�.fz.c�.pyfNz-cz-mzskip:zonly:��stdout�stderrrzRunning f2py failed: %s
%s�rz{:s}*)z/usr/bin/rebasez
--databasez--obliviousz	--verbose)rr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�errrrr�build_moduleesl

�
�
��
�
��
���rbc	Cs�|durd}t|d��,}t|d��
}|�|�Wd�n1s!wYt|g||||d�Wd�S1s:wYdS)z6
    Compile and import Fortran code using f2py.

    Nr2)�suffix�w�rPrQrRrS)r�open�writerb)�source_coderPrQrRrcrSr�frrr�
build_code�s��$�rjc		Cs tdurtSdatrtSt�dttj��d��}|tttj�d�}t�	�}z?t
j�|d�}t|d��
}|�
|�Wd�n1sCwYtjddg}tj|tjtj|d�}|��\}}Wt�|�nt�|�wt�d	|�}|r�tt|�d
���tt|�d���tt|�d���fatS)
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)
        )�syspathzsetup.pyrd�config)r5r6r]sCOMPILERS:(\d+),(\d+),(\d+)r��)�_compiler_statusr�textwrap�dedentr"rr�dictrrr8r:rfrgrArBrCrDrErFrr�re�search�bool�int�group)	rT�tmpdir�scriptrir^r_r`ra�mrrr�_get_compiler_status�s<
����r{cC�
t�dSr�r{rrrr�has_c_compiler�
r~cCr|)Nrr}rrrr�has_f77_compilerrr�cCr|)Nrmr}rrrr�has_f90_compilerrr�c
Ks�t�}g}|D]$}tj�|�std|��tj�|tj�|��}t�||�|�	|�qt
�|��dd�}dt
tj��d|�d�}tj�|t�d�}	|�	|	�t|	d��}
|
�|�d	��Wd
�n1shwYt��}z@t�|�tj|	ddg}tj|tjtjd
�}
|
��\}}|
jdkr�td|dd
�t|�f��Wt�|�|D]}t�|�q�nt�|�|D]}t�|�q�wt|�tj|S)z6
    Build a module via distutils and import it.

    r0�
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-ir4rz%Running distutils build failed: %s
%sr7) rr8rr9rr:r;rr<r=rprq�replacer"rr!rfrg�encoder?r@rArBrCrDrErFrGrrH�
__import__r)rO�config_coderSr&rUrVrXrYrTryrir]r^r_r`rarrr�build_module_distutilssV��
�
�
��
�
��
r�c@s<eZdZdZdZgZgZgZdZdZ	e
dd��Zdd�ZdS)�F2PyTestNr2cCs*t|�}d|j�dd�d�d|j�d�S)N�_�.r����_ext_module)�type�
__module__�rsplitr.)�self�clsrrrrSjs"zF2PyTest.module_namecCsLtjdkr
t�d�|jdurdSt�st�d�g}|jr$|�|j�|jdur/|�	|j
�d}d}d}|D]}t|��d�rCd}q7t|��d�rMd}q7t|��d�rVd}q7|rat
�sat�d	�|rkt�skt�d
�|rxt�sxt
�sxt�d�|jdur�t|j|j|j|j|j
|jd�|_|jdur�t|j|j|j|j|jd
�|_dSdS)N�win32z)Fails with MinGW64 Gfortran (Issue #9673)zNo C compiler availableFr2Tr1r3z No Fortran 77 compiler availablez No Fortran 90 compiler availablezNo Fortran compiler available)rPrQrRrcrSre)rrI�pytestrQ�moduler~�sourcesrKrTr=rc�str�endswithr�r�rjrPrRrSrb)r��codes�	needs_f77�	needs_f90�	needs_pyfrXrrr�setup_methodos\




�





�
	��zF2PyTest.setup_method)
r.r��__qualname__rTr�rPrQrRrcr��propertyrSr�rrrrr�as
r�cGsttjj�j��}|j|�Sr	)r�numpy�f2py�__file__�parent�resolve�joinpath)r%rUrrr�getpath�s
r�c	cs8�t��}t�|�zdVWt�|�dSt�|�wr	)rr]r8r@)r�curpathrrr�	switchdir�s�
r�)0�__doc__rLr8rrBrrrrprsr��
contextlibr��pathlibr�numpy.compatr�numpy._utilsr�
numpy.testingrr�	importlibrr
rrIr�r��NUMPY_INSTALL_ROOT�listrJrrr!r/rbrjror{r~r�r�r�r�r��contextmanagerr�rrrr�<module>s^

I�>	
DJ