From e6cdc2861cf32f2c7293b304e4dfbad24972fff9 Mon Sep 17 00:00:00 2001 From: dhananjay6561 Date: Fri, 20 Nov 2026 13:02:32 +0530 Subject: [PATCH 1/2] reset rich progress bar between executions Signed-off-by: dhananjay6561 --- hamilton/plugins/h_rich.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hamilton/plugins/h_rich.py b/hamilton/plugins/h_rich.py index d9729aab6..0b260d2f0 100644 --- a/hamilton/plugins/h_rich.py +++ b/hamilton/plugins/h_rich.py @@ -102,6 +102,10 @@ def __init__( @override def run_before_graph_execution(self, *, execution_path: Collection[str], **kwargs: Any): + # the same adapter is reused across executions of a driver, so drop the previous run's bars + for task_id in list(self._progress.task_ids): + self._progress.remove_task(task_id) + self._task_based = False self._progress.add_task(self._group_desc, total=len(execution_path)) self._progress.start() From a1ad378d6b7e04ec90f193861847b7d88f63af7f Mon Sep 17 00:00:00 2001 From: dhananjay6561 Date: Fri, 20 Nov 2026 13:02:32 +0530 Subject: [PATCH 2/2] add tests for rich progress bar Signed-off-by: dhananjay6561 --- tests/plugins/test_h_rich.py | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/plugins/test_h_rich.py diff --git a/tests/plugins/test_h_rich.py b/tests/plugins/test_h_rich.py new file mode 100644 index 000000000..a5595d2fb --- /dev/null +++ b/tests/plugins/test_h_rich.py @@ -0,0 +1,56 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import pytest + +from hamilton import ad_hoc_utils, driver + +pytest.importorskip("rich") + +from hamilton.plugins.h_rich import RichProgressBar # noqa: E402 + + +def _build_driver(progress_bar: RichProgressBar) -> driver.Driver: + def normalized(raw_value: float) -> float: + return raw_value / 100.0 + + def total(normalized: float) -> float: + return normalized + 5.0 + + module = ad_hoc_utils.create_temporary_module(normalized, total) + return driver.Builder().with_adapters(progress_bar).with_modules(module).build() + + +def test_progress_bar_reaches_total(): + progress_bar = RichProgressBar(disable=True) + dr = _build_driver(progress_bar) + + dr.execute(["total"], inputs={"raw_value": 200.0}) + + (task,) = progress_bar._progress.tasks + assert task.completed == task.total == 2 + + +def test_progress_bar_starts_fresh_on_each_execution(): + """Reusing the driver must show one bar per run, not stack a new empty bar on the old one.""" + progress_bar = RichProgressBar(disable=True) + dr = _build_driver(progress_bar) + + dr.execute(["total"], inputs={"raw_value": 200.0}) + dr.execute(["total"], inputs={"raw_value": 300.0}) + + (task,) = progress_bar._progress.tasks + assert task.completed == task.total == 2