o
    ci                  
   @   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htmlFSettingValue)tablefmt	showindexheadersr   )tabler   
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,   D/home/ubuntu/.local/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/   r0   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  r1   zRun `pip install -U r2   zOutdated packages:
r3   r4   )r6   import_moduler
   __version__r9   ImportErrortextwrapindentr:   r;   r<   )r/   r0   outdatedr>   versionmoduleoutdated_strsinstall_args	installedoutdated_strinstall_strr,   r,   r-   _has_outdated`   s,   
 
rO   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rQ   r,   r-   wrapped   s   4repr_with_fallback.<locals>.wrapper.<locals>.wrappedr   rQ   rX   r,   rW   r-   wrapper   s   z#repr_with_fallback.<locals>.wrapperc                 S   s   t | dd }|S )Nc                 _   s   dt | iS )Nz
text/plain)reprrS   r,   r,   r-   rX      s   rY   r   rZ   r,   r,   r-   r[      s   
)_can_display_ipywidgetsr   )rP   r/   r[   r,   r,   r-   repr_with_fallback   s   r^   c                  C   s$   dt jv rddlm}  |  jjS dS )NIPythonr   get_ipython )sysmodulesr_   ra   	__class____name__r`   r,   r,   r-   _get_ipython_shell_name   s   

rg   c                 G   s*   t  rt|d| ist|d| isdS dS )Nr/   TF)in_notebookr@   rO   )r/   r0   r,   r,   r-   r]      s   r]   
shell_namec                 C      | st  } | dkS )z9Return whether we are in a Jupyter notebook or qtconsole.ZMQInteractiveShellrg   ri   r,   r,   r-   rh         rh   c                 C   rj   )z3Return whether we are in a terminal running IPythonTerminalInteractiveShellrl   rm   r,   r,   r-   in_ipython_shell   rn   rp   )Nr   rR   )#r6   loggingrc   rE   	functoolsr   typingr   r   r   r   r   r	   packaging.versionr
   )ray._private.thirdparty.tabulate.tabulater   ray.util.annotationsr   ray.widgetsr   	getLoggerrf   r;   r   r"   r.   r@   rO   r^   rg   r#   r]   rh   rp   r,   r,   r,   r-   <module>   s^     
1

!-