[pitivi: 17/65] Add a pre-hook commit to check the pep8 compliance of each commit
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi: 17/65] Add a pre-hook commit to check the pep8 compliance of each commit
- Date: Mon, 4 Jul 2011 01:20:40 +0000 (UTC)
commit 23bed12e31592b6a980459fc4555597587b47730
Author: Thibault Saunier <thibault saunier collabora com>
Date: Wed Jun 22 23:42:23 2011 -0400
Add a pre-hook commit to check the pep8 compliance of each commit
autogen.sh | 7 +++++++
pre-commit.hook | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/autogen.sh b/autogen.sh
index 6270007..f0157a8 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -42,6 +42,13 @@ autoheader_check || DIE=1
die_check $DIE
+# install pre-commit hook for doing clean commits
+if test ! \( -x .git/hooks/pre-commit -a -L .git/hooks/pre-commit \);
+then
+ rm -f .git/hooks/pre-commit
+ ln -s ../../pre-commit.hook .git/hooks/pre-commit
+fi
+
# if no arguments specified then this will be printed
if test -z "$*"; then
echo "+ checking for autogen.sh options"
diff --git a/pre-commit.hook b/pre-commit.hook
new file mode 100755
index 0000000..238b322
--- /dev/null
+++ b/pre-commit.hook
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+from __future__ import with_statement
+import os
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+
+
+def system(*args, **kwargs):
+ kwargs.setdefault('stdout', subprocess.PIPE)
+ proc = subprocess.Popen(args, **kwargs)
+ out, err = proc.communicate()
+ return out
+
+
+def main():
+ modified = re.compile('^[AM]+\s+(?P<name>.*\.py)', re.MULTILINE)
+ files = system('git', 'status', '--porcelain')
+ files = modified.findall(files)
+
+ tempdir = tempfile.mkdtemp()
+ for name in files:
+ filename = os.path.join(tempdir, name)
+ filepath = os.path.dirname(filename)
+ if not os.path.exists(filepath):
+ os.makedirs(filepath)
+ with file(filename, 'w') as f:
+ system('git', 'show', ':' + name, stdout=f)
+ try:
+ output = system('pep8', '.', cwd=tempdir)
+ except OSError:
+ output = "You should install the pep8 style checker to be able"\
+ " to commit in this repo.\nIt allow us to garantee that "\
+ "anything that is commited respects the pep8 coding style "\
+ "standard.\nYou can install it:\n"\
+ " * on ubuntu, debian: $sudo apt-get install pep8 \n"\
+ " * on fedora: #yum install python-pep8 \n"\
+ " * Or add the official pep8 from http://www.python.org/dev/peps/pep-0008/"\
+ " in your $PATH"
+
+ shutil.rmtree(tempdir)
+ if output:
+ print output,
+ sys.exit(1)
+
+
+if __name__ == '__main__':
+ main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]