mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
added basic run single hook implmentation
This commit is contained in:
parent
871ab4d72f
commit
27c341e2fb
3 changed files with 37 additions and 1 deletions
|
|
@ -15,6 +15,10 @@ def in_env():
|
|||
|
||||
def install_environment():
|
||||
assert local.path('setup.py').exists()
|
||||
# Return immediately if we already have a virtualenv
|
||||
if local.path('py_env').exists():
|
||||
return
|
||||
|
||||
# Install a virtualenv
|
||||
local['virtualenv'][PY_ENV]()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,45 @@
|
|||
|
||||
import argparse
|
||||
import os.path
|
||||
from pre_commit import git
|
||||
from pre_commit.clientlib.validate_config import validate_config
|
||||
from pre_commit.repository import Repository
|
||||
|
||||
def install():
|
||||
"""Install the pre-commit hook."""
|
||||
git.create_pre_commit()
|
||||
|
||||
|
||||
def uninstall():
|
||||
"""Uninstall the pre-commit hook."""
|
||||
raise NotImplementedError
|
||||
git.remove_pre_commit()
|
||||
|
||||
|
||||
def run_hooks(arguments):
|
||||
"""Actually run the hooks."""
|
||||
raise NotImplementedError
|
||||
|
||||
def run_single_hook(hook_id):
|
||||
configs = validate_config([])
|
||||
for config in configs:
|
||||
repo = Repository(config)
|
||||
if hook_id in repo.hooks:
|
||||
repo.install()
|
||||
|
||||
retcode, stdout, stderr = repo.run_hook(hook_id, map(os.path.abspath, ['pre_commit/constants.py']))
|
||||
|
||||
if retcode != repo.hooks[hook_id].get('expected_return_value', 0):
|
||||
for out in (stdout, stderr):
|
||||
out = out.rstrip()
|
||||
if len(out) > 0:
|
||||
print out
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
else:
|
||||
print "No hook with id {0}".format(hook_id)
|
||||
return 1
|
||||
|
||||
|
||||
def run(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
|
|
@ -30,6 +55,10 @@ def run(argv):
|
|||
action='store_true',
|
||||
help='Uninstall the pre-commit script.',
|
||||
)
|
||||
group.add_argument(
|
||||
'-r', '--run',
|
||||
help='Run a hook'
|
||||
)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
|
|
@ -37,5 +66,7 @@ def run(argv):
|
|||
return install()
|
||||
elif args.uninstall:
|
||||
return uninstall()
|
||||
elif args.run:
|
||||
return run_single_hook(args.run)
|
||||
else:
|
||||
return run_hooks(args)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue