py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-03-10 17:15:34 +01:00
|
|
|
from __future__ import print_function
|
2016-03-10 18:22:27 +01:00
|
|
|
from __future__ import absolute_import
|
2016-08-18 18:48:08 +02:00
|
|
|
import logging
|
2013-02-19 04:40:57 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2017-08-25 13:55:28 +02:00
|
|
|
import argparse
|
2017-07-06 06:48:26 +02:00
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
2018-08-04 22:02:09 +02:00
|
|
|
from zulint import lister
|
2018-08-04 23:33:19 +02:00
|
|
|
from zulint.command import add_default_linter_arguments, LinterConfig
|
2017-06-05 16:43:16 +02:00
|
|
|
from typing import cast, Callable, Dict, Iterator, List
|
2016-03-22 21:20:33 +01:00
|
|
|
|
2016-08-18 20:05:04 +02:00
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def run():
|
|
|
|
# type: () -> None
|
2017-08-25 13:55:28 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--force', default=False,
|
|
|
|
action="store_true",
|
|
|
|
help='Run tests despite possible problems.')
|
|
|
|
parser.add_argument('--full',
|
|
|
|
action='store_true',
|
|
|
|
help='Check some things we typically ignore')
|
|
|
|
parser.add_argument('--no-gitlint',
|
|
|
|
action='store_true',
|
|
|
|
help='Disable gitlint')
|
2017-08-25 15:23:02 +02:00
|
|
|
limited_tests_group = parser.add_mutually_exclusive_group()
|
|
|
|
limited_tests_group.add_argument('--frontend',
|
|
|
|
action='store_true',
|
|
|
|
help='Only check files relevant to frontend')
|
|
|
|
limited_tests_group.add_argument('--backend',
|
|
|
|
action='store_true',
|
|
|
|
help='Only check files relevant to backend')
|
2018-08-04 23:18:50 +02:00
|
|
|
add_default_linter_arguments(parser)
|
2017-08-25 13:55:28 +02:00
|
|
|
args = parser.parse_args()
|
2016-08-18 20:05:42 +02:00
|
|
|
|
2016-11-23 18:28:21 +01:00
|
|
|
tools_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
root_dir = os.path.dirname(tools_dir)
|
|
|
|
sys.path.insert(0, root_dir)
|
|
|
|
|
2017-06-05 16:29:04 +02:00
|
|
|
from tools.linter_lib.custom_check import build_custom_checkers
|
2017-06-05 16:34:21 +02:00
|
|
|
from tools.linter_lib.exclude import EXCLUDED_FILES
|
2017-06-05 16:43:16 +02:00
|
|
|
from tools.linter_lib.pyflakes import check_pyflakes
|
2017-06-05 16:49:59 +02:00
|
|
|
from tools.linter_lib.pep8 import check_pep8
|
2017-06-05 16:29:04 +02:00
|
|
|
|
2016-11-23 18:28:21 +01:00
|
|
|
from tools.lib.test_script import (
|
|
|
|
get_provisioning_status,
|
|
|
|
)
|
|
|
|
|
|
|
|
os.chdir(root_dir)
|
|
|
|
|
2017-08-25 13:55:28 +02:00
|
|
|
if not args.force:
|
2016-11-23 18:28:21 +01:00
|
|
|
ok, msg = get_provisioning_status()
|
|
|
|
if not ok:
|
|
|
|
print(msg)
|
|
|
|
print('If you really know what you are doing, use --force to run anyway.')
|
|
|
|
sys.exit(1)
|
2016-08-18 20:05:42 +02:00
|
|
|
|
2017-11-16 22:20:50 +01:00
|
|
|
backend_file_types = ['py', 'sh', 'pp', 'json', 'md', 'txt', 'text', 'yaml', 'rst']
|
2018-07-25 14:07:24 +02:00
|
|
|
frontend_file_types = ['js', 'css', 'scss', 'handlebars', 'html']
|
2017-08-25 15:23:02 +02:00
|
|
|
file_types = backend_file_types + frontend_file_types
|
|
|
|
if args.backend:
|
|
|
|
file_types = backend_file_types
|
|
|
|
if args.frontend:
|
|
|
|
file_types = frontend_file_types
|
|
|
|
|
2016-12-11 14:30:45 +01:00
|
|
|
by_lang = cast(Dict[str, List[str]],
|
2017-08-25 13:55:28 +02:00
|
|
|
lister.list_files(args.targets, modified_only=args.modified,
|
2017-08-25 15:23:02 +02:00
|
|
|
ftypes=file_types,
|
2016-12-11 14:30:45 +01:00
|
|
|
use_shebang=True, group_by_ftype=True, exclude=EXCLUDED_FILES))
|
2016-08-18 20:05:42 +02:00
|
|
|
|
|
|
|
# Invoke the appropriate lint checker for each language,
|
|
|
|
# and also check files for extra whitespace.
|
|
|
|
|
|
|
|
logging.basicConfig(format="%(asctime)s %(message)s")
|
|
|
|
logger = logging.getLogger()
|
2017-08-25 13:55:28 +02:00
|
|
|
if args.verbose:
|
2016-08-18 20:05:42 +02:00
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
else:
|
|
|
|
logger.setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
check_custom_checks_py, check_custom_checks_nonpy = build_custom_checkers(by_lang)
|
|
|
|
|
2018-08-04 23:33:19 +02:00
|
|
|
linter_config = LinterConfig(by_lang)
|
|
|
|
linter_config.external_linter('add_class', ['tools/find-add-class'], ['js'])
|
|
|
|
linter_config.external_linter('css', ['node', 'node_modules/.bin/stylelint'], ['css', 'scss'])
|
|
|
|
linter_config.external_linter('eslint', ['node', 'node_modules/.bin/eslint',
|
|
|
|
'--quiet', '--cache'], ['js'])
|
|
|
|
linter_config.external_linter('tslint', ['node', 'node_modules/.bin/tslint', '-c',
|
|
|
|
'static/ts/tslint.json'], ['ts'])
|
|
|
|
linter_config.external_linter('puppet', ['puppet', 'parser', 'validate'], ['pp'])
|
|
|
|
linter_config.external_linter('templates', ['tools/check-templates'], ['handlebars', 'html'])
|
|
|
|
linter_config.external_linter('urls', ['tools/check-urls'], ['py'])
|
|
|
|
linter_config.external_linter('swagger', ['node', 'tools/check-swagger'], ['yaml'])
|
2017-07-06 07:01:43 +02:00
|
|
|
|
2017-12-16 11:15:44 +01:00
|
|
|
# Disabled check for imperative mood until it is stabilized
|
|
|
|
if not args.no_gitlint:
|
2018-08-04 23:33:19 +02:00
|
|
|
linter_config.external_linter('commit_messages', ['tools/commit-message-lint'])
|
2017-07-06 07:01:43 +02:00
|
|
|
|
2018-08-04 23:33:19 +02:00
|
|
|
@linter_config.lint
|
2017-12-13 19:38:15 +01:00
|
|
|
def custom_py():
|
|
|
|
# type: () -> int
|
2017-07-06 07:01:43 +02:00
|
|
|
failed = check_custom_checks_py()
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
2018-08-04 23:33:19 +02:00
|
|
|
@linter_config.lint
|
2017-12-13 19:38:15 +01:00
|
|
|
def custom_nonpy():
|
|
|
|
# type: () -> int
|
2017-07-06 07:01:43 +02:00
|
|
|
failed = check_custom_checks_nonpy()
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
2018-08-04 23:33:19 +02:00
|
|
|
@linter_config.lint
|
2017-12-13 19:38:15 +01:00
|
|
|
def pyflakes():
|
|
|
|
# type: () -> int
|
2017-08-25 13:55:28 +02:00
|
|
|
failed = check_pyflakes(args, by_lang)
|
2017-07-06 07:01:43 +02:00
|
|
|
return 1 if failed else 0
|
|
|
|
|
2018-08-04 23:33:19 +02:00
|
|
|
@linter_config.lint
|
2017-12-13 19:38:15 +01:00
|
|
|
def pep8():
|
|
|
|
# type: () -> int
|
2017-08-25 15:23:02 +02:00
|
|
|
failed = check_pep8(by_lang['py'])
|
|
|
|
return 1 if failed else 0
|
2016-08-18 18:42:17 +02:00
|
|
|
|
2018-08-04 23:33:19 +02:00
|
|
|
linter_config.do_lint()
|
2016-08-18 18:42:17 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run()
|