Created
August 31, 2018 13:07
-
-
Save harshil93r/ad8d1d3e0577d00202eb3c0b37d76fe0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- mode: python -*- | |
all_okay = True | |
from subprocess import Popen, PIPE | |
import sys | |
from termcolor import colored | |
syntax_checker = "pylint" | |
def run(command): | |
p = Popen(command.split(), stdout=PIPE, stderr=PIPE) | |
p.wait() | |
return p.returncode, p.stdout.read().strip(), p.stderr.read() | |
_, files_modified, _= run("git diff-index --name-only HEAD") | |
for fname in files_modified.split(): | |
fname = fname.decode('utf-8') | |
if fname.endswith(".py") and not fname.endswith('urls.py') and not fname.endswith('__init__.py'): | |
exit_code, _, errors = run("%s %s"%(syntax_checker, fname)) | |
if exit_code != 0: | |
all_okay = False | |
for err in _.decode('utf-8').split(r'\n'): | |
print(colored(err, 'red')) | |
print("\rChecking syntax on %s: FAILED! \n"%(fname)) | |
else: | |
print(colored("\rChecking syntax on %s: OK!"%(fname),'green')) | |
if not all_okay: | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment