Merge pull request #1098 from geieredgar/switch-to-pre-commit-color-env

Switch from NO_COLOR to PRE_COMMIT_COLOR environment variable
This commit is contained in:
Anthony Sottile 2019-07-23 09:07:54 -07:00 committed by GitHub
commit 332b98bd86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 20 deletions

View file

@ -48,9 +48,6 @@ def use_color(setting):
if setting not in COLOR_CHOICES:
raise InvalidColorSetting(setting)
if os.environ.get('NO_COLOR'):
return False
return (
setting == 'always' or
(setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)

View file

@ -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`.',
)

View file

@ -1,6 +1,5 @@
from __future__ import unicode_literals
import os
import sys
import mock
@ -51,18 +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, clear=True):
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