From 9e397a13db9bd1db477d87729a756d671b40a4cf Mon Sep 17 00:00:00 2001 From: JoshKarpel Date: Sun, 21 Mar 2021 10:19:10 -0500 Subject: [PATCH 1/3] disabled progress does not start live --- rich/progress.py | 3 ++- tests/test_progress.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/rich/progress.py b/rich/progress.py index 8a246ee56..4f96d1117 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -634,7 +634,8 @@ def finished(self) -> bool: def start(self) -> None: """Start the progress display.""" - self.live.start(refresh=True) + if not self.disable: + self.live.start(refresh=True) def stop(self) -> None: """Stop the progress display.""" diff --git a/tests/test_progress.py b/tests/test_progress.py index cca4ad6fd..3d40d2e31 100644 --- a/tests/test_progress.py +++ b/tests/test_progress.py @@ -434,6 +434,20 @@ def get_time() -> float: ) +def test_live_is_started_if_progress_is_enabled() -> None: + progress = Progress(auto_refresh=False, disable=False) + + with progress: + assert progress.live._started + + +def test_live_is_not_started_if_progress_is_disabled() -> None: + progress = Progress(auto_refresh=False, disable=True) + + with progress: + assert not progress.live._started + + if __name__ == "__main__": _render = render_progress() print(_render) From d278c0c149fcb2a2bd3dbf1f20dda992511f0f55 Mon Sep 17 00:00:00 2001 From: JoshKarpel Date: Sun, 21 Mar 2021 10:36:12 -0500 Subject: [PATCH 2/3] add proto CHANGELOG.md entry, update CONTRIBUTORS.md --- CHANGELOG.md | 6 ++++++ CONTRIBUTORS.md | 1 + 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15f3deac1..ace629dbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [9.13.1] - 2021-03-21 + +### Fixed + +- Disabled Progress no longer displays itself when starting https://github.com/willmcgugan/rich/pull/1125 + ## [9.13.0] - 2021-03-06 ### Added diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c6db7bf90..26b677298 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -6,6 +6,7 @@ The following people have contributed to the development of Rich: - [Oleksis Fraga](https://github.com/oleksis) - [Finn Hughes](https://github.com/finnhughes) +- [Josh Karpel](https://github.com/JoshKarpel) - [Hedy Li](https://github.com/hedythedev) - [Alexander Mancevice](https://github.com/amancevice) - [Will McGugan](https://github.com/willmcgugan) From 34c56204e9e3135f3d2860103bd85b613e49e663 Mon Sep 17 00:00:00 2001 From: JoshKarpel Date: Thu, 25 Mar 2021 17:33:49 -0500 Subject: [PATCH 3/3] test that Progress writes nothing when disabled --- tests/test_progress.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_progress.py b/tests/test_progress.py index 3d40d2e31..046912052 100644 --- a/tests/test_progress.py +++ b/tests/test_progress.py @@ -448,6 +448,30 @@ def test_live_is_not_started_if_progress_is_disabled() -> None: assert not progress.live._started +def test_no_output_if_progress_is_disabled() -> None: + console = Console( + file=io.StringIO(), + force_terminal=True, + width=60, + color_system="truecolor", + legacy_windows=False, + _environ={}, + ) + progress = Progress( + console=console, + disable=True, + ) + test = ["foo", "bar", "baz"] + expected_values = iter(test) + with progress: + for value in progress.track(test, description="test"): + assert value == next(expected_values) + result = console.file.getvalue() + print(repr(result)) + expected = "" + assert result == expected + + if __name__ == "__main__": _render = render_progress() print(_render)