Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Run pre-commit code checkers

Project Description

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 Currently supported checkers

See run_pre_commit_hook.py for example usage.

Installation

  1. cd $REPOSITORY_ROOT_DIR
  2. git submodule add git@github.com:droslaw/GitHooks.git
  3. cp GitHooks/samples/run_pre_commit_hook.py ./
  4. 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.

Configuration

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

ExitCodeChecker:

Description:Run system shell command and fail if exit code is non 0

Usage: Create ExitCodeChecker object with arguments:

  1. command to execute (string)
  2. 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

pylint:

Description:Check passes if pylint code rate for particular file is greather or equal to accepted code rate. Accepted code rate is
Requirements:pylint

Usage:

# ...
from checker import PylintChecker
# ...
ACCEPTED_PYLINT_RATE = 9
jobs = []
# ...
jobs.append(PylintChecker(file_name, ACCEPTED_PYLINT_RATE))
Release History

Release History

This version
History Node

0.1.0.2

History Node

0.1.0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
GitHooks-0.1.0.2.tar.gz (6.1 kB) Copy SHA256 Checksum SHA256 Source Nov 3, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting