From 80e49d4190483cb01c8ac40b5a1c9b35d5ffca6a Mon Sep 17 00:00:00 2001 From: Hannah Bast Date: Wed, 29 Jul 2026 08:42:26 +0200 Subject: [PATCH] Give the progress bar a proper width also when the output is piped When the output of `qlever update-wikidata` is piped (for example, through `tee` to keep a log file), `tqdm` cannot detect the terminal width and falls back to a bar of only 10 characters. Use the width from the `COLUMNS` environment variable (or 80) in that case; on a terminal, the width remains dynamic as before. --- src/qlever/commands/update_wikidata.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/qlever/commands/update_wikidata.py b/src/qlever/commands/update_wikidata.py index b7d9630b..bb40da3c 100644 --- a/src/qlever/commands/update_wikidata.py +++ b/src/qlever/commands/update_wikidata.py @@ -5,7 +5,9 @@ import logging import os import re +import shutil import signal +import sys import time from datetime import datetime, timezone from enum import Enum, auto @@ -716,12 +718,23 @@ def execute(self, args) -> bool: # Process one event at a time (unless using cached file). if not use_cached_file: + # The width of the progress bar: dynamic on a terminal; + # when the output is piped (for example, through `tee`), + # `tqdm` cannot detect the terminal width and falls back to + # a bar of only 10 characters, so use the width from the + # `COLUMNS` environment variable (or 80) instead. + ncols = ( + None + if sys.stderr.isatty() + else shutil.get_terminal_size().columns + ) with tqdm_logging_redirect( loggers=[logging.getLogger("qlever")], desc="Batch", total=args.batch_size, leave=False, bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt}{postfix}", + ncols=ncols, ) as pbar: for event in self.iter_sse_events(source): # Skip events that are not of type `message` (should not