U cfC@sddlZddlZddlZddlZddlmZmZddlmZddl m Z m Z ddl m Z ddlmZmZddlmZddlmZdd lmZdd lmZmZdd lmZmZmZdd lmZdd lmZmZm 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/ej0dkr&ddlm1Z1n ddl2m1Z1ddl3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:ddl;mZ>ddl?m@Z@ddlAmBZBddlCmDZDddlEmFZFddlGmHZHmIZIddlJmKZKmLZLe(deMZNe.dZOe gePfZQe.de+eZRGdddeZSde/e*eOe%eOfeTe)ePeUe)e7eUe)e gePfePeFeFeFeFePeUeUe%eOd)d*d+ZVGd,d-d-eeZWGd.d/d/e!eRe$eRZXd0d!dd"dd#d$d%d&d'd"d1 eeMeTeUe)e7eUe)e gePfePeFeFeFeFeUe!ed2d3d4ZYejZddd0d!dd"dd#d$d%d&d'd"d6 e/eTd7e[fe/e1d8e1d9feMe)eTe)eTe)eTe)eMeTeUe)e7eUe)e gePfePeFeFeFeFeUe!e+d:d;d<Z\ejZddd0d!dd"dd#d$d%d&d'd"d6 e/eTd7e[fe1d=eMe)eTe)eTe)eTe)eMeTeUe)e7eUe)e gePfePeFeFeFeFeUe!ed:d>d<Z\ddd0d!dd"dd#d$d%d&d'd"d6 e/eTd7e[fe/e1d=e1d8e1d9feMe)eTe)eTe)eTe)eMeTeUe)e7eUe)e gePfePeFeFeFeFeUe/e!ee!e+fd:d?d<Z\Gd@dAdAeZ]GdBdCdCe]Z^GdDdEdEe]Z_GdFdGdGe]Z`GdHdIdIe]ZaGdJdKdKe]ZbGdLdMdMe`ZcGdNdOdOe]ZdGdPdQdQe]ZeGdRdSdSe]ZfGdTdUdUe]ZgGdVdWdWe]ZhGdXdYdYe]ZiGdZd[d[e'Zje Gd\d]d]ZkGd^d_d_e>Zlemd`krddlnZnddloZoddalpmqZqddblrmsZsddcltmuZudddlGmIZIeudedfd!dgZteIdhdidjZGeGvdkdldmdneqdodpeGdqdrdsdtduetesdvg ZwddwlxmyZyeyewZze7d!dxZ6ele_fel{ebfe6d"dyZ|e|j}dzd{d|Z~e|j}d}d{d|Ze|j}d~dd|Ze|jse|je~dde|jeddeodendddkre|eezqW5QRXdS)N)ABCabstractmethoddeque) dataclassfield) timedelta) RawIOBaseUnsupportedOperation)ceil)mmap) length_hint)PathLikestat)EventRLockThread) TracebackType)AnyBinaryIOCallableContextManagerDequeDictGenericIterableList NamedTupleNewTypeOptionalSequenceTextIOTupleTypeTypeVarUnion))Literal)filesize get_console)ConsoleGroup JustifyMethodRenderableType) Highlighter) JupyterMixin)Live) ProgressBar)Spinner) StyleType)ColumnTable)TextTextTypeTaskID ProgressType_IcsjeZdZdZddedfdd Zddd d Zddd d Zee e ee ee dd ddZ Z S) _TrackThreadz)A thread to periodically update progress.Progressr:)progresstask_id update_periodcs.||_||_||_t|_d|_tdS)Nr)r?r@rArdone completedsuper__init__)selfr?r@rA __class__G/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/rich/progress.pyrEBs z_TrackThread.__init__NreturncCsd|j}|jj}|j}d}|jj}||sJ|j}||kr |||||}q |jj|j|jdddS)NrT)rCrefresh)r@r?advancerArBwaitrCupdate)rFr@rNrAlast_completedrOrCrIrIrJrunKsz_TrackThread.runcCs ||SNstartrFrIrIrJ __enter__Ysz_TrackThread.__enter__exc_typeexc_valexc_tbrLcCs|j|dSrS)rBsetjoinrFrYrZr[rIrIrJ__exit__]s z_TrackThread.__exit__)__name__ __module__ __qualname____doc__floatrErRrWrr# BaseExceptionrr_ __classcell__rIrIrGrJr=?s  r= Working...TF bar.back bar.complete bar.finished bar.pulse皙?)sequence descriptiontotal auto_refreshconsole transientget_timerefresh_per_secondstylecomplete_stylefinished_style pulse_stylerAdisable show_speedrLc cs|rtdgng}|t|| | | dt|dtddft||||||pLd| d}||j|||| dEd HW5QRXd S) aTrack progress by iterating over a sequence. Args: sequence (Iterable[ProgressType]): A sequence (must support "len") you wish to iterate over. 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). 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}rvrwrxry)r{T)elapsed_when_finishedrhrqrrrsrtrurz)rprorAN) TextColumnextend BarColumnTaskProgressColumnTimeRemainingColumnr>track)rnrorprqrrrsrtrurvrwrxryrArzr{columnsr?rIrIrJrgs:(  rc@seZdZdZd9edeeddddZddd d Ze e e e e e e dd d d Z edddZedddZeedddZedddZedddZeedddZeedddZedddZedddZedd d!Zd:eed#d$d%Zeeee fd&d'd(Z!d;eed#d)d*Z"d_Readerz9A reader that tracks progress while it's being read from.Tr>N)handler?task close_handlerLcCs"||_||_||_||_d|_dSNF)rr?rr_closed)rFrr?rrrIrIrJrEs z_Reader.__init__rKcCs|j|SrS)rrWrVrIrIrJrWs z_Reader.__enter__rXcCs |dSrS)closer^rIrIrJr_sz_Reader.__exit__cCs|SrSrIrVrIrIrJ__iter__sz_Reader.__iter__cCs$t|j}|jj|jt|d|SNrN)nextrr?rNrlen)rFlinerIrIrJ__next__s z_Reader.__next__cCs|jSrS)rrVrIrIrJclosedsz_Reader.closedcCs |jSrS)rfilenorVrIrIrJrsz_Reader.filenocCs |jSrS)risattyrVrIrIrJrsz_Reader.isattycCs|jjSrS)rmoderVrIrIrJrsz _Reader.modecCs|jjSrS)rnamerVrIrIrJrsz _Reader.namecCs |jSrS)rreadablerVrIrIrJrsz_Reader.readablecCs |jSrS)rseekablerVrIrIrJrsz_Reader.seekablecCsdSrrIrVrIrIrJwritablesz_Reader.writable)sizerLcCs&|j|}|jj|jt|d|Sr)rreadr?rNrr)rFrblockrIrIrJrs z _Reader.read)bcCs"|j|}|jj|j|d|Sr)rreadintor?rNr)rFrnrIrIrJrs z_Reader.readintocCs&|j|}|jj|jt|d|Sr)rreadliner?rNrr)rFrrrIrIrJrs z_Reader.readline)hintrLcCs,|j|}|jj|jttt|d|Sr)r readlinesr?rNrsummapr)rFrlinesrIrIrJrs z_Reader.readlinescCs|jr|jd|_dS)NT)rrrrrVrIrIrJrs z _Reader.closer)offsetwhencerLcCs$|j||}|jj|j|d|S)NrC)rseekr?rPr)rFrrposrIrIrJrsz _Reader.seekcCs |jSrS)rtellrVrIrIrJr sz _Reader.tell)srLcCs tddS)Nwrite)r )rFrrIrIrJr sz _Reader.write)T)r)r)r)r)*r`rarbrcrr:boolrErWrr#rerr_rbytesrpropertyrintrrstrrrrrrrr% bytearray memoryviewr rrrrrrrrrrIrIrIrJrsH   rc@sTeZdZdZdeddddZeddd Zeee ee ee dd d d Z dS) _ReadContextzEA utility class to handle a context for both a reader and a progress.r>N)r?readerrLcCs||_||_dSrS)r?r)rFr?rrIrIrJrEsz_ReadContext.__init__rKcCs|j|jSrS)r?rUrrWrVrIrIrJrWs z_ReadContext.__enter__rXcCs|j|j|||dSrS)r?stoprr_r^rIrIrJr_s z_ReadContext.__exit__) r`rarbrcr<rErWrr#rerr_rIrIrIrJrs r Reading...) rorqrrrsrtrurvrwrxryrz)filerprorqrrrsrtrurvrwrxryrzrLc  Csh|rtdgng} | t|| | | dttft| |||||pDd| 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}rhr)rpro)rrrDownloadColumnrr> wrap_filer)rrprorqrrrsrtrurvrwrxryrzrr?rrIrIrJr&s0%  rr) rprorqrrrsrtrurvrwrxryrz PathLike[str]rtr)rr bufferingencodingerrorsnewlinerprorqrrrsrtrurvrwrxryrzrLc CsdSrSrIrrrrrrrprorqrrrsrtrurvrwrxryrzrIrIrJopengsrrbc CsdSrSrIrrIrIrJrsc  Csr|rtdgng}|t| |||dttft||| | | | pDd|d}|j||||||||d}t||S)aRead 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}rhr)rrrrrrpro)rrrrrr>rr)rrrrrrrprorqrrrsrtrurvrwrxryrzrr?rrIrIrJrsB1   c@sjeZdZUdZdZeeed<deeddddZ eddd Z d e d d d Z e d e d ddZdS)ProgressColumnz3Base class for a widget to use in progress display.N max_refresh) table_columnrLcCs||_i|_d|_dSrS) _table_column_renderable_cache _update_time)rFrrIrIrJrEszProgressColumn.__init__rKcCs |jp tS)z.Get a table column, used to build tasks table.)rr6rVrIrIrJget_table_columnszProgressColumn.get_table_columnTaskrrLcCsr|}|jdk rT|jsTz|j|j\}}Wntk r@YnX||j|krT|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)rtrrCridKeyErrorrender)rFr current_time timestamp renderablerIrIrJ__call__s  zProgressColumn.__call__cCsdS)z"Should return a renderable object.NrIrFrrIrIrJrszProgressColumn.render)N)r`rarbrcrrrd__annotations__r6rErr/rrrrIrIrIrJrs rcsDeZdZdZd ddeeedfddZded d d ZZ S) RenderableColumnzA column to insert an arbitrary column. Args: renderable (RenderableType, optional): Any renderable. Defaults to empty string. Nr)rrcs||_tj|ddSNr)rrDrE)rFrrrGrIrJrE szRenderableColumn.__init__rrcCs|jSrS)rrrIrIrJr&szRenderableColumn.render)r) r`rarbrcr/rr6rErrfrIrIrGrJrsrcsbeZdZdZdeeeeeee dfdd Z deeeedd d d Z d e dddZ ZS) SpinnerColumnaA 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 " ". dotsprogress.spinner? N) spinner_namervspeed finished_textrcs<t|||d|_t|tr$t|n||_tj|ddS)Nrvrr) r4spinner isinstancerr8 from_markuprrDrE)rFrrvrrrrGrIrJrE4s  zSpinnerColumn.__init__)r spinner_stylerrLcCst|||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)rFrrrrIrIrJ set_spinnerDs zSpinnerColumn.set_spinnerrrcCs |jr |jn|j|}|SrS)finishedrrrrt)rFrtextrIrIrJrSs zSpinnerColumn.render)rrrrN)rr)r`rarbrcrrr5rdr9r6rErr/rrfrIrIrGrJr*s,  rc sLeZdZdZd eeeeee ee ddfdd Z d e d d d Z ZS)rzA column containing text.noneleftTN) text_formatrvjustifymarkup highlighterrrLcs:||_||_||_||_||_tj|p0tddddS)NTno_wrapr)rrrvrrrDrEr6)rFrrvrrrrrGrIrJrE_s zTextColumn.__init__rrcCsR|jj|d}|jr*tj||j|jd}nt||j|jd}|jrN|j||SNr)rvr) rformatrr8rrvrr highlight)rFr_textrrIrIrJros zTextColumn.render)rrTNN)r`rarbrcrr5r.rrr0r6rEr8rrfrIrIrGrJr\s rc sLeZdZdZdeeeeeeeeddfd d Zd e d d dZ Z S)raRenders 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". (rirjrkrlN) bar_widthrvrwrxryrrLcs0||_||_||_||_||_tj|ddSr)rrvrwrxryrDrE)rFrrvrwrxryrrGrIrJrEs zBarColumn.__init__rrc Cs^t|jdk rtd|jndtd|j|jdkr2dn td|j|j ||j|j|j |j d S)z&Gets a progress bar widget for a task.Nrr)) rprCwidthpulseanimation_timervrwrxry) r3rpmaxrCrstartedrtrvrwrxryrrIrIrJrs zBarColumn.render)rrirjrkrlN) r`rarbrcrrr5r6rEr3rrfrIrIrGrJrzs" rc@s eZdZdZdedddZdS)TimeElapsedColumnzRenders time elapsed.rrcCsJ|jr |jn|j}|dkr&tdddSttdt|d}tt|ddS)zShow time elapsed.N-:--:--progress.elapsedrvr)seconds)r finished_timeelapsedr8rrrr)rFrr deltarIrIrJrs  zTimeElapsedColumn.renderNr`rarbrcr8rrIrIrIrJrsrc sheZdZdZdeeeeeee ee edd fd d Z e ee ed d dZdedddZZS)raShow 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}%rrrTNF) rtext_format_no_percentagervrrrrr{rLc s(||_||_tj||||||ddS)N)rrvrrrr)rr{rDrE) rFrrrvrrrrr{rGrIrJrEs zTaskProgressColumn.__init__)rrLcCsT|dkrtdddStt|dddddgd \}}||}t|d |d ddS) zRender the speed in iterations per second. Args: task (Task): A Task object. Returns: Text: Text object containing the task speed. Nrzprogress.percentageru×10³u×10⁶u×10⁹u×10¹²z.1fz it/s)r8r*pick_unit_and_suffixr)clsrunitsuffix data_speedrIrIrJ render_speeds   zTaskProgressColumn.render_speedrrcCs|jdkr"|jr"||jp|jS|jdkr2|jn|j}|j|d}|jr`t j ||j |j d}nt ||j |j d}|j r|j ||Sr)rpr{rfinished_speedrrrrrr8rrvrrr)rFrrrrrIrIrJrs  zTaskProgressColumn.render)r rrrTNNF)r`rarbrcrr5r.rrr0r6rE classmethodrdr8rrrfrIrIrGrJrs.rcsDeZdZdZdZd eeeedfdd Zde d d d Z Z S) raRenders 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)compactr~rcs||_||_tj|ddSr)rr~rDrE)rFrr~rrGrIrJrEszTimeRemainingColumn.__init__rrcCs|jr|jr|j}d}n |j}d}|jdkr8td|dS|dkrVt|jrLdnd|dStt|d\}}t|d\}}|jr|s|d d |d }n|d d |d d |d }t||dS) zShow time remaining.rzprogress.remainingNrrz--:--r<02d:d) r~rr time_remainingrpr8rdivmodr)rFr task_timervminutesrhours formattedrIrIrJr s    zTimeRemainingColumn.render)FFN) r`rarbrcrrrr6rEr8rrfrIrIrGrJrs rc@s eZdZdZdedddZdS)FileSizeColumnzRenders completed filesize.rrcCstt|j}t|ddS)Show data completed.zprogress.filesizer)r*decimalrrCr8rFr data_sizerIrIrJr+szFileSizeColumn.renderNr rIrIrIrJr$(sr$c@s eZdZdZdedddZdS)TotalFileSizeColumnzRenders total filesize.rrcCs*|jdk rtt|jnd}t|ddS)r%Nrzprogress.filesize.totalr)rpr*r&rr8r'rIrIrJr4szTotalFileSizeColumn.renderNr rIrIrIrJr)1sr)cs>eZdZdZd eeedfdd Zdedd d Z Z S) 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) separatorrcs||_tj|ddSr)r,rDrE)rFr,rrGrIrJrEFszMofNCompleteColumn.__init__rrcCsPt|j}|jdk rt|jnd}tt|}t||d|j|ddS)zShow completed/total.N?rprogress.downloadr)rrCrprrr8r,)rFrrCrp total_widthrIrIrJrJs  zMofNCompleteColumn.render)r+N) r`rarbrcrrr6rEr8rrfrIrIrGrJr*:s r*cs@eZdZdZd eeeddfdd Zdedd d Z Z S) rzRenders 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_unitsrrLcs||_tj|ddSr)r0rDrE)rFr0rrGrIrJrE\szDownloadColumn.__init__rrc Cst|j}|jdk rt|jn|}|jrNt|dddddddd d g d \}}n$t|dd d ddddddg d\}}|dkr~dnd}||}|d|d}|jdk rt|j} | |} | d|d} nd} |d| d|} t| dd} | S)z.Calculate common unit for completed and total.NrKiBMiBGiBTiBPiBEiBZiBYiBikBMBGBTBPBEBZBYBrr)rz,.fr-r+rr.r)rrCrpr0r*rr8)rFrrC unit_and_suffix_calculation_baserr precisioncompleted_ratio completed_strrp total_ratio total_strdownload_status download_textrIrIrJrbs2     zDownloadColumn.render)FN) r`rarbrcrrr6rEr8rrfrIrIrGrJrUsrc@s eZdZdZdedddZdS)TransferSpeedColumnz&Renders human readable transfer speed.rrcCs@|jp |j}|dkr tdddStt|}t|dddS)zShow data transfer speed.Nr-zprogress.data.speedrz/s)rrr8r*r&r)rFrrrrIrIrJrs   zTransferSpeedColumn.renderNr rIrIrIrJrJsrJc@s"eZdZUdZeed<eed<dS)ProgressSamplez$Sample of progress for a given time.rrCN)r`rarbrcrdrrIrIrIrJrKs rKc@seZdZUdZeed<eed<eeed<eed<e ed<dZ eeed<d Z e ed <e ed Zeeefed <e dd d dZeeed<e dd d dZeeed<dZeeed<e ddd d dZeeed<e d edZeed<edddZee dddZeeedddZeeeddd Zee dd!d"Zeedd#d$Z eeedd%d&Z!eeedd'd(Z"ddd)d*Z#dS)+rzInformation regarding a progress task. This object should be considered read-only outside of the :class:`~Progress` class. rrorprC _get_timeNr Tvisible)default_factoryfieldsF)defaultinitrepr start_time stop_timercCs tddS)Nr)maxlenrrIrIrIrJz Task.)rNrQrR _progress)rRrN_lockrKcCs|S)z(float: Get the current time, in seconds.)rLrVrIrIrJrtsz Task.get_timecCs |jdk S)z#bool: Check if the task as started.N)rSrVrIrIrJrsz Task.startedcCs|jdkrdS|j|jS)zPOptional[float]: Get the number of steps remaining, if a non-None total was set.N)rprCrVrIrIrJ remainings zTask.remainingcCs2|jdkrdS|jdk r$|j|jS||jS)z]Optional[float]: Time elapsed since task was started, or ``None`` if the task hasn't started.N)rSrTrtrVrIrIrJr s    z Task.elapsedcCs |jdk S)zCheck if the task has finished.N)r rVrIrIrJrsz Task.finishedcCs.|js dS|j|jd}tdtd|}|S)zOfloat: Get progress of task as a percentage. If a None total was set, returns 0Y@)rprCminr)rFrCrIrIrJ percentages zTask.percentagec Cs|jdkrdS|j~|j}|s.W5QRdS|dj|dj}|dkrXW5QRdSt|}t|tdd|D}||}|W5QRSQRXdS)z=Optional[float]: Get the estimated speed in steps per second.Nrrcss|] }|jVqdSrSr).0samplerIrIrJ szTask.speed..)rSrYrXriterrr)rFr? total_time iter_progresstotal_completedrrIrIrJrs z Task.speedcCs:|jr dS|j}|sdS|j}|dkr*dSt||}|S)zJOptional[float]: Get estimated time to completion, or ``None`` if no data.r[N)rrrZr )rFrrZestimaterIrIrJrs zTask.time_remainingcCs|jd|_d|_dS)zReset progress.N)rXclearr rrVrIrIrJ_resets z Task._reset)$r`rarbrcr:rrrrdGetTimeCallabler rMrrdictrOrrrSrTrrXrrKrrYrtrrrZr rr^rrrhrIrIrIrJrsD    rc@seZdZdZddddddddddd eeefeee e e e e e ee e e dd d d Z e eed fd d dZeed ddZeeed ddZeeed ddZee d ddZdd ddZdd ddZdd ddZeeeeeeeddddZdXeee e!e fee eeee ee d"d#d$Z"dYdd%d&e#ee$eeee#d'd(d)Z%e&j'dZddd%d+eed,e(fe)d-e$eeeeeeee$eeee#d. d/d0Z*e&j'd[ddd%d+eed,e(fee)d1e)d2fe$eeeeeeee$eeee+d. d3d0Z*d\ddd%d+eed,e(fee)d-e)d2e)d1fe$eeeeeeee$eeeee#e+fd. d4d0Z*edd5d6d7Z,edd5d8d9Z-ddddddd:eee ee ee eeee e e.dd; dddd?ee ee e$ee eee.dd@dAdBZ0d]ee ddDdEdFZ1dd dGdHZ2e3d dIdJZ4ee3d dKdLZ5eee6dMdNdOZ7e3d dPdQZ8d^ee ee e$e e.edSdTdUZ9edd5dVdWZ:dS)_r>aRenders an auto-updating progress bar(s). Args: console (Console, optional): Optional Console instance. Default will 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. NTrhg>@F) rrrqruspeed_estimate_periodrsredirect_stdoutredirect_stderrrtrzexpand) rrrrqrurkrsrlrmrtrzrnrLc Gs|dkstdt|_| p"||_||_| |_| |_i|_t d|_ t |pRt ||||||j d|_|pr|jj|_|jj|_|jj|_dS)Nrzrefresh_per_second must be > 0)rrrqrursrlrmget_renderable)AssertionErrorrrYget_default_columnsrrkrzrn_tasksr: _task_indexr2r+roliverrrtprintlog) rFrrrqrurkrsrlrmrtrzrnrrIrIrJrE)s(   zProgress.__init__.rKcCstdtttfS)aGet 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|)rrrr)rrIrIrJrqMs zProgress.get_default_columnscCs|jjSrS)rtrrrVrIrIrJrrlszProgress.consolec Cs,|jt|jW5QRSQRXdS)zGet a list of Task instances.N)rYlistrrvaluesrVrIrIrJtaskspszProgress.tasksc Cs,|jt|jW5QRSQRXdS)zA list of task IDs.N)rYrwrrkeysrVrIrIrJtask_idsvszProgress.task_idsc CsJ|j:|jsW5QRdStdd|jDW5QRSQRXdS)z'Check if all tasks have been completed.Tcss|] }|jVqdSrS)r)r_rrIrIrJrasz$Progress.finished..N)rYrrallrxrVrIrIrJr|szProgress.finishedcCs|js|jjdddS)zStart the progress display.T)rMN)rzrtrUrVrIrIrJrUszProgress.startcCs |j|jjs|jdS)zStop the progress display.N)rtrrris_interactiverurVrIrIrJrs z Progress.stopcCs ||SrSrTrVrIrIrJrWszProgress.__enter__rXcCs |dSrS)rr^rIrIrJr_szProgress.__exit__rgrm)rnrpr@rorArLc cs|dkrtt|pd}|dkr0|j||d}n|j||d|jjr~t|||$}|D]}|V|jd7_qXW5QRXn,|j}|j } |D]}|V||d| qdS)aTrack progress by iterating over a sequence. Args: sequence (Sequence[ProgressType]): A sequence of values you want to iterate over and track progress. total: (float, optional): Total number of steps. Default is len(sequence). 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. Nrpr)) rdr add_taskrPrtrqr=rCrNrM) rFrnrpr@rorA track_threadvaluerNrMrIrIrJrs  zProgress.trackr)r@ro)rrpr@rorLc Cs~d}|dk r|}n&|dk r8|j|j|j}W5QRX|dkrHtd|dkr`|j||d}n|j||dt|||ddS)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~Fr)rYrrrp ValueErrorrrPr)rFrrpr@ro total_bytesrIrIrJrszProgress.wrap_filer)rpr@rorr) rrrrrrrpr@rorLc CsdSrSrI rFrrrrrrrpr@rorIrIrJrsz Progress.openrrc CsdSrSrIrrIrIrJrscCsdt|dd} | dkr(td||dk} | dkrR|dkrRtdtd }n&| d krx|d krltd n |dkrxd }|d krt|j}|d kr|j | |d}n|j ||dt j |d|d} t | ||dd} |dkrt j| |||| dS| 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)brrrzinvalid mode {!r}r)rzaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be usedr)rrrzcan't have unbuffered text I/ONr~r)rTr)rr)rrrline_buffering)r]sortedrrwarningswarnRuntimeWarningrst_sizerrPiorr TextIOWrapper)rFrrrrrrrpr@ro_moderrrrIrIrJrs>!  )r@rLc Cs4|j$|j|}|jdkr&||_W5QRXdS)zStart 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)rYrrrSrt)rFr@rrIrIrJ start_task[s   zProgress.start_taskc Cs>|j.|j|}|}|jdkr*||_||_W5QRXdS)zStop a task. This will freeze the elapsed time on the task. Args: task_id (TaskID): ID of task. N)rYrrrtrSrT)rFr@rrrIrIrJ stop_taskis   zProgress.stop_task)rprCrNrorMrM) r@rprCrNrorMrMrOrLc Ks*|j |j|} | j} |dk r:|| jkr:|| _| |dk rP| j|7_|dk r^|| _|dk rl|| _|dk rz|| _| j|| j| } | } | |j } | j }|j }|r|dj | kr|q| dkr|t| | | jdk r| j| jkr| jdkr| j| _W5QRX|r&|dS)aUpdate 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)rYrrrCrprhrorMrOrPrtrkrXpopleftrappendrKr r rM)rFr@rprCrNrorMrMrOrcompleted_startupdate_completedrold_sample_timerXrrIrIrJrPxsB      zProgress.updater)rUrprCrMro)r@rUrprCrMrorOrLc Ks|}|jf|j|} | |r*|nd| _|dk r>|| _|| _|dk rR|| _|r\|| _|dk rj|| _ d| _ W5QRX| dS)aReset 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) rtrYrrrhrSrprCrMrOror rM) rFr@rUrprCrMrorOrrrIrIrJresets  zProgress.resetr))r@rNrLc Cs|}|j|j|}|j}|j|7_|j|}||j}|j}|j} |rh|dj|krh| qNt|dkr|| qh| t |||j dk r|j|j kr|j dkr|j |_ |j|_W5QRXdS)zAdvance task by a number of steps. Args: task_id (TaskID): ID of task. advance (float): Number of steps to advance. Default is 1. rrN)rtrYrrrCrkrXrrrrrKrpr r rr) rFr@rNrrrrrrXrrIrIrJrNs,     zProgress.advancecCs|js|jjr|jdS)z*Refresh (render) the progress information.N)rzrt is_startedrMrVrIrIrJrMszProgress.refreshcCst|}|S)z*Get a renderable for the progress display.)r-get_renderables)rFrrIrIrJros zProgress.get_renderableccs||j}|VdS)z5Get a number of renderables for the progress display.N)make_tasks_tablery)rFtablerIrIrJrs zProgress.get_renderables)ryrLcsRdd|jD}tj|d|jd}|D]$jr(|jfdd|jDq(|S)zGet 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. css.|]&}t|trtddn |VqdS)TrN)rrr6rcopy)r__columnrIrIrJras z,Progress.make_tasks_table..)rr))paddingrnc3s,|]$}t|tr|jdn|VqdS)rN)rrr)r_columnrrIrJras)rr7gridrnrMadd_row)rFry table_columnsrrIrrJr s   zProgress.make_tasks_tablec Cs&|j|W5QRSQRXdS)z+Makes the Progress class itself renderable.N)rYrorVrIrIrJ__rich__*szProgress.__rich__r\)rorUrprCrMrOrLc Ksr|jZt|j||||||j|jd}||j|j<|rB||j|j}tt|jd|_W5QRX||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`. )rMrOrLrYr)) rYrrsrtrrrr:rrM) rFrorUrprCrMrOrnew_task_indexrIrIrJr/s$  zProgress.add_taskc Cs|j|j|=W5QRXdS)z]Delete a task if it exists. Args: task_id (TaskID): A task ID. N)rYrr)rFr@rIrIrJ remove_taskZszProgress.remove_task)NNrgrm)N)rNNN)rNNN)rrNNN)r))Tr\rT);r`rarbrcr%rrrr,rrdrirErr"rqrrrrrryr:r{rrUrrWr#rerr_rr;r rrrrtypingoverloadrr(rr!rrrrPrrNrMr/rorr7rrrrrIrIrIrJr>sn  $   , *       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_valuepython) line_numbersZfoobarZbaz123z: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)rrrsz[red]Downloadingrr~z[green]Processingz[yellow]Thinkingrrg333333?g{Gz?d)rgNTNFNrhrirjrkrlrmFT)rNNN)rNNN)rrNNN)rsysrrabcrr collectionsr dataclassesrrdatetimerr r mathr r operatorr osrr threadingrrrtypesrrrrrrrrrrrrrr r!r"r#r$r% version_infor(Zpip._vendor.typing_extensionsrr*r+rrr,r-r.r/rr0jupyterr1rtr2 progress_barr3rr4rvr5rr6r7rr8r9rr:r;rdrir<r=rrrrrrrrrrrrrrrrrr$r)r*rrJrKrr>r`randomtimepanelrrulersyntaxrrZprogress_renderables itertoolsrZexamplesrqr?rZtask1Ztask2Ztask3rrPsleeprandintrvrrIrIrIrJs,      P          * Fd A    V*2* H0  1  }P