From e4d425981d4c801b7c24fc904157ef69704649a3 Mon Sep 17 00:00:00 2001 From: Sandip Agarwal Date: Wed, 10 Aug 2016 13:23:12 +0530 Subject: [PATCH 1/2] support for showing pylint violations in case of passing of limit --- .gitignore | 1 + git-pylint-commit-hook | 8 ++++++-- git_pylint_commit_hook/commit_hook.py | 17 +++++++++-------- git_pylint_commit_hook/settings.conf | 2 +- setup.py | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index f24cd99..420be1b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ var sdist develop-eggs .installed.cfg +.idea # Installer logs pip-log.txt diff --git a/git-pylint-commit-hook b/git-pylint-commit-hook index 79d420c..6b06fdd 100755 --- a/git-pylint-commit-hook +++ b/git-pylint-commit-hook @@ -12,7 +12,7 @@ LICENSE: http://www.apache.org/licenses/LICENSE-2.0.html """ -VERSION = '2.1.1' +VERSION = '2.1.2' import argparse import sys @@ -48,6 +48,10 @@ def main(): '--suppress-report', action='store_true', help='Suppress report output if pylint fails') + parser.add_argument( + '--always-show-violations', + action='store_true', + help='Show violations in case of pass as well') parser.add_argument( '--version', action='store_true', @@ -59,7 +63,7 @@ def main(): sys.exit(0) result = commit_hook.check_repo( - args.limit, args.pylint, args.pylintrc, args.pylint_params, args.suppress_report) + args.limit, args.pylint, args.pylintrc, args.pylint_params, args.suppress_report, args.always_show_violations) if result: sys.exit(0) diff --git a/git_pylint_commit_hook/commit_hook.py b/git_pylint_commit_hook/commit_hook.py index 7983911..60cee6b 100644 --- a/git_pylint_commit_hook/commit_hook.py +++ b/git_pylint_commit_hook/commit_hook.py @@ -13,6 +13,7 @@ 'status, stdout, stderr' ) + def _futurize_str(obj): if isinstance(obj, bytes): obj = obj.decode('utf-8') @@ -132,7 +133,7 @@ def _stash_unstaged(): def check_repo( limit, pylint='pylint', pylintrc='.pylintrc', pylint_params=None, - suppress_report=False): + suppress_report=False, always_show_violations=False): """ Main function doing the checks :type limit: float @@ -145,6 +146,8 @@ def check_repo( :param pylint_params: Custom pylint parameters to add to the pylint command :type suppress_report: bool :param suppress_report: Suppress report if score is below limit + :type always_show_violations: bool + :param always_show_violations: Show violations in case of pass as well """ # List of checked files and their results python_files = [] @@ -218,15 +221,14 @@ def check_repo( # Verify the score score = _parse_score(out) - if score >= float(limit): - status = 'PASSED' - else: - status = 'FAILED' - all_filed_passed = False + status, all_filed_passed = ('PASSED', True) if score >= float(limit) else ('FAILED', False) # Add some output print('{:.2}/10.00\t{}'.format(decimal.Decimal(score), status)) - if 'FAILED' in status: + status_check_list = ['FAILED'] + if always_show_violations: + status_check_list.append('PASSED') + if status in status_check_list: if suppress_report: command.append('--reports=n') proc = subprocess.Popen( @@ -236,7 +238,6 @@ def check_repo( out, _ = proc.communicate() print(_futurize_str(out)) - # Bump parsed files i += 1 diff --git a/git_pylint_commit_hook/settings.conf b/git_pylint_commit_hook/settings.conf index 885777b..0efa5df 100644 --- a/git_pylint_commit_hook/settings.conf +++ b/git_pylint_commit_hook/settings.conf @@ -1,2 +1,2 @@ [general] -version: 2.1.1 +version: 2.1.2 diff --git a/setup.py b/setup.py index 5131d55..a344122 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='git-pylint-commit-hook', - version='2.1.1', + version='2.1.2', license='Apache License, Version 2.0', description='Git commit hook that checks Python files with pylint', author='Sebastian Dahlgren', From ca6e9436583ec784b1a0b865e4290dca3837aac2 Mon Sep 17 00:00:00 2001 From: Sandip Agarwal Date: Fri, 12 Aug 2016 15:29:19 +0530 Subject: [PATCH 2/2] reverted incorrect code change --- git_pylint_commit_hook/commit_hook.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/git_pylint_commit_hook/commit_hook.py b/git_pylint_commit_hook/commit_hook.py index 60cee6b..b65923d 100644 --- a/git_pylint_commit_hook/commit_hook.py +++ b/git_pylint_commit_hook/commit_hook.py @@ -221,7 +221,11 @@ def check_repo( # Verify the score score = _parse_score(out) - status, all_filed_passed = ('PASSED', True) if score >= float(limit) else ('FAILED', False) + if score >= float(limit): + status = 'PASSED' + else: + status = 'FAILED' + all_filed_passed = False # Add some output print('{:.2}/10.00\t{}'.format(decimal.Decimal(score), status))