Skip to content

Commit

Permalink
Add a way to specify files to ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
tsaunier committed Feb 11, 2016
1 parent 38fd9ac commit e2a3c76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion git-pylint-commit-hook
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,19 @@ def main():
'--version',
action='store_true',
help='Print current version number')
parser.add_argument(
'--ignore', dest='ignored_files', action='append',
default=[], help='Add regex to blacklist files or directories, '
'allowing to pylint those files.')
args = parser.parse_args()

if args.version:
print('git-pylint-commit-hook version {}'.format(VERSION))
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.ignored_files)

if result:
sys.exit(0)
Expand Down
13 changes: 11 additions & 2 deletions git_pylint_commit_hook/commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ def _is_python_file(filename):
return 'python' in first_line and '#!' in first_line


def _is_blacklisted(filename, blacklist):
for black_regex in blacklist:
if re.findall(black_regex, filename):
return True

return False


_SCORE_REGEXP = re.compile(
r'^Your\ code\ has\ been\ rated\ at\ (\-?[0-9\.]+)/10')

Expand All @@ -87,7 +95,7 @@ def _parse_score(pylint_output):

def check_repo(
limit, pylint='pylint', pylintrc='.pylintrc', pylint_params=None,
suppress_report=False):
suppress_report=False, ignored_files=[]):
""" Main function doing the checks
:type limit: float
Expand All @@ -110,7 +118,8 @@ def check_repo(
# Find Python files
for filename in _get_list_of_committed_files():
try:
if _is_python_file(filename):
if _is_python_file(filename) and not _is_blacklisted(filename,
ignored_files):
python_files.append((filename, None))
except IOError:
print('File not found (probably deleted): {}\t\tSKIPPED'.format(
Expand Down

0 comments on commit e2a3c76

Please sign in to comment.