Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 332b98b

Browse files
authored
Merge pull request #1098 from geieredgar/switch-to-pre-commit-color-env
Switch from NO_COLOR to PRE_COMMIT_COLOR environment variable
2 parents 1874cea + aaa249b commit 332b98b

3 files changed

Lines changed: 2 additions & 20 deletions

File tree

pre_commit/color.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ def use_color(setting):
4848
if setting not in COLOR_CHOICES:
4949
raise InvalidColorSetting(setting)
5050

51-
if os.environ.get('NO_COLOR'):
52-
return False
53-
5451
return (
5552
setting == 'always' or
5653
(setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)

pre_commit/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838

3939
def _add_color_option(parser):
4040
parser.add_argument(
41-
'--color', default='auto', type=color.use_color,
41+
'--color', default=os.environ.get('PRE_COMMIT_COLOR', 'auto'),
42+
type=color.use_color,
4243
metavar='{' + ','.join(color.COLOR_CHOICES) + '}',
4344
help='Whether to use color in output. Defaults to `%(default)s`.',
4445
)

tests/color_test.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import unicode_literals
22

3-
import os
43
import sys
54

65
import mock
@@ -51,18 +50,3 @@ def test_use_color_tty_without_color_support():
5150
def test_use_color_raises_if_given_shenanigans():
5251
with pytest.raises(InvalidColorSetting):
5352
use_color('herpaderp')
54-
55-
56-
def test_no_color_env_unset():
57-
with mock.patch.dict(os.environ, clear=True):
58-
assert use_color('always') is True
59-
60-
61-
def test_no_color_env_empty():
62-
with mock.patch.dict(os.environ, NO_COLOR=''):
63-
assert use_color('always') is True
64-
65-
66-
def test_no_color_env_non_empty():
67-
with mock.patch.dict(os.environ, NO_COLOR=' '):
68-
assert use_color('always') is False

0 commit comments

Comments
 (0)