xhddlmZddlZddlZddlZddlmZmZddlm 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/m0Z0m1Z1erddl2m3Z3ddl4m5Z5m6Z6ddl7m8Z8m9Z9m:Z:m;Z;ddlm?Z?ddl@mAZAddlBmCZCddlDmEZEddlFmGZGddlHmIZImJZJddlKmLZLmMZMe+deNZOe0dZPe"geQfZRej0de-e!ZSGddeZT dddCZUGdDdEee!ZVGdFdGe#eSe&eSZWdHd!dd"dd#d$d%d&d'd"dI ddMZXejY dddHd!dd"dd#d$d%d&d'd"dO ddZZZejY dddHd!dd"dd#d$d%d&d'd"dO dd\ZZ dddHd!dd"dd#d$d%d&d'd"dO dd`ZZGdadbeZ[Gdcdde[Z\Gdedfe[Z]Gdgdhe[Z^Gdidje[Z_Gdkdle[Z`Gdmdne^ZaGdodpe[ZbGdqdre[ZcGdsdte[ZdGdudve[ZeGdwdxe[ZfGdydze[ZgGd{d|e*Zhe Gd}d~ZiGdde?ZjekdkrddllZlddlmZmddlnmoZoddlpmqZqddlrmsZsddlHmJZJesddd!ZreJdddZHeHtddddeoddeHdddddereqdg ZuddlvmwZweweuZxe8d!Z7eje]gejye`Re7d"d5Zzez{ddZ|ez{ddZ}ez{ddZ~ezjsxeze|deze}demjdeljdddkrezeexezjxddddS#1swxYwYdSdS)) annotationsN)ABCabstractmethoddeque) dataclassfield) timedelta) RawIOBaseUnsupportedOperation)ceil)mmap) length_hint)PathLikestat)EventRLockThread) TracebackType) TYPE_CHECKINGAnyBinaryIOCallableContextManagerDequeDictGenericIterableListLiteral NamedTupleNewTypeOptionalTextIOTupleTypeTypeVarUnion)Self)filesize get_console)ConsoleGroup JustifyMethodRenderableType) Highlighter) JupyterMixin)Live) ProgressBar)Spinner) StyleType)ColumnTable)TextTextTypeTaskID ProgressType_Ic<eZdZdZdfd Zdd Zdd ZddZxZS) _TrackThreadz)A thread to periodically update progress.progress 'Progress'task_id'TaskID' update_periodfloatc||_||_||_t|_d|_t ddS)NrT)daemon)r@rBrDrdone completedsuper__init__)selfr@rBrD __class__s ]/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/rich/progress.pyrKz_TrackThread.__init__CsL   *GG  %%%%%returnNonecP|j}|jj}|j}d}|jj}||sK|jjjr:|j}||kr||||z |}||s|jjj:|j |j|jddS)NrT)rIrefresh) rBr@advancerDrHwaitlive is_startedrIupdate)rLrBrTrDlast_completedrUrIs rNrunz_TrackThread.runLs,-'* y~$}%% +$-*<*G +I**^!;<< ? ?@@UW  NN --'     * 5 5 5 d ; ; ;     !-3H   >> #' "                           s1!BB#&B#ceZdZdZ d;ddZd?dZd@dZe dAdZ dBdZ dAdZ e dCdZ e dCd ZdAd!ZdAd"ZdAd#ZdDdEd&ZdFd)ZdDdEd*ZdDdGd-ZdHd.ZdIdJd2ZdBd3ZdKd6ZdLd9Zd:S)M_Readerz9A reader that tracks progress while it's being read from.Thandlerr@rAtaskr; close_handlerrPrQcL||_||_||_||_d|_dSNF)rr@rr_closed)rLrr@rrs rNrKz_Reader.__init__s,    ( rO '_Reader'c8|j|Sr])rrar`s rNraz_Reader.__enter__s  rOrcrdrerfrgrhc.|dSr])closerls rNrmz_Reader.__exit__s rOc|Sr]r`s rN__iter__z_Reader.__iter__s rObytesct|j}|j|jt ||SNrT)nextrr@rTrlen)rLlines rN__next__z_Reader.__next__s9DK   diT;;; rOc|jSr])rr`s rNclosedz_Reader.closeds |rOrc4|jSr])rfilenor`s rNrz_Reader.fileno{!!###rOc4|jSr])risattyr`s rNrz_Reader.isattyrrOrc|jjSr])rmoder`s rNrz _Reader.mode {rOc|jjSr])rnamer`s rNrz _Reader.namerrOc4|jSr])rreadabler`s rNrz_Reader.readable{##%%%rOc4|jSr])rseekabler`s rNrz_Reader.seekablerrOcdSrrr`s rNwritablez_Reader.writablesurOsizec|j|}|j|jt ||Sr)rreadr@rTrr)rLrblocks rNrz _Reader.reads?   && diU<<< rOb"Union[bytearray, memoryview, mmap]c||j|}|j|j||Sr)rreadintor@rTr)rLrns rNrz_Reader.readintos9 K  # # di333rOc|j|}|j|jt ||Sr)rreadliner@rTrr)rLrrs rNrz_Reader.readlines?{##D)) diT;;; rOhint List[bytes]c |j|}|j|jt t t||Sr)r readlinesr@rTrsummapr)rLrliness rNrz_Reader.readlinessI %%d++ diSe__1E1EFFF rOcT|jr|jd|_dS)NT)rrrrr`s rNrz _Reader.close s,   K      rOroffsetwhencec~|j||}|j|j||S)NrI)rseekr@rXr)rLrrposs rNrz _Reader.seeks;kvv.. TY#666 rOc4|jSr])rtellr`s rNrz _Reader.tells{!!!rOsrc td)Nwriter )rLrs rNrz _Reader.writes"7+++rOr Iterable[Any]c td)N writelinesr)rLrs rNrz_Reader.writeliness"<000rON)T) rrr@rArr;rrrPrQ)rPrro)rPr)rPrrPr)rPr)rPr)r)rrrPr)rr)rrrPrrn)r)rrrrrPr)rrrPr)rrrPrQ)rprqrrrsrKrarmrrpropertyrrrrrrrrrrrrrrrrrrrOrNrrsCC"      X$$$$$$$$   X    X &&&&&&&&      """",,,,111111rOrc*eZdZdZddZdd ZddZdS) _ReadContextzEA utility class to handle a context for both a reader and a progress.r@rAreaderr=rPrQc"||_||_dSr])r@r)rLr@rs rNrKz_ReadContext.__init__ s    rOcf|j|jSr])r@r_rrar`s rNraz_ReadContext.__enter__$s* {$$&&&rOrcrdrerfrgrhcp|j|j|||dSr])r@stoprrmrls rNrmz_ReadContext.__exit__(s8  Xw77777rON)r@rArr=rPrQ)rPr=ro)rprqrrrsrKrarmrrOrNrrsVOO!!!!''''888888rOr Reading...) rrrrrrrrrrrfilerContextManager[BinaryIO]c "|rtdgng} | t|| | | tt ft | |||||pd| 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. rrrwr)rr)rrrDownloadColumnrr wrap_filer)rrrrrrrrrrrrrrr@rs rNrr2sJEPW> ? ?@@UW  NN --'         ! !     !-3H  E{  K KF & ) ))rOr) rrrrrrrrrrrr"Union[str, 'PathLike[str]', bytes]r"Union[Literal['rt'], Literal['r']] bufferingencoding Optional[str]errorsnewline Optional[int]ContextManager[TextIO]c dSr]rrrrrrrrrrrrrrrrrrrs rNopenrs , DrO Literal['rb']c dSr]rrs rNrrrrOr1Union[Literal['rb'], Literal['rt'], Literal['r']]7Union[ContextManager[BinaryIO], ContextManager[TextIO]]c ,|rtdgng}|t| |||tt ft ||| | | | pd|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. rrrwr)rrrrrrr)rrrrrrrr)rrrrrrrrrrrrrrrrrrrr@rs rNrrsbEPW> ? ?@@UW  NN --'         ! !     !-3H]]   F & ) ))rOcTeZdZUdZdZded<ddd Zdd ZddZe ddZ dS)ProgressColumnz3Base class for a widget to use in progress display.Nr max_refresh table_columnOptional[Column]rPrQc0||_i|_d|_dSr]) _table_column_renderable_cache _update_time)rLrs rNrKzProgressColumn.__init__s )MO-1rOr7c,|jp tS)z.Get a table column, used to build tasks table.)rr7r`s rNget_table_columnzProgressColumn.get_table_columns!-VXX-rOr'Task'r0c|}|j>|js7 |j|j\}}||jz|kr|Sn#t $rYnwxYw||}||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). )rrrIridKeyErrorrender)rLr current_time timestamp renderables rN__call__zProgressColumn.__call__ s}}   ' ' &(,(>tw(G% :t//,>>%%?     [[&& +7*Dtw'sA AAcdS)z"Should return a renderable object.NrrLrs rNrzProgressColumn.render srOr])rrrPrQ)rPr7rrrPr0) rprqrrrsr__annotations__rKrr!rrrrOrNrrs==#'K''''22222 .....111^111rOrc6eZdZdZ ddddfd Zdd ZxZS)RenderableColumnzA column to insert an arbitrary column. Args: renderable (RenderableType, optional): Any renderable. Defaults to empty string. Nrr r0rrcZ||_t|dSNr))r rJrK)rLr rrMs rNrKzRenderableColumn.__init__,s-% l33333rOrrrPc|jSr])r r#s rNrzRenderableColumn.render2s rO)r()r r0rrr$rprqrrrsrKrrtrus@rNr'r'%sr,.4SW44444444 rOr'cFeZdZdZ ddfd Z dddZddZxZS) 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_namerrOptional[StyleType]speedrE finished_textr:rrct||||_t|trt j|n||_t|dS)Nrr6r)) r5spinner isinstancerr9 from_markupr7rJrK)rLr4rr6r7rrMs rNrKzSpinnerColumn.__init__@sm|5FFF --- D ] + + +  l33333rO spinner_stylerPrQc4t||||_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. r9N)r5r:)rLr4r=r6s rN set_spinnerzSpinnerColumn.set_spinnerPs|=NNN rOrrr0cz|jr|jn+|j|}|Sr])finishedr7r:rr)rLrtexts rNrzSpinnerColumn.render_s=} 6D  $$T]]__55  rO)r0r1r2r3N) r4rrr5r6rEr7r:rr)r1r2)r4rr=r5r6rErPrQr$)rprqrrrsrKr?rrtrus@rNr/r/6s#%7"%)- 4444444&.@ O O O O OrOr/c8eZdZdZ ddfd ZddZxZS)rzA column containing text.noneleftTN text_formatrrr6justifyr/markupr highlighterOptional[Highlighter]rrrPrQc||_||_||_||_||_t |ptddS)NTno_wrapr))rFrGrrHrIrJrKr7)rLrFrrGrHrIrrMs rNrKzTextColumn.__init__ks['&-   & l&JfT6J6J6JKKKKKrOrrr9c|j|}|jr"tj||j|j}nt||j|j}|jr|j||SNr)rrG) rFformatrHr9r<rrGrI highlight)rLr_textrBs rNrzTextColumn.render{s ''T'22 ; G#ET\RRRDDTZFFFD   -   & &t , , , rO)rDrETNN)rFrrr6rGr/rHrrIrJrrrPrQrrrPr9r-rus@rNrrhst## "!'-1)-LLLLLLL rOrc:eZdZdZ ddfd ZddZxZS)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". (rxryrzr{N bar_widthrrr6rrrrrrPrQc||_||_||_||_||_t |dSr+)rWrrrrrJrK)rLrWrrrrrrMs rNrKzBarColumn.__init__sL# ,,& l33333rOrrr4c  t|jtd|jndtd|j|jdntd|j|j ||j|j|j |j  S)z&Gets a progress bar widget for a task.Nrr*) rrIwidthpulseanimation_timerrrr) r4rmaxrIrWstartedrrrrrr#s rNrzBarColumn.renders(, (>#a$$$D!T^,,.0$$c!T^6L6Ll"==??*..(    rO)rVrxryrzr{N)rWrrr6rr6rr6rr6rrrPrQ)rrrPr4r-rus@rNrrst$&%$2$2!,)-4444444         rOrceZdZdZddZdS) TimeElapsedColumnzRenders time elapsed.rrrPr9c|jr|jn|j}|tddSt t dt |}tt|dS)zShow time elapsed.N-:--:--progress.elapsedrr)seconds)rA finished_timeelapsedr9r r]rr)rLrrgdeltas rNrzTimeElapsedColumn.rendersk(, G$$$4< ? );<<< <#aW"6"6777CJJ&89999rONrTrprqrrrsrrrOrNr`r`s.::::::rOr`cVeZdZdZ d!d"fd Zed#dZd$d ZxZS)%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}%r(rDrETNFrFrtext_format_no_percentagerr6rGr/rHrrIrJrrrrPrQc r||_||_t||||||dS)N)rFrrGrHrIr)rlrrJrK) rLrFrlrrGrHrIrrrMs rNrKzTaskProgressColumn.__init__sR*C&$ ##%      rOr6rr9c|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. Nr(zprogress.percentagerd)r(u×10³u×10⁶u×10⁹u×10¹²z.1fz it/s)r9r+pick_unit_and_suffixr)clsr6unitsuffix data_speeds rN render_speedzTaskProgressColumn.render_speedsx ="7888 84 JJ < < <   f T\ z44v444YeLLL L"#i.."55,,w < A A"666666II @@@W@@@7@@@IIU++++rO)FFN)r{rrrrrrT)rprqrrrsrrKrrtrus@rNrrsrK&+)- 4444444,,,,,,,,rOrceZdZdZddZdS) FileSizeColumnzRenders completed filesize.rrrPr9cptjt|j}t |dS)Show data completed.zprogress.filesizerd)r+decimalrrIr9rLr data_sizes rNrzFileSizeColumn.render7s0$S%8%899 I%89999rONrTrirrOrNrr4s.%%::::::rOrceZdZdZddZdS) TotalFileSizeColumnzRenders total filesize.rrrPr9c|j&tjt|jnd}t |dS)rNr(zprogress.filesize.totalrd)rr+rrr9rs rNrzTotalFileSizeColumn.render@s;9=9OH$S__555UW I%>????rONrTrirrOrNrr=s4!!@@@@@@rOrc.eZdZdZddfd Zdd ZxZS)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 separatorrrrcZ||_t|dSr+)rrJrK)rLrrrMs rNrKzMofNCompleteColumn.__init__Rs+" l33333rOrrrPr9ct|j}|jt|jnd}tt |}t ||d|j|dS)zShow completed/total.N?rprogress.downloadrd)rrIrrrr9r)rLrrIr total_widths rNrzMofNCompleteColumn.renderVst'' #':#9DJs#e**oo + @ @ @ @ @ @ @%    rO)rN)rrrrrTr-rus@rNrrFs`  4444444        rOrc0eZdZdZ ddfd ZddZxZS)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_unitsrrrrPrQcZ||_t|dSr+)rrJrK)rLrrrMs rNrKzDownloadColumn.__init__hs.) l33333rOrrr9ct|j}|jt|jn|}|jrt j|gdd\}}nt j|gdd\}}|dkrdnd}||z }|d|d }|j"t|j} | |z } | d|d } nd } |d | d |} t | d } | S)z.Calculate common unit for completed and total.N) rKiBMiBGiBTiBPiBEiBZiBYiBi) rkBMBGBTBPBEBZBYBror*rz,.frrr3rrd)rrIrrr+rpr9)rLrrI unit_and_suffix_calculation_baserrrs precisioncompleted_ratio completed_strr total_ratio total_strdownload_status download_texts rNrzDownloadColumn.renderns+''  $z5C OOO9 )   #80QQQLD&& $80IIILD& AA #d**;i;;;; : ! OOE$,K&7)7777III*AAYAAAA_4GHHH rO)FN)rrrrrPrQrTr-rus@rNrrasgLP4444444 !!!!!!!!rOrceZdZdZddZdS) TransferSpeedColumnz&Renders human readable transfer speed.rrrPr9c|jp|j}|tddStjt |}t|ddS)zShow data transfer speed.Nrzprogress.data.speedrdz/s)rwr6r9r+rr)rLrr6rts rNrzTransferSpeedColumn.renders]#1tz =#8999 9%c%jj11 z%%%-BCCCCrONrTrirrOrNrrs400DDDDDDrOrc*eZdZUdZded< ded<dS)ProgressSamplez$Sample of progress for a given time.rErrIN)rprqrrrsr%rrOrNrrs3..$$rOrceZdZUdZded< ded< ded< ded < d ed < d Zded < dZded< eeZ ded< ed ddZ ded< ed ddZ ded< d Z ded< edddZ ded<edeZded< d+d!Zed,d"Zed-d#Zed-d$Zed,d%Zed+d&Zed-d'Zed-d(Zd.d*Zd S)/TaskzInformation regarding a progress task. This object should be considered read-only outside of the :class:`~Progress` class. r;rrrrrrErIGetTimeCallable _get_timeNrfTrvisible)default_factoryzDict[str, Any]fieldsF)defaultinitrepr start_time stop_timerwc"tdS)Nro)maxlenrrrOrNz Task.sT 2 2 2rO)rrrzDeque[ProgressSample] _progress)rrr_lockrPc*|S)z(float: Get the current time, in seconds.)rr`s rNrz Task.get_times~~rOc|jduS)z#bool: Check if the task as started.N)rr`s rNr^z Task.startedsd**rOc2|jdS|j|jz S)zPOptional[float]: Get the number of steps remaining, if a non-None total was set.NrrIr`s rN remainingzTask.remainings  : 4zDN**rOcx|jdS|j|j|jz S||jz S)z]Optional[float]: Time elapsed since task was started, or ``None`` if the task hasn't started.N)rrrr`s rNrgz Task.elapseds= ? "4 > %>DO3 3}}00rOc|jduS)zCheck if the task has finished.N)rfr`s rNrAz Task.finisheds!--rOcx|jsdS|j|jz dz}tdtd|}|S)zOfloat: Get progress of task as a percentage. If a None total was set, returns 0Y@)rrIminr])rLrIs rN percentagezTask.percentagesEz 3^dj0E9 s3 2233 rOc^|jdS|j5|j}|s ddddS|dj|djz }|dkr ddddSt |}t |t d|D}||z }|cdddS#1swxYwYdS)z=Optional[float]: Get the estimated speed in steps per second.Nrrc3$K|] }|jV dSr]r).0samples rN zTask.speed.. s%!O!Ov&"2!O!O!O!O!O!OrO)rrrriterrr)rLr@ total_time iter_progresstotal_completedr6s rNr6z Task.speedsI ? "4 Z  ~H         ""/(1+2GGJQ        !NNM    !!O!O!O!O!OOOO#j0E                  s B""B"=B""B&)B&ch|jrdS|j}|sdS|j}|dSt||z }|S)zJOptional[float]: Get estimated time to completion, or ``None`` if no data.rN)rAr6rr )rLr6restimates rNrzTask.time_remainingsP = 3  4N  4 E)**rOrQcT|jd|_d|_dS)zReset progress.N)rclearrfrwr`s rN_resetz Task._resets, !"rO)rPrEr)rPrrn)rprqrrrsr%rfrr dictrrrrwrrrrrr^rrgrArr6rrrrOrNrrsr JJJG'>*+%)M))))(GJ"U4888F8888?"'%5u"M"M"MJMMMMN!&t%e!L!L!LILLLLN&*N****>',u22U(((I5eU;;;E;;;;    +++X++++X+ 111X1...X.XX"   X ######rOrc eZdZdZddddddddddd dsdZedtdZedudZedvd Z edwd"Z edxd#Z dyd$Z dyd%Z dzd'Zd{d.Z d|d}d=Z d~dd>d?ddCZej dddd>dEddNZej dddd>dEddQZ dddd>dEddUZddWZddXZdddddddYdd`Zddd/dddaddcZdddeZdydfZddhZddjZddnZddoZ dddqZddrZ dS)raRenders 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. NTrwg>@F) rrrspeed_estimate_periodrredirect_stdoutredirect_stderrrrexpandrUnion[str, ProgressColumn]rrrrrrErrrrrOptional[GetTimeCallable]rrrPrQc |dks Jdt|_| p||_||_| |_| |_i|_td|_ t|p t||||||j |_ |p |jj|_|jj|_|jj|_dS)Nrzrefresh_per_second must be > 0)rrrrrrget_renderable)rrget_default_columnsrrrr_tasksr; _task_indexr3r,rrVrrprintlog) rLrrrrrrrrrrrs rNrKzProgress.__init__5s"A%%%'G%%%WW <$":":"<"< %:"  *, #)!99,{}}%1++.    !9DL$9 \' <#rOTuple[ProgressColumn, ...]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)rqs rNrzProgress.get_default_columnsYs32 A B B KK   ! !   rOr-c|jjSr])rVrr`s rNrzProgress.consolexs y  rO List[Task]c|j5t|jcdddS#1swxYwYdS)zGet a list of Task instances.N)rlistrvaluesr`s rNtaskszProgress.tasks|sZ . . **,,-- . . . . . . . . . . . . . . . . . . &;?? List[TaskID]c|j5t|jcdddS#1swxYwYdS)zA list of task IDs.N)rrrkeysr`s rNtask_idszProgress.task_idssZ , , ((**++ , , , , , , , , , , , , , , , , , ,rc|j5|js ddddStd|jDcdddS#1swxYwYdS)z'Check if all tasks have been completed.NTc3$K|] }|jV dSr])rA)rrs rNrz$Progress.finished..s$FFt}FFFFFFrO)rrallrr`s rNrAzProgress.finishedsZ G G;  G G G G G G G GFF1C1C1E1EFFFFF G G G G G G G G G G G G G G G G G Gs A/AA!AcN|js|jddSdS)zStart the progress display.T)rSN)rrVr_r`s rNr_zProgress.starts2| * IOODO ) ) ) ) ) * *rOc|j|jjs'|jjs|jdSdSdS)zStop the progress display.N)rVrris_interactive is_jupyterrr`s rNrz Progress.stops[ |* !4<3J ! L    ! ! ! !rOr)c.||Sr]r^r`s rNrazProgress.__enter__rbrOrcrdrerfrgrhc.|dSr])rrls rNrmzProgress.__exit__s rOrrvr|r}r~rrrIrrBOptional[TaskID]rrrDc#K|tt|pd}|||||}n|||||jjrFt |||5}|D]}|V|xjdz c_ ddddS#1swxYwYdS|j} |j } |D]}|V| |d| dS)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. Nrr*) rEradd_taskrXrVrr?rIrTrS) rLr}rrIrBrrD track_threadvaluerTrSs rNrzProgress.tracksb0 =+h//008DE ?mmKu mRRGG KKu K B B B 9 ! dG];; 0|%00EKKK **a/***0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 lGlG!   ###   s3BB"Br)rBrrrrc d}||}n3|1|j5|j|j}dddn #1swxYwY|td||||}n|||t |||dS)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)rrr ValueErrorrrXr)rLrrrBr total_bytess rNrzProgress.wrap_files.(,  KK   9 9"k'28  9 9 9 9 9 9 9 9 9 9 9 9 9 9 9  R  ?mmK{mCCGG KK{K 3 3 3tT7????s 044r)rrBrrrrrrrrrcdSr]r rLrrrrrrrrBrs rNrz Progress.open  rO"Union[Literal['r'], Literal['rt']]r$cdSr]rrs rNrz Progress.openrrOr r Union[BinaryIO, TextIO]c6dt|d} | dvrtd||dk} | dkr#|dkrtjdt d }n!| d vr|d krtd |dkrd }|t |j}||| |}n| ||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. r(F)reverse)brrtr z invalid mode r*rzaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be usedr)r r rzcan't have unbuffered text I/ONrrb)rTr)r r )rrrline_buffering)rksortedrwarningswarnRuntimeWarningrst_sizerrXiorr TextIOWrapper)rLrrrrrrrrBr_moder"rrs rNrz Progress.opensjBtU33344 ) ) )5T5566 6#a D==Y!^^ Ms   II k ! !A~~ !ABBBa  =JJ&E ?mmKum==GG KKuK - - -ty999wTBBB ;  #!-   rOr;c|j5|j|}|j||_ddddS#1swxYwYdS)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)rrrr)rLrBrs rN start_taskzProgress.start_taskksZ 2 2;w'D&"&--// 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s.AA Ac|j5|j|}|}|j||_||_ddddS#1swxYwYdS)zStop a task. This will freeze the elapsed time on the task. Args: task_id (TaskID): ID of task. N)rrrrr)rLrBrrs rN stop_taskzProgress.stop_taskysZ * *;w'D==??L&".)DN  * * * * * * * * * * * * * * * * * *s7A  AA)rrIrTrrrSrTrOptional[bool]rSrrc |j5|j|} | j} |&|| jkr|| _| || xj|z c_||| _||| _||| _| j|| j| z } | } | |j z } | j }|j }|r.|dj | kr||r|dj | k| dkr#|t| | | j#| j| jkr| j | j| _dddn #1swxYwY|r|dSdS)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)rrrIrrrrrrXrrrpopleftrappendrrfrgrS)rLrBrrIrTrrrSrrcompleted_startupdate_completedrold_sample_timerr1s rNrXzProgress.updates0Z 2 2;w'D"nO Udj%8%8"  "')$!*&#. "& K  v & & &#~? ==??L*T-GGOI'G  ! 6 H H   ! 6 H H!##   >N!O!OPPP &Ndj00&.%)\"A 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2D   LLNNNNN  sD=EEE)r_rrIrrr_c P|}|j5|j|} | |r|nd| _||| _|| _||| _|r|| _||| _ d| _ dddn #1swxYwY| 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) rrrrrrrIrrrrfrS) rLrBr_rrIrrrrrs rNresetzProgress.resets,}} Z & &;w'D KKMMM.3=llDO " &DN"&  %$ &#. !%D  & & & & & & & & & & & & & & & sABB B r*cl|}|j5|j|}|j}|xj|z c_|j|z }||jz }|j}|j} |r.|dj|kr| |r|dj|kt|dkr| t|dk| t|||j /|j|j kr|j |j |_ |j|_ddddS#1swxYwYdS)zAdvance task by a number of steps. Args: task_id (TaskID): ID of task. advance (float): Number of steps to advance. Default is 1. rroN)rrrrIrrr1rrr2rrrfrgr6rw) rLrBrTrrr3r4r5rr1s rNrTzProgress.advances}} Z 1 1;w'D"nO NNg %NN#~? *T-GGOI'G  ! 6 H H   ! 6 H Hi..4'' i..4''   ^L:JKK L L L &Ndj00&.%)\"&*j#) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1sDD))D-0D-cf|js'|jjr|jdSdSdS)z*Refresh (render) the progress information.N)rrVrWrSr`s rNrSzProgress.refresh sF|  4 I           rOr0c<t|}|S)z*Get a renderable for the progress display.)r.get_renderables)rLr s rNrzProgress.get_renderablesD00223 rOIterable[RenderableType]c#FK||j}|VdS)z5Get a number of renderables for the progress display.N)make_tasks_tabler)rLtables rNr;zProgress.get_renderabless(%%dj11 rOrIterable[Task]r8cd|jD}tj|d|jd}|D]$jr|jfd|jD%|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|]O}t|trtdn%|VPdS)TrLN)r;rr7rcopy)r_columns rNrz,Progress.make_tasks_table.."sr  gs++7t$$$$--//4466       rO)rr*)paddingrc3K|]:}t|tr|n |V;dS)rPN)r;rrQ)rcolumnrs rNrz,Progress.make_tasks_table../sf # *&#66.FMMtM444!' rO)rr8gridrradd_row)rLr table_columnsr?rs @rNr>zProgress.make_tasks_tables   <     M6$+NNN  D|   '+l    rOcl|j5|cdddS#1swxYwYdS)z+Makes the Progress class itself renderable.N)rrr`s rN__rich__zProgress.__rich__:s} Z ) )&&(( ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s )--rc n|j5t|j||||||j|j}||j|j<|r||j|j}t t|jdz|_dddn #1swxYwY||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`. )rrrrr*N) rrrrrr,r;rrS) rLrr_rrIrrrnew_task_indexs rNrzProgress.add_task?s0Z A A -j   D-1DK( ) 2 0111!-N%c$*:&;&;a&?@@D  A A A A A A A A A A A A A A A sBBBBcV|j5|j|=ddddS#1swxYwYdS)z]Delete a task if it exists. Args: task_id (TaskID): A task ID. N)rr)rLrBs rN remove_taskzProgress.remove_taskjszZ % % G$ % % % % % % % % % % % % % % % % % %s "")rrrrrrrrErrErrrrrrrrrrrrrPrQ)rPr)rPr-)rPr)rPrrrn)rPr)ro)NrNrvr|)r}r~rrrIrrBr rrrDrErPr~r]) rrrrrBr rrrPrrNNN)rrrrrrrrrrrrrrrBr rrrPr)rrrrrrrrrrrrrrrBr rrrPr$r rNNN)rrrr rrrrrrrrrrrBr rrrPr)rBr;rPrQ)rBr;rrrIrrTrrrrr/rSrrrrPrQ)rBr;r_rrrrIrrr/rrrrrPrQ)r*)rBr;rTrErPrQ)rPr0)rPr<)rr@rPr8)TrrT)rrr_rrrrIrrrrrrPr;)!rprqrrrsrKrxrrrrrrAr_rrarmrrtypingoverloadrr,r.rXr7rTrSrr;r>rLrrPrrOrNrr%s  $&*!$&'+ $ $.2"$"$"$"$"$"$H   [ <!!!X!...X. ,,,X, GGGXG**** !!!! "&$('"+++++` $(@ %)' (@(@(@(@(@(@T _ "& $!%   $$('      _   _ "& $!%   $$('      _  $CF"& $!%K $$('KKKKKKZ 2 2 2 2 * * * *&"&%)#'%)"&;;;;;;B!%"&%)%%%%%%N11111<      B))))!& )))))V%%%%%%rOr__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)typerBz Syntax...zGive it a try!)cycle)record)rrz[red]Downloadingrorz[green]Processingz[yellow]Thinkingrzrg333333?g{Gz?d)rvNrTNFNrwrxryrzr{r|FT)"r}r~rrrrrIrrrrrrrrrrrErr6rr6rr6rr6rDrErrrrrPr~)rrrrrrrrrrrrrrrrErr6rr6rr6rr6rrrPrrQ)&rrrrrrrrrrrrrrrrrrrrrrrrrrErr6rr6rr6rr6rrrPr)&rrrrrrrrrrrrrrrrrrrrrrrrrrErr6rr6rr6rr6rrrPrrR)&rrrr rrrrrrrrrrrrrrrrrrrrrrErr6rr6rr6rr6rrrPr ) __future__rr(rSr$abcrr collectionsr dataclassesrr datetimer r r mathr roperatorrosrr threadingrrrtypesrrrrrrrrrrrr r!r"r#r$r%r&r'r(typing_extensionsr)r(r+r,rr-r.r/r0rIr1jupyterr2rVr3 progress_barr4r:r5rr6r?r7r8rBr9r:rr;r<rErr=r?rrrrrTrrr'r/rrr`rrrrrrrrrrrprandomtimepanelrVrulerWsyntaxrXrIprogress_renderables itertoolsrcexamplesrr@rtask1task2task3rArXsleeprandintrrrrOrNrs """""" ########((((((((........ **********,'&&&&&&########BBBBBBBBBBBB$$$$$$!!!!!!%%%%%% 3  w~&& 2u9%V^D&(++%%%%%6%%%T$!!%.2 "! . .(!K K K K K \d1d1d1d1d1id1d1d1N88888>"%wr{8882$!%.2 "! . .(>*>*>*>*>*>*B" !   #!%.2 "! . .('      0" !   #!%.2 "! . .('      4?B" ! S* #!%.2 "! . .('S*S*S*S*S*S*l'1'1'1'1'1S'1'1'1T~"/////N///d<' ' ' ' ' ' ' ' T : : : : : : : :EEEEEEEEP-,-,-,-,-,.-,-,-,`:::::^:::@@@@@.@@@        6.....^...b D D D D D. D D D%%%%%Z%%% z#z#z#z#z#z#z# z#zM %M %M %M %M %|M %M %M %` zMMMKKK V " F E% & &E MM#sC    E 899' &$455    u)**HgT"""G     % % ' '        - !!"4D!AA!!"5T!BB!!"4D!AA# - OOE3O / / / OOE3O / / / DJt   v~a%%)) TT(^^,,, # -------------------]s9CQ  QQ