o
    -wi?                     @  sn  d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
 ddlZddlmZ ddlZddlZddlmZ ddlmZ dd	lmZmZ d
ZeZdZdZeZdZdZdZedededededediZeeeeeeeedZ dZ!	 dZ"	 dZ#dZ$d+d,ddZ%G d d dej&Z'G d!d" d"ej&Z(G d#d$ d$e'Z)G d%d& d&e(Z*G d'd( d(e'Z+G d)d* d*e(Z,dS )-z*Terminal, Jupyter and file output for W&B.    )annotationsN)CallableIterator)override)term)wandb_setup   )ipython	sparkline2   (         
   CRITICALERRORWARNINGINFODEBUGNOTSET)r   FATALr   WARNr   r   r   r   u   ⢿⣻⣽⣾⣷⣯⣟⡿   a  
    <style>
        table.wandb td:nth-child(1) {
            padding: 0 10px;
            text-align: left;
            width: auto;
        }

        table.wandb td:nth-child(2) {
            text-align: left;
            width: 100%;
        }
    </style>
a  
    <style>
        .wandb-row {
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
            justify-content: flex-start;
            width: 100%;
        }
        .wandb-col {
            display: flex;
            flex-direction: column;
            flex-basis: 100%;
            flex: 1;
            padding: 10px;
        }
    </style>
settingswandb.Settings | NonereturnPrinterc                 C  s2   | st   }r|j} t rt| dS t| dS )a  Returns a printer appropriate for the environment we're in.

    Args:
        settings: The settings of a run. If not provided and `wandb.setup()`
            has been called, then global settings are used. Otherwise,
            settings (such as silent mode) are ignored.
    )r   )r   singleton_if_setupr   r	   
in_jupyter_PrinterJupyter_PrinterTerm)r   	singleton r"   R/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/sdk/lib/printer.pynew_printera   s
   

r$   c                   @  sF  e Zd ZdZejejd@ddZejdddAddZ	ej	dBdCddZ
ejdBdDddZedEddZeejdFddZeejdFddZdGd"d#ZejdHd$d%ZejdHd&d'ZejdBdId)d*ZejdHd+d,ZejdJd.d/ZejdHd0d1ZejdKd3d4ZejdHd5d6ZejdBdLd:d;ZejdMd>d?ZdS )Nr   z-An object that shows styled text to the user.r   Iterator[DynamicText | None]c                 C     dS )a  A context manager providing a handle to a block of changeable text.

        Since `wandb` may be outputting to a terminal, it's important to only
        use this when `wandb` is performing blocking calls, or else text output
        by non-`wandb` code may get overwritten.

        Returns None if dynamic text is not supported, such as if stderr is not
        a TTY and we're not in a Jupyter notebook.
        Nr"   selfr"   r"   r#   dynamic_textu       zPrinter.dynamic_textNleveltextstr | list[str] | tuple[str]r,   str | int | NoneNonec                C  r&   )zDisplay text to the user.

        Args:
            text: The text to display. If given an iterable of strings, they're
                joined with newlines.
            level: The logging level, for controlling verbosity.
        Nr"   r(   r-   r,   r"   r"   r#   display   r*   zPrinter.displaystrpercent_donefloat | Nonec                 C  r&   )zSet the text on the progress indicator.

        Args:
            text: The text to set, which must end with \r.
            percent_done: The current progress, between 0 and 1.
        Nr"   r(   r-   r4   r"   r"   r#   progress_update   r*   zPrinter.progress_update
str | Nonec                 C  r&   )zClose the progress indicator.

        After this, `progress_update` should not be used.

        Args:
            text: The final text to set on the progress indicator.
                Ignored in Jupyter notebooks.
        Nr"   r(   r-   r"   r"   r#   progress_close   r*   zPrinter.progress_closename_or_levelintc              	   C  sh   t | tr zt|   W S  ty   td|  dt  w t | tr'| S | du r-tS td|  )zReturns the number corresponding to the logging level.

        Args:
            name_or_level: The logging level passed to `display`.

        Raises:
            ValueError: if the input is not a valid logging level.
        zUnknown level name: z, supported levels: NzUnknown status level )	
isinstancer3   _name_to_levelupperKeyError
ValueErrorkeysr<   r   )r;   r"   r"   r#   _sanitize_level   s   


zPrinter._sanitize_levelboolc                 C  r&   )z8Whether text passed to display may contain HTML styling.Nr"   r'   r"   r"   r#   supports_html   r*   zPrinter.supports_htmlc                 C  r&   )z=Whether text passed to display may contain arbitrary Unicode.Nr"   r'   r"   r"   r#   supports_unicode   r*   zPrinter.supports_unicodeserieslist[int | float]c                 C  s   | j rt|S dS )zReturns a Unicode art representation of the series of numbers.

        Also known as "ASCII art", except this uses non-ASCII
        Unicode characters.

        Returns None if the output doesn't support Unicode.
        N)rF   r
   sparkify)r(   rG   r"   r"   r#   
sparklines   s   
zPrinter.sparklinesc                 C  r&   )z"Returns the text styled like code.Nr"   r9   r"   r"   r#   code   r*   zPrinter.codec                 C  r&   )z(Returns the text styled like a run name.Nr"   r9   r"   r"   r#   name   r*   zPrinter.namelinkc                 C  r&   )a  Returns the text styled like a link.

        Args:
            link: The target link.
            text: The text to show for the link. If not set, or if we're not
                in an environment that supports clickable links,
                this is ignored.
        Nr"   r(   rM   r-   r"   r"   r#   rM      r*   zPrinter.linkc                 C  r&   )z/Returns the text styled to draw less attention.Nr"   r9   r"   r"   r#   secondary_text   r*   zPrinter.secondary_texttickc                 C  r&   )zReturns a frame of an animated loading symbol.

        May return an empty string.

        Args:
            tick: An index into the animation.
        Nr"   r(   rP   r"   r"   r#   loading_symbol   r*   zPrinter.loading_symbolc                 C  r&   )z'Returns the text colored like an error.Nr"   r9   r"   r"   r#   error   r*   zPrinter.errorrL   c                 C  r&   )z9Returns the string for a named emoji, or an empty string.Nr"   r(   rL   r"   r"   r#   emoji   r*   zPrinter.emojic                 C  r&   )z)Returns the text styled like a file path.Nr"   r9   r"   r"   r#   files  r*   zPrinter.filesrowslist[list[str]]titlec                 C  r&   )z1Returns a grid of strings with an optional title.Nr"   )r(   rW   rY   r"   r"   r#   grid  r*   zPrinter.gridcolumns	list[str]c                 C  r&   )z2Returns the column text combined in a compact way.Nr"   r(   r[   r"   r"   r#   panel  r*   zPrinter.panelr   r%   r-   r.   r,   r/   r   r0   Nr-   r3   r4   r5   r   r0   r-   r8   r   r0   )r;   r/   r   r<   r   rD   )rG   rH   r   r8   r-   r3   r   r3   rM   r3   r-   r8   r   r3   rP   r<   r   r3   rL   r3   r   r3   rW   rX   rY   r8   r   r3   r[   r\   r   r3   )__name__
__module____qualname____doc__
contextlibcontextmanagerabcabstractmethodr)   r2   r7   r:   staticmethodrC   propertyrE   rF   rJ   rK   rL   rM   rO   rR   rS   rU   rV   rZ   r^   r"   r"   r"   r#   r   r   sT    


	c                   @  s    e Zd ZdZejd	ddZdS )
DynamicTextz5A handle to a block of text that's allowed to change.r-   r3   r   r0   c                 C  r&   )a^  Change the text.

        Args:
            text: The text to put in the block, with lines separated
                by \n characters. The text should not end in \n unless
                a blank line at the end of the block is desired.
                May include styled output from methods on the Printer
                that created this.
        Nr"   r9   r"   r"   r#   set_text  r*   zDynamicText.set_textNr-   r3   r   r0   )rk   rl   rm   rn   rq   rr   rv   r"   r"   r"   r#   ru     s    ru   c                      s*  e Zd Zd? fddZeejd@dd	Zed
ddAddZe	dBdCddZ
edBdDddZedBdEddZeedFddZeedFd d!ZedGd"d#ZedGd$d%ZedBdHd'd(ZedId*d+ZedGd,d-ZedJd0d1ZedGd2d3ZedGd4d5ZedBdKd9d:ZedLd=d>Z  ZS )Mr    r   r   r   r0   c                  s$   t    || _tg d| _d S )N)-\|/)super__init__	_settings	itertoolscycle	_progress)r(   r   	__class__r"   r#   r}   !  s   
z_PrinterTerm.__init__r%   c                 c  sn    | j r| j jrd V  d S t }|sd V  nt|V  W d    d S W d    d S 1 s0w   Y  d S ra   )r~   silentr   r)   _DynamicTermTextr(   handler"   r"   r#   r)   &  s   
"z_PrinterTerm.dynamic_textNr+   r-   r.   r,   r/   c                C  s@   | j r	| j jr	d S t|ttfrd|n|}| || d S N
)r~   r   r=   listtuplejoin_display_fn_mappingr1   r"   r"   r#   r2   3  s   z_PrinterTerm.displayCallable[[str], None]c                 C  s   t | } | tkrtjS t|   krtk rtjS  t|   kr%tk r&tjS  t|   kr2tk r3tj	S  t
|   kr?tk rCtj	S  tj	S tj	S ra   )r   rC   r   wandb	termerrorr   r   termwarnr   termlogr   r+   r"   r"   r#   r   @  s    
z _PrinterTerm._display_fn_mappingr3   r4   r5   c                 C  s4   | j r	| j jr	d S tjt| j d| dd d S )N F)newline)r~   r   r   r   nextr   r6   r"   r"   r#   r7   Q  s   "z_PrinterTerm.progress_updater8   c                 C  s(   | j r	| j jr	d S |pd}t| d S )NzO                                                                               )r~   r   r   r   r9   r"   r"   r#   r:   X  s   z_PrinterTerm.progress_closerD   c                 C  r&   )NFr"   r'   r"   r"   r#   rE   `     z_PrinterTerm.supports_htmlc                 C  s   t jtjS ra   )r   utilis_unicode_safesysstderrr'   r"   r"   r#   rF   e  s   z_PrinterTerm.supports_unicodec                 C     t j|dd}|S )NT)boldclickstyler(   r-   retr"   r"   r#   rK   j     z_PrinterTerm.codec                 C  r   )Nyellowfgr   r   r"   r"   r#   rL   o  r   z_PrinterTerm.namerM   c                 C  s   t j|ddd}|S )NblueT)r   	underliner   )r(   rM   r-   r   r"   r"   r#   rM   t  s   z_PrinterTerm.linkrL   c                 C  s@   t  }t dkrtjtjrt ddddddd}||d	S )
NWindowsu   ⭐️u   🧹u   🚀u   🦍u   🐢u   ️⚡)starbroomrocketgorillaturtle	lightning )	dictplatformsystemr   r   r   r   stdoutget)r(   rL   emojisr"   r"   r#   rU   {  s   	z_PrinterTerm.emojic                 C     t j|ddS )Nwhiter   r   r9   r"   r"   r#   rO     s   z_PrinterTerm.secondary_textrP   r<   c                 C  s(   | j sdS |tt }tjt| tdS )Nr   r   )rF   len_PROGRESS_SYMBOL_ANIMATIONr   r   _PROGRESS_SYMBOL_COLOR)r(   rP   idxr"   r"   r#   rR     s   z_PrinterTerm.loading_symbolc                 C  r   )Nredr   r   r9   r"   r"   r#   rS        z_PrinterTerm.errorc                 C  s   t j|ddd}|S )NmagentaT)r   r   r   r   r"   r"   r#   rV     s   z_PrinterTerm.filesrW   rX   rY   c                   sh   t dd |D dddt|d d  g d fd	d
|D }|r/| d| dS | dS )Nc                 s  s    | ]	}t |d  V  qdS )r   N)r   .0rowr"   r"   r#   	<genexpr>  s    z$_PrinterTerm.grid.<locals>.<genexpr>r   z{:>{max_len}}z{}r   r   r   c                   s   g | ]
} j |d iqS )max_lenformatr   
format_rowr   r"   r#   
<listcomp>  s    z%_PrinterTerm.grid.<locals>.<listcomp>)maxr   r   r(   rW   rY   rZ   r"   r   r#   rZ     s   
z_PrinterTerm.gridr[   r\   c                 C  s   dd | S r   )r   r]   r"   r"   r#   r^     r   z_PrinterTerm.panelr   r   r   r0   r_   r`   ra   )r,   r/   r   r   rb   rc   rd   re   rf   rh   rg   ri   rj   )rk   rl   rm   r}   r   ro   rp   r)   r2   rs   r   r7   r:   rt   rE   rF   rK   rL   rM   rU   rO   rR   rS   rV   rZ   r^   __classcell__r"   r"   r   r#   r       sP    
r    c                   @  s$   e Zd ZdddZedd	d
ZdS )r   r   term.DynamicBlockr   r0   c                 C  s
   || _ d S ra   )_handler   r"   r"   r#   r}     s   
z_DynamicTermText.__init__r-   r3   c                 C  s   | j | d S ra   )r   rv   r9   r"   r"   r#   rv     s   z_DynamicTermText.set_textN)r   r   r   r0   rw   rk   rl   rm   r}   r   rv   r"   r"   r"   r#   r     s    
r   c                      s  e Zd Zd< fddZeejd=dd	Zed
dd>ddZe	ed?ddZ
e	ed?ddZed@ddZed@ddZedAdBddZedCd!d"Zed@d#d$ZedDd'd(Zed@d)d*Zed@d+d,Ze	
dAdEd/d0ZedAdFd1d2ZedAdGd6d7ZedHd:d;Z  ZS )Ir   r   r   r   r0   c                  s0   t    || _t | _ddlm} || _d S Nr   )r2   )	r|   r}   r~   r	   jupyter_progress_barr   IPythonr2   _ipython_display)r(   r   r2   r   r"   r#   r}     s
   


z_PrinterJupyter.__init__r%   c                 c  s`    | j r| j jrd V  d S | jj| jddd}|r+t|V  || jd d S d V  d S )Nr   T)
display_id)r~   r   r   r2   HTML_DynamicJupyterTextupdater   r"   r"   r#   r)     s   


z_PrinterJupyter.dynamic_textNr+   r-   r.   r,   r/   c                C  sT   | j r	| j jr	d S t|ttfrd|n|}d| }| j| j	| d S Nz<br>)
r~   r   r=   r   r   r   
splitlinesr   r2   r   r1   r"   r"   r#   r2     s
   z_PrinterJupyter.displayrD   c                 C  r&   NTr"   r'   r"   r"   r#   rE     r   z_PrinterJupyter.supports_htmlc                 C  r&   r   r"   r'   r"   r"   r#   rF     r   z _PrinterJupyter.supports_unicoder3   c                 C  s   d| dS )N<code>r"   r9   r"   r"   r#   rK        z_PrinterJupyter.codec                 C     d| dS )Nz<strong style="color:#cdcd00">	</strong>r"   r9   r"   r"   r#   rL     r   z_PrinterJupyter.namerM   r8   c                 C  s   d|d|p| dS )Nz<a href=z target="_blank">z</a>r"   rN   r"   r"   r#   rM     s   z_PrinterJupyter.linkrL   c                 C  r&   Nr   r"   rT   r"   r"   r#   rU        z_PrinterJupyter.emojic                 C  s   |S ra   r"   r9   r"   r"   r#   rO     r   z_PrinterJupyter.secondary_textrP   r<   c                 C  r&   r   r"   rQ   r"   r"   r#   rR     r   z_PrinterJupyter.loading_symbolc                 C  r   )Nz<strong style="color:red">r   r"   r9   r"   r"   r#   rS     r   z_PrinterJupyter.errorc                 C  r   )Nr   z</code>r"   r9   r"   r"   r#   rV     r   z_PrinterJupyter.filesr4   r5   c                 C  s6   | j r| j js
| jsd S |d u rd}| j|| d S )Ng      ?)r~   r   r   r   r6   r"   r"   r#   r7     s
   z_PrinterJupyter.progress_updatec                 C  s   | j r
| j   d S d S ra   )r   closer9   r"   r"   r#   r:     s   z_PrinterJupyter.progress_closerW   rX   rY   c                   sd   d ddt|d  dg d  fdd|D }d| d	}|r+d
| d| dS t | dS )Nr   z<tr>z<td>{}</td>r   z</tr>c                   s   g | ]} j | qS r"   r   r   r   r"   r#   r   %  s    z(_PrinterJupyter.grid.<locals>.<listcomp>z<table class="wandb">z</table>z<h3>z
</h3><br/>z<br/>)r   r   _JUPYTER_TABLE_STYLESr   r"   r   r#   rZ   "  s   z_PrinterJupyter.gridr[   r\   c                 C  s$   d dd |D }t d| dS )Nr   c                 S  s   g | ]}d | dqS )z<div class="wandb-col"></div>r"   )r   colr"   r"   r#   r   -  s    z)_PrinterJupyter.panel.<locals>.<listcomp>z<div class="wandb-row">r   )r   _JUPYTER_PANEL_STYLES)r(   r[   r   r"   r"   r#   r^   +  s   z_PrinterJupyter.panelr   r_   r`   rd   re   ra   rf   rh   rg   rb   rc   ri   rj   )rk   rl   rm   r}   r   ro   rp   r)   r2   rt   rE   rF   rK   rL   rM   rU   rO   rR   rS   rV   r7   r:   rZ   r^   r   r"   r"   r   r#   r     sN    	r   c                   @  s$   e Zd Zd
ddZedddZd	S )r   r   r0   c                 C  s   ddl m} |j| _|| _d S r   )r   r2   r   _ipython_to_htmlr   )r(   r   r2   r"   r"   r#   r}   2  s   
z_DynamicJupyterText.__init__r-   r3   c                 C  s$   d | }| j| | d S r   )r   r   r   r   r   r9   r"   r"   r#   rv   8  s   z_DynamicJupyterText.set_textN)r   r0   rw   r   r"   r"   r"   r#   r   1  s    
r   ra   )r   r   r   r   )-rn   
__future__r   rq   ro   r   r   r   typingr   r   r   typing_extensionsr   r   
wandb.utilwandb.errorsr   	wandb.sdkr   r   r	   r
   r   r   r   r   r   r   r   r   _level_to_namer>   r   r   r   r   r$   ABCr   ru   r    r   r   r   r"   r"   r"   r#   <module>   sl    
  	v