o
    -wi/                     @  s  U 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Zddl	Z	ddl
mZmZmZ ddlZer9ddlZejddddZdZejd	d
ddZejdddZdaded< 	 daded< 	 daded< 	 daded< 	 daded< 	 e Zded< 	 e	 Z	 g Zded< 	 G dd deZ dLd#d$Z!ej"dMd&d'Z#dNd(d)Z$	*			dOdPd0d1Z%			dQdPd2d3Z&			dQdPd4d5Z'G d6d7 d7Z(dRd9d:Z)e*d;Z+dSd>d?Z,dSd@dAZ-d*ddddej.fdTdBdCZ/dTdDdEZ0ej"dFdG Z1dTdHdIZ2dTdJdKZ3dS )Uz2Global functions for printing to stderr for wandb.    )annotationsN)TYPE_CHECKINGIteratorProtocolwandbblueT)fgboldERRORredgreen)bgr   WARNINGyellow)r   Fbool_silentSupportsLeveledLogging | None_logger
_show_info_show_warnings_show_errorszset[str]_printed_messageszlist[DynamicBlock]_dynamic_blocksc                   @  s.   e Zd ZdZdddZddd	Zdd
dZdS )SupportsLeveledLoggingz;Portion of the standard logging.Logger used in this module.msgstrreturnNonec                 C     d S N selfr   r    r    N/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/errors/term.pyinfo9       zSupportsLeveledLogging.infoc                 C  r   r   r    r!   r    r    r#   warning:   r%   zSupportsLeveledLogging.warningc                 C  r   r   r    r!   r    r    r#   error;   r%   zSupportsLeveledLogging.errorN)r   r   r   r   )__name__
__module____qualname____doc__r$   r&   r'   r    r    r    r#   r   6   s
    

r   settingswandb.Settingsloggerr   r   c                 C  s    | j a| ja| ja| ja|adS )a  Configure the global logging functions.

    Args:
        settings: The settings object passed to wandb.setup() or wandb.init().
        logger: A fallback logger to use for "silent" mode. In this mode,
            the logger is used instead of printing to stderr.
    N)	silentr   	show_infor   show_warningsr   show_errorsr   r   )r,   r.   r    r    r#   	termsetup>   s
   r3   Iterator[DynamicBlock | None]c                  c  s    t sts
dV  dS t sdV  dS tjddkrdV  dS t } t t	|  W d   n1 s4w   Y  z$| V  W t g | _
t  t|  W d   dS 1 sWw   Y  dS t g | _
t  t|  W d   w 1 svw   Y  w )a^  A context manager that provides a handle to a new dynamic text area.

    The text goes to stderr. Returns None if dynamic text is not supported.

    Dynamic text must only be used while `wandb` has control of the terminal,
    or else text written by other programs will be overwritten. It's
    appropriate to use during a blocking operation.

    ```
    with term.dynamic_text() as text_area:
        if text_area:
            text_area.set_text("Writing to a terminal.")
            for i in range(2000):
                text_area.set_text(f"Still going... ({i}/2000)")
                time.sleep(0.001)
        else:
            wandb.termlog("Writing to a file or dumb terminal.")
            time.sleep(1)
            wandb.termlog("Finished 1000/2000 tasks, still working...")
            time.sleep(1)
    wandb.termlog("Done!", err=True)
    ```
    NTERMdumb)r   r   _sys_stderr_isattyosenvirongetDynamicBlock_dynamic_text_lockr   append_lines_to_print_l_rerender_dynamic_blocksremoveblockr    r    r#   dynamic_textQ   s2   	(rC   c                   C  s
   t j S )zJReturns sys.stderr.isatty().

    Defined here for patching in tests.
    )sysstderrisattyr    r    r    r#   r7      s   
r7    stringr   newlinerepeatprefixc                 C  s   t | |||t d dS )a  Log an informational message to stderr.

    The message may contain ANSI color sequences and the \n character.
    Colors are stripped if stderr is not a TTY.

    Args:
        string: The message to display.
        newline: Whether to add a newline to the end of the string.
        repeat: If false, then the string is not printed if an exact match has
            already been printed through any of the other logging functions
            in this file.
        prefix: Whether to include the 'wandb:' prefix.
    )rI   rJ   rK   r/   N)_logr   rH   rI   rJ   rK   r    r    r#   termlog   s   
rN   c                 C  6   d dd | dD } t| |||t tjd dS )zQLog a warning to stderr.

    The arguments are the same as for `termlog()`.
    
c                 S     g | ]	}t  d | qS  )WARN_STRING.0sr    r    r#   
<listcomp>       ztermwarn.<locals>.<listcomp>rI   rJ   rK   r/   levelN)joinsplitrL   r   loggingr   rM   r    r    r#   termwarn      

r_   c                 C  rO   )zPLog an error to stderr.

    The arguments are the same as for `termlog()`.
    rP   c                 S  rQ   rR   )ERROR_STRINGrU   r    r    r#   rX      rY   ztermerror.<locals>.<listcomp>rZ   N)r\   r]   rL   r   r^   r
   rM   r    r    r#   	termerror   r`   rb   c                   @  s8   e Zd ZdZdd Zddd	d
ZdddZdddZdS )r;   z3A handle to a changeable text area in the terminal.c                 C  s   g | _ d| _d S )Nr   )r>   _num_lines_printedr"   r    r    r#   __init__   s   
zDynamicBlock.__init__Ttextr   r   r   c                 C  sP   t  | | _|rdd | jD | _t  W d   dS 1 s!w   Y  dS )a@  Replace the text in this block.

        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.
            prefix: Whether to include the "wandb:" prefix.
        c                 S  rQ   z: 
LOG_STRINGrV   liner    r    r#   rX      s    z)DynamicBlock.set_text.<locals>.<listcomp>N)r<   
splitlinesr>   r?   )r"   rf   rK   r    r    r#   set_text   s   	
"zDynamicBlock.set_textc                 C  s&   d}t j|| j tjdd d| _dS )zSend terminal commands to clear all previously printed lines.

        The lock must be held, and the cursor must be on the line after this
        block of text.
        z
[Am[2KFfilenlr   N)clickechorc   rD   rE   )r"   move_up_and_delete_liner    r    r#   _l_clear   s   
zDynamicBlock._l_clearc                   sJ   | j rt  tjd fdd| j D tjd |  jt| j 7  _dS )zFPrint out this block of text.

        The lock must be held.
        rP   c                 3  s    | ]}t | V  qd S r   )_ansi_shortenrj   
term_widthr    r#   	<genexpr>  s
    
z(DynamicBlock._l_print.<locals>.<genexpr>)ro   N)	r>   _shutil_get_terminal_widthrq   rr   r\   rD   rE   rc   lenrd   r    rv   r#   _l_print  s   	zDynamicBlock._l_printN)T)rf   r   r   r   r   r   )r(   r)   r*   r+   re   rm   rt   r{   r    r    r    r#   r;      s    
r;   intc                  C  s   t  \} }| S )zPReturns the width of the terminal.

    Defined here for patching in tests.
    )shutilget_terminal_size)columns_r    r    r#   ry   (  s   ry   z\[(K|.*?m)rf   widthc                 C  sl   t | }|st| |S | |d krt| d|  |S | d|  t| | d ||   S )zBShorten text potentially containing ANSI sequences to fit a width.   N)_ANSI_REsearch_raw_shortenstartendru   )rf   r   
first_ansir    r    r#   ru   4  s   


ru   c                 C  s$   t | |kr| S | d|d  d S )zShorten text to fit a width, replacing the end with "...".

    Unlike textwrap.shorten(), this does not drop whitespace or do anything
    smart.
    Nr   z...)rz   )rf   r   r    r    r#   r   E  s   r   c              	   C  s,  t  t n |s'| tv r	 W d    W d    d S ttdk r't|  |r6ddd | dD } |p9t}|sFtj	| t
j|d n'tsIn$|tjkrWtt|  n|tjkrett|  ntt|  W d    n1 sww   Y  W d    d S W d    d S 1 sw   Y  d S )Ni  rP   c                 S  rQ   rg   rh   rU   r    r    r#   rX   b  rY   z_log.<locals>.<listcomp>rn   )r<   _l_above_dynamic_textr   rz   addr\   r]   r   rq   rr   rD   rE   r   r^   r
   r'   unstyler   r&   r$   )rH   rI   rJ   rK   r/   r[   r    r    r#   rL   Q  s*   


PrL   c                   C  s,   t  	 W d   dS 1 sw   Y  dS )zClear and re-print all dynamic text.

    The lock must be held. The cursor must be positioned at the start of
    the first line after the dynamic text area.
    N)r   r    r    r    r#   r?   q  s   "r?   c                   c  s$    t   z	dV  W t  dS t  w )zA context manager for inserting static text above any dynamic text.

    The lock must be held. The cursor must be positioned at the start of the
    first line after the dynamic text area.

    The dynamic text is re-rendered.
    N)_l_clear_dynamic_blocks_l_print_dynamic_blocksr    r    r    r#   r   |  s
   	r   c                  C  s   t tD ]} |   qdS )zDelete all dynamic text.

    The lock must be held, and the cursor must be positioned at the start
    of the first line after the dynamic text area. After this, the cursor
    is positioned at the start of the first line after all static text.
    N)reversedr   rt   rA   r    r    r#   r     s   
r   c                  C  s   t D ]} |   qdS )zOutput all dynamic text.

    The lock must be held. After this, the cursor is positioned at the start
    of the first line after the dynamic text area.
    N)r   r{   rA   r    r    r#   r     s   
r   )r,   r-   r.   r   r   r   )r   r4   )r   r   )rG   TTT)
rH   r   rI   r   rJ   r   rK   r   r   r   )TTT)r   r}   )rf   r   r   r}   r   r   r|   )4r+   
__future__r   
contextlibr^   r8   rer~   rD   	threadingtypingr   r   r   rq   r   styleri   LOG_STRING_NOCOLORra   rT   r   __annotations__r   r   r   r   setr   Lockr<   r   r   r3   contextmanagerrC   r7   rN   r_   rb   r;   ry   compiler   ru   r   INFOrL   r?   r   r   r   r    r    r    r#   <module>   s    

?	
I
	


 

