tools: Add bright_red_output() to tools/lint-all

This commit is contained in:
Steve Howell 2016-08-18 11:05:04 -07:00 committed by Tim Abbott
parent ffe648baa8
commit f955991120
1 changed files with 17 additions and 11 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function
from __future__ import absolute_import from __future__ import absolute_import
from contextlib import contextmanager
import logging import logging
import os import os
import re import re
@ -11,7 +12,7 @@ import traceback
try: try:
import lister import lister
from typing import cast, Any, Callable, Dict, List, Optional from typing import cast, Any, Callable, Dict, List, Optional, Generator
except ImportError as e: except ImportError as e:
print("ImportError: {}".format(e)) print("ImportError: {}".format(e))
print("You need to run the Zulip linters inside a Zulip dev environment.") print("You need to run the Zulip linters inside a Zulip dev environment.")
@ -36,6 +37,19 @@ zproject/settings.py
zproject/test_settings.py zproject/test_settings.py
""".split() """.split()
@contextmanager
def bright_red_output():
# type: () -> Generator[None, None, None]
# Make the lint output bright red
sys.stdout.write('\x1B[1;31m')
sys.stdout.flush()
try:
yield
finally:
# Restore normal terminal colors
sys.stdout.write('\x1B[0m')
def check_pyflakes(options, by_lang): def check_pyflakes(options, by_lang):
# type: (Any, Dict[str, List[str]]) -> bool # type: (Any, Dict[str, List[str]]) -> bool
if not by_lang['py']: if not by_lang['py']:
@ -393,11 +407,7 @@ def run():
lint_functions[func.__name__] = func lint_functions[func.__name__] = func
return func return func
try: with bright_red_output():
# Make the lint output bright red
sys.stdout.write('\x1B[1;31m')
sys.stdout.flush()
@lint @lint
def templates(): def templates():
# type: () -> int # type: () -> int
@ -456,9 +466,5 @@ def run():
sys.exit(1 if failed else 0) sys.exit(1 if failed else 0)
finally:
# Restore normal terminal colors
sys.stdout.write('\x1B[0m')
if __name__ == '__main__': if __name__ == '__main__':
run() run()