mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
linter: Create error printing library.
For performance reasons, we spawn each linter in a separate OS thread. The downside of this is that all lints would end up in stdout without much visual separation, resulting in confusing error log. This commit introduce the `print_err` function, which shows which linter each line of lint is from.
This commit is contained in:
@@ -25,6 +25,13 @@ FAIL = '\033[91m'
|
|||||||
ENDC = '\033[0m'
|
ENDC = '\033[0m'
|
||||||
BLACKONYELLOW = '\x1b[0;30;43m'
|
BLACKONYELLOW = '\x1b[0;30;43m'
|
||||||
WHITEONRED = '\x1b[0;37;41m'
|
WHITEONRED = '\x1b[0;37;41m'
|
||||||
|
BOLDRED = '\x1B[1;31m'
|
||||||
|
|
||||||
|
GREEN = '\x1b[32m'
|
||||||
|
YELLOW = '\x1b[33m'
|
||||||
|
BLUE = '\x1b[34m'
|
||||||
|
MAGENTA = '\x1b[35m'
|
||||||
|
CYAN = '\x1b[36m'
|
||||||
|
|
||||||
def get_deployment_version(extract_path):
|
def get_deployment_version(extract_path):
|
||||||
# type: (str) -> str
|
# type: (str) -> str
|
||||||
|
|||||||
33
tools/linter_lib/printer.py
Normal file
33
tools/linter_lib/printer.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
from __future__ import print_function, absolute_import
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from itertools import cycle
|
||||||
|
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
|
||||||
|
from scripts.lib.zulip_tools import ENDC, BOLDRED, GREEN, YELLOW, BLUE, MAGENTA, CYAN
|
||||||
|
|
||||||
|
from typing import Union, Text
|
||||||
|
|
||||||
|
colors = cycle([GREEN, YELLOW, BLUE, MAGENTA, CYAN])
|
||||||
|
|
||||||
|
|
||||||
|
def print_err(name, color, line):
|
||||||
|
# type: (str, str, Union[Text, bytes]) -> None
|
||||||
|
|
||||||
|
# Decode with UTF-8 if in Python 3 and `line` is of bytes type.
|
||||||
|
# (Python 2 does this automatically)
|
||||||
|
if sys.version_info[0] == 3 and isinstance(line, bytes):
|
||||||
|
line = line.decode('utf-8')
|
||||||
|
|
||||||
|
print('{}{}{}|{end} {}{}{end}'.format(
|
||||||
|
color,
|
||||||
|
name,
|
||||||
|
' ' * max(0, 10 - len(name)),
|
||||||
|
BOLDRED,
|
||||||
|
line.rstrip(),
|
||||||
|
end=ENDC)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Python 2's print function does not have a `flush` option.
|
||||||
|
sys.stdout.flush()
|
||||||
Reference in New Issue
Block a user