As @cbensimon noticed, the progress bar is not correctly closed when an error occurs or when hf_transfer is used. This PR fixes this by using a context manager. The progress bar is now always closed if created internally. When passed by the user, the progress bar is not closed as it is a the user's discretion to manage it.
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
When downloading files in
file_download.py
, we use a progress bar. This progress bar can be either passed by the user or we create a classic tqdm bar (see update in https://github.com/huggingface/huggingface_hub/pull/2143).As @cbensimon noticed, the progress bar is not correctly closed when an error occurs or when
hf_transfer
is used. This PR fixes this by using a context manager. The progress bar is now always closed if created internally. When passed by the user, the progress bar is not closed as it is a the user's discretion to manage it.Better to review with "hide whitespace" checked.