From 07797f3fff7090d091b9fb64fff4358f81487190 Mon Sep 17 00:00:00 2001 From: Edgar Geier Date: Tue, 23 Jul 2019 17:37:44 +0200 Subject: [PATCH 1/6] Revert "Change test to remove missed branch" This reverts commit 84dcb911196783cde209b095acc26d4089a24200. --- tests/color_test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/color_test.py b/tests/color_test.py index 4ba3f327..fb311c85 100644 --- a/tests/color_test.py +++ b/tests/color_test.py @@ -54,7 +54,9 @@ def test_use_color_raises_if_given_shenanigans(): def test_no_color_env_unset(): - with mock.patch.dict(os.environ, clear=True): + with mock.patch.dict(os.environ): + if 'NO_COLOR' in os.environ: + del os.environ['NO_COLOR'] assert use_color('always') is True From 69b2cb5ea67eec5f171490c7a5f4aa568718e39c Mon Sep 17 00:00:00 2001 From: Edgar Geier Date: Tue, 23 Jul 2019 17:38:29 +0200 Subject: [PATCH 2/6] Revert "Simplify NO_COLOR check" This reverts commit e9ff1be96c831a1f77708b782dca19fe6d7250da. --- pre_commit/color.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre_commit/color.py b/pre_commit/color.py index 2ede410a..102639ad 100644 --- a/pre_commit/color.py +++ b/pre_commit/color.py @@ -48,7 +48,7 @@ def use_color(setting): if setting not in COLOR_CHOICES: raise InvalidColorSetting(setting) - if os.environ.get('NO_COLOR'): + if 'NO_COLOR' in os.environ and os.environ['NO_COLOR']: return False return ( From e82c1e7259d646793368746dcfbf6e8d23408b0c Mon Sep 17 00:00:00 2001 From: Edgar Geier Date: Tue, 23 Jul 2019 17:38:50 +0200 Subject: [PATCH 3/6] Revert "Add tests for NO_COLOR support" This reverts commit 85204550425b69990c0c3b28e66296b013901a33. --- tests/color_test.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tests/color_test.py b/tests/color_test.py index fb311c85..6e11765c 100644 --- a/tests/color_test.py +++ b/tests/color_test.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -import os import sys import mock @@ -51,20 +50,3 @@ def test_use_color_tty_without_color_support(): def test_use_color_raises_if_given_shenanigans(): with pytest.raises(InvalidColorSetting): use_color('herpaderp') - - -def test_no_color_env_unset(): - with mock.patch.dict(os.environ): - if 'NO_COLOR' in os.environ: - del os.environ['NO_COLOR'] - assert use_color('always') is True - - -def test_no_color_env_empty(): - with mock.patch.dict(os.environ, NO_COLOR=''): - assert use_color('always') is True - - -def test_no_color_env_non_empty(): - with mock.patch.dict(os.environ, NO_COLOR=' '): - assert use_color('always') is False From df919e6ab52d9bbcecba98e86ded5d9d722d3cab Mon Sep 17 00:00:00 2001 From: Edgar Geier Date: Tue, 23 Jul 2019 17:39:34 +0200 Subject: [PATCH 4/6] Revert "Require NO_COLOR environment variable to be non-empty to disable colors" This reverts commit 01d3a72a0ed1e3a43a45b9908a5b9200593dee32. --- pre_commit/color.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre_commit/color.py b/pre_commit/color.py index 102639ad..831d50bf 100644 --- a/pre_commit/color.py +++ b/pre_commit/color.py @@ -48,7 +48,7 @@ def use_color(setting): if setting not in COLOR_CHOICES: raise InvalidColorSetting(setting) - if 'NO_COLOR' in os.environ and os.environ['NO_COLOR']: + if 'NO_COLOR' in os.environ: return False return ( From c75d8939f892b7806c33e96f8c2c2ff8cafd04ff Mon Sep 17 00:00:00 2001 From: Edgar Geier Date: Tue, 23 Jul 2019 17:40:08 +0200 Subject: [PATCH 5/6] Revert "Don't use color if NO_COLOR environment variable is set" This reverts commit 1bf9ff74939d899fe18a2325a29b7a59f953d214. --- pre_commit/color.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pre_commit/color.py b/pre_commit/color.py index 831d50bf..c785e2c9 100644 --- a/pre_commit/color.py +++ b/pre_commit/color.py @@ -48,9 +48,6 @@ def use_color(setting): if setting not in COLOR_CHOICES: raise InvalidColorSetting(setting) - if 'NO_COLOR' in os.environ: - return False - return ( setting == 'always' or (setting == 'auto' and sys.stdout.isatty() and terminal_supports_color) From aaa249bda9403dc2699eae0d73e64a16bf02ad65 Mon Sep 17 00:00:00 2001 From: Edgar Geier Date: Tue, 23 Jul 2019 17:42:28 +0200 Subject: [PATCH 6/6] Overwrite default value of --color argument with PRE_COMMIT_COLOR env var --- pre_commit/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pre_commit/main.py b/pre_commit/main.py index 67a67a05..53c2dba5 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -38,7 +38,8 @@ os.environ.pop('__PYVENV_LAUNCHER__', None) def _add_color_option(parser): parser.add_argument( - '--color', default='auto', type=color.use_color, + '--color', default=os.environ.get('PRE_COMMIT_COLOR', 'auto'), + type=color.use_color, metavar='{' + ','.join(color.COLOR_CHOICES) + '}', help='Whether to use color in output. Defaults to `%(default)s`.', )