o �J�h���@s�ddlmZddlZddlZddlZddlmZmZddlm Z ddl m Z m Z ddl mZddlmZmZddlmZdd lmZdd lmZdd lmZmZdd lmZmZmZdd lmZddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1er�ddl2m3Z3ddl4m5Z5m6Z6ddl7m8Z8m9Z9m:Z:m;Z;ddl<m=Z=ddl>m?Z?ddl@mAZAddlBmCZCddlDmEZEddlFmGZGddlHmIZImJZJddlKmLZLmMZMe+deN�ZOe0d�ZPe"geQfZRe�0de-e!�ZSGdd�de�ZT  !  "  # $ % & ' ( " !d�d�dCdD�ZUGdEdF�dFee!�ZVGdGdH�dHe#eSe&eS�ZWdId!dd"dd#d$d%d&d'd"dJ� d�dNdO�ZXejY P   d�ddId!dd"dd#d$d%d&d'd"dQ� d�d\d]��ZZejY P   d�ddId!dd"dd#d$d%d&d'd"dQ� d�d_d]��ZZ ` P   d�ddId!dd"dd#d$d%d&d'd"dQ� d�dcd]�ZZGddde�dee�Z[Gdfdg�dge[�Z\Gdhdi�die[�Z]Gdjdk�dke[�Z^Gdldm�dme[�Z_Gdndo�doe[�Z`Gdpdq�dqe^�ZaGdrds�dse[�ZbGdtdu�due[�ZcGdvdw�dwe[�ZdGdxdy�dye[�ZeGdzd{�d{e[�ZfGd|d}�d}e[�ZgGd~d�de*�Zhe Gd�d��d���ZiGd�d��d�e?�Zjekd�k�r�ddllZlddlmZmdd�lnmoZodd�lpmqZqdd�lrmsZsdd�lHmJZJesd�d�d!d��ZreJd�d�d��ZHeH�td�d�d��d�eod��d�eHd�d�d�d��d�ereqd��g Zudd�lvmwZweweu�Zxe8d!d��Z7eje]�gej�y��e`��Re7d"d����QZzezj{d�d�d��Z|ezj{d�d�d��Z}ezj{d�dd��Z~ezj�s�ezj�e|d�d��ezj�e}d�d��em��d��el��dd��dk�r�ez��e�ex��ezj�r�Wd�dSWd�dS1�s�wYdSdS)��)� annotationsN)�ABC�abstractmethod��deque)� dataclass�field)� timedelta)� RawIOBase�UnsupportedOperation)�ceil)�mmap)� length_hint)�PathLike�stat)�Event�RLock�Thread)� TracebackType)� TYPE_CHECKING�Any�BinaryIO�Callable�ContextManager�Deque�Dict�Generic�Iterable�List�Literal� NamedTuple�NewType�Optional�TextIO�Tuple�Type�TypeVar�Union)�Self�)�filesize� get_console)�Console�Group� JustifyMethod�RenderableType)� Highlighter)� JupyterMixin)�Live)� ProgressBar)�Spinner)� StyleType)�Column�Table)�Text�TextType�TaskID� ProgressType�_Ics@eZdZdZd�fdd � Zdd d �Zddd�Zddd�Z�ZS)� _TrackThreadz)A thread to periodically update progress.�progress� 'Progress'�task_id�'TaskID'� update_period�floatcs2||_||_||_t�|_d|_t�jdd�dS)NrT)�daemon)r>r@rBr�done� completed�super�__init__)�selfr>r@rB�� __class__��KC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\rich\progress.pyrHCs z_TrackThread.__init__�return�NonecCs~|j}|jj}|j}d}|jj}||�s2|jjjr2|j}||kr)||||�|}||�s2|jjjs|jj |j|jdd�dS)NrT)rF�refresh) r@r>�advancerBrE�wait�live� is_startedrF�update)rIr@rQrBZlast_completedrRrFrLrLrM�runLs�z_TrackThread.run�'_TrackThread'cC� |��|S�N��start�rIrLrLrM� __enter__Z�z_TrackThread.__enter__�exc_type�Optional[Type[BaseException]]�exc_val�Optional[BaseException]�exc_tb�Optional[TracebackType]cCs|j��|��dSrY)rE�set�join�rIr_rarcrLrLrM�__exit__^s  z_TrackThread.__exit__)r>r?r@rArBrC�rNrO)rNrW�r_r`rarbrcrdrNrO) �__name__� __module__� __qualname__�__doc__rHrVr]rh� __classcell__rLrLrJrMr=@s  r=� Working...TF� �bar.back� bar.complete� bar.finished� bar.pulse皙�����?�sequence�Iterable[ProgressType]� description�str�total�Optional[float]rF�int� auto_refresh�bool�console�Optional[Console]� transient�get_time�Optional[Callable[[], float]]�refresh_per_secondrC�styler5�complete_style�finished_style� pulse_stylerB�disable� show_speedrNc cs��|rtd�gng}|�t| | | | d�t|d�tdd�f�t||||||p'd|d��}|�|j||||| d�Ed HWd �d S1sGwYd S) a�Track progress by iterating over a sequence. You can also track progress of an iterable, which might require that you additionally specify ``total``. Args: sequence (Iterable[ProgressType]): Values you wish to iterate over and track progress. description (str, optional): Description of task show next to progress bar. Defaults to "Working". total: (float, optional): Total number of steps. Default is len(sequence). completed (int, optional): Number of steps completed so far. Defaults to 0. auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True. transient: (bool, optional): Clear the progress on exit. Defaults to False. console (Console, optional): Console to write to. Default creates internal Console instance. refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10. style (StyleType, optional): Style for the bar background. Defaults to "bar.back". complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete". finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished". pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse". update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1. disable (bool, optional): Disable display of progress. show_speed (bool, optional): Show speed if total isn't known. Defaults to True. Returns: Iterable[ProgressType]: An iterable of the values in the sequence. �([progress.description]{task.description}�r�r�r�r�)r�T)�elapsed_when_finishedrq�r~r�r�r�r�r�)r{rFryrBN)� TextColumn�extend� BarColumn�TaskProgressColumn�TimeRemainingColumn�Progress�track)rwryr{rFr~r�r�r�r�r�r�r�r�rBr�r��columnsr>rLrLrMr�hs@�,���� � �"�r�c@seZdZdZ dQdRd d�ZdSdd�ZdTdd�ZdUdd�ZdVdd�Ze dWdd ��Z dXd"d#�Z dWd$d%�Z e dYd'd(��Z e dYd)d*��ZdWd+d,�ZdWd-d.�ZdWd/d0�ZdZd[d3d4�Zd\d7d8�ZdZd[d9d:�ZdZd]d=d>�Zd^d?d@�Zd_d`dDdE�ZdXdFdG�ZdadJdK�ZdbdNdO�ZdPS)c�_Readerz9A reader that tracks progress while it's being read from.T�handlerr>r?�taskr:� close_handlerrNrOcCs"||_||_||_||_d|_dS�NF)r�r>r�r��_closed)rIr�r>r�r�rLrLrMrH�s  z_Reader.__init__� '_Reader'cCs|j��|SrY)r�r]r\rLrLrMr]�s z_Reader.__enter__r_r`rarbrcrdcC� |��dSrY)�closergrLrLrMrh�� z_Reader.__exit__cCs|SrYrLr\rLrLrM�__iter__��z_Reader.__iter__�bytescCs$t|j�}|jj|jt|�d�|S�N�rQ)�nextr�r>rQr��len)rI�linerLrLrM�__next__�s z_Reader.__next__cC�|jSrY)r�r\rLrLrM�closed�sz_Reader.closedr}cC� |j��SrY)r��filenor\rLrLrMr��� z_Reader.filenocCr�rY)r��isattyr\rLrLrMr��r�z_Reader.isattyrzcC�|jjSrY)r��moder\rLrLrMr���z _Reader.modecCr�rY)r��namer\rLrLrMr��r�z _Reader.namecCr�rY)r��readabler\rLrLrMr��r�z_Reader.readablecCr�rY)r��seekabler\rLrLrMr��r�z_Reader.seekablecC�dSr�rLr\rLrLrM�writable�r�z_Reader.writable������sizecC�&|j�|�}|jj|jt|�d�|Sr�)r��readr>rQr�r�)rIr��blockrLrLrMr��� z _Reader.read�b�"Union[bytearray, memoryview, mmap]cCs"|j�|�}|jj|j|d�|Sr�)r��readintor>rQr�)rIr��nrLrLrMr��s z_Reader.readintocCr�r�)r��readliner>rQr�r�)rIr�r�rLrLrMr��r�z_Reader.readline�hint� List[bytes]cCs,|j�|�}|jj|jttt|��d�|Sr�)r�� readlinesr>rQr��sum�mapr�)rIr��linesrLrLrMr�s z_Reader.readlinescCs|jr|j��d|_dS)NT)r�r�r�r�r\rLrLrMr� s  z _Reader.closer�offset�whencecCs$|j�||�}|jj|j|d�|S)N�rF)r��seekr>rUr�)rIr�r��posrLrLrMr�sz _Reader.seekcCr�rY)r��tellr\rLrLrMr�r�z _Reader.tell�srcC�td��)N�write�r )rIr�rLrLrMr��z _Reader.writer�� Iterable[Any]cCr�)N� writelinesr�)rIr�rLrLrMr�r�z_Reader.writelinesN)T) r�rr>r?r�r:r�rrNrO)rNr�rj)rNr)rNr��rNr)rNr})rNrz)r�)r�r}rNr�)r�r�)r�r}rNr�ri)r)r�r}r�r}rNr})r�rrNr})r�r�rNrO)rkrlrmrnrHr]rhr�r��propertyr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rLrLrLrMr��s8 �                   r�c@s.eZdZdZddd �Zdd d �Zddd�ZdS)� _ReadContextzEA utility class to handle a context for both a reader and a progress.r>r?�readerr<rNrOcCs||_||_dSrY)r>r�)rIr>r�rLrLrMrH s z_ReadContext.__init__cCs|j��|j��SrY)r>r[r�r]r\rLrLrMr]$s  z_ReadContext.__enter__r_r`rarbrcrdcCs|j��|j�|||�dSrY)r>�stopr�rhrgrLrLrMrh(s z_ReadContext.__exit__N)r>r?r�r<rNrO)rNr<rj)rkrlrmrnrHr]rhrLrLrLrMr�s   r�� Reading...) ryr~r�r�r�r�r�r�r�r�r��filer�ContextManager[BinaryIO]c  Csh|rtd�gng} | �t|| | | d�t�t�f�t| |||||p"d| d��}|j|||d�}t||�S)aRead bytes from a file while tracking progress. Args: file (Union[str, PathLike[str], BinaryIO]): The path to the file to read, or a file-like object in binary mode. total (int): Total number of bytes to read. description (str, optional): Description of task show next to progress bar. Defaults to "Reading". auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True. transient: (bool, optional): Clear the progress on exit. Defaults to False. console (Console, optional): Console to write to. Default creates internal Console instance. refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10. style (StyleType, optional): Style for the bar background. Defaults to "bar.back". complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete". finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished". pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse". disable (bool, optional): Disable display of progress. Returns: ContextManager[BinaryIO]: A context manager yielding a progress reader. r�r�rqr�)r{ry)r�r�r��DownloadColumnr�r�� wrap_filer�)r�r{ryr~r�r�r�r�r�r�r�r�r�r�r>r�rLrLrMr�2s0%���� � r�r�) r{ryr~r�r�r�r�r�r�r�r�r��"Union[str, 'PathLike[str]', bytes]r��"Union[Literal['rt'], Literal['r']]� buffering�encoding� Optional[str]�errors�newline� Optional[int]�ContextManager[TextIO]c C�dSrYrL�r�r�r�r�r�r�r{ryr~r�r�r�r�r�r�r�r�r�rLrLrM�opens�r�� Literal['rb']c Cr�rYrLr�rLrLrMr��r��r�1Union[Literal['rb'], Literal['rt'], Literal['r']]�7Union[ContextManager[BinaryIO], ContextManager[TextIO]]c  Csr|rtd�gng}|�t| |||d�t�t�f�t||| | | | p"d|d��}|j||||||||d�}t||�S)a�Read bytes from a file while tracking progress. Args: path (Union[str, PathLike[str], BinaryIO]): The path to the file to read, or a file-like object in binary mode. mode (str): The mode to use to open the file. Only supports "r", "rb" or "rt". buffering (int): The buffering strategy to use, see :func:`io.open`. encoding (str, optional): The encoding to use when reading in text mode, see :func:`io.open`. errors (str, optional): The error handling strategy for decoding errors, see :func:`io.open`. newline (str, optional): The strategy for handling newlines in text mode, see :func:`io.open` total: (int, optional): Total number of bytes to read. Must be provided if reading from a file handle. Default for a path is os.stat(file).st_size. description (str, optional): Description of task show next to progress bar. Defaults to "Reading". auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True. transient: (bool, optional): Clear the progress on exit. Defaults to False. console (Console, optional): Console to write to. Default creates internal Console instance. refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10. style (StyleType, optional): Style for the bar background. Defaults to "bar.back". complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete". finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished". pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse". disable (bool, optional): Disable display of progress. encoding (str, optional): The encoding to use when reading in text mode. Returns: ContextManager[BinaryIO]: A context manager yielding a progress reader. r�r�rqr�)r�r�r�r�r�r{ry)r�r�r�r�r�r�r�r�)r�r�r�r�r�r�r{ryr~r�r�r�r�r�r�r�r�r�r�r>r�rLrLrMr��sB1���� � � c@sLeZdZUdZdZded<ddd d �Zdd d �Zddd�Ze ddd��Z dS)�ProgressColumnz3Base class for a widget to use in progress display.Nr|� max_refresh� table_column�Optional[Column]rNrOcCs||_i|_d|_dSrY)� _table_column�_renderable_cacheZ _update_time)rIr�rLrLrMrHs zProgressColumn.__init__r6cCs |jpt�S)z.Get a table column, used to build tasks table.)r�r6r\rLrLrM�get_table_columns zProgressColumn.get_table_columnr��'Task'r/cCsp|��}|jdur)|js)z |j|j\}}Wn tyYn w||j|kr)|S|�|�}||f|j|j<|S)aCalled by the Progress object to return a renderable for the given task. Args: task (Task): An object containing information regarding the task. Returns: RenderableType: Anything renderable (including str). N)r�r�rFr��id�KeyError�render)rIr�� current_time� timestamp� renderablerLrLrM�__call__ s  � zProgressColumn.__call__cCr�)z"Should return a renderable object.NrL�rIr�rLrLrMr� szProgressColumn.renderrY)r�r�rNrO)rNr6�r�r�rNr/) rkrlrmrnr��__annotations__rHr�rrr�rLrLrLrMr��s     r�cs6eZdZdZ ddd�d�fd d �Zddd�Z�ZS)�RenderableColumnz�A column to insert an arbitrary column. Args: renderable (RenderableType, optional): Any renderable. Defaults to empty string. �N�r�r�r/r�r�c�||_t�j|d�dS�Nr)r�rGrH)rIr�r�rJrLrMrH,�zRenderableColumn.__init__r�r�rNcCr�rY)r�rrLrLrMr�2szRenderableColumn.render)r)r�r/r�r�r�rkrlrmrnrHr�rorLrLrJrMr%s��rcsHeZdZdZ     dd�fdd� Z  dd dd�Zd!dd�Z�ZS)"� SpinnerColumna�A column with a 'spinner' animation. Args: spinner_name (str, optional): Name of spinner animation. Defaults to "dots". style (StyleType, optional): Style of spinner. Defaults to "progress.spinner". speed (float, optional): Speed factor of spinner. Defaults to 1.0. finished_text (TextType, optional): Text used when task is finished. Defaults to " ". �dots�progress.spinner��?� N� spinner_namerzr��Optional[StyleType]�speedrC� finished_textr9r�r�cs<t|||d�|_t|t�rt�|�n||_t�j|d�dS)N�r�rr) r4�spinner� isinstancerzr8� from_markuprrGrH)rIrr�rrr�rJrLrMrH@s  ��zSpinnerColumn.__init__� spinner_stylerNrOcCst|||d�|_dS)a-Set a new spinner. Args: spinner_name (str): Spinner name, see python -m rich.spinner. spinner_style (Optional[StyleType], optional): Spinner style. Defaults to "progress.spinner". speed (float, optional): Speed factor of spinner. Defaults to 1.0. rN)r4r)rIrrrrLrLrM� set_spinnerPs zSpinnerColumn.set_spinnerr�r�r/cCs$|jr|j}|S|j�|���}|SrY)�finishedrrr�r�)rIr��textrLrLrMr�_s����zSpinnerColumn.render)r r rrN) rrzr�rrrCrr9r�r�)r r)rrzrrrrCrNrOr)rkrlrmrnrHrr�rorLrLrJrMr 6s � �r cs8eZdZdZ     dd�fdd� Zddd�Z�ZS)r�zA column containing text.�none�leftTN� text_formatrzr�r5�justifyr.�markupr� highlighter�Optional[Highlighter]r�r�rNrOcs:||_||_||_||_||_t�j|ptdd�d�dS)NT��no_wrapr)rrr�r r!rGrHr6)rIrr�rr r!r�rJrLrMrHks  zTextColumn.__init__r�r�r8cCsR|jj|d�}|jrtj||j|jd�}n t||j|jd�}|jr'|j�|�|S�N�r�)r�r) r�formatr r8rr�rr!� highlight)rIr��_textrrLrLrMr�{s zTextColumn.render)rrTNN)rrzr�r5rr.r rr!r"r�r�rNrO�r�r�rNr8r rLrLrJrMr�hs�r�cs:eZdZdZ      dd�fdd� Zddd�Z�ZS)r�aRenders a visual progress bar. Args: bar_width (Optional[int], optional): Width of bar or None for full width. Defaults to 40. style (StyleType, optional): Style for the bar background. Defaults to "bar.back". complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete". finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished". pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse". �(rrrsrtruN� bar_widthr�r�r5r�r�r�r�r�rNrOcs0||_||_||_||_||_t�j|d�dSr)r,r�r�r�r�rGrH)rIr,r�r�r�r�r�rJrLrMrH�s  zBarColumn.__init__r�r�r3c Cs^t|jdur td|j�ndtd|j�|jdurdntd|j�|j |��|j|j|j |j d� S)z&Gets a progress bar widget for a task.Nrr)) r{rF�widthZpulseZanimation_timer�r�r�r�) r3r{�maxrFr,�startedr�r�r�r�r�rrLrLrMr��s �zBarColumn.render)r+rrrsrtruN)r,r�r�r5r�r5r�r5r�r5r�r�rNrO)r�r�rNr3r rLrLrJrMr��s �r�c@�eZdZdZd dd�ZdS) �TimeElapsedColumnzRenders time elapsed.r�r�rNr8cCsJ|jr|jn|j}|durtddd�Sttdt|��d�}tt|�dd�S)zShow time elapsed.N�-:--:--�progress.elapsed�r�r)�seconds)r� finished_time�elapsedr8r r.r}rz)rIr�r7�deltarLrLrMr��s  zTimeElapsedColumn.renderNr*�rkrlrmrnr�rLrLrLrMr1��r1csLeZdZdZ        d$d%�fdd� Zed&dd��Zd'd"d#�Z�ZS)(r�aShow task progress as a percentage. Args: text_format (str, optional): Format for percentage display. Defaults to "[progress.percentage]{task.percentage:>3.0f}%". text_format_no_percentage (str, optional): Format if percentage is unknown. Defaults to "". style (StyleType, optional): Style of output. Defaults to "none". justify (JustifyMethod, optional): Text justification. Defaults to "left". markup (bool, optional): Enable markup. Defaults to True. highlighter (Optional[Highlighter], optional): Highlighter to apply to output. Defaults to None. table_column (Optional[Column], optional): Table Column to use. Defaults to None. show_speed (bool, optional): Show speed if total is unknown. Defaults to False. �-[progress.percentage]{task.percentage:>3.0f}%rrrTNFrrz�text_format_no_percentager�r5rr.r rr!r"r�r�r�rNrOc s(||_||_t�j||||||d�dS)N)rr�rr r!r�)r<r�rGrH) rIrr<r�rr r!r�r�rJrLrMrH�s  �zTaskProgressColumn.__init__rr|r8cCsN|dur tddd�St�t|�gd�d�\}}||}t|d�|�d�dd�S) z�Render the speed in iterations per second. Args: task (Task): A Task object. Returns: Text: Text object containing the task speed. Nrzprogress.percentager4)ru×10³u×10⁶u×10⁹u×10¹²��z.1fz it/s)r8r*�pick_unit_and_suffixr})�clsr�unit�suffix� data_speedrLrLrM� render_speed�s �zTaskProgressColumn.render_speedr�r�cCs�|jdur|jr|�|jp|j�S|jdur|jn|j}|j|d�}|jr0t j ||j |j d�}n t ||j |j d�}|j rB|j �|�|Sr%)r{r�rC�finished_speedrr<rr'r r8rr�rr!r()rIr�rr)rrLrLrMr��s�  zTaskProgressColumn.render)r;rrrTNNF)rrzr<rzr�r5rr.r rr!r"r�r�r�rrNrO)rr|rNr8r*) rkrlrmrnrH� classmethodrCr�rorLrLrJrMr��s� r�cs8eZdZdZdZ   dd�fd d � Zddd�Z�ZS)r�aRenders estimated time remaining. Args: compact (bool, optional): Render MM:SS when time remaining is less than an hour. Defaults to False. elapsed_when_finished (bool, optional): Render time elapsed when the task is finished. Defaults to False. ��?FN�compactrr�r�r�cs||_||_t�j|d�dSr)rGr�rGrH)rIrGr�r�rJrLrMrHszTimeRemainingColumn.__init__r�r�rNr8cCs�|jr |jr |j}d}n|j}d}|jdurtd|d�S|dur.t|jr)d|d�Sd|d�Stt|�d�\}}t|d�\}}|jrM|sM|d �d |d ��}n |d �d |d �d |d ��}t||d�S) zShow time remaining.r3zprogress.remainingNrr4z--:--r2�<Z02d�:�d) r�rr6�time_remainingr{r8rG�divmodr})rIr�Z task_timer��minutesr5�hours� formattedrLrLrMr�s     zTimeRemainingColumn.render)FFN)rGrr�rr�r�r*)rkrlrmrnr�rHr�rorLrLrJrMr�s� r�c@r0) �FileSizeColumnzRenders completed filesize.r�r�rNr8cCst�t|j��}t|dd�S)�Show data completed.zprogress.filesizer4)r*�decimalr}rFr8�rIr�� data_sizerLrLrMr�7s zFileSizeColumn.renderNr*r9rLrLrLrMrP4r:rPc@r0) �TotalFileSizeColumnzRenders total filesize.r�r�rNr8cCs*|jdur t�t|j��nd}t|dd�S)rQNrzprogress.filesize.totalr4)r{r*rRr}r8rSrLrLrMr�@s zTotalFileSizeColumn.renderNr*r9rLrLrLrMrU=r:rUcs.eZdZdZdd�fdd � Zddd�Z�ZS)�MofNCompleteColumnaHRenders completed count/total, e.g. ' 10/1000'. Best for bounded tasks with int quantities. Space pads the completed count so that progress length does not change as task progresses past powers of 10. Args: separator (str, optional): Text to separate completed and total values. Defaults to "/". �/N� separatorrzr�r�crr)rXrGrH)rIrXr�rJrLrMrHRszMofNCompleteColumn.__init__r�r�rNr8cCsPt|j�}|jdurt|j�nd}tt|��}t||�d��|j�|��dd�S)zShow completed/total.N�?rJ�progress.downloadr4)r}rFr{r�rzr8rX)rIr�rFr{� total_widthrLrLrMr�Vs  �zMofNCompleteColumn.render)rWN)rXrzr�r�r*r rLrLrJrMrVFs rVcs0eZdZdZ dd�fd d � Zddd�Z�ZS)r�z�Renders file size downloaded and total, e.g. '0.5/2.3 GB'. Args: binary_units (bool, optional): Use binary units, KiB, MiB etc. Defaults to False. FN� binary_unitsrr�r�rNrOcrr)r\rGrH)rIr\r�rJrLrMrHhr zDownloadColumn.__init__r�r�r8cCs�t|j�}|jdurt|j�n|}|jr t�|gd�d�\}}n t�|gd�d�\}}|dkr1dnd}||}|d|�d ��}|jdurVt|j�} | |} | d|�d ��} nd } |�d | �d |��} t| d d�} | S)z.Calculate common unit for completed and total.N) r�ZKiBZMiBZGiBZTiBZPiBZEiBZZiBZYiBi) r�ZkBZMBZGBZTBZPBZEBZZBZYBr=r)rz,.�frYrWrrZr4)r}rFr{r\r*r>r8)rIr�rFZ unit_and_suffix_calculation_baser@rA� precisionZcompleted_ratioZ completed_strr{� total_ratioZ total_strZdownload_statusZ download_textrLrLrMr�ns2 � ��   zDownloadColumn.render)FN)r\rr�r�rNrOr*r rLrLrJrMr�as �r�c@r0) �TransferSpeedColumnz&Renders human readable transfer speed.r�r�rNr8cCs@|jp|j}|durtddd�St�t|��}t|�d�dd�S)zShow data transfer speed.NrYzprogress.data.speedr4z/s)rDrr8r*rRr})rIr�rrBrLrLrMr��s  zTransferSpeedColumn.renderNr*r9rLrLrLrMr`�r:r`c@s$eZdZUdZded< ded<dS)�ProgressSamplez$Sample of progress for a given time.rCr�rFN)rkrlrmrnrrLrLrLrMra�s rac@sXeZdZUdZded< ded< ded< ded < d ed < d Zded < dZded< eed�Z ded< ed ddd�Z ded< ed ddd�Z ded< d Z ded< edd�ddd�Z ded<eded�Zded < d5d"d#�Zed6d$d%��Zed7d&d'��Zed7d(d)��Zed6d*d+��Zed5d,d-��Zed7d.d/��Zed7d0d1��Zd8d3d4�Zd S)9�Taskz�Information regarding a progress task. This object should be considered read-only outside of the :class:`~Progress` class. r:r�rzryr|r{rCrF�GetTimeCallable� _get_timeNr6Tr�visible)�default_factoryzDict[str, Any]�fieldsF)�default�init�repr� start_time� stop_timerDcCs tdd�S)Nr=)�maxlenrrLrLrLrM�<lambda>�s z Task.<lambda>)rfrirjzDeque[ProgressSample]� _progress)rjrfr�_lockrNcCs|��S)z(float: Get the current time, in seconds.)rdr\rLrLrMr��r�z Task.get_timecC� |jduS)z#bool: Check if the task as started.N)rkr\rLrLrMr/�� z Task.startedcCs|jdurdS|j|jS)zPOptional[float]: Get the number of steps remaining, if a non-None total was set.N�r{rFr\rLrLrM� remaining�s  zTask.remainingcCs2|jdurdS|jdur|j|jS|��|jS)z]Optional[float]: Time elapsed since task was started, or ``None`` if the task hasn't started.N)rkrlr�r\rLrLrMr7�s   z Task.elapsedcCrq)zCheck if the task has finished.N)r6r\rLrLrMr�rrz Task.finishedcCs.|jsdS|j|jd}tdtd|��}|S)zOfloat: Get progress of task as a percentage. If a None total was set, returns 0��Y@)r{rF�minr.)rIrFrLrLrM� percentage�s zTask.percentagecCs�|jdurdS|j�D|j}|s Wd�dS|dj|dj}|dkr0 Wd�dSt|�}t|�tdd�|D��}||}|Wd�S1sQwYdS)z=Optional[float]: Get the estimated speed in steps per second.Nr�rcs��|]}|jVqdSrYr�)�.0�samplerLrLrM� <genexpr> ��zTask.speed.<locals>.<genexpr>)rkrpror��iterr�r�)rIr>Z total_timeZ iter_progressZtotal_completedrrLrLrMr�s" ��$�z Task.speedcCs:|jrdS|j}|s dS|j}|durdSt||�}|S)zJOptional[float]: Get estimated time to completion, or ``None`` if no data.ruN)rrrtr )rIrrtZestimaterLrLrMrKs zTask.time_remainingrOcCs|j��d|_d|_dS)zReset progress.N)ro�clearr6rDr\rLrLrM�_resets  z Task._reset)rNrCr�)rNr|ri)rkrlrmrnrr6rer�dictrgrkrlrDrorrpr�r�r/rtr7rrxrrKr�rLrLrLrMrb�sZ     �         rbc @s�eZdZdZddddddddddd� d�dd�Zed�dd��Zed�d d!��Zed�d#d$��Z ed�d&d'��Z ed�d(d)��Z d�d*d+�Z d�d,d-�Z d�d/d0�Zd�d7d8�Z  9  : ;d�d�dGdH�Z d�ddIdJ�d�dNdO�Zej P   d�dddIdQ�d�dZd[��Zej P   d�dddIdQ�d�d^d[��Z _ P   d�dddIdQ�d�dbd[�Zd�ddde�Zd�dfdg�Zdddddddh�d�dodp�Zddd9dddq�d�dsdt�Zd�d�dvdw�Zd�dxdy�Zd�d{d|�Zd�d~d�Zd�d�d��Zd�d�d��Z  � 9 d�d�d�d��Zd�d�d��Z dS)�r�a�Renders an auto-updating progress bar(s). Args: console (Console, optional): Optional Console instance. Defaults to an internal Console instance writing to stdout. auto_refresh (bool, optional): Enable auto refresh. If disabled, you will need to call `refresh()`. refresh_per_second (Optional[float], optional): Number of times per second to refresh the progress information or None to use default (10). Defaults to None. speed_estimate_period: (float, optional): Period (in seconds) used to calculate the speed estimate. Defaults to 30. transient: (bool, optional): Clear the progress on exit. Defaults to False. redirect_stdout: (bool, optional): Enable redirection of stdout, so ``print`` may be used. Defaults to True. redirect_stderr: (bool, optional): Enable redirection of stderr. Defaults to True. get_time: (Callable, optional): A callable that gets the current time, or None to use Console.get_time. Defaults to None. disable (bool, optional): Disable progress display. Defaults to False expand (bool, optional): Expand tasks table to fit width. Defaults to False. NTrqg>@F) r�r~r��speed_estimate_periodr��redirect_stdout�redirect_stderrr�r��expandr��Union[str, ProgressColumn]r�r�r~rr�rCr�r�r�r�r��Optional[GetTimeCallable]r�r�rNrOc Gs�|dksJd��t�|_| p|��|_||_| |_| |_i|_td�|_ t |p)t �||||||j d�|_ |p9|jj|_|jj|_|jj|_dS)Nrzrefresh_per_second must be > 0)r�r~r�r�r�r��get_renderable)rrp�get_default_columnsr�r�r�r��_tasksr:� _task_indexr2r+r�rSr�r��print�log) rIr�r~r�r�r�r�r�r�r�r�r�rLrLrMrH5s( � zProgress.__init__�Tuple[ProgressColumn, ...]cCstd�t�t�t�fS)a�Get the default columns used for a new Progress instance: - a text column for the description (TextColumn) - the bar itself (BarColumn) - a text column showing completion percentage (TextColumn) - an estimated-time-remaining column (TimeRemainingColumn) If the Progress instance is created without passing a columns argument, the default columns defined here will be used. You can also create a Progress instance using custom columns before and/or after the defaults, as in this example: progress = Progress( SpinnerColumn(), *Progress.get_default_columns(), "Elapsed:", TimeElapsedColumn(), ) This code shows the creation of a Progress display, containing a spinner to the left, the default columns, and a labeled elapsed time column. r�)r�r�r�r�)r?rLrLrMr�Ys �zProgress.get_default_columnsr,cCr�rY)rSr�r\rLrLrMr�xr�zProgress.console� List[Task]cC�8|j�t|j���Wd�S1swYdS)zGet a list of Task instances.N)rp�listr��valuesr\rLrLrM�tasks|� $�zProgress.tasks� List[TaskID]cCr�)zA list of task IDs.N)rpr�r��keysr\rLrLrM�task_ids�r�zProgress.task_idscCsZ|j� |js Wd�dStdd�|j��D��Wd�S1s&wYdS)z'Check if all tasks have been completed.NTcsryrY)r)rzr�rLrLrMr|�r}z$Progress.finished.<locals>.<genexpr>)rpr��allr�r\rLrLrMr�s �$�zProgress.finishedcCs|js |jjdd�dSdS)zStart the progress display.T)rPN)r�rSr[r\rLrLrMr[�s�zProgress.startcCs0|j��|jjs|jjs|j��dSdSdS)zStop the progress display.N)rSr�r��is_interactive� is_jupyterr�r\rLrLrMr��s �z Progress.stopr(cCrXrYrZr\rLrLrMr]�r^zProgress.__enter__r_r`rarbrcrdcCr�rY)r�rgrLrLrMrh�r�zProgress.__exit__rrprvrwrxr{r|rFr}r@�Optional[TaskID]ryrzrBc cs��|dur tt|��p d}|dur|j|||d�}n|j|||d�|jjrNt|||��}|D] }|V|jd7_q/Wd�dS1sGwYdS|j} |j } |D] }|V| |d�| �qVdS)aCTrack progress by iterating over a sequence. You can also track progress of an iterable, which might require that you additionally specify ``total``. Args: sequence (Iterable[ProgressType]): Values you want to iterate over and track progress. total: (float, optional): Total number of steps. Default is len(sequence). completed (int, optional): Number of steps completed so far. Defaults to 0. task_id: (TaskID): Task to track. Default is new task. description: (str, optional): Description of task, if new task is created. update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1. Returns: Iterable[ProgressType]: An iterable of values taken from the provided sequence. Nrsr)) rCr�add_taskrUrSr~r=rFrQrP) rIrwr{rFr@ryrBZ track_thread�valuerQrPrLrLrMr��s(��"� �zProgress.trackr�)r@ryr�rr�cCs�d}|dur |}n|dur&|j�|j|j}Wd�n1s!wY|dur.td��|dur:|j||d�}n|j||d�t|||dd�S)ajTrack progress file reading from a binary file. Args: file (BinaryIO): A file-like object opened in binary mode. total (int, optional): Total number of bytes to read. This must be provided unless a task with a total is also given. task_id (TaskID): Task to track. Default is new task. description (str, optional): Description of task, if new task is created. Returns: BinaryIO: A readable file-like object in binary mode. Raises: ValueError: When no total value can be extracted from the arguments or the task. Nz?unable to get the total number of bytes, please specify 'total'�r{F�r�)rpr�r{� ValueErrorr�rUr�)rIr�r{r@ry� total_bytesrLrLrMr��s��zProgress.wrap_filer�)r{r@ryr�r�r�r�r�r�r�r�c Cr�rYrL� rIr�r�r�r�r�r�r{r@ryrLrLrMr���z Progress.open�"Union[Literal['r'], Literal['rt']]r#c Cr�rYrLr�rLrLrMr�r�r�r��Union[BinaryIO, TextIO]cCs�d�t|dd��} | dvrtd|����|dk} | dkr)|dkr)t�dt�d }n| d vr;|d kr5td ��|dkr;d }|d urDt|�j}|d urP|j| |d�}n|j ||d�t j |d|d�} t | ||dd�} |dvrut j | |||| d�S| S)a#Track progress while reading from a binary file. Args: path (Union[str, PathLike[str]]): The path to the file to read. mode (str): The mode to use to open the file. Only supports "r", "rb" or "rt". buffering (int): The buffering strategy to use, see :func:`io.open`. encoding (str, optional): The encoding to use when reading in text mode, see :func:`io.open`. errors (str, optional): The error handling strategy for decoding errors, see :func:`io.open`. newline (str, optional): The strategy for handling newlines in text mode, see :func:`io.open`. total (int, optional): Total number of bytes to read. If none given, os.stat(path).st_size is used. task_id (TaskID): Task to track. Default is new task. description (str, optional): Description of task, if new task is created. Returns: BinaryIO: A readable file-like object in binary mode. Raises: ValueError: When an invalid mode is given. rF)�reverse)�br�rtr�z invalid mode r)r�zaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be usedr�)r�r�rzcan't have unbuffered text I/ONr��rb)r�Tr�)r�r�)r�r�r��line_buffering)rf�sortedr��warnings�warn�RuntimeWarningr�st_sizer�rU�ior�r�� TextIOWrapper)rIr�r�r�r�r�r�r{r@ry�_moder�r�r�rLrLrMr�s>!� �r:cCsZ|j� |j|}|jdur|��|_Wd�dSWd�dS1s&wYdS)z�Start a task. Starts a task (used when calculating elapsed time). You may need to call this manually, if you called ``add_task`` with ``start=False``. Args: task_id (TaskID): ID of task. N)rpr�rkr�)rIr@r�rLrLrM� start_taskks   �"�zProgress.start_taskcCsT|j�|j|}|��}|jdur||_||_Wd�dS1s#wYdS)z�Stop a task. This will freeze the elapsed time on the task. Args: task_id (TaskID): ID of task. N)rpr�r�rkrl)rIr@r�r�rLrLrM� stop_taskys  "�zProgress.stop_task)r{rFrQryrerPrQre�Optional[bool]rPrgrcKsH|j��|j|} | j} |dur|| jkr|| _| ��|dur'| j|7_|dur.|| _|dur5|| _|dur<|| _| j�|�| j| } |� �} | |j } | j }|j }|rk|dj | krk|�|rk|dj | ks_| dkrw|�t| | ��| jdur�| j| jkr�| jdur�| j| _Wd�n1s�wY|r�|��dSdS)a�Update information associated with a task. Args: task_id (TaskID): Task id (returned by add_task). total (float, optional): Updates task.total if not None. completed (float, optional): Updates task.completed if not None. advance (float, optional): Add a value to task.completed if not None. description (str, optional): Change task description if not None. visible (bool, optional): Set visible flag if not None. refresh (bool): Force a refresh of progress information. Default is False. **fields (Any): Additional data fields required for rendering. Nr)rpr�rFr{r�ryrergrUr�r�ro�popleftr��appendrar6r7rP)rIr@r{rFrQryrerPrgr��completed_start�update_completedr��old_sample_timeror�rLrLrMrU�sD    �   ��" �zProgress.update)r[r{rFreryr[c Ks�|��}|j�8|j|} | ��|r|nd| _|dur|| _|| _|dur)|| _|r.|| _|dur5|| _ d| _ Wd�n1sBwY|� �dS)a�Reset a task so completed is 0 and the clock is reset. Args: task_id (TaskID): ID of task. start (bool, optional): Start the task after reset. Defaults to True. total (float, optional): New total steps in task, or None to use current total. Defaults to None. completed (int, optional): Number of steps completed. Defaults to 0. visible (bool, optional): Enable display of the task. Defaults to True. description (str, optional): Change task description if not None. Defaults to None. **fields (str): Additional data fields required for rendering. N) r�rpr�r�rkr{rFrergryr6rP) rIr@r[r{rFreryrgr�r�rLrLrM�reset�s" � zProgress.resetr)c Cs*|��}|j��|j|}|j}|j|7_|j|}||j}|j}|j} |r<|dj|kr<| �|r<|dj|ks0t|�dkrK| �t|�dksB|� t ||��|j durs|j|j kr{|j dur�|j |_ |j|_Wd�dSWd�dSWd�dSWd�dS1s�wYdS)z�Advance task by a number of steps. Args: task_id (TaskID): ID of task. advance (float): Number of steps to advance. Default is 1. rr=N)r�rpr�rFr�ror�r�r�r�rar{r6r7rrD) rIr@rQr�r�r�r�r�ror�rLrLrMrQ�s8   �  �    ���"�zProgress.advancecCs$|js|jjr|j��dSdSdS)z*Refresh (render) the progress information.N)r�rSrTrPr\rLrLrMrP s�zProgress.refreshr/cCst|���}|S)z*Get a renderable for the progress display.)r-�get_renderables)rIr�rLrLrMr�s zProgress.get_renderable�Iterable[RenderableType]ccs�|�|j�}|VdS)z5Get a number of renderables for the progress display.N)�make_tasks_tabler�)rI�tablerLrLrMr�s�  zProgress.get_renderablesr��Iterable[Task]r7csRdd�|jD�}tj|d|jd��}|D]��jr&|j�fdd�|jD��q|S)z�Get a table to render the Progress display. Args: tasks (Iterable[Task]): An iterable of Task instances, one per row of the table. Returns: Table: A table instance. css0�|]}t|t�rtdd�n|����VqdS)Tr#N)rrzr6r��copy)rzZ_columnrLrLrMr|"s�� �  �z,Progress.make_tasks_table.<locals>.<genexpr>)rr))�paddingr�c3s.�|]}t|t�r|j�d�n|��VqdS)r&N)rrzr')rz�columnr&rLrMr|/s��� �)r�r7�gridr�re�add_row)rIr�Z table_columnsr�rLr&rMr�s � ��� zProgress.make_tasks_tablecCs2|j� |��Wd�S1swYdS)z+Makes the Progress class itself renderable.N)rpr�r\rLrLrM�__rich__:s$�zProgress.__rich__rvc Ks�|j�2t|j||||||j|jd�}||j|j<|r!|�|j�|j}tt|j�d�|_Wd�n1s8wY|��|S)aAdd a new 'task' to the Progress display. Args: description (str): A description of the task. start (bool, optional): Start the task immediately (to calculate elapsed time). If set to False, you will need to call `start` manually. Defaults to True. total (float, optional): Number of total steps in the progress if known. Set to None to render a pulsing animation. Defaults to 100. completed (int, optional): Number of steps completed so far. Defaults to 0. visible (bool, optional): Enable display of the task. Defaults to True. **fields (str): Additional data fields required for rendering. Returns: TaskID: An ID you can use when calling `update`. )rergrdrpr)N) rprbr�r�r�r�r:r}rP) rIryr[r{rFrergr�Znew_task_indexrLrLrMr�?s&�  �zProgress.add_taskcCs4|j� |j|=Wd�dS1swYdS)z]Delete a task if it exists. Args: task_id (TaskID): A task ID. N)rpr�)rIr@rLrLrM� remove_taskjs "�zProgress.remove_task)r�r�r�r�r~rr�rCr�rCr�rr�rr�rr�r�r�rr�rrNrO)rNr�)rNr,)rNr�)rNr�r�ri)rNr(rj)NrNrprv)rwrxr{r|rFr}r@r�ryrzrBrCrNrxrY) r�rr{r�r@r�ryrzrNr�r�NNN)r�r�r�r�r�r}r�r�r�r�r�r�r{r�r@r�ryrzrNr)r�r�r�r�r�r}r�r�r�r�r�r�r{r�r@r�ryrzrNr#�r�r�NNN)r�r�r�r�r�r}r�r�r�r�r�r�r{r�r@r�ryrzrNr�)r@r:rNrO)r@r:r{r|rFr|rQr|ryr�rer�rPrrgrrNrO)r@r:r[rr{r|rFr}rer�ryr�rgrrNrO)r))r@r:rQrCrNrO)rNr/)rNr�)r�r�rNr7)TrvrT)ryrzr[rr{r|rFr}rerrgrrNr:)!rkrlrmrnrHrEr�r�r�r�r�rr[r�r]rhr�r��typing�overloadr�r�r�rUr�rQrPr�r�r�r�r�r�rLrLrLrMr�%s��$           �0��*� �� �� � M �A� '     ! �+r��__main__)�Panel)�Rule)�Syntax)r7a~def loop_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]: """Iterate and generate a tuple with a flag for last value.""" iter_values = iter(values) try: previous_value = next(iter_values) except StopIteration: return for value in iter_values: yield False, previous_value previous_value = value yield True, previous_value�python)Z line_numbersZfooZbarZbaz�1�2�3z:Text may be printed while the progress bars are rendering.z(In fact, [i]any[/i] renderable will workzSuch as [magenta]tables[/]...zPretty printed structures...ZexamplezPretty printed)�typerz Syntax...zGive it a try!)�cycle)�record)r�r�z[red]Downloadingr=r�z[green]Processingz[yellow]ThinkingrFr�g333333�?g{�G�z�?�d)rpNrTNFNrqrrrsrtrurvFT)"rwrxryrzr{r|rFr}r~rr�r�r�rr�r�r�rCr�r5r�r5r�r5r�r5rBrCr�rr�rrNrx)r�rr{r}ryrzr~rr�r�r�rr�r�r�rCr�r5r�r5r�r5r�r5r�rrNr�r�)&r�r�r�r�r�r}r�r�r�r�r�r�r{r�ryrzr~rr�r�r�rr�r�r�rCr�r5r�r5r�r5r�r5r�rrNr�)&r�r�r�r�r�r}r�r�r�r�r�r�r{r�ryrzr~rr�r�r�rr�r�r�rCr�r5r�r5r�r5r�r5r�rrNr�r�)&r�r�r�r�r�r}r�r�r�r�r�r�r{r�ryrzr~rr�r�r�rr�r�r�rCr�r5r�r5r�r5r�r5r�rrNr�)�� __future__rr�r�r��abcrr� collectionsr� dataclassesrr�datetimer r r �mathr r �operatorr�osrr� threadingrrr�typesrrrrrrrrrrrrr r!r"r#r$r%r&r'Ztyping_extensionsr(rr*r+r�r,r-r.r/r!r0�jupyterr1rSr2Z progress_barr3rr4r�r5r�r6r7rr8r9r}r:r;rCrcr<r=r�r�r�r�r�r�r�rr r�r�r1r�r�rPrUrVr�r`rarbr�rk�random�time�panelr��ruler��syntaxr�r�Zprogress_renderables� itertoolsr�Zexamplesr�r>r�Ztask1Ztask2Ztask3rrU�sleep�randintr�r�rLrLrLrM�<module>s�       T         * �Ng�A������V*2* H0  1  } T     � �  ����  �� $��
Memory