diff --git a/src/huggingface_hub/cli/_output.py b/src/huggingface_hub/cli/_output.py index e1ac21c57c..c9a6799fb0 100644 --- a/src/huggingface_hub/cli/_output.py +++ b/src/huggingface_hub/cli/_output.py @@ -27,7 +27,7 @@ import click from huggingface_hub.errors import ConfirmationError -from huggingface_hub.utils import ANSI, StatusLine, disable_progress_bars, is_agent, tabulate +from huggingface_hub.utils import ANSI, StatusLine, disable_progress_bars, enable_progress_bars, is_agent, tabulate class OutputFormat(str, Enum): @@ -67,6 +67,8 @@ def set_mode(self, mode: OutputFormat = OutputFormat.auto) -> None: self.mode = mode if mode != OutputFormat.human: disable_progress_bars() + else: + enable_progress_bars() def set_no_truncate(self, no_truncate: bool) -> None: """Toggle off cell truncation for human table output.""" diff --git a/tests/test_cli_output.py b/tests/test_cli_output.py index a3cde9289f..d83935b2cf 100644 --- a/tests/test_cli_output.py +++ b/tests/test_cli_output.py @@ -86,6 +86,20 @@ def test_auto_resets_after_explicit(): assert o.mode == HUMAN +def test_explicit_human_reenables_progress_bars(): + # Global progress-bar state: restore it on teardown so other tests are unaffected. + from huggingface_hub.utils import are_progress_bars_disabled, enable_progress_bars + + o = Output() + o.set_mode(AGENT) + assert are_progress_bars_disabled() + try: + o.set_mode(HUMAN) + assert not are_progress_bars_disabled() + finally: + enable_progress_bars() + + # ============================================================================= # out.result() # =============================================================================