
    5pjYA                        % S r SSKrSSKrSSKrSSKrSSKrSSKJrJr  SSK	J
r
Jr  SSKJrJr  SSKJr  SSKJrJrJrJr  SSKJr  S	S
KJr  0 r\\\4   \S'    " S S5      r S1S\S-  SS4S jjr!S1S\S-  S\4S jjr"S\#S\S-  4S jr$ " S S\5      r\RK                  \RL                  " 5       5         " S S5      r'\S\\-  S\\RP                     4S j5       r)SS.S\*\   S\#S\S-  S\4S jjr+SSSSSSSS.S \S\#S!\#S-  S"\#S#\S$\S\S-  S%\*\   S-  S&\S-  S\\   4S' jjr,\" S(5      r-\" S)5      r.S*\#S-  S+\*\   S\
4S, jr/SSS-.S.\\-/\.4   S/\\-   S*\#S-  S%\*\   S-  S\0\.   4
S0 jjr1g)2u	  Utility helpers to handle progress bars in `huggingface_hub`.

Example:
    1. Use `huggingface_hub.utils.tqdm` as you would use `tqdm.tqdm` or `tqdm.auto.tqdm`.
    2. To disable progress bars, either use `disable_progress_bars()` helper or set the
       environment variable `HF_HUB_DISABLE_PROGRESS_BARS` to 1.
    3. To re-enable progress bars, use `enable_progress_bars()`.
    4. To check whether progress bars are disabled, use `are_progress_bars_disabled()`.

NOTE: Environment variable `HF_HUB_DISABLE_PROGRESS_BARS` has the priority.

Example:
    ```py
    >>> from huggingface_hub.utils import are_progress_bars_disabled, disable_progress_bars, enable_progress_bars, tqdm

    # Disable progress bars globally
    >>> disable_progress_bars()

    # Use as normal `tqdm`
    >>> for _ in tqdm(range(5)):
    ...    pass

    # Still not showing progress bars, as `disable=False` is overwritten to `True`.
    >>> for _ in tqdm(range(5), disable=False):
    ...    pass

    >>> are_progress_bars_disabled()
    True

    # Re-enable progress bars globally
    >>> enable_progress_bars()

    # Progress bar will be shown !
    >>> for _ in tqdm(range(5)):
    ...   pass
    100%|███████████████████████████████████████| 5/5 [00:00<00:00, 117817.53it/s]
    ```

Group-based control:
    ```python
    # Disable progress bars for a specific group
    >>> disable_progress_bars("peft.foo")

    # Check state of different groups
    >>> assert not are_progress_bars_disabled("peft"))
    >>> assert not are_progress_bars_disabled("peft.something")
    >>> assert are_progress_bars_disabled("peft.foo"))
    >>> assert are_progress_bars_disabled("peft.foo.bar"))

    # Enable progress bars for a subgroup
    >>> enable_progress_bars("peft.foo.bar")

    # Check if enabling a subgroup affects the parent group
    >>> assert are_progress_bars_disabled("peft.foo"))
    >>> assert not are_progress_bars_disabled("peft.foo.bar"))

    # No progress bar for `name="peft.foo"`
    >>> for _ in tqdm(range(5), name="peft.foo"):
    ...     pass

    # Progress bar will be shown for `name="peft.foo.bar"`
    >>> for _ in tqdm(range(5), name="peft.foo.bar"):
    ...     pass
    100%|███████████████████████████████████████| 5/5 [00:00<00:00, 117817.53it/s]

    ```
    N)IterableIterator)ThreadPoolExecutoras_completed)contextmanagernullcontext)Path)CallableContextManagerTypeVarcast)tqdm   )HF_HUB_DISABLE_PROGRESS_BARSprogress_bar_statesc                   H    \ rS rSrSrS
S\S-  SS4S jjrSS jrSS jrS	r	g)disable_progress_barsm   a  
Disable progress bars either globally or for a specified group.

This function updates the state of progress bars based on a group name.
If no group name is provided, all progress bars are disabled. The operation
respects the `HF_HUB_DISABLE_PROGRESS_BARS` environment variable's setting.

Works as both a regular call and a context manager:
    disable_progress_bars()           # disables until enable_progress_bars()
    with disable_progress_bars():     # disables for the block, re-enables on exit
        ...

Args:
    name (`str`, *optional*):
        The name of the group for which to disable the progress bars. If None,
        progress bars are disabled globally.

Raises:
    Warning: If the environment variable precludes changes.
Nnamereturnc                 f   Xl         [        SL a  [        R                  " S5        SU l        g [        U5      (       + U l        Uc  [        R                  5         S[        S'   g [         Vs/ s H  o"R                  U S35      (       d  M  UPM!     nnU H
  n[        U	 M     S[        U'   g s  snf )NFzlCannot disable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=0` is set and has priority._global.)	r   r   warningswarn_should_reenableare_progress_bars_disabledr   clear
startswith)selfr   keykeys_to_removes       V/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/huggingface_hub/utils/tqdm.py__init__disable_progress_bars.__init__   s    	'50MM~ %*D!$>t$D D<%%'-2	*-@_-@cNNVZU[[\S]D^c-@N_%', &(-% `s   ,B.B.c                     U $ N r    s    r#   	__enter__disable_progress_bars.__enter__           c                 R    U R                   (       a  [        U R                  5        g g r'   )r   enable_progress_barsr   )r    excs     r#   __exit__disable_progress_bars.__exit__   s       + !r-   )r   r   r'   )r   r   )r   N)
__name__
__module____qualname____firstlineno____doc__strr$   r*   r1   __static_attributes__r(   r-   r#   r   r   m   s(    *.S4Z .4 .(,r-   r   r   r   c                 "   [         SL a  [        R                  " S5        gU c  [        R	                  5         S[        S'   g[         Vs/ s H  oR                  U  S35      (       d  M  UPM!     nnU H
  n[        U	 M     S[        U '   gs  snf )a  
Enable progress bars either globally or for a specified group.

This function sets the progress bars to enabled for the specified group or globally
if no group is specified. The operation is subject to the `HF_HUB_DISABLE_PROGRESS_BARS`
environment setting.

Args:
    name (`str`, *optional*):
        The name of the group for which to enable the progress bars. If None,
        progress bars are enabled globally.

Raises:
    Warning: If the environment variable precludes changes.
TzkCannot enable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=1` is set and has priority.Nr   r   )r   r   r   r   r   r   )r   r!   r"   s      r#   r/   r/      s      $t+y	
 	|!!#)-I&)<[)<#RVQWWXz@Z#)<[!C#C( "$(D! \s   
B*Bc                    [         SL a  gU c  [        R                  SS5      (       + $ U (       aD  U [        ;   a  [        U    (       + $ SR                  U R	                  S5      SS 5      n U (       a  MD  [        R                  SS5      (       + $ )a  
Check if progress bars are disabled globally or for a specific group.

This function returns whether progress bars are disabled for a given group or globally.
It checks the `HF_HUB_DISABLE_PROGRESS_BARS` environment variable first, then the programmatic
settings.

Args:
    name (`str`, *optional*):
        The group name to check; if None, checks the global setting.

Returns:
    `bool`: True if progress bars are disabled, False otherwise.
TNr   r   )r   r   getjoinsplitr   s    r#   r   r      s     $t+|&**9d;;;
&&*4000xx

3,- $
 #&&y$777r-   	log_levelc                 d    U [         R                  :X  a  g[        R                  " S5      S:X  a  gg)z
Determine if tqdm progress bars should be disabled based on logging level and environment settings.

see https://github.com/huggingface/huggingface_hub/pull/2000 and https://github.com/huggingface/huggingface_hub/pull/2698.
TTQDM_POSITIONz-1FN)loggingNOTSETosgetenv)rA   s    r#   is_tqdm_disabledrH      s*     GNN"	yy!T)r-   c                   D   ^  \ rS rSrSrU 4S jrS\SS4U 4S jjrSrU =r	$ )	r      z
Class to override `disable` argument in case progress bars are globally disabled.

Taken from https://github.com/tqdm/tqdm/issues/619#issuecomment-619639324.
c                 t   > UR                  SS 5      n[        U5      (       a  SUS'   [        TU ]  " U0 UD6  g )Nr   Tdisable)popr   superr$   )r    argskwargsr   	__class__s       r#   r$   tqdm.__init__   s:    zz&$'%d++ $F9$)&)r-   attrr   Nc                 T   >  [         TU ]  U5        g! [         a
    US:w  a  e  gf = f)zBFix for https://github.com/huggingface/huggingface_hub/issues/1603_lockN)rN   __delattr__AttributeError)r    rS   rQ   s     r#   rV   tqdm.__delattr__   s3    	G% 	w 	s    ''r(   )
r3   r4   r5   r6   r7   r$   r8   rV   r9   __classcell__)rQ   s   @r#   r   r      s%    *   r-   r   c                   L    \ rS rSrSrS rS rS rSS\\	-  S-  SS4S	 jjr
S
rg)silent_tqdmi  z#Fake tqdm object that does nothing.c                     g r'   r(   )r    rO   rP   s      r#   r$   silent_tqdm.__init__	      r-   c                     U $ r'   r(   r)   s    r#   r*   silent_tqdm.__enter__  r,   r-   c                     g r'   r(   )r    exc_type	exc_value	tracebacks       r#   r1   silent_tqdm.__exit__  r^   r-   nNr   c                     g r'   r(   )r    rf   s     r#   updatesilent_tqdm.update  r^   r-   r(   )   )r3   r4   r5   r6   r7   r$   r*   r1   intfloatrh   r9   r(   r-   r#   r[   r[     s5    -ed* 4  r-   r[   pathc           	   #     ^^#    [        U [        5      (       a  [        U 5      n U R                  S5       nU R	                  5       R
                  n[        SSUSU R                  S9mUR                  mS
S[        S-  S[        4UU4S	 jjjnX1l        Uv   TR                  5         SSS5        g! , (       d  f       g= f7f)u  
Open a file as binary and wrap the `read` method to display a progress bar when it's streamed.

First implemented in `transformers` in 2019 but removed when switched to git-lfs. Used in `huggingface_hub` to show
progress bar when uploading an LFS file to the Hub. See github.com/huggingface/transformers/pull/2078#discussion_r354739608
for implementation details.

Note: currently implementation handles only files stored on disk as it is the most common use case. Could be
      extended to stream any `BinaryIO` object but we might have to debug some corner cases.

Example:
```py
>>> with tqdm_stream_file("config.json") as f:
>>>     httpx.put(url, data=f)
config.json: 100%|█████████████████████████| 8.19k/8.19k [00:02<00:00, 3.72kB/s]
```
rbBTr   )unit
unit_scaletotalinitialdescsizeNr   c                 L   > T" U 5      nTR                  [        U5      5        U$ r'   )rh   len)rv   dataf_readpbars     r#   _inner_read%tqdm_stream_file.<locals>._inner_read8  s!    $<DKKD	"Kr-   )r<   )
isinstancer8   r	   openstatst_sizer   r   readrk   bytesclose)rm   f
total_sizer|   rz   r{   s       @@r#   tqdm_stream_filer     s     & $Dz	4AYY[((

 	cDj 	% 	 	
 

+ 
s   2CA2B1(	C1
B?;Cr@   clsc                     [        U [        5      (       a  [        U [        5      (       d  U " S0 UD6$ [	        U5      nU " SXBS.UD6$ )a  Create a progress bar.

For our `tqdm` subclass (or subclasses of it): respects all disable signals
(`HF_HUB_DISABLE_PROGRESS_BARS`, `disable_progress_bars()`, log level) and uses
`disable=None` for TTY auto-detection (see https://github.com/huggingface/huggingface_hub/pull/2000),
unless `TQDM_POSITION=-1` forces bars on (https://github.com/huggingface/huggingface_hub/pull/2698).

For other classes: does not inject `disable` or `name`. the custom class is fully
responsible for its own behavior. Vanilla tqdm defaults to `disable=False` (bar shows).
Omits `name` which vanilla tqdm rejects with `TqdmKeyError`. See https://github.com/huggingface/huggingface_hub/issues/4050.
)rL   r   r(   )r~   type
issubclassr   rH   )r   rA   r   rP   rL   s        r#   _create_progress_barr   D  sH     sD!!jd&;&;}V} y)G4w4V44r-   rp   T)rs   rt   rq   rr   r   
tqdm_class	_tqdm_barru   rs   rt   rq   rr   r   r   c        	         X    Ub  [        U5      $ [        U=(       d    [        UUUUUUU S9$ )N)r   rA   r   rq   rr   rs   rt   ru   )r   r   r   )	ru   rA   rs   rt   rq   rr   r   r   r   s	            r#   _get_progress_bar_contextr   Z  sA     9%%
  $	 	r-   TRmax_workers	bar_classc                     [        US5      (       a4  [        US5      (       a#  [        XR                  UR                  5       4S9$ [        U S9$ )a  Create a `ThreadPoolExecutor` that shares the tqdm lock with its worker threads.

Like `tqdm.contrib.concurrent.thread_map`, we make sure the bar class has a lock and pass it to the
worker threads, so that bars created inside the mapped function (e.g. the per-file download bars in
`snapshot_download`) don't race on concurrent `update()` calls. `get_lock()` creates the shared
class-level lock if needed. Classes that don't implement tqdm's locking API (e.g. `silent_tqdm`)
render nothing anyway, so no lock is needed.
get_lockset_lock)r   initializerinitargs)r   )hasattrr   r   r   r   r   s     r#   _make_thread_pool_executorr   |  sN     y*%%')Z*H*H!#1C1CyOaOaOcNe
 	
 +66r-   )r   r   fniterablec          
         [        U5      nUc+  [        S[        R                  " 5       =(       d    SS-   5      nUR	                  S[        U5      5        U=(       d    [        nS/[        U5      -  nU" S0 UD6 n[        X&S9 n	[        U5       V
Vs0 s H  u  pU	R                  X5      U
_M     nn
n [        U5       H)  nUR                  5       X|U   '   UR                  S5        M+      SSS5        SSS5        [        SU5      $ s  snn
f ! [         a    U H  nUR                  5         M     e f = f! , (       d  f       NP= f! , (       d  f       NY= f)	a  Drop-in replacement for `tqdm.contrib.concurrent.thread_map`.

The version shipped by `tqdm` consumes results in submission order and the progress bar only advances when the "next
item in input order" finishes. A single slow early item pins the bar near zero while later items
complete, with everything flushed at once at the end. This helper avoids that problem by consuming items in completion
order.

See https://github.com/huggingface/huggingface_hub/issues/4518 for more details.

Args:
    fn (`Callable`):
        Function to apply to each item.
    iterable (`Iterable`):
        Items to process.
    max_workers (`int`, *optional*):
        Maximum number of worker threads. Defaults to tqdm's own default.
    tqdm_class (`type`, *optional*):
        Progress bar class to use. Defaults to `huggingface_hub`'s `tqdm`.
    **tqdm_kwargs:
        Additional keyword arguments forwarded to the progress bar (e.g. `desc`).

Returns:
    `list`: Results in the same order as `iterable`.
N    rj      rs   r   zlist[R]r(   )listminrF   	cpu_count
setdefaultrx   r   r   	enumeratesubmitr   resultrh   BaseExceptioncancelr   )r   r   r   r   tqdm_kwargsitemsr   resultsr{   executorindexitemfuture_to_indexfutures                 r#   hf_thread_mapr     s0   @ NE"r||~2a787CJ/"dI#fs5z1G K D"{PT\OXY^O_`O_8??24e;O_`		&739==?/0A 8	 	Q 	! 	7## a
  	 * *	 	QP 	! sH   ;
E
D9D
2D968D/E
D9%D66D99
E	E


Er'   )2r7   iorD   rF   	threadingr   collections.abcr   r   concurrent.futuresr   r   
contextlibr   r   pathlibr	   typingr
   r   r   r   	tqdm.autor   old_tqdm	constantsr   r   dictr8   bool__annotations__r   r/   r   rk   rH   r   RLockr[   BufferedReaderr   r   r   r   r   r   r   r   r   r(   r-   r#   <module>r      sS  BH 
  	   . ? 2  : : & 4 (* T#t)_ )/, /,d)sTz )T )@8S4Z 84 8:
 
t 
8 4 ioo     *4#: *(23D3D*E * *Z UY 5h 5C 5sTz 5go 54 (,!
  :	
    * X% d{ D< CLCL7sTz 7d8n 7Yk 7( #(,5$!a5$qk5$ t	5$
 X%5$ 
!W5$r-   