mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04: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
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,5 +1,6 @@
|
||||||
*.pyc
|
*.pyc
|
||||||
.pydevproject
|
.pydevproject
|
||||||
|
.pre-commit-files
|
||||||
.project
|
.project
|
||||||
.coverage
|
.coverage
|
||||||
/py_env
|
/py_env
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ def in_env():
|
||||||
|
|
||||||
def install_environment():
|
def install_environment():
|
||||||
assert local.path('setup.py').exists()
|
assert local.path('setup.py').exists()
|
||||||
|
# Return immediately if we already have a virtualenv
|
||||||
|
if local.path('py_env').exists():
|
||||||
|
return
|
||||||
|
|
||||||
# Install a virtualenv
|
# Install a virtualenv
|
||||||
local['virtualenv'][PY_ENV]()
|
local['virtualenv'][PY_ENV]()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,45 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import os.path
|
||||||
from pre_commit import git
|
from pre_commit import git
|
||||||
|
from pre_commit.clientlib.validate_config import validate_config
|
||||||
|
from pre_commit.repository import Repository
|
||||||
|
|
||||||
def install():
|
def install():
|
||||||
"""Install the pre-commit hook."""
|
"""Install the pre-commit hook."""
|
||||||
git.create_pre_commit()
|
git.create_pre_commit()
|
||||||
|
|
||||||
|
|
||||||
def uninstall():
|
def uninstall():
|
||||||
"""Uninstall the pre-commit hook."""
|
"""Uninstall the pre-commit hook."""
|
||||||
raise NotImplementedError
|
git.remove_pre_commit()
|
||||||
|
|
||||||
|
|
||||||
def run_hooks(arguments):
|
def run_hooks(arguments):
|
||||||
"""Actually run the hooks."""
|
"""Actually run the hooks."""
|
||||||
raise NotImplementedError
|
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):
|
def run(argv):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
@ -30,6 +55,10 @@ def run(argv):
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Uninstall the pre-commit script.',
|
help='Uninstall the pre-commit script.',
|
||||||
)
|
)
|
||||||
|
group.add_argument(
|
||||||
|
'-r', '--run',
|
||||||
|
help='Run a hook'
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
|
|
@ -37,5 +66,7 @@ def run(argv):
|
||||||
return install()
|
return install()
|
||||||
elif args.uninstall:
|
elif args.uninstall:
|
||||||
return uninstall()
|
return uninstall()
|
||||||
|
elif args.run:
|
||||||
|
return run_single_hook(args.run)
|
||||||
else:
|
else:
|
||||||
return run_hooks(args)
|
return run_hooks(args)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue