show color in hook outputs when attached to a tty

This commit is contained in:
Anthony Sottile 2019-10-12 15:57:40 -07:00
parent c8620f35e1
commit 7c3404ef1f
27 changed files with 200 additions and 76 deletions

View file

@ -5,6 +5,7 @@ import io
import json
import logging
import os
import shlex
import pre_commit.constants as C
from pre_commit import five
@ -54,6 +55,10 @@ _KEYS = tuple(item.key for item in MANIFEST_HOOK_DICT.items)
class Hook(collections.namedtuple('Hook', ('src', 'prefix') + _KEYS)):
__slots__ = ()
@property
def cmd(self):
return tuple(shlex.split(self.entry)) + tuple(self.args)
@property
def install_key(self):
return (
@ -95,9 +100,9 @@ class Hook(collections.namedtuple('Hook', ('src', 'prefix') + _KEYS)):
# Write our state to indicate we're installed
_write_state(self.prefix, venv, _state(self.additional_dependencies))
def run(self, file_args):
def run(self, file_args, color):
lang = languages[self.language]
return lang.run_hook(self, file_args)
return lang.run_hook(self, file_args, color)
@classmethod
def create(cls, src, prefix, dct):