From 264da3c3db06115fdb24986704af344c2dc3ba18 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 5 Aug 2022 15:33:40 +0100 Subject: [PATCH 1/5] Add support for FORCE_COLOR environment variable --- rich/console.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rich/console.py b/rich/console.py index 8c6049a49..790dae352 100644 --- a/rich/console.py +++ b/rich/console.py @@ -697,7 +697,12 @@ def __init__( self._height = height self._color_system: Optional[ColorSystem] - self._force_terminal = force_terminal + + if force_terminal is not None: + self._force_terminal = force_terminal + else: + self._force_terminal = self._environ.get("FORCE_COLOR") is not None + self._file = file self.quiet = quiet self.stderr = stderr From f417474dc18e17129d568e85220236b4f5e7f9d3 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 5 Aug 2022 15:37:25 +0100 Subject: [PATCH 2/5] Add test for force color --- tests/test_console.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_console.py b/tests/test_console.py index 2db88af0b..07692f198 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -895,3 +895,11 @@ def test_render_lines_height_minus_vertical_pad_is_negative(): # Ensuring that no exception is raised... console.render_lines(Padding("hello", pad=(1, 0)), options=options) + + +@mock.patch.dict(os.environ, {"FORCE_COLOR": "anything"}) +def test_force_color(): + # Even though we use a non-tty file, the presence of FORCE_COLOR env var + # means is_terminal returns True. + console = Console(file=io.StringIO()) + assert console.is_terminal From 4adfe2f16c22933eeb0d53cf04ef7dc3cf41a73b Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Tue, 9 Aug 2022 11:56:59 +0100 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90cd313d6..48c7c0eb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ 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). + +## [Unreleased] + +### Added + +- Add support for `FORCE_COLOR` env var https://github.com/Textualize/rich/pull/2449 + ## [12.5.2] - 2022-07-18 ### Added From c218be2a4dd7f0ef0610ebe8b4bf5309acbc9bee Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Tue, 9 Aug 2022 13:33:13 +0100 Subject: [PATCH 4/5] Use Python3.11 beta 5 in CI instead of beta 4 --- .github/workflows/pythonpackage.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index dbadb79d8..4ba60cdee 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest, macos-latest] - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11.0-beta.4"] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11.0-beta.5"] defaults: run: shell: bash @@ -36,12 +36,12 @@ jobs: source $VENV make typecheck - name: Test with pytest (with coverage) - if: matrix.python-version != '3.11.0-beta.4' + if: matrix.python-version != '3.11.0-beta.5' run: | source $VENV pytest tests -v --cov=./rich --cov-report=xml:./coverage.xml --cov-report term-missing - name: Test with pytest (no coverage) - if: matrix.python-version == '3.11.0-beta.4' + if: matrix.python-version == '3.11.0-beta.5' run: | source $VENV pytest tests -v From 0162d17c0e0f835319f23d8e836c5697cc05c10b Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Tue, 9 Aug 2022 13:46:34 +0100 Subject: [PATCH 5/5] Remove 3.11b5 from CI --- .github/workflows/pythonpackage.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 4ba60cdee..40685a56e 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest, macos-latest] - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11.0-beta.5"] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] defaults: run: shell: bash @@ -36,15 +36,9 @@ jobs: source $VENV make typecheck - name: Test with pytest (with coverage) - if: matrix.python-version != '3.11.0-beta.5' run: | source $VENV pytest tests -v --cov=./rich --cov-report=xml:./coverage.xml --cov-report term-missing - - name: Test with pytest (no coverage) - if: matrix.python-version == '3.11.0-beta.5' - run: | - source $VENV - pytest tests -v - name: Upload code coverage uses: codecov/codecov-action@v2 with: