QA/Execution/Web Testing/Automation/PEP8 Pre Commit Hook

< QA‎ | Execution‎ | Web Testing‎ | Automation
Revision as of 17:06, 5 September 2012 by Davehunt (talk | contribs)

PEP8 Pre-Commit Hook

The style guide specifies that all Python code adheres to PEP8. To prevent committing code that does not pass PEP8, follow these steps to installing a pre-commit to run staged files using the pep8 checker.

Install pep8:

    pip install pep8

Set the git global templates directory:

   git config --global init.templatedir /usr/local/git/share/git-core/templates

Clone the pre-commit hook and move it to the templates directory:

   git clone git://gist.github.com/3560385.git
   sudo mv 3560385/pre-commit /usr/local/git/share/git-core/templates/hooks
   rm -rf 3560385

Ensure that the pre-commit hook file is marked as executable:

   chmod +x /usr/local/git/share/git-core/templates/hooks/pre-commit

Reinitialize any existing git repositories:

   git init

Troubleshooting

If you have done everything as above and your pre-commit hook still won't fire, trying ensuring that the file in your local git repository is also marked as executable:

   chmod +x .git/hooks/pre-commit