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
|
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__)
|
|
|
|
|
2019-05-30 17:41:23 +02:00
|
|
|
from linter_lib.custom_check import python_rules, non_py_rules
|
2018-08-04 23:33:19 +02:00
|
|
|
from zulint.command import add_default_linter_arguments, LinterConfig
|
2018-08-05 20:13:49 +02:00
|
|
|
import random
|
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')
|
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)
|
|
|
|
|
2018-08-07 14:26:46 +02:00
|
|
|
from tools.linter_lib.exclude import EXCLUDED_FILES, PUPPET_CHECK_RULES_TO_EXCLUDE
|
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 (
|
2019-06-20 18:27:09 +02:00
|
|
|
assert_provisioning_status_ok,
|
2016-11-23 18:28:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
os.chdir(root_dir)
|
|
|
|
|
2019-06-20 18:27:09 +02:00
|
|
|
assert_provisioning_status_ok(args.force)
|
2016-08-18 20:05:42 +02:00
|
|
|
|
|
|
|
# Invoke the appropriate lint checker for each language,
|
|
|
|
# and also check files for extra whitespace.
|
|
|
|
|
2019-06-21 18:40:38 +02:00
|
|
|
linter_config = LinterConfig(args)
|
|
|
|
|
|
|
|
by_lang = linter_config.list_files(groups={
|
|
|
|
'backend': ['py', 'sh', 'pp', 'json', 'md', 'txt', 'text', 'yaml', 'rst'],
|
|
|
|
'frontend': ['js', 'ts', 'css', 'scss', 'handlebars', 'html'],
|
|
|
|
}, exclude=EXCLUDED_FILES)
|
|
|
|
|
2018-08-04 23:33:19 +02:00
|
|
|
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',
|
2019-04-14 07:44:23 +02:00
|
|
|
'--quiet', '--cache', '--ext', '.js,.ts'], ['js', 'ts'])
|
2018-08-04 23:33:19 +02:00
|
|
|
linter_config.external_linter('puppet', ['puppet', 'parser', 'validate'], ['pp'])
|
2018-08-07 14:26:46 +02:00
|
|
|
linter_config.external_linter('puppet-lint',
|
|
|
|
['puppet-lint'] + PUPPET_CHECK_RULES_TO_EXCLUDE, ['pp'])
|
2018-08-04 23:33:19 +02:00
|
|
|
linter_config.external_linter('templates', ['tools/check-templates'], ['handlebars', 'html'])
|
|
|
|
linter_config.external_linter('swagger', ['node', 'tools/check-swagger'], ['yaml'])
|
2018-08-03 02:09:42 +02:00
|
|
|
linter_config.external_linter('shellcheck', ['shellcheck', '-x'], ['sh'])
|
2019-06-18 19:12:54 +02:00
|
|
|
command = ['tools/run-mypy']
|
|
|
|
if args.force:
|
|
|
|
command.append('--force')
|
|
|
|
linter_config.external_linter('mypy', command, ['py'], pass_targets=False)
|
|
|
|
linter_config.external_linter('gitlint', ['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
|
2019-05-30 17:41:23 +02:00
|
|
|
failed = python_rules.check(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 custom_nonpy():
|
|
|
|
# type: () -> int
|
2019-05-30 17:41:23 +02:00
|
|
|
failed = False
|
|
|
|
for rule in non_py_rules:
|
|
|
|
failed = failed or rule.check(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 pyflakes():
|
|
|
|
# type: () -> int
|
2018-08-05 05:05:15 +02:00
|
|
|
failed = check_pyflakes(by_lang['py'], args)
|
2017-07-06 07:01:43 +02:00
|
|
|
return 1 if failed else 0
|
|
|
|
|
2018-08-05 20:13:49 +02:00
|
|
|
python_part1 = {x for x in by_lang['py'] if random.randint(0, 1) == 0}
|
|
|
|
python_part2 = {y for y in by_lang['py'] if y not in python_part1}
|
|
|
|
|
|
|
|
@linter_config.lint
|
|
|
|
def pep8_1of2():
|
|
|
|
# type: () -> int
|
|
|
|
failed = check_pep8(list(python_part1))
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
2018-08-04 23:33:19 +02:00
|
|
|
@linter_config.lint
|
2018-08-05 20:13:49 +02:00
|
|
|
def pep8_2of2():
|
2017-12-13 19:38:15 +01:00
|
|
|
# type: () -> int
|
2018-08-05 20:13:49 +02:00
|
|
|
failed = check_pep8(list(python_part2))
|
2017-08-25 15:23:02 +02:00
|
|
|
return 1 if failed else 0
|
2019-06-21 18:36:41 +02:00
|
|
|
|
|
|
|
linter_config.do_lint()
|
2016-08-18 18:42:17 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run()
|