
    xKgg2                     D   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j=                         Zd Z e!dk(  r e         yy)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                  p    t               d   } | s&t        j                  dt        j                         y| S )Nzfull-revisionidz>Cannot find git commit hash. Source links could be inaccurate.)categorymain)r   warningswarnr   NumbaWarning)fulls    ]/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/misc/help/inspector.py_get_commitr      s4    >+,DL((	
 K    zLhttps://github.com/numba/numba/blob/{commit}/{path}#L{firstline}-L{lastline}c                    |xs t         }|j                  }|j                          |j                  j                          i }i }	 |j	                  |       }|j                  |      }|j                  D ]  }	 |j                         ||<    	 ||d<   ||d<   ||d<   |S # t        $ r d||<   Y ;w xY w# t        $ r d}d}Y 4w xY w)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LLN
!!#DL*&&x0 ..t4	NND*%)%9%9%;T" # D!D'DK " *%)T"*  $#	$s$   B3 8BB0/B03CCc              #     K   |i n|}t        |       D ]  }|j                  d      rt        | |      }t        j                  t        j
                  f}t        ||      sNt        | ||      }||v r	||   |d<   n dj                  | j                  |      ||<   |j                  t        ||             |  yw)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      -BUEF??3fd#"//1L1LM#/6#6%<!#JDM*117; 2 =E#J$S89
% s   B>C c                   B    e Zd ZdZd Zed        Zed        Zd Zd Z	y)_Statz9For gathering simple statistic of (un)supported functionsc                      d| _         d| _        y Nr   	supportedunsupportedselfs    r   __init__z_Stat.__init__j   s    r   c                 8    | j                   | j                  z   }|S Nr<   )r@   totals     r   rD   z_Stat.totaln   s    !1!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                   dk(  rydj                  | j                  | j                   | j                        S )Nr   emptyz0supported = {supported} / {total} = {ratio:.2f}%)r=   rD   rG   )rD   r3   r=   rG   r?   s    r   describez_Stat.describex   s>    ::?AHHnn**** I 
 	
r   c                 l    dj                  | j                  j                  | j                               S )Nz{clsname}({describe}))clsnamerJ   )r3   	__class__r4   rJ   r?   s    r   __repr__z_Stat.__repr__   s0    &--NN++]]_ . 
 	
r   N)
r4   
__module____qualname____doc__rA   propertyrD   rG   rJ   rN    r   r   r9   r9   h   s<    C    

r   r9   c                 (    t        d | D               S )Nc              3   >   K   | ]  }|j                  d         yw)r&   N)r,   .0xs     r   	<genexpr>z(filter_private_module.<locals>.<genexpr>   s     @.?1<<$.?s   anymodule_componentss    r   filter_private_moduler^      s    @.?@@@@r   c                 (    t        d | D               S )Nc              3   &   K   | ]	  }|d k(    yw)testsNrS   rV   s     r   rY   z&filter_tests_module.<locals>.<genexpr>   s     ;):A1<):s   rZ   r\   s    r   filter_tests_modulerb      s    ;):;;;;r   c              #     K   d }| j                   dz   }t        j                  | j                  ||      }fd}| j                   } ||      s|  |D ]t  }|d   } ||      rt	               5  	 t        |      }|j                  d      dd D ]  }		 t        ||	      } ddd       t        t        j                        sq| v y# t        $ r Y ddd       w xY w# t        $ r d}Y  Ow xY w# 1 sw Y   TxY ww)zSYield all modules in a given package.

    Recursively walks the package tree.
    c                      y rC   rS   )r&   s    r   <lambda>z)list_modules_in_package.<locals>.<lambda>   s    tr   .)onerrorc                 P    | j                  d      t        fdD              S )Nrf   c              3   0   K   | ]  } |         y wrC   rS   )rW   	filter_fnr]   s     r   rY   z@list_modules_in_package.<locals>.check_filter.<locals>.<genexpr>   s"      4$2y !!233$2s   )splitr[   )modnamer]   module_filterss    @r   check_filterz-list_modules_in_package.<locals>.check_filter   s,    #MM#. 4$2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
 G !!*  )
  c*12.!#t,C / " #w112	5 "    & C sl   A/D2C84C?C8C&#C8%*D	C#C8	D"C##C8&C5	1C84C5	5C88D	=Dc                       e Zd ZdZd Zd Zy)	FormatterzBase class for formatters.
    c                     || _         y rC   )_fileobj)r@   fileobjs     r   rA   zFormatter.__init__   s	    r   c                 R    |j                  d| j                         t        |i | y )Nfile)
setdefaultr   print)r@   argskwargss      r   r   zFormatter.print   s#    &$--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
y	)
HTMLFormatterz Formatter that outputs HTML
    c                 ,    dd l }|j                  |      S r;   )htmlescape)r@   textr   s      r   r   zHTMLFormatter.escape   s    {{4  r   c                 *    | j                  d|d       y )Nz<h1></h2>r   r@   r   s     r   titlezHTMLFormatter.title   s    

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

67G,

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

7r   c                 d   | j                  d       | j                  dj                  ||             | j                  dj                  |             | j                  d|d       | j                  d       |j                         D ]  \  }}|r| j                  d       |d   }	|d   }
|d	   }|d
   }| j                  dj                  | j                  |	      | j                  |
      | j                  |      |d   |d                | j                  dj                  | j                  |d   xs d                   n8| j                  dj                  | j                  t	        |                         | j                  d        | j                  d       | j                  d       y )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   sn   

6

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

=''12

<N;

6#MMOLD&

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

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

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

8??4;;s4y+ABCJJw% ,& 	

7

7r   c                     | j                  d       | j                  dj                  ||             | j                  d       y )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                 `    | j                  dj                  |j                                      y )Nr   )r   r3   rJ   )r@   statss     r   write_statisticzHTMLFormatter.write_statistic  s     

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

4

3T?#

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

7

3W%&

r   c                 $    | j                          y rC   r   r?   s    r   r   z ReSTFormatter.end_module_section$  s    

r   c                 X   | j                  dj                  ||             | j                  d       | j                          |r | j                  dj                  |             | j                          |j                         D ]  \  }}|rc|d   }	|d   }
|d   }|d   }t        j                  t        ||d   |d	   
      }| j                  dj                  |	|
||d   |d	   |             k| j                  dj                  t        |                    | j                          y )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'  s   

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

>"

JJ,33E:;

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

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

3::3t9EF' ,( 	

r   c                      y rC   rS   r   s      r   r   z$ReSTFormatter.write_unsupported_itemG  s    r   c                    |j                   dk(  r| j                  d       n[d}| j                  |j                  |j                               | j                          | j                  |j	                                | j                          y )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9CJJszz$"2"234JJLJJt}}'

r   Nr   rS   r   r   r   r     s+    

@r   r   c                    | j                  dj                  |             i }|D ]a  }t               }|j                  }| j	                  | j                  |             t        |||      D ]  }|d   }	|	|xj                  dz  c_        | j                  | j                  |d   j                        | j                  |d         | j                  t        |	            | j                  |d         |d	   |j                  d
             |xj                  dz  c_        | j                  | j                  |d   j                        | j                  |d                 | j                  |       | j                          d y)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  sh    OO%,,\:;Iw,,&&y'7'7'@A"3vYGD,'F!!#..%,,T(^-D-DE&--d6l;&--c&k:'..tK/@A 0((7+ /    A% 00%,,T(^-D-DE&--d6l; 1  H( 	!!$'$$&3 r   c                    t        |       }t        |d      rt        |      }n|g}|dk(  r2t        |dz   d      5 }t	        |      }t        || |       ddd       y|dk(  r2t        |dz   d      5 }t        |      }t        || |       ddd       yt        d	j                  |            # 1 sw Y   yxY w# 1 sw Y   yxY w)
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I 	I +* *)s   B/2B;/B8;Cz6
Inspect Numba support for a given top-level package.
c                  @   t        j                  t              } | j                  ddt        d       | j                  dddd	       | j                  d
ddd	       | j                         }|j                  }|j                  }|j                  }t        |||       y )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EF
93!   60   v'9G  
 D<<LKKMyyH<=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<
   5L 1h <9I <9~>I >B'BI>	EG 
:, zF r   