OMG we're running a hook

This commit is contained in:
Anthony Sottile 2014-03-13 22:12:33 -07:00
parent 47bad120e4
commit 871ab4d72f
11 changed files with 105 additions and 25 deletions

View file

@ -5,30 +5,10 @@ from plumbum import local
import pre_commit.constants as C
from pre_commit.clientlib.validate_manifest import validate_manifest
from pre_commit.hooks_workspace import in_hooks_workspace
from pre_commit.languages.all import languages
from pre_commit.util import cached_property
def install_python(repo):
assert local.path('setup.py').exists()
local['virtualenv']['py_env']()
local['bash']['-c', 'source py_env/bin/activate && pip install .']()
def install_ruby(repo):
raise NotImplementedError
def install_node(repo):
raise NotImplementedError
language_to_repo_setup_strategy = {
'python': install_python,
'ruby': install_ruby,
'node': install_node,
}
class Repository(object):
def __init__(self, repo_config):
self.repo_config = repo_config
@ -84,4 +64,9 @@ class Repository(object):
with self.in_checkout():
for language in C.SUPPORTED_LANGUAGES:
if language in self.languages:
language_to_repo_setup_strategy[language](self)
languages[language].install_environment()
def run_hook(self, hook_id, file_args):
with self.in_checkout():
hook = self.hooks[hook_id]
return languages[hook['language']].run_hook(hook, file_args)