Created
September 21, 2018 16:19
-
-
Save Dref360/5a1de7c756ee8e25e36800971bc87691 to your computer and use it in GitHub Desktop.
pre-commit for VITAL. to plate in .git/hooks/pre-commit and chmod +x
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 | |
| import subprocess | |
| import sys | |
| def get_staged(): | |
| proc = subprocess.Popen(['git', 'diff', '--name-only', '--cached'], stdout=subprocess.PIPE) | |
| staged_files = proc.stdout.readlines() | |
| staged_files = [f.decode('utf-8') for f in staged_files] | |
| staged_files = [f.strip() for f in staged_files] | |
| staged_files = [f for f in staged_files if f.endswith('.py')] | |
| return staged_files | |
| def main(): | |
| abort = False | |
| staged = get_staged() | |
| print("RUNNING PEP8") | |
| try: | |
| out = subprocess.check_output((sys.executable, '-m', 'pytest', '--pep8', | |
| '-m', 'pep8', '-n0', *staged), | |
| stderr=subprocess.STDOUT) | |
| except subprocess.CalledProcessError as e: | |
| out = e.stdout | |
| out = out.decode('utf8') | |
| print(out) | |
| if 'FAILURES' in out: | |
| abort = True | |
| print("Running Tests") | |
| try: | |
| out = subprocess.check_output((sys.executable, '-m', 'pytest', 'tests'), | |
| stderr=subprocess.STDOUT) | |
| except subprocess.CalledProcessError as e: | |
| out = e.stdout | |
| out = out.decode('utf8') | |
| print(out) | |
| if 'FAILURE' in out: | |
| abort = True | |
| if abort: | |
| sys.exit(1) | |
| else: | |
| sys.exit(0) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment