From 2aa8821b705f4e47f7d1457f11caea85caf08521 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 13 Mar 2014 09:07:55 -0700 Subject: [PATCH] Added pre-commit.py script --- .gitignore | 1 + pre_commit/run.py | 42 ++++++++++++++++++++++++++++++++++++++++++ scripts/pre-commit.py | 8 ++++++++ setup.py | 3 +++ 4 files changed, 54 insertions(+) create mode 100644 pre_commit/run.py create mode 100755 scripts/pre-commit.py diff --git a/.gitignore b/.gitignore index fe211142..831f634e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ build dist *.egg-info +*.iml diff --git a/pre_commit/run.py b/pre_commit/run.py new file mode 100644 index 00000000..c281ff72 --- /dev/null +++ b/pre_commit/run.py @@ -0,0 +1,42 @@ + +import argparse + + +def install(): + """Install the pre-commit hook.""" + raise NotImplementedError + + +def uninstall(): + """Uninstall the pre-commit hook.""" + raise NotImplementedError + + +def run_hooks(arguments): + """Actually run the hooks.""" + raise NotImplementedError + + +def run(argv): + parser = argparse.ArgumentParser() + + group = parser.add_mutually_exclusive_group(required=False) + group.add_argument( + '-i', '--install', + action='store_true', + help='Install the pre-commit script.', + ) + group.add_argument( + '-u', '--uninstall', + action='store_true', + help='Uninstall the pre-commit script.', + ) + + args = parser.parse_args(argv) + + if args.install: + install() + elif args.uninstall: + uninstall() + else: + run_hooks(args) \ No newline at end of file diff --git a/scripts/pre-commit.py b/scripts/pre-commit.py new file mode 100755 index 00000000..063ad9c2 --- /dev/null +++ b/scripts/pre-commit.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python + +if __name__ == '__main__': + import sys + + from pre_commit.run import run + + sys.exit(run(sys.argv[1:])) \ No newline at end of file diff --git a/setup.py b/setup.py index afb1d1da..24ada47a 100644 --- a/setup.py +++ b/setup.py @@ -9,4 +9,7 @@ setup( 'argparse', 'simplejson', ], + scripts=[ + 'scripts/pre-commit.py', + ], )