
    J/Phg2                     v   d 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 d Z e            ZdZdd	Zdd
Z G d de          Zd Zd ZeefZefdZ G d de          Z G d de          Z G d de          ZddZd Zd                                Zd Z e!dk    r e              dS dS )z
This file contains `__main__` so that it can be run as a commandline tool.

This file contains functions to inspect Numba's support for a given Python
module or a Python package.
    N)errors)get_versions)
cpu_target)captured_stdoutc                  v    t                      d         } | s"t          j        dt          j                   dS | S )Nzfull-revisionidz>Cannot find git commit hash. Source links could be inaccurate.)categorymain)r   warningswarnr   NumbaWarning)fulls    Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/misc/help/inspector.py_get_commitr      sG    >>+,D L(	
 	
 	
 	
 vK    zLhttps://github.com/numba/numba/blob/{commit}/{path}#L{firstline}-L{lastline}c                    |pt           }|j        }|                                 |j                                         i }i }	 |                    |           }|                    |          }|j        D ]/}	 |                                ||<   # t          $ r d||<   Y ,w xY wn# t          $ r d}d}Y nw xY w||d<   ||d<   ||d<   |S )a  Return information about the support of a function.

    Returns
    -------
    info : dict
        Defined keys:
        - "numba_type": str or None
            The numba type object of the function if supported.
        - "explained": str
            A textual description of the support.
        - "source_infos": dict
            A dictionary containing the source location of each definition.
    Nznot supported
numba_type	explainedsource_infos)
r   typing_contextrefreshtarget_contextresolve_value_typeexplain_function_type	templatesget_source_infoAttributeError
ValueError)functiontargettyctinfor   nbtyr   temps           r   inspect_functionr$   "   s    !zF DLLNNN
!!###DL*&&x00 ..t44	N 	* 	*D*%)%9%9%;%;T""! * * *%)T"""*	*  $ $ $#			$ D!D'DKs$   B% 7BB! B!%B65B6c              #     K   |i n|}t          |           D ]}|                    d          rt          | |          }t          j        t          j        f}t          ||          sQt          | ||          }||v r||         |d<   nd                    | j	        |          ||<   |
                    t          ||                     |V  dS )zwInspect a module object and yielding results from `inspect_function()`
    for each function object in the module.
    N_)modulenameobjaliasz{module}.{name})r'   r(   )r   )dir
startswithgetattrpytypesFunctionTypeBuiltinFunctionType
isinstancedictformat__name__updater$   )r'   r   r*   r(   r)   supported_typesr!   s          r   inspect_moduler7   M   s       -BBUEF  ??3 	fd##"/1LM#// 	6#666%<<!#JDMM*117; 2 = =E#J$S888999



% r   c                   P    e Zd ZdZd Zed             Zed             Zd Zd Z	dS )_Statz9For gathering simple statistic of (un)supported functionsc                 "    d| _         d| _        d S Nr   	supportedunsupportedselfs    r   __init__z_Stat.__init__j   s    r   c                 $    | j         | j        z   }|S Nr<   )r@   totals     r   rD   z_Stat.totaln   s    !11r   c                 *    | j         | j        z  dz  }|S )Nd   )r=   rD   )r@   ratios     r   rG   z_Stat.ratios   s    +c1r   c                 j    | j         dk    rdS d                    | j        | j         | j                  S )Nr   emptyz0supported = {supported} / {total} = {ratio:.2f}%)r=   rD   rG   )rD   r3   r=   rG   r?   s    r   describez_Stat.describex   s?    :??7AHHn** I 
 
 	
r   c                 h    d                     | j        j        |                                           S )Nz{clsname}({describe}))clsnamerJ   )r3   	__class__r4   rJ   r?   s    r   __repr__z_Stat.__repr__   s2    &--N+]]__ . 
 
 	
r   N)
r4   
__module____qualname____doc__rA   propertyrD   rG   rJ   rN    r   r   r9   r9   h   s}        CC     X   X
 
 

 
 
 
 
r   r9   c                 6    t          d | D                        S )Nc              3   @   K   | ]}|                     d           V  dS )r&   N)r,   .0xs     r   	<genexpr>z(filter_private_module.<locals>.<genexpr>   s.      @@1<<$$@@@@@@r   anymodule_componentss    r   filter_private_moduler^      s#    @@.?@@@@@@@r   c                 6    t          d | D                        S )Nc              3   "   K   | ]
}|d k    V  dS )testsNrS   rV   s     r   rY   z&filter_tests_module.<locals>.<genexpr>   s&      ;;A1<;;;;;;r   rZ   r\   s    r   filter_tests_modulerb      s#    ;;):;;;;;;;r   c              #   0  K   d }| j         dz   }t          j        | j        ||          }fd}| j         } ||          s| V  |D ]}|d         } ||          rt	                      5  	 t          |          }n# t          $ r Y ddd           Mw xY w|                    d          dd         D ]&}		 t          ||	          }# t          $ r d}Y  nw xY wddd           n# 1 swxY w Y   t          |t          j                  s|V  dS )zSYield all modules in a given package.

    Recursively walks the package tree.
    c                     d S rC   rS   )r&   s    r   <lambda>z)list_modules_in_package.<locals>.<lambda>   s    t r   .)onerrorc                 f    |                      d          t          fdD                       S )Nrf   c              3   0   K   | ]} |           V  d S rC   rS   )rW   	filter_fnr]   s     r   rY   z@list_modules_in_package.<locals>.check_filter.<locals>.<genexpr>   sE       4 4  !y!2333 4 4 4 4 4 4r   )splitr[   )modnamer]   module_filterss    @r   check_filterz-list_modules_in_package.<locals>.check_filter   sN    #MM#.. 4 4 4 4$24 4 4 4 4 	4r      N)r4   pkgutilwalk_packages__path__r   
__import__	Exceptionrk   r-   r   r1   r.   
ModuleType)
packagerm   onerror_ignoreprefixpackage_walkerrn   rl   pkginfomodparts
    `        r   list_modules_in_packager}      s     
 $^N#F*  N4 4 4 4 4
 G<   !  !*<   	 	 	 ))   	 	 	 	 	 	 	  c**122.  !#t,,CC%   CEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	" #w122 					5 sZ   .C+0B ?C+ 
B
C+B"C+;CC+C	C+C	C++C/	2C/	c                       e Zd ZdZd Zd ZdS )	FormatterzBase class for formatters.
    c                     || _         d S rC   )_fileobj)r@   fileobjs     r   rA   zFormatter.__init__   s    r   c                 T    |                     d| j                   t          |i | d S )Nfile)
setdefaultr   print)r@   argskwargss      r   r   zFormatter.print   s3    &$-000tvr   N)r4   rO   rP   rQ   rA   r   rS   r   r   r   r      s<                  r   r   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
HTMLFormatterz Formatter that outputs HTML
    c                 4    dd l }|                    |          S r;   )htmlescape)r@   textr   s      r   r   zHTMLFormatter.escape   s    {{4   r   c                 4    |                      d|d           d S )Nz<h1></h2>r   r@   r   s     r   titlezHTMLFormatter.title   s    

64)))))r   c                 ^    |                      d|d           |                      d           d S )Nz<h2>r   <ul>r   r@   rl   s     r   begin_module_sectionz"HTMLFormatter.begin_module_section   s0    

67G,,,

6r   c                 0    |                      d           d S )N</ul>r   r?   s    r   end_module_sectionz HTMLFormatter.end_module_section   s    

7r   c                 H   |                      d           |                      d                    ||                     |                      d                    |                     |                      d|d           |                      d           |                                D ]O\  }}|r|                      d           |d         }	|d         }
|d	         }|d
         }|                      d                    |                     |	          |                     |
          |                     |          |d         |d                              |                      d                    |                     |d         pd                               nH|                      d                    |                     t	          |                                         |                      d           Q|                      d           |                      d           d S )N<li>z{}.<b>{}</b>z: <b>{}</b>z
<div><pre>z</pre></div>r   r(   sigfilenamelinesz)<p>defined by <b>{}</b>{} at {}:{}-{}</p>r   ro   	<p>{}</p>	docstring z<li>{}</li>r   )r   r3   itemsr   str)r@   rl   itemnametypenamer   sourcesr*   tclssourceimplr   r   r   s                r   write_supported_itemz"HTMLFormatter.write_supported_item   s   

6

>((
 
 	 	 	 	

=''11222

<N;;;

6#MMOO 	  	 LD& D

6"""f~Um!*-w

?FFD))4;;s+;+;H--uQxq    

;--KK{ 3 9r::      

8??4;;s4yy+A+ABBCCCJJw

7

7r   c                     |                      d           |                      d                    ||                     |                      d           d S )Nr   z{}.<b>{}</b>: UNSUPPORTEDr   )r   r3   r@   rl   r   s      r   write_unsupported_itemz$HTMLFormatter.write_unsupported_item  s]    

6

.55
 
 	 	 	 	

7r   c                 z    |                      d                    |                                                     d S )Nr   )r   r3   rJ   )r@   statss     r   write_statisticzHTMLFormatter.write_statistic  s2    

;%%enn&6&67788888r   Nr4   rO   rP   rQ   r   r   r   r   r   r   r   rS   r   r   r   r      s         ! ! !* * *      B  9 9 9 9 9r   r   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
ReSTFormatterzDFormatter that output ReSTructured text format for Sphinx docs.
    c                     |S rC   rS   r   s     r   r   zReSTFormatter.escape  s    r   c                     |                      |           |                      dt          |          z             |                                   d S )N=r   lenr   s     r   r   zReSTFormatter.title  sA    

4

3T?###

r   c                     |                      |           |                      dt          |          z             |                                   d S )N-r   r   s     r   r   z"ReSTFormatter.begin_module_section  sB    

7

3W%&&&

r   c                 .    |                                   d S rC   r   r?   s    r   r   z ReSTFormatter.end_module_section$  s    

r   c                    |                      d                    ||                     |                      d           |                                   |r(|                      d                    |                     |                                   |                                D ]\  }}|r|d         }	|d         }
|d         }|d         }t                              t          ||d         |d	         
          }|                      d                    |	|
||d         |d	         |                     |                      d                    t          |                               |                                   d S )Nz.. function:: {}.{}z   :noindex:z   Alias to: ``{}``r(   r   r   r   r   ro   )commitpath	firstlinelastlinez,   - defined by ``{}{}`` at `{}:{}-{} <{}>`_z   - defined by ``{}``)r   r3   r   
github_urlr   r   )r@   rl   r   r   r   r   r*   r   r   r   r   r   r   source_links                 r   r   z"ReSTFormatter.write_supported_item'  su   

(//BBCCC

>"""

 	<JJ,33E::;;;

#MMOO 	G 	GLD& Gf~Um!*-w(//!!#Ah"1X	 0   

BIIc8U1XuQx     

3::3t99EEFFFF

r   c                     d S rC   rS   r   s      r   r   z$ReSTFormatter.write_unsupported_itemG  s    r   c                 D   |j         dk    r|                     d           njd}|                     |                    |j                             |                                  |                     |                                           |                                  d S )Nr   zThis module is not supported.z%Not showing {} unsupported functions.)r=   r   r3   r>   rJ   )r@   statmsgs      r   r   zReSTFormatter.write_statisticJ  s    >QJJ677779CJJszz$"233444JJLLLJJt}}'''

r   Nr   rS   r   r   r   r     s             
  
    @      r   r   c                    |                      d                    |                     i }|D ]}t                      }|j        }|                     |                     |                     t          |||          D ] }|d         }	|	|xj        dz  c_        |                     |                     |d         j                  |                     |d                   |                     t          |	                    |                     |d                   |d	         |
                    d
                     |xj        dz  c_        |                     |                     |d         j                  |                     |d                              "|                     |           |                                  dS )zFormat modules.
    zListings for {})r   r*   r   Nro   r'   r(   r   r   r*   )rl   r   r   r   r   r*   )rl   r   )r   r3   r9   r4   r   r   r7   r=   r   r   getr>   r   r   r   )
	formatterpackage_namemod_sequencer   	alias_mapr{   r   rl   r!   nbtypes
             r   _format_module_infosr   U  s    OO%,,\::;;;I ' 'ww,&&y'7'7'@'@AAA"3vYGGG 	 	D,'F!!#..%,,T(^-DEE&--d6l;;&--c&kk::'..tK/@AA 0((7++ /       A%  00%,,T(^-DEE&--d6l;; 1    
 	!!$'''$$&&&&3' 'r   c                    t          |           }t          |d          rt          |          }n|g}|dk    rOt          |dz   d          5 }t	          |          }t          || |           ddd           dS # 1 swxY w Y   dS |dk    rOt          |dz   d          5 }t          |          }t          || |           ddd           dS # 1 swxY w Y   dS t          d	                    |                    )
a  Write listing information into a file.

    Parameters
    ----------
    package_name : str
        Name of the package to inspect.
    filename : str
        Output filename. Always overwrite.
    output_format : str
        Support formats are "html" and "rst".
    rr   r   z.htmlw)r   Nrstz.rstz#Output format '{}' is not supported)	rs   hasattrr}   openr   r   r   r   r3   )r   r   output_formatrv   modsfoutfmtrs          r   write_listingsr   v  s    &&Gw
## &w//y(W$c** 	;d ...D |T:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 
%		(V#S)) 	;T ...D |T:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 188GGI I 	Is$   "A;;A?A?!"CCCz6
Inspect Numba support for a given top-level package.
c                  N   t          j        t                    } |                     ddt          d           |                     dddd	           |                     d
ddd	           |                                 }|j        }|j        }|j        }t          |||           d S )N)descriptionrv   zPackage to inspect)metavartypehelpz--formatr3   r   z!Output format; i.e. "html", "rst")destdefaultr   z--filer   inspector_outputz8Output filename. Defaults to "inspector_output.<format>")
argparseArgumentParserprogram_descriptionadd_argumentr   
parse_argsrv   r3   r   r   )parserr   r   r   r   s        r   r	   r	     s    $1DEEEF
93!     60     v'9G    
 D<LKMyH<=99999r   __main__rC   )NN)"rQ   r   rp   r
   typesr.   
numba.corer   numba._versionr   numba.core.registryr   numba.tests.supportr   r   r   r   r$   r7   objectr9   r^   rb   _default_module_filtersr}   r   r   r   r   r   stripr   r	   r4   rS   r   r   <module>r      s.                 ' ' ' ' ' ' * * * * * * / / / / / /   
[
( ( ( (V   6
 
 
 
 
F 
 
 
@A A A< < <
   5L 1 1 1 1h       <9 <9 <9 <9 <9I <9 <9 <9~> > > > >I > > >B' ' ' 'BI I I>	EGG 
: : :, zDFFFFF r   