wL i)UdZddlZddlZddlZddlZddlmZmZddlm Z ddl m Z m Z m Z mZmZddlmZddlmZiZe eefed <dd eed dfd Zdd eed dfd Zdd eed efdZded eefdZGddeZedee efd e ej<fdZddddddddededeedededed eedeed e efdZ y) 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)contextmanager nullcontext)Path)ContextManagerDictIteratorOptionalUnion)tqdm)HF_HUB_DISABLE_PROGRESS_BARSprogress_bar_statesnamereturnctdurtjdy|tj dtd<ytDcgc]}|j |ds|}}|D] }t|= dt|<ycc}w)a4 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 warningswarnrclear startswithrkeykeys_to_removes `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/huggingface_hub/utils/tqdm.pydisable_progress_barsrls $u, z   |!!#).I&)<[#RVQWWXz@Z#[[! )C#C( )$)D!\ A?!A?ctdurtjdy|tj dtd<ytDcgc]}|j |ds|}}|D] }t|= dt|<ycc}w)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.Nrrrrs renable_progress_barsr s $t+ y   |!!#)-I&)<[#RVQWWXz@Z#[[! )C#C( )$(D!\rctdury|tjdd S|r8|tvr t| Sdj|j ddd}|r8tjdd S)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. TNrr)r rgetjoinsplit)rs rare_progress_bars_disabledr&s~$t+ |&**9d;;;  & &*400 0xx 3,-  #&&y$7 77 log_levelc^|tjk(rytjddk(ryy)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)loggingNOTSETosgetenvr(s ris_tqdm_disabledr0s* GNN" yy!T) r'c6eZdZdZfdZdeddffd ZxZS)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. ch|jdd}t|rd|d<t| |i|y)NrTdisable)popr&super__init__)selfargskwargsr __class__s rr6z tqdm.__init__s7zz&$' %d + $F9  $)&)r'attrrNcP t||y#t$r |dk7rYywxYw)zBFix for https://github.com/huggingface/huggingface_hub/issues/1603_lockN)r5 __delattr__AttributeError)r7r;r:s rr>ztqdm.__delattr__s3  G  % w s %%)__name__ __module__ __qualname____doc__r6strr> __classcell__)r:s@rr r s% * r'r pathc#~Kt|tr t|}|jd5}|j j }t dd|d|j|jd dttdtffd }||_|jd d d y #1swYy xYww) 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] ``` rbBTr)unit unit_scaletotalinitialdescsizercL|}jt||SN)updatelen)rOdataf_readpbars r _inner_readz%tqdm_stream_file.._inner_reads!$9%%    95  r'rQ)!rCior+r-r contextlibrrpathlibrtypingrrrr r tqdm.autor old_tqdm constantsr rrDbool__annotations__rr r&r]r0BufferedReaderrbrer'rrqsdBH  2BB&4(*T#t)_)* **@)x}))@8Xc]8d8:   8,*5s+*9J9J0K**b  $  C=      3-~Dr'