mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
added node hooks setup and jshint
This commit is contained in:
parent
356e4ba13b
commit
7fbc935d1c
4 changed files with 51 additions and 6 deletions
|
|
@ -6,3 +6,11 @@
|
||||||
-
|
-
|
||||||
id: pyflakes
|
id: pyflakes
|
||||||
files: '*.py'
|
files: '*.py'
|
||||||
|
|
||||||
|
-
|
||||||
|
repo: git@github.com:pre-commit/jshint
|
||||||
|
sha: 191734354d1191e3771c004c3e905a94728d0349
|
||||||
|
hooks:
|
||||||
|
-
|
||||||
|
id: jshint
|
||||||
|
files: '*.js'
|
||||||
6
pre_commit/languages/helpers.py
Normal file
6
pre_commit/languages/helpers.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
def run_hook(env, hook, file_args):
|
||||||
|
return env.run(
|
||||||
|
' '.join([hook['entry']] + hook.get('args', []) + list(file_args)),
|
||||||
|
retcode=None,
|
||||||
|
)
|
||||||
|
|
@ -1,7 +1,40 @@
|
||||||
|
import contextlib
|
||||||
|
from plumbum import local
|
||||||
|
from plumbum.machines.session import ShellSession
|
||||||
|
from pre_commit.languages import helpers
|
||||||
|
|
||||||
|
from pre_commit.languages import python
|
||||||
|
|
||||||
|
NODE_ENV = 'node_env'
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def in_env():
|
||||||
|
with ShellSession(local['bash'].popen()) as env:
|
||||||
|
env.run('. {0}/bin/activate'.format(NODE_ENV))
|
||||||
|
yield env
|
||||||
|
|
||||||
|
|
||||||
def install_environment():
|
def install_environment():
|
||||||
raise NotImplementedError
|
assert local.path('package.json').exists()
|
||||||
|
|
||||||
|
if local.path('node_env').exists():
|
||||||
|
return
|
||||||
|
|
||||||
|
# Install a virtualenv
|
||||||
|
local['virtualenv'][python.PY_ENV]()
|
||||||
|
|
||||||
|
with python.in_env() as python_env:
|
||||||
|
python_env.run('pip install nodeenv')
|
||||||
|
|
||||||
|
print "Creating nodeenv"
|
||||||
|
local['nodeenv'][NODE_ENV]()
|
||||||
|
print "Done nodeenv"
|
||||||
|
|
||||||
|
with in_env() as node_env:
|
||||||
|
node_env.run('npm install -g')
|
||||||
|
|
||||||
|
|
||||||
def run_hook(hook, file_args):
|
def run_hook(hook, file_args):
|
||||||
raise NotImplementedError
|
with python.in_env():
|
||||||
|
with in_env() as node_env:
|
||||||
|
return helpers.run_hook(node_env, hook, file_args)
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
from plumbum import local
|
from plumbum import local
|
||||||
from plumbum.machines.session import ShellSession
|
from plumbum.machines.session import ShellSession
|
||||||
|
from pre_commit.languages import helpers
|
||||||
|
|
||||||
PY_ENV = 'py_env'
|
PY_ENV = 'py_env'
|
||||||
|
|
||||||
|
|
@ -30,7 +31,4 @@ def install_environment():
|
||||||
def run_hook(hook, file_args):
|
def run_hook(hook, file_args):
|
||||||
with in_env() as env:
|
with in_env() as env:
|
||||||
# TODO: batch filenames
|
# TODO: batch filenames
|
||||||
return env.run(
|
return helpers.run_hook(env, hook, file_args)
|
||||||
' '.join([hook['entry']] + hook.get('args', []) + list(file_args)),
|
|
||||||
retcode=None,
|
|
||||||
)
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue