From ec0fb2fd9517be61c31ac413c725deaecadb5dc3 Mon Sep 17 00:00:00 2001 From: Kaushik B <45285388+kaushikb11@users.noreply.github.com> Date: Wed, 1 Dec 2021 11:44:19 +0530 Subject: [PATCH] Raise exception if rich is less than 10.2.2 (#10839) --- CHANGELOG.md | 3 +++ pytorch_lightning/callbacks/progress/rich_progress.py | 8 +++++--- tests/callbacks/test_rich_progress_bar.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f6cd87edb065..406310a5341e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -190,6 +190,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Disabled batch_size extraction for torchmetric instances because they accumulate the metrics internally ([#10815](https://github.com/PyTorchLightning/pytorch-lightning/pull/10815)) +- Improved exception message if `rich` version is less than `10.2.2` ([#10839](https://github.com/PyTorchLightning/pytorch-lightning/pull/10839)) + + ## [1.5.4] - 2021-11-30 ### Fixed diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index e2a269d659127..50a017a72934c 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -17,7 +17,8 @@ from typing import Any, Optional, Union from pytorch_lightning.callbacks.progress.base import ProgressBarBase -from pytorch_lightning.utilities import _RICH_AVAILABLE +from pytorch_lightning.utilities.exceptions import MisconfigurationException +from pytorch_lightning.utilities.imports import _RICH_AVAILABLE Task, Style = None, None if _RICH_AVAILABLE: @@ -228,9 +229,10 @@ def __init__( theme: RichProgressBarTheme = RichProgressBarTheme(), ) -> None: if not _RICH_AVAILABLE: - raise ModuleNotFoundError( - "`RichProgressBar` requires `rich` to be installed. Install it by running `pip install -U rich`." + raise MisconfigurationException( + "`RichProgressBar` requires `rich` >= 10.2.2. Install it by running `pip install -U rich`." ) + super().__init__() self._refresh_rate: int = refresh_rate self._leave: bool = leave diff --git a/tests/callbacks/test_rich_progress_bar.py b/tests/callbacks/test_rich_progress_bar.py index 8ca7326fd78f6..5b0123e3060d3 100644 --- a/tests/callbacks/test_rich_progress_bar.py +++ b/tests/callbacks/test_rich_progress_bar.py @@ -85,7 +85,7 @@ def predict_dataloader(self): def test_rich_progress_bar_import_error(): if not _RICH_AVAILABLE: - with pytest.raises(ImportError, match="`RichProgressBar` requires `rich` to be installed."): + with pytest.raises(ImportError, match="`RichProgressBar` requires `rich` >= 10.2.2."): Trainer(callbacks=RichProgressBar())