o
    1 i                  
   @   s  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mZm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZ d dlmZ eeZeded	ef d
Ze	d%dede
e dedefddZddde	eee
e f  de
e fddZddde	eee
e f  de
e fddZede	eee
e f  deegef fddZdefddZdefddZ ed&d e
e defd!d"Z!ed&d e
e defd#d$Z"dS )'    Nwraps)AnyCallableIterableOptionalTypeVarUnion)Version)tabulate)DeveloperAPI)TemplateF.)boundnoneobjtitle
max_heightreturnc                 C   s   i }t |  D ]>\}}t|ttttfrt|||< qt|ts&t|drFt	dj
tt|tr4| nt | ddddgddd	||< qt	dj
t| d
dddgd|d	}|rgt	dj
||d}|S |}|S )a]  Generate a generic html repr using a table.

    Args:
        obj: Object for which a repr is to be generated
        title: If present, a title for the section is included
        max_height: Maximum height of the table; valid values
            are given by the max-height CSS property

    Returns:
        HTML representation of the object
    __dict__zscrollableTable.html.j2htmlFZSettingValue)ZtablefmtZ	showindexheadersr   )tabler   Z
unsafehtmlztitle_data.html.j2)r   data)varsitems
isinstancestrboolintfloatdicthasattrr   renderr   )r   r   r   r   kvr   content r(   \/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/ray/widgets/util.pymake_table_html_repr   s:   


r*   )messagedepsr+   c                 G   sd   g }|D ]\}}t j|du r|| q|r0| s#dd| d} tjd| d|  dd |S )	zReturn a list of missing dependencies.

    Args:
        deps: Dependencies to check for
        message: Message to be emitted if a dependency isn't found

    Returns:
        A list of dependencies which can't be found, if any
    NzRun `pip install  ` for rich notebook output.zMissing packages: z.    
stacklevel)	importlibutil	find_specappendjoinloggerinfo)r+   r,   missinglib_r(   r(   r)   _has_missingD   s   
r<   c              
   G   s   g }|D ](\}}zt |}|r"t|jt|k r"||||jg W q ty,   Y qw |rxg }g }|D ]\}}}|| d| d| d|  || d|  q5td|d}	d|}
| skd|
 d} t	j
d	|	 d|  d
d |S )Nz==z found, needs z>=
z  r-   zRun `pip install -U r.   zOutdated packages:
r/   r0   )r2   import_moduler
   __version__r5   ImportErrortextwrapindentr6   r7   r8   )r+   r,   Zoutdatedr:   versionmoduleZoutdated_strsinstall_args	installedZoutdated_strZinstall_strr(   r(   r)   _has_outdated`   s,   
 
rG   notebook_depsc                  G   s>   d}t | d|irdtdtfdd}|S dtdtfdd}|S )a  Decorator which strips rich notebook output from mimebundles in certain cases.

    Fallback to plaintext and don't use rich output in the following cases:
    1. In a notebook environment and the appropriate dependencies are not installed.
    2. In a ipython shell environment.
    3. In Google Colab environment.
        See https://github.com/googlecolab/colabtools/ issues/60 for more information
        about the status of this issue.

    Args:
        notebook_deps: The required dependencies and version for notebook environment.

    Returns:
        A function that returns the usual _repr_mimebundle_, unless any of the 3
        conditions above hold, in which case it returns a mimebundle that only contains
        a single text/plain mimetype.
    z[Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.r+   funcr   c                    s   t   fdd}|S )Nc                    s    | g|R i |S Nr(   selfargskwargsrI   r(   r)   wrapped   s   4repr_with_fallback.<locals>.wrapper.<locals>.wrappedr   rI   rP   r(   rO   r)   wrapper   s   z#repr_with_fallback.<locals>.wrapperc                 S   s   t | dd }|S )Nc                 _   s   dt | iS )Nz
text/plain)reprrK   r(   r(   r)   rP      s   rQ   r   rR   r(   r(   r)   rS      s   
)_can_display_ipywidgetsr   )rH   r+   rS   r(   r(   r)   repr_with_fallback   s   rV   c                  C   s$   dt jv rddlm}  |  jjS dS )NIPythonr   get_ipython )sysmodulesrW   rY   	__class____name__rX   r(   r(   r)   _get_ipython_shell_name   s   

r_   c                 G   s*   t  rt|d| ist|d| isdS dS )Nr+   TF)in_notebookr<   rG   )r+   r,   r(   r(   r)   rU      s   rU   
shell_namec                 C      | st  } | dkS )z9Return whether we are in a Jupyter notebook or qtconsole.ZMQInteractiveShellr_   ra   r(   r(   r)   r`         r`   c                 C   rb   )z3Return whether we are in a terminal running IPythonTerminalInteractiveShellrd   re   r(   r(   r)   in_ipython_shell   rf   rh   )Nr   rJ   )#r2   loggingr[   rA   	functoolsr   typingr   r   r   r   r   r	   Zpackaging.versionr
   Z)ray._private.thirdparty.tabulate.tabulater   Zray.util.annotationsr   Zray.widgetsr   	getLoggerr^   r7   r   r   r*   r<   rG   rV   r_   r   rU   r`   rh   r(   r(   r(   r)   <module>   s^     
1

!-