From 1c8d3595463924ff30bb95bec5c0a57c1c114116 Mon Sep 17 00:00:00 2001 From: Rohitt Vashishtha Date: Fri, 7 Jul 2017 04:26:46 +0530 Subject: [PATCH] tools: Add pep8 linter. This commit adds the tools/lint script to run the pep8 linter as well as modifies .travis.yml to run the linter in Travis. --- .travis.yml | 2 +- tools/lint | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 tools/lint diff --git a/.travis.yml b/.travis.yml index 7cae865..1138744 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,5 @@ install: - pip install . - bots_api/provision.py script: - # TODO run linter here + - tools/lint - bots_api/test-bots diff --git a/tools/lint b/tools/lint new file mode 100755 index 0000000..27811e3 --- /dev/null +++ b/tools/lint @@ -0,0 +1,36 @@ +#! /usr/bin/env python + +from pep8 import check_pep8 +from server_lib import lister + +import sys +import optparse +from typing import cast, Callable, Dict, Iterator, List + +EXCLUDED_FILES = [ + # This is an external file that doesn't comply with our codestyle + 'integrations/perforce/git_p4.py', +] + +def lint_all(args, options): + + by_lang = cast(Dict[str, List[str]], + lister.list_files(args, modified_only=options.modified, + ftypes=['py', 'sh', 'js', 'pp', 'css', 'handlebars', + 'html', 'json', 'md', 'txt', 'text', 'yaml'], + use_shebang=True, group_by_ftype=True, exclude=EXCLUDED_FILES)) + failed = check_pep8(by_lang['py']) + return failed + +def run(): + # type: () -> None + parser = optparse.OptionParser() + parser.add_option('--modified', '-m', + action='store_true', + help='Only check modified files') + (options, args) = parser.parse_args() + failed = lint_all(args, options) + sys.exit(1 if failed else 0) + +if __name__ == '__main__': + run()