mirror of https://github.com/zulip/zulip.git
zulint: Extract run_parallel and do_lint.
This commit is contained in:
parent
acf8ec492d
commit
f74bb8a9b2
27
tools/lint
27
tools/lint
|
@ -14,31 +14,10 @@ from lib import sanity_check
|
|||
sanity_check.check_venv(__file__)
|
||||
|
||||
from zulint import lister
|
||||
from zulint.command import add_default_linter_arguments
|
||||
from zulint.command import add_default_linter_arguments, do_lint
|
||||
from typing import cast, Callable, Dict, Iterator, List
|
||||
|
||||
|
||||
def run_parallel(lint_functions):
|
||||
# type: (Dict[str, Callable[[], int]]) -> bool
|
||||
pids = []
|
||||
for name, func in lint_functions.items():
|
||||
pid = os.fork()
|
||||
if pid == 0:
|
||||
logging.info("start " + name)
|
||||
result = func()
|
||||
logging.info("finish " + name)
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
os._exit(result)
|
||||
pids.append(pid)
|
||||
failed = False
|
||||
|
||||
for pid in pids:
|
||||
(_, status) = os.waitpid(pid, 0)
|
||||
if status != 0:
|
||||
failed = True
|
||||
return failed
|
||||
|
||||
def run():
|
||||
# type: () -> None
|
||||
parser = argparse.ArgumentParser()
|
||||
|
@ -188,9 +167,7 @@ def run():
|
|||
failed = check_pep8(by_lang['py'])
|
||||
return 1 if failed else 0
|
||||
|
||||
failed = run_parallel(lint_functions)
|
||||
|
||||
sys.exit(1 if failed else 0)
|
||||
do_lint(lint_functions)
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
|
|
|
@ -4,6 +4,11 @@ from __future__ import print_function
|
|||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from typing import Any, Callable, Dict, List
|
||||
|
||||
def add_default_linter_arguments(parser):
|
||||
# type: (argparse.ArgumentParser) -> None
|
||||
|
@ -16,3 +21,29 @@ def add_default_linter_arguments(parser):
|
|||
parser.add_argument('targets',
|
||||
nargs='*',
|
||||
help='Specify directories to check')
|
||||
|
||||
def run_parallel(lint_functions):
|
||||
# type: (Dict[str, Callable[[], int]]) -> bool
|
||||
pids = []
|
||||
for name, func in lint_functions.items():
|
||||
pid = os.fork()
|
||||
if pid == 0:
|
||||
logging.info("start " + name)
|
||||
result = func()
|
||||
logging.info("finish " + name)
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
os._exit(result)
|
||||
pids.append(pid)
|
||||
failed = False
|
||||
|
||||
for pid in pids:
|
||||
(_, status) = os.waitpid(pid, 0)
|
||||
if status != 0:
|
||||
failed = True
|
||||
return failed
|
||||
|
||||
def do_lint(lint_functions):
|
||||
# type: (Dict[str, Callable[[], int]]) -> None
|
||||
failed = run_parallel(lint_functions)
|
||||
sys.exit(1 if failed else 0)
|
||||
|
|
Loading…
Reference in New Issue