Run pre-commit code checkers
This script does any number of checks like unittests or pylint checks before git commit. If at least one check will not pass, commit is aborted.
Checks are treated as jobs divided among couple of workers. Number of workers is equal to number of your cpu logical cores, every worker is executed in separate process.
Some checks are performed on whole project (unittest), other checks are performed on every file (e.g. pylint). Only files added to git staging area are taken into account during jobs creation.
See run_pre_commit_hook.py for example usage.
- cd $REPOSITORY_ROOT_DIR
- git submodule add email@example.com:droslaw/GitHooks.git
- cp GitHooks/samples/run_pre_commit_hook.py ./
- cp GitHooks/samples/pre-commit .git/hooks/pre-commit; chmod +x .git/hooks/pre-commit
Make sure that every requirement of checkers (pylint, pep8 etc.) are installed in your system or active virtual environment. You should install them manually.
To customize pre-commit checking edit run_pre_commit_hook.py copied to parent repository. Purpose of run_pre_commit_hook.py is to create checker jobs and send them to execution in last step. In this file you can specify which checkers for which files will be created.
Currently supported checkers
|Description:||Run system shell command and fail if exit code is non 0|
Usage: Create ExitCodeChecker object with arguments:
- command to execute (string)
- task name displayed before result in console
# ... from checker import ExitCodeChecker # ... jobs =  # ... jobs.append(ExitCodeChecker('python3 -m unittest discover .', 'python unittest'))
- Example result:
- * python unittest: OK
|Description:||Check passes if pylint code rate for particular file is greather or equal to accepted code rate. Accepted code rate is|
# ... from checker import PylintChecker # ... ACCEPTED_PYLINT_RATE = 9 jobs =  # ... jobs.append(PylintChecker(file_name, ACCEPTED_PYLINT_RATE))