Skip to content

Instantly share code, notes, and snippets.

@SeavantUUz
Last active August 28, 2015 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeavantUUz/a9374a4f5ff230c9c056 to your computer and use it in GitHub Desktop.
Save SeavantUUz/a9374a4f5ff230c9c056 to your computer and use it in GitHub Desktop.
# coding: utf-8
__inspired__ = 'jimmyislive <https://github.com/jimmyislive/hg-pylint-commit-hook>'
__author__ = 'AprocySanae'
import os
import subprocess
from hgapi import hgapi
import re
from StringIO import StringIO
Threshold = 5
golden_fingers = {
}
PATTERN = 'Your code has been rated at -*(\d+\.\d*)/10'
def pylint_hook(ui, repo, **kwargs):
base_path = os.path.dirname(repo.path)
hgrepo = hgapi.Repo(os.path.abspath(os.curdir))
hg_status = hgrepo.hg_status()
candidate_files = []
candidate_files.extend(hg_status['A'])
candidate_files.extend(hg_status['M'])
failed = False
for item in candidate_files:
file_path = os.path.join(base_path, item)
if file_path.endswith('.py'):
p = subprocess.Popen(['pylint', file_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdoutdata, stderrdata = p.communicate()
print ('>>>CHECKING {}!<<<'.format(item))
print('***\nStdErr: {}\n***'.format(stderrdata))
print('***\nStdOut: {}\n***'.format(stdoutdata))
match = re.search(PATTERN, stdoutdata, re.I|re.M)
if match and len(match.groups()):
score = float(match.group(1))
score += golden_fingers.get(item, 0)
if score >= Threshold:
print 'File {} is a real man, score: {}'.format(item, score)
else:
failed = True
print '***WARNING!!!!****\nFile {} is a not real man'.format(item)
else:
failed = True
print '****ERROR!!!***'
if failed:
print 'pylint checks failed!'
return True
else:
print 'GOOD JOB! MAN!'
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment