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'],
|
2019-08-31 03:16:37 +02:00
|
|
|
'frontend': ['js', 'ts', 'css', 'scss', 'hbs', 'html', 'lock'],
|
2019-06-21 18:40:38 +02:00
|
|
|
}, exclude=EXCLUDED_FILES)
|
|
|
|
|
2019-06-21 20:37:06 +02:00
|
|
|
linter_config.external_linter('add_class', ['tools/find-add-class'], ['js'],
|
|
|
|
description="Compares addClass() between JavaSsript and CSS.")
|
|
|
|
linter_config.external_linter('css', ['node', 'node_modules/.bin/stylelint'], ['css', 'scss'],
|
2019-06-24 08:48:31 +02:00
|
|
|
fix_arg='--fix',
|
2019-06-21 20:37:06 +02:00
|
|
|
description="Standard CSS style and formatting linter "
|
|
|
|
"(config: .stylelintrc)")
|
2018-08-04 23:33:19 +02:00
|
|
|
linter_config.external_linter('eslint', ['node', 'node_modules/.bin/eslint',
|
2019-06-21 20:37:06 +02:00
|
|
|
'--quiet', '--cache', '--ext', '.js,.ts'], ['js', 'ts'],
|
2019-06-24 08:48:31 +02:00
|
|
|
fix_arg='--fix',
|
2019-06-21 20:37:06 +02:00
|
|
|
description="Standard JavaScript style and formatting linter"
|
|
|
|
"(config: .eslintrc).")
|
|
|
|
linter_config.external_linter('puppet', ['puppet', 'parser', 'validate'], ['pp'],
|
|
|
|
description="Runs the puppet parser validator, "
|
|
|
|
"checking for syntax errors.")
|
2018-08-07 14:26:46 +02:00
|
|
|
linter_config.external_linter('puppet-lint',
|
2019-06-21 20:37:06 +02:00
|
|
|
['puppet-lint'] + PUPPET_CHECK_RULES_TO_EXCLUDE, ['pp'],
|
2019-06-24 08:48:31 +02:00
|
|
|
fix_arg='--fix',
|
2019-06-21 20:37:06 +02:00
|
|
|
description="Standard puppet linter"
|
|
|
|
"(config: tools/linter_lib/exclude.py)")
|
2019-07-12 00:52:56 +02:00
|
|
|
linter_config.external_linter('templates', ['tools/check-templates'], ['hbs', 'html'],
|
2019-06-21 20:37:06 +02:00
|
|
|
description="Custom linter checks whitespace formatting"
|
2019-07-18 02:41:47 +02:00
|
|
|
"of HTML templates.",
|
|
|
|
fix_arg='--fix')
|
2019-08-04 17:59:21 +02:00
|
|
|
linter_config.external_linter('openapi', ['node', 'tools/check-openapi'], ['yaml'],
|
2019-06-21 20:37:06 +02:00
|
|
|
description="Validates our OpenAPI/Swagger API documentation"
|
|
|
|
"(zerver/openapi/zulip.yaml) ")
|
|
|
|
linter_config.external_linter('shellcheck', ['shellcheck', '-x'], ['sh'],
|
|
|
|
description="Standard shell script linter.")
|
2019-06-18 19:12:54 +02:00
|
|
|
command = ['tools/run-mypy']
|
|
|
|
if args.force:
|
|
|
|
command.append('--force')
|
2019-06-21 20:37:06 +02:00
|
|
|
linter_config.external_linter('mypy', command, ['py'], pass_targets=False,
|
|
|
|
description="Static type checker for Python (config: mypy.ini)")
|
2019-07-20 20:40:36 +02:00
|
|
|
linter_config.external_linter('tsc', ['tools/run-tsc'], ['ts'], pass_targets=False,
|
2019-11-04 23:37:32 +01:00
|
|
|
description="TypeScript compiler (config: tsconfig.json)")
|
2019-08-31 03:16:37 +02:00
|
|
|
linter_config.external_linter('yarn-deduplicate', ['tools/run-yarn-deduplicate'], ['lock'],
|
|
|
|
pass_targets=False,
|
|
|
|
description="Shares duplicate packages in yarn.lock")
|
2019-06-21 20:37:06 +02:00
|
|
|
linter_config.external_linter('gitlint', ['tools/commit-message-lint'],
|
|
|
|
description="Checks commit messages for common formatting errors."
|
|
|
|
"(config: .gitlint)")
|
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-06-21 20:37:06 +02:00
|
|
|
"""Runs custom checks for python files (config: tools/linter_lib/custom_check.py)"""
|
2019-06-23 13:41:06 +02:00
|
|
|
failed = python_rules.check(by_lang, verbose=args.verbose)
|
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-06-21 20:37:06 +02:00
|
|
|
"""Runs custom checks for non-python files (config: tools/linter_lib/custom_check.py)"""
|
2019-05-30 17:41:23 +02:00
|
|
|
failed = False
|
|
|
|
for rule in non_py_rules:
|
2019-06-23 13:41:06 +02:00
|
|
|
failed = failed or rule.check(by_lang, verbose=args.verbose)
|
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
|
2019-06-21 20:37:06 +02:00
|
|
|
"""Standard Python bug and code smell linter (config: tools/linter_lib/pyflakes.py)"""
|
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
|
2019-06-21 20:37:06 +02:00
|
|
|
"""Standard Python style linter on 50% of files (config: tools/linter_lib/pep8.py)"""
|
2018-08-05 20:13:49 +02:00
|
|
|
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
|
2019-06-21 20:37:06 +02:00
|
|
|
"""Standard Python style linter on other 50% of files (config: tools/linter_lib/pep8.py)"""
|
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()
|