Pre-commit hook for Git checking Python code quality. The hook will check files ending with .py
or that has a she bang (#!) containing python
.
By default the script looks in the root directory of your project for a .pylintrc file, which it passes to pylint. It also looks for a [pre-commit-hook] section for options of it's own.
Install via PyPI
pip install git-pylint-commit-hook
The commit hook will automatically be called when you are running git commit
. If you want to skip the tests for a certain commit, use the -n
flag, git commit -n
.
Settings are loaded by default from the .pylintrc file in the root of your repo.
[pre-commit-hook]
command=custom_pylint
params=--rcfile=/path/to/another/pylint.rc
limit=8.0
command is for the actual command, for instance if pylint is not installed globally, but is in a virtualenv inside the project itself.
params lets you pass custom parameters to pylint
limit is the lowest value which you want to allow for a pylint score. Any lower than this, and the script will fail and won't commit.
Any of these can be bypassed directly in the pre-commit hook itself. You can also set a different default place to look for the pylintrc file.
The test suite requires nose2
to be installed. Install it with pip install nose2
, then run the tests by executing the following command (in the project root folder):
nose2
This commit hook is written in Python and has the following requirements:
- pylint (
sudo pip install pylint
) - Python >2.5 and <3.0
- Add option to suppress pylint report if score is below limit. Thanks @jwkvam for the PR
- 2.0.6 fails if pylint params is not set
- Separate code for testing if a file is Python into a new function
- Add unit tests for
_current_commit
andget_list_of_committed_files
- Make hook work properly on initial commit. Thanks @evvers for the PR
- Add pylint to install_requires. Thanks @evvers for the PR
- Fixed error in decimal representation
- Added
--version
flag to command line #22 - Packaging fixes
- Documentation updated and moved to Read The Docs
git-pylint-commit-hook
is now a regular command- Installation via PyPI:
pip install git-pylint-commit-hook
- Configurable using command line parameters. See the documentation for details
- Added support for default .pylintrc file, and also for loading our own options from there.
- Bug when skipping init.py files fixed. Wrong path was checked under some circumstanses
- Added support for negative pylint scores #4
- Added support for custom command line params to pylint #6
- Fixed bug #3 Empty .py files fails according to pylint
- Fixed bug #1 Files parsed number is not increased
- Fixed bug with non-python files getting checked, if they contained
python
on the first row
- Added support for handling moved or deleted files
- Initial release of the commit hook