"Te7+ ddlZddlZddlZddlZddlmZmZddlmZddl 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/ej`dk\rddlm1Z1nddl2m1Z1ddl3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:ddl;mZ>ddl?m@Z@ddlAmBZBddlCmDZDddlEmFZFddlGmHZHmIZIddlJmKZKmLZLe(deMZNe.dZOe gePfZQej\de+eZRGddeZS dd'e/e*eOe%eOfd(eTd)e)ePd*eUd+e)e7d,eUd-e)e gePfd.ePd/eFd0eFd1eFd2eFd3ePd4eUd5eUd6e%eOf d7ZVGd8d9eeZWGd:d;e!eRe$eRZXded)eMd(eTd*eUd+e)e7d,eUd-e)e gePfd.ePd/eFd0eFd1eFd2eFd4eUd6e!efd?ZYej ddde/eTdAe[fdBe/e1dCe1dDfdEeMdFe)eTdGe)eTdHe)eTd)e)eMd(eTd*eUd+e)e7d,eUd-e)e gePfd.ePd/eFd0eFd1eFd2eFd4eUd6e!e+f&dIZ\ej ddde/eTdAe[fdBe1dJdEeMdFe)eTdGe)eTdHe)eTd)e)eMd(eTd*eUd+e)e7d,eUd-e)e gePfd.ePd/eFd0eFd1eFd2eFd4eUd6e!ef&dKZ\ ddde/eTdAe[fdBe/e1dJe1dCe1dDfdEeMdFe)eTdGe)eTdHe)eTd)e)eMd(eTd*eUd+e)e7d,eUd-e)e gePfd.ePd/eFd0eFd1eFd2eFd4eUd6e/e!ee!e+ff&dLZ\GdMdNeZ]GdOdPe]Z^GdQdRe]Z_GdSdTe]Z`GdUdVe]ZaGdWdXe]ZbGdYdZe`ZcGd[d\e]ZdGd]d^e]ZeGd_d`e]ZfGdadbe]ZgGdcdde]ZhGdedfe]ZiGdgdhe'Zje GdidjZkGdkdle>Zlemdmk(rhddlnZnddloZoddnlpmqZqddolrmsZsddpltmuZuddqlGmIZIeudrdsd tZteIdudvdwZGeGjdxdydzd{eqd|d}eGd~ddddetesdg ZwddlxmyZyeyewZze7d Z6ele_geljebe6d!d5Z|e|jddZ~e|jddZe|jddZe|jsxe|je~de|jedeojdenjdddkre|j eeze|jsxdddyy#1swYyxYw)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_IcpeZdZdZdddddeffd Zdd Zdd Zd ee e d ee dee dd fdZ xZ S) _TrackThreadz)A thread to periodically update progress.progressProgresstask_idr; update_periodcx||_||_||_t|_d|_t |y)Nr)r@rBrCrdone completedsuper__init__)selfr@rBrC __class__s //usr/lib/python3/dist-packages/rich/progress.pyrHz_TrackThread.__init__Bs4   *G  returnNcT|j}|jj}|j}d}|jj }||s(|j }||k7r||||z |}||s(|jj|j|j dy)NrT)rFrefresh)rBr@advancerCrEwaitrFupdate)rIrBrPrClast_completedrQrFs rKrunz_TrackThread.runKs,,--''** yy~~}%I*^!; ?@UW  NN --'   * 5 d ;   !-3H  >> E{-"        s0ABB7B8B< BBB Bc eZdZdZ d'dedddededdf d Zd(d Zd e e e d e e d e e ddfdZ defdZdefdZedefdZdefdZdefdZedefdZedefdZdefdZdefdZdefdZd)dedefdZdeeee ffdZ!d)dedefdZ"d)dede#efdZ$d*d Z%d+d!ed"edefd#Z&defd$Z'd%e(defd&Z)y),_Readerz9A reader that tracks progress while it's being read from.handler@rAtask close_handlerMNcJ||_||_||_||_d|_yNF)rr@rr_closed)rIrr@rrs rKrHz_Reader.__init__s(    ( rLc:|jj|SrV)rrZrYs rKrZz_Reader.__enter__s  rLr\r]r^c$|jyrV)closerbs rKrcz_Reader.__exit__s rLc|SrVrYs rK__iter__z_Reader.__iter__s rLct|j}|jj|jt ||SNrP)nextrr@rPrlen)rIlines rK__next__z_Reader.__next__s4DKK  diiT; rLc|jSrV)rrYs rKclosedz_Reader.closeds ||rLc6|jjSrV)rfilenorYs rKrz_Reader.fileno{{!!##rLc6|jjSrV)risattyrYs rKrz_Reader.isattyrrLc.|jjSrV)rmoderYs rKrz _Reader.mode{{rLc.|jjSrV)rnamerYs rKrz _Reader.namerrLc6|jjSrV)rreadablerYs rKrz_Reader.readable{{##%%rLc6|jjSrV)rseekablerYs rKrz_Reader.seekablerrLcyrrrYs rKwritablez_Reader.writablesrLsizec|jj|}|jj|jt ||Sr)rreadr@rPrr)rIrblocks rKrz _Reader.reads:   & diiU< rLbc|jj|}|jj|j||Sr)rreadintor@rPr)rIrns rKrz_Reader.readintos6 KK  # dii3rLc|jj|}|jj|jt ||Sr)rreadliner@rPrr)rIrrs rKrz_Reader.readlines:{{##D) diiT; rLhintc |jj|}|jj|jt t t||Sr)r readlinesr@rPrsummapr)rIrliness rKrz_Reader.readlinessA %%d+ diiSe_1EF rLc^|jr|jjd|_y)NT)rrrrrYs rKrz _Reader.closes"    KK    rLoffsetwhencec|jj||}|jj|j||S)NrF)rseekr@rRr)rIrrposs rKrz _Reader.seeks8kkvv. TYY#6 rLc6|jjSrV)rtellrYs rKrz _Reader.tell s{{!!rLsctd)Nwrite)r )rIrs rKrz _Reader.write s "7++rL)T)rMr)rd)r)*rerfrgrhrr;boolrHrZr r$rjrrcrbytesrpropertyrintrrstrrrrrrrr& bytearray memoryviewr rrrrrrrrrrrLrKrrsC"        4 ./-('   (% $$$$ c   c  &$&&$&$e % :t ;< S% c4;  3C "c",s,s,rLrc`eZdZdZdddeddfdZdefdZd eee d ee d ee ddfd Z y) _ReadContextzEA utility class to handle a context for both a reader and a progress.r@rAreaderrMNc ||_||_yrV)r@r)rIr@rs rKrHz_ReadContext.__init__s    rLcj|jj|jjSrV)r@rXrrZrYs rKrZz_ReadContext.__enter__s% {{$$&&rLr\r]r^cr|jj|jj|||yrV)r@stoprrcrbs rKrcz_ReadContext.__exit__s*  Xw7rL) rerfrgrhr=rHrZr r$rjrrcrrLrKrrsjO!!R!D!'2'84 ./8-(8' 8  8rLr Reading...) rsrurvrwrxryrzr{r|r}r~filec |r tdgng} | jt|| | | tt ft | |||||xsd| d}|j |||}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. rrrmr)rtrs)rrrDownloadColumnrrA wrap_filer)rrtrsrurvrwrxryrzr{r|r}r~rr@rs rKrr&sJEP> ?@UW  NN --'      !   !-3H  E{  KF & ))rL) rtrsrurvrwrxryrzr{r|r}r~ PathLike[str]rrtr bufferingencodingerrorsnewlinec yrVrrrrrrrrtrsrurvrwrxryrzr{r|r}r~s rKopenrg, rLrbc yrVrrs rKrrrrLc |r tdgng}|jt| |||tt ft ||| | | | xsd|d}|j ||||||||}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. rrrmr)rrrrrrtrs)rrrrrrArr)rrrrrrrtrsrurvrwrxryrzr{r|r}r~rr@rs rKrrsbEP> ?@UW  NN --'      !   !-3H]]  F & ))rLcteZdZUdZdZeeed<d deeddfdZ defdZ dd de fd Z e dd de fd Zy) ProgressColumnz3Base class for a widget to use in progress display.N max_refresh table_columnrMc.||_i|_d|_yrV) _table_column_renderable_cache _update_time)rIrs rKrHzProgressColumn.__init__s)MO-1rLc2|jxs tS)z.Get a table column, used to build tasks table.)rr7rYs rKget_table_columnzProgressColumn.get_table_columns!!-VX-rLrTaskc.|j}|j=|js1 |j|j\}}||jz|kDr|S|j |}||f|j|j<|S#t $rY9wxYw)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). )rxrrFridKeyErrorrender)rIr current_time timestamp renderables rK__call__zProgressColumn.__call__s}}    ' &(,(>(>tww(G% :t///,>%%[[& +7*Dtww'  sB BBcy)z"Should return a renderable object.NrrIrs rKrzProgressColumn.rendersrLrV)rerfrgrhrr ri__annotations__r7rHrr0rrrrrLrKrrsl=#'K%'2Xf%522 .&.V.161n11rLrcLeZdZdZ d dddedeeffdZddd efd ZxZ S) RenderableColumnzA column to insert an arbitrary column. Args: renderable (RenderableType, optional): Any renderable. Defaults to empty string. Nrrrc4||_t| |yNr )rrGrH)rIrrrJs rKrHzRenderableColumn.__init__ s% l3rLrrrMc|jSrV)rrs rKrzRenderableColumn.render&s rL)) rerfrgrhr0r r7rHrrkrls@rKr r sB,.4SW4(4@H@P4 6nrLr c eZdZdZ ddedeedededee f fd Z dded eeded dfd Z d d d e fdZ xZS) 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 " ". N spinner_namerzspeed finished_textrct||||_t|trt j |n||_t|!|y)Nrzrr ) r5spinner isinstancerr9 from_markuprrGrH)rIrrzrrrrJs rKrHzSpinnerColumn.__init__4sN|5F --   ] +  l3rL spinner_stylerMc*t||||_y)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)r5r)rIrrrs rK set_spinnerzSpinnerColumn.set_spinnerDs|=N rLrrc|jr|j}|S|jj|j }|SrV)finishedrrrrx)rIrtexts rKrzSpinnerColumn.renderSsH}}     $$T]]_5  rL)dotsprogress.spinner? N)r r!)rerfrgrhrr r6rir:r7rHrr0rrkrls@rKrr*s#%7"%)- 44 "4 4  4 v& 4&.@ O O * O O  O6nrLrcheZdZdZ ddededededee dee d dffd Z d d d e fd Z xZS)rzA column containing text.N text_formatrzjustifymarkup highlighterrrMc||_||_||_||_||_t ||xs tdy)NTno_wrapr )r$r%rzr&r'rGrHr7)rIr$rzr%r&r'rrJs rKrHzTextColumn.__init___sD'&-   & l&JfT6JKrLrrcB|jj|}|jr-tj||j |j }n"t||j |j }|jr|jj||SNr)rzr%) r$formatr&r9rrzr%r' highlight)rIr_textrs rKrzTextColumn.renderosv  ''T'2 ;;##ET\\RDTZZFD       & &t , rL)noneleftTNN)rerfrgrhrr6r/rr r1r7rHr9rrkrls@rKrr\s# "!'-1)-LLL L  L k* Lv&L L 6drLrcjeZdZdZ ddeedededededeed dffd Zd d d e fd Z xZ 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". N bar_widthrzr{r|r}rrMcl||_||_||_||_||_t ||yr )r4rzr{r|r}rGrH)rIr4rzr{r|r}rrJs rKrHzBarColumn.__init__s;# ,,& l3rLrrc \t|jtd|jndtd|j|jdntd|j|j |j |j|j|j|j S)z&Gets a progress bar widget for a task.Nrr*) rtrFwidthpulseanimation_timerzr{r|r}) r4rtmaxrFr4startedrxrzr{r|r}rs rKrzBarColumn.renders(, (>#a$D!T^^,..0$c!T^^6Lll"==?**....((  rL)(rnrorprqN) rerfrgrhr rr6r7rHr4rrkrls@rKrrzs$&%$2$2!,)-4C=44" 4 " 4  4v&4 4  6  k  rLrc eZdZdZdddefdZy)TimeElapsedColumnzRenders time elapsed.rrrMc|jr |jn |j}| tddSt t dt |}tt|dS)zShow time elapsed.-:--:--progress.elapsedrzr)seconds)r finished_timeelapsedr9r r:rr)rIrrEdeltas rKrzTimeElapsedColumn.rendersS(, $$$4<< ? );< <#aW"67CJ&899rLNrerfrgrhr9rrrLrKr>r>s:6:d:rLr>ceZdZdZ ddedededededee d ee d ed dffd Z e d ee d efdZddd efdZxZS)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. Nr$text_format_no_percentagerzr%r&r'rrrMc L||_||_t | ||||||y)N)r$rzr%r&r'r)rIrrGrH) rIr$rIrzr%r&r'rrrJs rKrHzTaskProgressColumn.__init__s9*C&$ ##%  rLrc| tddStjt|gdd\}}||z }t|d|ddS)zRender the speed in iterations per second. Args: task (Task): A Task object. Returns: Text: Text object containing the task speed. rzprogress.percentagerB)ru×10³u×10⁶u×10⁹u×10¹²z.1fz it/s)r9r+pick_unit_and_suffixr)clsrunitsuffix data_speeds rK render_speedzTaskProgressColumn.render_speeds_ ="78 844 J <  f T\ z#&vhe43.0f}%rr1r2TNNF)rerfrgrhrr6r/rr r1r7rH classmethodrir9rRrrkrls@rKrrs K)+!!'-1)-   $'       k* v&    ,S%STSS& 6 d rLrcReZdZdZdZ d dededeeffd Zddd e fd Z xZ 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. ?compactrrcB||_||_t| |yr )rXrrGrH)rIrXrrrJs rKrHzTimeRemainingColumn.__init__s$  %:" l3rLrrrMc|jr|jr|j}d}n|j}d}|j t d|S|!t |j rd|Sd|Stt|d\}}t|d\}}|j r |s |dd |d}n |d d |dd |d}t ||S) zShow time remaining.rAzprogress.remainingrrBz--:--r@<02d:d) rrrDtime_remainingrtr9rXdivmodr)rIr task_timerzminutesrChours formatteds rKrzTimeRemainingColumn.render s  % %$--**I&E++I(E :: %( (  4<<eL LYeL L"#i."5,w <<"3-q 6I )1WSM73-@IIU++rL)FFN) rerfrgrhrrr r7rHr9rrkrls@rKrrsSK&+)- 44 $4v& 4,6,d,rLrc eZdZdZdddefdZy)FileSizeColumnzRenders completed filesize.rrrMcltjt|j}t |dS)Show data completed.zprogress.filesizerB)r+decimalrrFr9rIr data_sizes rKrzFileSizeColumn.render+s)$$S%89 I%899rLNrGrrLrKrfrf(s%:6:d:rLrfc eZdZdZdddefdZy)TotalFileSizeColumnzRenders total filesize.rrrMc|j(tjt|jnd}t |dS)rhrzprogress.filesize.totalrB)rtr+rirr9rjs rKrzTotalFileSizeColumn.render4s49=9OH$$S_5UW I%>??rLNrGrrLrKrmrm1s!@6@d@rLrmcDeZdZdZd dedeeffd ZdddefdZ xZ 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 "/". separatorrc4||_t| |yr )rqrGrH)rIrqrrJs rKrHzMofNCompleteColumn.__init__Fs" l3rLrrrMct|j}|jt|jnd}tt |}t ||d|j |dS)zShow completed/total.?r^progress.downloadrB)rrFrtrrr9rq)rIrrFrt total_widths rKrzMofNCompleteColumn.renderJsc' #'::#9DJJs#e*o +a((8 @%  rL)/N) rerfrgrhrr r7rHr9rrkrls@rKrprp:s3 4#48F;K4 6 d rLrpcJeZdZdZ d dedeeddffd Zdddefd Z xZ 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. N binary_unitsrrMc4||_t| |yr )ryrGrH)rIryrrJs rKrHzDownloadColumn.__init__\s) l3rLrrct|j}|jt|jn|}|jrt j |gdd\}}nt j |gdd\}}|dk(rdnd}||z }|d|d}|j#t|j} | |z } | d|d} nd } |d | d |} t | d } | S)z.Calculate common unit for completed and total.) rKiBMiBGiBTiBPiBEiBZiBYiBi) rkBMBGBTBPBEBZBYBrLr*rz,.frtrwr"rurB)rrFrtryr+rMr9)rIrrF unit_and_suffix_calculation_baserOrP precisioncompleted_ratio completed_strrt total_ratio total_strdownload_status download_texts rKrzDownloadColumn.renderbs'  $zz5C O9 )   #880QLD& $880ILD& A #d**2i[/: :: ! OE$,K&r)Ao6II*O1YKqA_4GH rL)FN) rerfrgrhrr r7rHr9rrkrls@rKrrUsDLP4 48@8H4 4 !6!d!rLrc eZdZdZdddefdZy)TransferSpeedColumnz&Renders human readable transfer speed.rrrMc|jxs |j}| tddStjt |}t|ddS)zShow data transfer speed.rtzprogress.data.speedrBz/s)rTrr9r+rir)rIrrrQs rKrzTransferSpeedColumn.rendersR##1tzz =#89 9%%c%j1 zl"%-BCCrLNrGrrLrKrrs0D6DdDrLrc(eZdZUdZeed< eed<y)ProgressSamplez$Sample of progress for a given time.rrFN)rerfrgrhrirrrLrKrrs.$rLrceZdZUdZeed< eed< eeed< eed< e ed< dZ eeed< d Z e ed < e e Zeeefed < e dd d Zeeed< e dd d Zeeed< dZeeed< e dd d Zeeed<e d eZeed< defdZede fdZedeefdZedeefdZede fdZedefdZ edeefdZ!edeefdZ"d!d Z#y)"rzInformation regarding a progress task. This object should be considered read-only outside of the :class:`~Progress` class. rrsrtrF _get_timeNrDTvisible)default_factoryfieldsF)defaultinitrepr start_time stop_timerTctdS)NrL)maxlenrrrLrKz Task.s T 2rL)rrr _progress)rr_lockrMc"|jS)z(float: Get the current time, in seconds.)rrYs rKrxz Task.get_times~~rLc|jduS)z#bool: Check if the task as started.N)rrYs rKr;z Task.startedsd**rLcN|jy|j|jz S)zPOptional[float]: Get the number of steps remaining, if a non-None total was set.N)rtrFrYs rK remainingzTask.remainings$ :: zzDNN**rLc|jy|j|j|jz S|j|jz S)z]Optional[float]: Time elapsed since task was started, or ``None`` if the task hasn't started.N)rrrxrYs rKrEz Task.elapsedsC ?? " >> %>>DOO3 3}}00rLc|jduS)zCheck if the task has finished.N)rDrYs rKrz Task.finisheds!!--rLc|jsy|j|jz dz}tdtd|}|S)zOfloat: Get progress of task as a percentage. If a None total was set, returns 0Y@)rtrFminr:)rIrFs rK percentagezTask.percentages>zz^^djj0E9 s3 23 rLcJ|jy|j5|j}|s dddy|dj|djz }|dk(r dddyt |}t |t d|D}||z }|cdddS#1swYyxYw)z=Optional[float]: Get the estimated speed in steps per second.Nrrc34K|]}|jywrVr).0samples rK zTask.speed..s!Ov&"2"2!O)rrrriterrr)rIr@ total_time iter_progresstotal_completedrs rKrz Task.speeds ?? " ZZ ~~H  ""//(1+2G2GGJQ  !NM  !!O!OOO#j0E   sB%B!.BB"cx|jry|j}|sy|j}|yt||z }|S)zJOptional[float]: Get estimated time to completion, or ``None`` if no data.rN)rrrr )rIrrestimates rKr_zTask.time_remainingsC == NN   E)*rLcT|jjd|_d|_y)zReset progress.N)rclearrDrTrYs rK_resetz Task._resets" !"rLrd)$rerfrgrhr;rrr riGetTimeCallablerDrrrdictrrrrrrTrrrrrrxrr;rrErrrr_rrrLrKrrs JG' E?>*+%)M8E?)(GTJ"48FDcN8?"'5u"MJMN!&t%e!LIxLN&*NHUO*>',2U(Iu^$eU;E5; % ++++8E?++ 1%11.$..Ex"   #rLrceZdZdZddddddddddd deeefd eed e d e d e d e de de dee de de ddfdZ e deedffdZedefdZedeefdZedeefdZede fdZdOdZdOdZdPdZdeeedeed eeddfd!Z dQd"eee e!e fd#ee d$eed%ed&e dee f d'Z" dRdd(d)d*e#d#ee$d$eed%ede#f d+Z%e&jN dSddd(d,d*eed-e(fd.e)d/d0e$d1eed2eed3eed#ee$d$eed%ede#fd4Z*e&jN dSddd(d,d*eed-e(fd.ee)d5e)d6fd0e$d1eed2eed3eed#ee$d$eed%ede+fd7Z* dTddd(d,d*eed-e(fd.ee)d/e)d6e)d5fd0e$d1eed2eed3eed#ee$d$eed%edee#e+ffd8Z*d$eddfd9Z,d$eddfd:Z-ddddddd;d$ed#ee dee d?e d@e.ddfdAZ/dddBdddCd$edDe d#ee dee d%eed@e.ddfdEZ0dUd$ed=e ddfdFZ1dOdGZ2de3fdHZ4dee3fdIZ5dJeede6fdKZ7de3fdLZ8 dVd%edDe d#ee de d@e.defdMZ9d$eddfdNZ:y)WrAaRenders 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. NTrmg>@F) rvruryspeed_estimate_periodrwredirect_stdoutredirect_stderrrxr~expandrrvruryrrwrrrxr~rrMc |dkDsJdt|_| xs|j|_||_| |_| |_i|_td|_ t|xs t||||||j|_ |xs|jj|_|jj |_|jj"|_y)Nrzrefresh_per_second must be > 0)rvruryrwrrget_renderable)rrget_default_columnsrrr~r_tasksr; _task_indexr3r,rlivervrxprintlog) rIrvruryrrwrrrxr~rrs rKrHzProgress.__init__)s"A%G'GG%W <$":":"< %:"  *, #)!9,{}%1++..  !9DLL$9$9 \\'' <<##rL.cPtdtttfS)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)rNs rKrzProgress.get_default_columnsMs(2 A B K   !   rLc.|jjSrV)rrvrYs rKrvzProgress.consolelsyy   rLc|j5t|jjcdddS#1swYyxYw)zGet a list of Task instances.N)rlistrvaluesrYs rKtaskszProgress.tasksps5ZZ . **,- . . . #:Ac|j5t|jjcdddS#1swYyxYw)zA list of task IDs.N)rrrkeysrYs rKtask_idszProgress.task_idsvs5ZZ , ((*+ , , ,rc|j5|js dddytd|jjDcdddS#1swYyxYw)z'Check if all tasks have been completed.NTc34K|]}|jywrV)r)rrs rKrz$Progress.finished..sFt}}Fr)rrallrrYs rKrzProgress.finished|sWZZ G;; G GF1C1C1EFF G G GsA)AA cV|js|jjdyy)zStart the progress display.T)rON)r~rrXrYs rKrXzProgress.starts || IIOODO )rLc|jj|jjs|jj yy)zStop the progress display.N)rrrvis_interactiverrYs rKrz Progress.stops2 ||** LL   +rLc&|j|SrVrWrYs rKrZzProgress.__enter__r[rLr\r]r^c$|jyrV)rrbs rKrczProgress.__exit__s rLrrrtrBrsrCc#K|tt|xsd}||j||}n|j|||jj r8t |||5}|D]}||xjdz c_ dddy|j}|j} |D]}|||d| y#1swYyxYww)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. Nrtr*) riradd_taskrRrrur?rFrPrO) rIrrrtrBrsrC track_threadvaluerPrOs rKrzProgress.tracks( =+h/08DE ?mmKum=G KKuK - 99 ! !dG]; 0|%0EK **a/*0 0 0 llGllG!  #   0 0sA'C)!C =CC Cr)rBrsrcd}||}n0|.|j5|j|j}ddd| td||j ||}n|j ||t |||dS#1swYNxYw)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'rFr)rrrt ValueErrorrrRr)rIrrtrBrs total_bytess rKrzProgress.wrap_files.(,  K   9"kk'288  9  Q  ?mmK{mCG KK{K 3tT7?? 9 9s A==B)rtrBrsrrrrrrrcyrVr rIrrrrrrrtrBrss rKrz Progress.open rLrrcyrVrrs rKrz Progress.openrrLcdjt|d} | dvrtdj||dk(} | dk(r"|dk(rt j dt d }n| d vr|d k(r td |dk(rd }|t|j}||j| | }n|j|| tj|d|} t| ||d} |dvrtj| |||| 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)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/Orr)rTr)rr)rrrline_buffering)rasortedrr.warningswarnRuntimeWarningrst_sizerrRiorr TextIOWrapper)rIrrrrrrrtrBrs_moderrrs rKrz Progress.opens(BtU34 ) )077=> >#a D=Y!^ MMs I k !A~ !ABBa  =J&&E ?mmKum=G KKuK -ty9wTB ; ##!-   rLc|j5|j|}|j|j|_dddy#1swYyxYw)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)rrrrx)rIrBrs rK start_taskzProgress.start_task[sEZZ 2;;w'D&"&--/ 2 2 2s 1AAc|j5|j|}|j}|j||_||_dddy#1swYyxYw)zStop a task. This will freeze the elapsed time on the task. Args: task_id (TaskID): ID of task. N)rrrxrr)rIrBrrs rK stop_taskzProgress.stop_taskisQZZ *;;w'D==?L&".)DN  * * *s :AA)rtrFrPrsrrOrFrPrrOrc <|j5|j|} | j} |&|| jk7r|| _| j || xj|z c_||| _||| _||| _| jj|| j| z } |j} | |jz } | j}|j}|r.|dj| kr||r|dj| kr| dkDr|jt| | | j6| j| jk\r| j | j"| _ddd|r|j%yy#1swYxYw)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)rrrFrtrrsrrrRrxrrpopleftrappendrrDrErO)rIrBrtrFrPrsrrOrrcompleted_startupdate_completedrold_sample_timerrs rKrRzProgress.updatexsy0ZZ 2;;w'D"nnO Udjj%8"  "')$!*&#. "& KK  v &#~~? ==?L*T-G-GGOI''G ! 6 6 H  ! 6 6 H!#   >N!OP &NNdjj0&&.%)\\"A 2D  LLN E 2 2sDFA"FFr)rXrtrFrrsrXc >|j}|j5|j|} | j|r|nd| _||| _|| _||| _|r|| _||| _ d| _ ddd|jy#1swYxYw)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) rxrrrrrtrFrrrsrDrO) rIrBrXrtrFrrsrrrs rKresetzProgress.resets,}} ZZ &;;w'D KKM.3lDO " &DN"& $ &#. !%D  &  & &s ABBc|j}|j5|j|}|j}|xj|z c_|j|z }||jz }|j }|j } |r.|dj|kr| |r|dj|krt|dkDr| t|dkDr|jt|||jG|j|jk\r.|j"|j|_ |j|_dddy#1swYyxYw)zAdvance task by a number of steps. Args: task_id (TaskID): ID of task. advance (float): Number of steps to advance. Default is 1. rrLN)rxrrrFrrrrrrrrtrDrErrT) rIrBrPrrrrrrrs rKrPzProgress.advances%}} ZZ 1;;w'D"nnO NNg %N#~~? *T-G-GGOI''G ! 6 6 H  ! 6 6 Hi.4' i.4'   ^L:JK L &NNdjj0&&.%)\\"&*jj#) 1 1 1sBE4#EA.EEc|js2|jjr|jjyyy)z*Refresh (render) the progress information.N)r~r is_startedrOrYs rKrOzProgress.refreshs,|| 4 4 II   !5|rLc2t|j}|S)z*Get a renderable for the progress display.)r.get_renderables)rIrs rKrzProgress.get_renderablesD0023 rLc#JK|j|j}|yw)z5Get a number of renderables for the progress display.N)make_tasks_tabler)rItables rKr zProgress.get_renderabless%%djj1 s!#rcd|jD}tj|d|jd}|D]1js|j fd|jD3|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. c3K|]>}t|tr tdn|jj @yw)Tr)N)rrr7rcopy)r_columns rKrz,Progress.make_tasks_table..sE gs+t$--/4467 sAA)rr*)paddingrc3rK|].}t|tr|jn|0yw)r-N)rrr.)rcolumnrs rKrz,Progress.make_tasks_table..s> # *&#6#MMtM4!'.s47)rr8gridrradd_row)rIr table_columnsrrs @rKrzProgress.make_tasks_table sn  <<   M6$++N D||  '+ll    rLcf|j5|jcdddS#1swYyxYw)z+Makes the Progress class itself renderable.N)rrrYs rK__rich__zProgress.__rich__*s* ZZ )&&( ) ) )s'0c |j5t|j||||||j|j}||j|j<|r|j |j|j}t t|jdz|_ddd|jS#1swYxYw)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`. )rrrrr*N) rrrrxrrr;rrO) rIrsrXrtrFrrrnew_task_indexs rKrzProgress.add_task/s0ZZ A  --jj D-1DKK(( ) 0 01!--N%c$*:*:&;a&?@D  A # A As BCC c`|j5|j|=dddy#1swYyxYw)z]Delete a task if it exists. Args: task_id (TaskID): A task ID. N)rr)rIrBs rK remove_taskzProgress.remove_taskZs,ZZ % G$ % % %s$-rd)rMrA)NN Working...皙?rVrNNNrrNNN)r*)TrrT);rerfrgrhr&rrr r-rrirrHrUr#rrrvrrrr;rrrXrrZr$rjrrcrr<r!rrrrtypingoverloadrr)rr"rrrrRrrPrOr0rr r8rrrr rrLrKrArAs $&*!$&'+ $ $.2"$^+,"$'""$ "$ " "$ % "$"$"$"$?+"$"$"$ "$H E.#*=$>  <!!!.tDz.. ,$v,,, G$GG* ! 4 ./-('   "&$('" '.0FFG''&! '  '  ' , 'X $(@ %)' (@(@}(@ &! (@  (@ (@T __ "& $!%   $$('  C%/0  dm    3-    #  }  &!          __ "& $!%   $$('  C%/0  GCL'$-/0    3-    #  }  &!         $CF"& $!%K $$('KC%/0KGDM74='#,>?K K 3- K  K#K}K&!KK x KZ 2& 2T 2 * *D *&"&%)#'%)"&;; ; E? ; % ;c];$;;; ;B!%"&%)%% %  %  %$%c]%% %N1v11d1<  .!9 htnB).)!& ))) )  )  )) )V%6%d%rLrA__main__)Panel)Rule)Syntax)r8a~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_numbersfoobarbaz123z: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...examplezPretty printed)typerz Syntax...zGive it a try!)cycle)record)rvrwz[red]DownloadingrLrz[green]Processingz[yellow]ThinkingrWrg333333?g{Gz?d)r!NTNFNrmrnrorprqr"FTr#r$)rsysr%rabcrr collectionsr dataclassesrrdatetimer r r mathr r operatorrosrr threadingrrrtypesrrrrrrrrrrrrr r!r"r#r$r%r& version_infor)typing_extensionsrr+r,rvr-r.r/r0r'r1jupyterr2rr3 progress_barr4rr5rzr6rr7r8rr9r:rr;r<rirr=r?rrrrrrr&rrrr rrrr>rrrfrmrprrrrrArerandomtimepanelr(ruler)syntaxr*rprogress_renderables itertoolsr5examplesrr@rtask1task2task3rrRsleeprandintrrrrLrKrSsY  #(. ***v)#BB$!% 3 ~& 2u9%V^^D&(+%6%T$!!%.2 "! . .(C H\*H\,BBCC C  E?C  C g  C  C xE *+C C  C C C C C C C l!C La,ia,H8>"%wr{82$!%.2 "! . .(>* >* >* >*  >* g  >*>*xE *+>*>* >*>*>*>*>*H>*B" !   #!%.2 "! . .(' _e+ ,  ws|+ ,  sm  SM  c]   C=   g   xE *+    ! "# $% &' (F)  0" !   #!%.2 "! . .(' _e+ , $-  sm  SM  c]   C=   g   xE *+    ! "# $% &' (H)  4?B" ! S* #!%.2 "! . .('S* _e+ ,S*  wt}gcl: ;S*S*sm S* SM S* c] S* C=S*S*S*g S*S*xE *+S*S* S* !S*"#S*$%S*&'S*( >( #^F%; ;<)S*l'1S'1T~"/N/d<' ' T : :EEP-,.-,`:^:@.@  6.^.b D. D%Z% z#z# z#zI %|I %X z  " F % &E MM#sC  E 89' &$45   )*HT"G    % % '     - !!"4D!A!!"5T!B!!"4D!A## OOE3O / OOE3O / DJJt v~~a%) T(^, ##--]\--s ?B>UU