Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for showing pylint violations in case of passing of limit #48

Merged
merged 2 commits into from
Sep 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var
sdist
develop-eggs
.installed.cfg
.idea

# Installer logs
pip-log.txt
Expand Down
8 changes: 6 additions & 2 deletions git-pylint-commit-hook
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions git_pylint_commit_hook/commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'status, stdout, stderr'
)


def _futurize_str(obj):
if isinstance(obj, bytes):
obj = obj.decode('utf-8')
Expand Down Expand Up @@ -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
Expand All @@ -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 = []
Expand Down Expand Up @@ -226,7 +229,10 @@ def check_repo(

# 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(
Expand All @@ -236,7 +242,6 @@ def check_repo(
out, _ = proc.communicate()
print(_futurize_str(out))


# Bump parsed files
i += 1

Expand Down
2 changes: 1 addition & 1 deletion git_pylint_commit_hook/settings.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[general]
version: 2.1.1
version: 2.1.2
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down