a
    Xg+                     @   sx  d Z ddlZddlZddlZddlZddlZddlZddlZ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mZ ddlmZmZ ddlmZ dadaejd	kreejjjZeed
Zdd Z dd Z!dd Z"dd Z#e#g g g dfddZ$e#g g g ddfddZ%da&dd Z'dd Z(dd Z)dd Z*e#dd  Z+G d!d" d"Z,d#d$ Z-ej.d%d& Z/dS )'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                   C   sV   t d urRztjt  W n ty*   Y n0 ztt  W n tyL   Y n0 d a d S N)_module_dirsyspathremove
ValueErrorshutilrmtreeOSError r   r   c/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/numpy/f2py/tests/util.py_cleanup(   s    r   c                   C   s6   t d u r2t a tt t tjvr2tjdt  t S Nr   )	r
   tempfilemkdtempatexitregisterr   r   r   insertr   r   r   r   get_module_dir6   s    

r   c                  C   s,   t   dt } td7 a| tjv r(td| S )Nz_test_ext_module_%d   z%Temporary module name already in use.)r   _module_numr   modulesRuntimeError)namer   r   r   get_temp_module_name@   s    
r!   c                    s   i  fdd} j |_ |S )Nc               
      st   t | |f}|vrZz | i ||< W n. tyX } z||<  W Y d }~n
d }~0 0 | }t|trp||S r	   )repr	Exception
isinstance)akwkeyeretfuncmemor   r   wrapperO   s    
z_memoize.<locals>.wrapper)__name__)r+   r-   r   r*   r   _memoizeL   s    r/   c              
   C   s  dt jd}t }g }g }| D ]j}	tj|	s<td|	 tj|tj|	}
t	|	|
 |
|
 tj|
\}}|dv r |
|
 q |sJ |du rt }dd|g| | }|r|dg| 7 }|r|d	g| 7 }t }zt| t jd|g| }tj|tjtjd
}| \}}|jdkrDtd|dd t|f W t| |D ]}	t|	 qTn"t| |D ]}	t|	 qv0 t jdkrtttj|d| tg dt  t|S )zH
    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: %s
%s   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_sourcesZf2py_sourcesfndstbaseextZ	f2py_optscwdcmdpouterrr   r   r   build_modulee   sd    



r`   c              	   C   s   |du rd}t |dX}t|d}||  W d   n1 sB0    Y  t|g||||dW  d   S 1 st0    Y  dS )z6
    Compile and import Fortran code using f2py.

    Nr2   )suffixwrP   rQ   rR   rS   )r   openwriter`   )Zsource_coderP   rQ   rR   ra   rS   r   fr   r   r   
build_code   s    (rg   c            	   	   C   s"  t d urt S da trt S tdttj d} | tttjd } t	 }z~t
j|d}t|d}||  W d    n1 s0    Y  tjddg}tj|tjtj|d}| \}}W t| nt| 0 td	|}|rtt|d
tt|dtt|dfa t S )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)
        )Zsyspathzsetup.pyrb   config)r5   r6   r[   s   COMPILERS:(\d+),(\d+),(\d+)r         )_compiler_statusr   textwrapdedentr"   r   r   dictr   r   r8   r:   rd   re   rA   rB   rC   rD   rE   rF   r   r   researchboolintgroup)	rT   Ztmpdirscriptrf   r\   r]   r^   r_   mr   r   r   _get_compiler_status   s:    
(rv   c                   C   s
   t  d S r   rv   r   r   r   r   has_c_compiler  s    rx   c                   C   s
   t  d S )Nr   rw   r   r   r   r   has_f77_compiler  s    ry   c                   C   s
   t  d S )Nri   rw   r   r   r   r   has_f90_compiler  s    rz   c              
   K   s  t  }g }| D ]H}tj|s*td| tj|tj|}t|| |	| qt
|dd}dttj d| d}tj|t d }	|	|	 t|	d }
|
|d	 W d
   n1 s0    Y  t }zt| tj|	ddg}tj|tjtjd}| \}}|jdkrDtd|dd
 t|f W t| |D ]}t| qTn"t| |D ]}t| qv0 t| tj| 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-ir4   r   z%Running distutils build failed: %s
%sr7   ) r   r8   r   r9   r   r:   r;   r   r<   r=   rl   rm   replacer"   r   r!   rd   re   encoder?   r@   rA   rB   rC   rD   rE   rF   rG   r   rH   
__import__r   )rO   Zconfig_coderS   r&   rU   rV   rW   rX   rT   rt   rf   r[   r\   r]   r^   r_   r   r   r   build_module_distutils  sN    
.


r   c                   @   s<   e Zd ZdZdZg Zg Zg ZdZdZ	e
dd Zdd ZdS )F2PyTestNr2   c                 C   s*   t | }d|jddd  d|j dS )N_.r   Z_ext_module)type
__module__rsplitr.   )selfclsr   r   r   rS   j  s    zF2PyTest.module_namec                 C   sL  t jdkrtd | jd ur"d S t s2td g }| jrH|| j | jd ur^|	| j
 d}d}d}|D ]>}t|drd}qnt|drd}qnt|drnd}qn|rt std	 |rt std
 |rt st std | jd urt| j| j| j| j| j
| jd| _| jd urHt| j| j| j| j| jd| _d S )Nwin32z)Fails with MinGW64 Gfortran (Issue #9673)zNo C compiler availableFr2   Tr1   r3   z No Fortran 77 compiler availablez No Fortran 90 compiler availablezNo Fortran compiler available)rP   rQ   rR   ra   rS   rc   )r   rI   pytestrQ   modulerx   sourcesrK   rT   r=   ra   strendswithry   rz   rg   rP   rR   rS   r`   )r   codesZ	needs_f77Z	needs_f90Z	needs_pyfrW   r   r   r   setup_methodo  sX    









	zF2PyTest.setup_method)r.   r   __qualname__rT   r   rP   rQ   rR   ra   r   propertyrS   r   r   r   r   r   r   a  s   
r   c                  G   s   t tjjj }|j|  S r	   )r   numpyZf2py__file__parentresolvejoinpath)r%   rU   r   r   r   getpath  s    r   c              	   c   s8   t  }t|  zd V  W t| nt| 0 d S r	   )r   r[   r8   r@   )r   Zcurpathr   r   r   	switchdir  s
    
r   )0__doc__rL   r8   r   rB   r   r   r   rl   ro   r   
contextlibr   pathlibr   Znumpy.compatr   Znumpy._utilsr   Znumpy.testingr   r   	importlibr   r
   r   rI   r   r   ZNUMPY_INSTALL_ROOTlistrJ   r   r   r!   r/   r`   rg   rk   rv   rx   ry   rz   r   r   r   contextmanagerr   r   r   r   r   <module>   s\   

I>	
DJ