
    ߔ9i                         U d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ exs d	aeed
<   ddZddZdefdZ G d de      Zede
eef   deej.                     fd       Zy)a  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)):
       do_something()

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

    are_progress_bars_disabled() # True

    # Re-enable progress bars globally
    enable_progress_bars()

    # Progress bar will be shown !
    for _ in tqdm(range(5)):
       do_something()
    ```
    N)contextmanager)Path)IteratorOptionalUnion)tqdm   )HF_HUB_DISABLE_PROGRESS_BARSF_hf_hub_progress_bars_disabledreturnc                  D    t         du rt        j                  d       yday)z
    Disable globally progress bars used in `huggingface_hub` except if `HF_HUB_DISABLE_PROGRESS_BARS` environment
    variable has been set.

    Use [`~utils.enable_progress_bars`] to re-enable them.
    FzlCannot disable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=0` is set and has priority.NTr
   warningswarnr        d/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/huggingface_hub/utils/tqdm.pydisable_progress_barsr   N   s(     $u,	
 	%)"r   c                  D    t         du rt        j                  d       yday)z
    Enable globally progress bars used in `huggingface_hub` except if `HF_HUB_DISABLE_PROGRESS_BARS` environment
    variable has been set.

    Use [`~utils.disable_progress_bars`] to disable them.
    TzkCannot enable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=1` is set and has priority.NFr   r   r   r   enable_progress_barsr   _   s(     $t+	
 	%*"r   c                      t         S )a$  Return whether progress bars are globally disabled or not.

    Progress bars used in `huggingface_hub` can be enable or disabled globally using [`~utils.enable_progress_bars`]
    and [`~utils.disable_progress_bars`] or by setting `HF_HUB_DISABLE_PROGRESS_BARS` as environment variable.
    )r   r   r   r   are_progress_bars_disabledr   p   s
     *)r   c                   6     e Zd ZdZ fdZdeddf fdZ xZS )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                 B    t               rd|d<   t        |   |i | y )NTdisable)r   super__init__)selfargskwargs	__class__s      r   r   ztqdm.__init__   s%    %' $F9$)&)r   attrr   Nc                 P    	 t         |   |       y# t        $ r	 |dk7  r Y yw xY w)zBFix for https://github.com/huggingface/huggingface_hub/issues/1603_lockN)r   __delattr__AttributeError)r   r"   r!   s     r   r%   ztqdm.__delattr__   s3    	G% 	w 	s    %%)__name__
__module____qualname____doc__r   strr%   __classcell__)r!   s   @r   r   r   z   s%    *
   r   r   pathc              #   ~  K   t        | t              rt        |       } | j                  d      5 }| j	                         j
                  }t        dd|d| j                        |j                  d
dt        t           dt        ffd}||_        | j                          d	d	d	       y	# 1 sw Y   y	xY ww)uT  
    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:
    >>>     requests.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sizer   c                 L     |       }j                  t        |             |S )N)updatelen)r6   dataf_readpbars     r   _inner_readz%tqdm_stream_file.<locals>._inner_read   s!    $<DKKD	"Kr   N))
isinstancer+   r   openstatst_sizer   namereadr   intbytesclose)r-   f
total_sizer=   r;   r<   s       @@r   tqdm_stream_filerJ      s     & $Dz	4 AYY[((

 	hsm 	U 	
 

+  s   -B=A7B1(	B=1B:6B=)r   N)r*   ior   
contextlibr   pathlibr   typingr   r   r   	tqdm.autor   old_tqdm	constantsr
   r   bool__annotations__r   r   r   r+   BufferedReaderrJ   r   r   r   <module>rU      s    (R 
  %  , , & 4 (D'Lu  L*"+"*D *8 * *5s+ *9J9J0K * *r   