U
    ?h-                     @   s   d Z ddlmZ ddlZzddlmZ W n  ek
rH   ddlmZ Y nX ddlm	Z	 ddl
Z
ddlmZ ddlZddlmZ dd	 Zd
d Zdd Zdd Zdd ZdZdZdd ZdddZedkre  dS )z`
Generate documentation for all registered implementation for lowering
using reStructured text.
    )check_outputN)StringIO)defaultdict)partial)
cpu_targetc                  C   s"   t dddddg} | ddS )Ngitlogz--pretty=format:'%H'z-n1ascii'")r   decodestrip)out r   V/var/www/html/venv/lib/python3.8/site-packages/numba/scripts/generate_lower_listing.pygit_hash   s    r   c                 C   s   t | d| jS )N__qualname__)getattr__name__)fnr   r   r   get_func_name   s    r   c                 C   s   t t}tjtjtj}| j D ]\}}|j	D ]v\}}i }|| 
| ||d< ||d< t|\}}	t|}
t|tjj|
|d|	|	t| d f|jd|d< q6q(|S )Nr   sig)start   )namefilenamelinesZ	docstringimpl)r   listospathdirnamenumba__file__Z_defnsitemsversionsappendinspectgetsourcelinesgetsourcefiler   relpathlen__doc__)backendfninfosZbasepathr   Zoselr   r   infocodeZfirstlinenor    r   r   r   gather_function_info   s     
r1   c                 C   s   t t| dS )Nfile)r   print)fobjr   r   r   bind_file_to_print4   s    r6   c                 C   s&   dd }t t|| }dd|S )Nc                 S   s0   z| j W S  tk
r*   t| d Y S X d S )Nr   )r   AttributeErrorreprr   )cr   r   r   fmt9   s    zformat_signature.<locals>.fmtz`({0})`z, )tuplemapformatjoin)r   r:   r   r   r   r   format_signature8   s    r?   zLhttps://github.com/numba/numba/blob/{commit}/{path}#L{firstline}-L{lastline}a8  
This lists all lowering definition registered to the CPU target.
Each subsection corresponds to a Python function that is supported by numba
nopython mode. These functions have one or more lower implementation with
different signatures. The compiler chooses the most specific implementation
from all overloads.
c                 C   s:  t  }z"t|}d}|| |dt|  |t t }dd }tt|| dd dD ]\}}| | }d|}	||	 |d	t|	  |  td
d |}
tt	|
|dd d}dg}dg}|D ]t\}}|d }|d }|d }|d }dj|f| }t
j|||d |d d}d|||}|| || qttt|}ttt|}d}|d | }|d | }d||}||d| d|  |||d |d  ||d| d|  t	|dd  |dd  D ]\}}|||| q||d| d|  |  qZ| W S |  X d S )NzLowering Listing=c                 S   s<   zd | jt| }W n tk
r2   t| }Y nX | |fS )Nz{0}.{1})r=   
__module__r   r7   r8   )r   fnamer   r   r   format_fname[   s
    z+format_function_infos.<locals>.format_fnamec                 S   s   | d S )Nr   r   xr   r   r   <lambda>b       z'format_function_infos.<locals>.<lambda>)keyz``{0}``-c                 S   s   t | d S )Nr   )r?   rD   r   r   r   rF   j   rG   c                 S   s   | d S )Nr   r   rD   r   r   r   rF   l   rG   	SignatureZ
Definitionr   r   r   r   z{0} lines {1}-{2}r   r   )commitr    	firstlinelastlinez``{0}`` `{1} <{2}>`_   z{{0:^{0}}}  {{1:^{1}}})r   closer6   r+   descriptionr   sortedr<   r=   zip
github_urlr&   maxgetvalue)r.   bufr4   Z
title_linerK   rC   r   rB   ZimpinfosZheader_lineZformatted_sigsZsorted_impinfosZcol_signaturesZcol_urlsZfmtsigr/   r   r   r   sourcelinkurlZmax_width_col_sigZmax_width_col_urlpaddingZwidth_col_sigZwidth_col_urlZline_formatr   r   r   r   format_function_infosN   sl     
 
 
"r[   c              	   C   sV   t j}|  t|}t|}| dkr0t| n"t| d}t||d W 5 Q R X dS )zG
    Generate lowering listing to ``path`` or (if None) to stdout.
    Nwr2   )r   Ztarget_contextrefreshr1   r[   r4   open)r    Zcpu_backendr.   r   r5   r   r   r   gen_lower_listing   s    
r_   __main__)N)r,   
subprocessr   os.pathr   r   ImportErroriocollectionsr   r'   	functoolsr   r"   Znumba.core.registryr   r   r   r1   r6   r?   rS   rP   r[   r_   r   r   r   r   r   <module>   s,   
	I
