
    i1                     @   % 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  SSKJ	r	J
r
  SSKJr  SSKJr  SSKJr  SS	KJr  0 r\\\4   \S
'   S&S\S-  SS4S jjrS&S\S-  SS4S jjrS&S\S-  S\4S jjrS\S\S-  4S jr " S S\5      r\R=                  \R>                  " 5       5         " S S5      r \	S\\-  S\\RB                     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%g)'u	  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)Iterator)contextmanagernullcontext)Path)ContextManager)tqdm   )HF_HUB_DISABLE_PROGRESS_BARSprogress_bar_statesnamereturnc                 "   [         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  
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.

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.
FzlCannot disable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=0` is set and has priority.N_global.r
   warningswarnr   clear
startswithr   keykeys_to_removes      O/home/rurouni/.local/lib/python3.13/site-packages/huggingface_hub/utils/tqdm.pydisable_progress_barsr   m   s      $u,z	
 	|!!#).I&)<[)<#RVQWWXz@Z#)<[!C#C( "$)D! \   
B*B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   s      r   enable_progress_barsr      s      $t+y	
 	|!!#)-I&)<[)<#RVQWWXz@Z#)<[!C#C( "$(D! \r   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   are_progress_bars_disabledr$      s     $t+|&**9d;;;
&&*4000xx

3,- $
 #&&y$777    	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)r&   s    r   is_tqdm_disabledr-      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$   super__init__)selfargskwargsr   	__class__s       r   r4   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)r3   __delattr__AttributeError)r5   r:   r8   s     r   r=   tqdm.__delattr__   s3    	G% 	w 	s    '' )
__name__
__module____qualname____firstlineno____doc__r4   strr=   __static_attributes____classcell__)r8   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_tqdm   z#Fake tqdm object that does nothing.c                     g Nr@   )r5   r6   r7   s      r   r4   silent_tqdm.__init__       r%   c                     U $ rM   r@   )r5   s    r   	__enter__silent_tqdm.__enter__   s    r%   c                     g rM   r@   )r5   exc_type	exc_value	tracebacks       r   __exit__silent_tqdm.__exit__   rO   r%   nNr   c                     g rM   r@   )r5   rY   s     r   updatesilent_tqdm.update   rO   r%   r@   )   )rA   rB   rC   rD   rE   r4   rQ   rW   intfloatr[   rG   r@   r%   r   rJ   rJ      s5    -ed* 4  r%   rJ   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$ rM   )r[   len)ri   dataf_readpbars     r   _inner_read%tqdm_stream_file.<locals>._inner_read&  s!    $<DKKD	"Kr%   )r   )
isinstancerF   r   openstatst_sizer   r   readr^   bytesclose)r`   f
total_sizero   rm   rn   s       @@r   tqdm_stream_filerz     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.
)r1   r   r@   )rq   type
issubclassr   r-   )r{   r&   r   r7   r1   s        r   _create_progress_barr   2  sH     sD!!jd&;&;}V} y)G4w4V44r%   rc   T)rf   rg   rd   re   r   
tqdm_class	_tqdm_barrh   rf   rg   rd   re   r   r   c        	         X    Ub  [        U5      $ [        U=(       d    [        UUUUUUU S9$ )N)r{   r&   r   rd   re   rf   rg   rh   )r   r   r   )	rh   r&   rf   rg   rd   re   r   r   r   s	            r   _get_progress_bar_contextr   H  sA     9%%
  $	 	r%   rM   )&rE   ior)   r+   	threadingr   collections.abcr   
contextlibr   r   pathlibr   typingr   	tqdm.autor   old_tqdm	constantsr
   r   dictrF   bool__annotations__r   r   r$   r^   r-   set_lockRLockrJ   BufferedReaderrz   r}   r   r   r@   r%   r   <module>r      s  BH 
  	   $ 2  ! & 4 (* T#t)_ )*d
 *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r%   