From 5d8221478729db1b8c1c064e64ac4d18983ae98d Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 5 Jan 2016 14:31:39 +0100 Subject: [PATCH] make-lint: Allow running pylint --py3k to detect Python3 issues Pylint can be run with the --py3k switch to detect porting issues. This is not compatible with regular checking (i.e. to do all checks, pylint must be run twice, with and without --py3k). So, do an additional run of pylint in a subprocess for the py3k checks. Add a --no-py3k switch to skip the additional py3k run. Also add a --no-lint switch to allow only running the py3 checks. https://fedorahosted.org/freeipa/ticket/5623 Reviewed-By: Jan Cholasta Reviewed-By: Martin Basti --- make-lint | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/make-lint b/make-lint index df829580b..cbc7d285a 100755 --- a/make-lint +++ b/make-lint @@ -26,6 +26,7 @@ import os import sys from optparse import OptionParser from fnmatch import fnmatch, fnmatchcase +import subprocess try: from pylint import checkers @@ -220,6 +221,10 @@ def main(): dest='fail', default=True, action='store_false') optparser.add_option('--enable-noerror', help='enable warnings and other non-error messages', dest='errors_only', default=True, action='store_false') + optparser.add_option('--no-py3k', help='Do not check for Python 3 porting issues', + dest='py3k', default=True, action='store_false') + optparser.add_option('--no-lint', help='Skip the main lint check', + dest='do_lint', default=True, action='store_false') options, args = optparser.parse_args() cwd = os.getcwd() @@ -306,33 +311,41 @@ def main(): linter.set_option('persistent', False) linter.set_option('disable', 'python3') - linter.check(files) + if options.do_lint: + linter.check(files) - if linter.msg_status != 0: - print(""" + if linter.msg_status != 0: + print(""" =============================================================================== Errors were found during the static code check. """, file=sys.stderr) - if len(linter.missing) > 0: - print("There are some missing imports:", file=sys.stderr) - for mod in sorted(linter.missing): - print(" " + mod, file=sys.stderr) - print(""" + if len(linter.missing) > 0: + print("There are some missing imports:", file=sys.stderr) + for mod in sorted(linter.missing): + print(" " + mod, file=sys.stderr) + print(""" Please make sure all of the required and optional (python-gssapi, python-rhsm) python packages are installed. """, file=sys.stderr) - print("""\ + print("""\ If you are certain that any of the reported errors are false positives, please mark them in the source code according to the pylint documentation. =============================================================================== """, file=sys.stderr) - if options.fail: - return linter.msg_status - else: - return 0 + if options.fail and linter.msg_status != 0: + return linter.msg_status + + if options.py3k: + args = ['pylint', '--py3k', '-d', 'no-absolute-import', '--reports=n'] + args.extend(files) + returncode = subprocess.call(args) + if options.fail and returncode != 0: + return returncode + + return 0 if __name__ == "__main__": sys.exit(main())