o
    TdJ                     @   s   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 dZ
ede
ZG dd	 d	Zd
d ZdddZedkr@e  dS dS )z:Module for displaying information about Numba's gdb set up    )
namedtupleN)dedent)configz4binary_loc, extension_loc, py_ver, np_ver, supported	_gdb_infoc                   @   sZ   e Zd ZdZdd ZdddZedd Zed	d
 Z	dd Z
dd Zdd Zdd ZdS )_GDBTestWrapperzmWraps the gdb binary and has methods for checking what the gdb binary
    has support for (Python and NumPy).c                 C   s,   t j}|d u rdt j }t||| _d S )Nz.No valid binary could be found for gdb named: )r   
GDB_BINARY
ValueError_gdb_binary)self
gdb_binarymsg r   k/home/ncw/WWW/www-new/content/articles/pi-bbp/venv/lib/python3.10/site-packages/numba/misc/numba_gdbinfo.py__init__   s   
z_GDBTestWrapper.__init__r   c                 C   sH   | j dg}|D ]}|d || q|ddg tj|ddddS )Nz-qz-exqT
   )capture_outputtimeouttext)r   appendextend
subprocessrun)r
   cmdgdb_callxr   r   r   _run_cmd   s   


z_GDBTestWrapper._run_cmdc                 C   s   | j S )N)r	   r
   r   r   r   r   #   s   z_GDBTestWrapper.gdb_binaryc                 C   s
   |j dkS )Nr   )
returncode)clsstatusr   r   r   success'   s   
z_GDBTestWrapper.successc                 C   s   |   S )zChecks that gdb will launch okr   r   r   r   r   check_launch+   s   z_GDBTestWrapper.check_launchc                 C      d}|  |fS )NzUpython from __future__ import print_function; import sys; print(sys.version_info[:2])r"   r
   r   r   r   r   check_python/   s   z_GDBTestWrapper.check_pythonc                 C   r$   )Nztpython from __future__ import print_function; import types; import numpy; print(isinstance(numpy, types.ModuleType))r"   r%   r   r   r   check_numpy4      z_GDBTestWrapper.check_numpyc                 C   r$   )Nzapython from __future__ import print_function; import types; import numpy;print(numpy.__version__)r"   r%   r   r   r   check_numpy_version:   r(   z#_GDBTestWrapper.check_numpy_versionN)r   )__name__
__module____qualname____doc__r   r   propertyr   classmethodr!   r#   r&   r'   r)   r   r   r   r   r      s    
	

r   c               
   C   sv  d} d}d}d}d}z#t  }| }||s)d|j d|j d|j }t||j} W n tyD } zd| } W Y d}~nZd}~ww | }||rt	
d	|j }	|	dur|	 \}
}|
 d
| }d}| }||rd|j vr|j dkrd}d}| }||rd|j vr|j }|r|rd}nd}nd}d}tjtjt|}t| ||||S )zEPrints information to stdout about the gdb setup that Numba has foundNFzNo Python supportzNo NumPy supportzgdb at 'z#' does not appear to work.
stdout: z	
stderr: z+Testing gdb binary failed. Reported Error: z\((\d+),\s+(\d+)\).T	TracebackTrueUnknownz!Full (Python and NumPy supported)z'Partial (Python only, no NumPy support)Nonezgdb_print_extension.py)r   r#   r!   r   stdoutstderrr   	Exceptionr&   rematchstripgroupsr'   r)   ospathjoindirname__file__r   )	gdb_stategdb_has_pythongdb_has_numpygdb_python_versiongdb_python_numpy_versiongdb_wrapperr    r   eversion_matchpymajorpyminorprint_ext_supportedprint_ext_fileprint_ext_pathr   r   r   collect_gdbinfoA   sd   





rN   -   c                 C   s   t  }td d|  d}t|d|jf  t|d|jf  t|d|jf  t|d|jf  t|d|jf  td	 td
 td|j d td d}tt| dS )z;Displays the information collected by collect_gdbinfo.
    zP--------------------------------------------------------------------------------z%-zs : %-szBinary locationzPrint extension locationzPython versionzNumPy versionz Numba printing extension support zTTo load the Numba gdb printing extension, execute the following from the gdb prompt:z
source 
a  
    =============================================================
    IMPORTANT: Before sharing you should remove any information
    in the above that you wish to keep private e.g. paths.
    =============================================================
    N)rN   print
binary_locextension_locpy_vernp_ver	supportedr   )sep_posgdb_infofmtwarnr   r   r   display_gdbinfo   s   r\   __main__)rO   )r-   collectionsr   r<   r8   r   textwrapr   numbar   _fieldsr   r   rN   r\   r*   r   r   r   r   <module>   s    
3
D
