Skip to main content

Git commit hook that checks Python files with pep8.

Project description

git_pep8_commit_hook

Build Status

Git pre-commit hook for checking coding style of Python code. The hook requires pep8. It will check files with the .py extension and files that contain #! (shebang) and python in the first line. Heavily inspired by and partly based on git-pylint-commit-hook by Sebastian Dahlgren.

Since pep8 itself, by default, looks for a setup.cfg file in the repository root directory, so does this script. The script works without the setup.cfg file. The options for the script can either be placed in the [pep8_pre_commit_hook] section of the configuration file or be passed as command line parameters. If the same option is specified in both the configuration file and the parameters, the configuration file takes precedence.

Installation

Install via PyPI

pip install git_pep8_commit_hook

Usage

Having installed the script, if you add it to your pre-commit file which should be placed in the hooks subfolder for the Git folder (usually .git/hooks), it will be called automatically when you run git commit. If you want to skip the checks for a certain commit, you can add the -n flag and run git commit -n.

Configuration

By default, the script looks for a setup.cfg in the root directory of your repository. If the script does not find a configuration file, it uses default settings. The file might look like this:

[pep8]
ignore = E226,E302,E41
max-line-length = 79

[pep8_pre_commit_hook]
max-violations-per-file = 5

The [pep8] section is used by pep8. The [pep8_pre_commit_hook] section is used by the commit hook script. You may specify the following options:

  • pep8-command is for the actual command, for instance if pep8 is not installed globally, but is in a virtualenv inside the project itself.

  • pep8-params lets you pass custom parameters to pep8

  • max-violations-per-file lets you specify how many violations of the PEP 0008 standard you are willing to accept for any file. If at least one file has more than the specified number of violations, the commit will be blocked. The default value is 0.

Alternatively you can pass the above directly to the commit hook script as arguments. In addition to the above, you can also pass the following arguments to the script:

  • config lets you specify an alternative config file for both pep8 itself and the commit hook script.

  • version displays the current version of the commit hook script.

  • help displays a help message explaining the arguments.

Running tests

The tests are written using pytest. You can run the tests without installing pytest and without installing the script by typing python runtests.py. Alternatively, you can install pytest by running pip install pytest. The script itself can be installed in development mode by running pip install -e . from the root directory of the repository. Then the tests can be run by executing py.test.

Requirements

This commit hook is written in Python and has the following requirements:

  • pep8 (sudo pip install pep8)

  • Python >= 2.7

Release notes

0.1.0 (2015-09-11)

  • Initial release.

Project details


Download files

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

Source Distribution

git_pep8_commit_hook-0.1.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

git_pep8_commit_hook-0.1.0-py2.py3-none-any.whl (8.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file git_pep8_commit_hook-0.1.0.tar.gz.

File metadata

File hashes

Hashes for git_pep8_commit_hook-0.1.0.tar.gz
Algorithm Hash digest
SHA256 432f27c621422b1ebcf9fd2c8275828878706ea1f05187991df2bafdd2e9fb2f
MD5 2b1e1d828383327c36eeb2b0f6e6cc68
BLAKE2b-256 3fb1e5e992d5938ac8317951bbbf2dba8d9348642e339b8fa2eb3bce22e19d55

See more details on using hashes here.

File details

Details for the file git_pep8_commit_hook-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for git_pep8_commit_hook-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c6d188873a7fc7aa27d22ab34d948d3c660cb2eef20d92a06a4f336018233087
MD5 7ab05e117efdfd1862e1ea2942bd472f
BLAKE2b-256 50f379dc6830daf7e5edbba3d0ae644a24b40e69a0be62ac2c4ffa3336f1bda4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page