From cda40c62d7ffbd2037c8973a197c3f006da99df1 Mon Sep 17 00:00:00 2001 From: mkb79 Date: Wed, 15 Nov 2023 07:52:49 +0100 Subject: [PATCH] fix: Fix progressbar issue (#165) * fix: Avoid tqdm progress bar interruption Avoid tqdm progress bar interruption by logger's output to console * doc: Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ src/audible_cli/_logging.py | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f69336..f719673 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Update marketplace choices in `manage auth-file add` command. Now all available marketplaces are listed. +### Bugfix + +- Avoid tqdm progress bar interruption by logger’s output to console. + ### Misc - add `freeze_support` to pyinstaller entry script (#78) diff --git a/src/audible_cli/_logging.py b/src/audible_cli/_logging.py index 82cbf18..47aea17 100644 --- a/src/audible_cli/_logging.py +++ b/src/audible_cli/_logging.py @@ -4,6 +4,7 @@ from warnings import warn import click +from tqdm import tqdm audible_cli_logger = logging.getLogger("audible_cli") @@ -100,10 +101,13 @@ def emit(self, record): try: msg = self.format(record) level = record.levelname.lower() - if self.echo_kwargs.get(level): - click.echo(msg, **self.echo_kwargs[level]) - else: - click.echo(msg) + + # Avoid tqdm progress bar interruption by logger's output to console + with tqdm.external_write_mode(): + if self.echo_kwargs.get(level): + click.echo(msg, **self.echo_kwargs[level]) + else: + click.echo(msg) except Exception: self.handleError(record)