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

View File

@@ -0,0 +1,24 @@
from pre_commit.languages import node
from pre_commit.languages import python
from pre_commit.languages import ruby
# A language implements the following two functions in its module:
#
# def install_environment():
# """Installs a repository in the given repository. Note that the current
# working directory will already be inside the repository.
# """
#
# def run_hook(hook, file_args):
# """Runs a hook and returns the returncode and output of running that hook.
#
# Returns:
# (returncode, stdout, stderr)
# """
languages = {
'node': node,
'python': python,
'ruby': ruby,
}

View File

@@ -0,0 +1,7 @@
def install_environment():
raise NotImplementedError
def run_hook(hook, file_args):
raise NotImplementedError

View File

@@ -0,0 +1,32 @@
import contextlib
from plumbum import local
from plumbum.machines.session import ShellSession
PY_ENV = 'py_env'
@contextlib.contextmanager
def in_env():
with ShellSession(local['bash'].popen()) as env:
env.run('source {0}/bin/activate'.format(PY_ENV))
yield env
def install_environment():
assert local.path('setup.py').exists()
# Install a virtualenv
local['virtualenv'][PY_ENV]()
with in_env() as env:
# Run their setup.py
env.run('pip install .')
def run_hook(hook, file_args):
with in_env() as env:
# TODO: batch filenames
return env.run(
' '.join([hook['entry']] + hook.get('args', []) + list(file_args)),
retcode=None,
)

View File

@@ -0,0 +1,7 @@
def install_environment():
raise NotImplementedError
def run_hook(hook, file_args):
raise NotImplementedError