mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
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:
commit
332b98bd86
3 changed files with 2 additions and 20 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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`.',
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue