Skip to content

Commit ca02afd

Browse files
committed
Merge remote-tracking branch 'origin/master' into performance_test
Conflicts: pre_commit/languages/python.py
2 parents 14d0d30 + cdea26a commit ca02afd

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@
66
-
77
id: pyflakes
88
files: '*.py'
9+
10+
-
11+
repo: git@github.com:pre-commit/jshint
12+
sha: 191734354d1191e3771c004c3e905a94728d0349
13+
hooks:
14+
-
15+
id: jshint
16+
files: '*.js'

pre_commit/languages/helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
def run_hook(env, hook, file_args):
3+
return env.run(
4+
' '.join([hook['entry']] + hook.get('args', []) + list(file_args)),
5+
retcode=None,
6+
)

pre_commit/languages/node.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1+
import contextlib
2+
from plumbum import local
3+
4+
from pre_commit.languages import helpers
5+
from pre_commit.languages import python
6+
7+
8+
NODE_ENV = 'node_env'
9+
10+
11+
class NodeEnv(object):
12+
def __init__(self, py_env):
13+
self.py_env = py_env
14+
self.env_prefix = '. {0}/bin/activate &&'.format(NODE_ENV)
15+
16+
def run(self, cmd, **kwargs):
17+
return self.py_env.run(' '.join([self.env_prefix, cmd]), **kwargs)
18+
19+
20+
@contextlib.contextmanager
21+
def in_env(py_env):
22+
yield NodeEnv(py_env)
23+
124

225
def install_environment():
3-
raise NotImplementedError
26+
assert local.path('package.json').exists()
27+
28+
if local.path('node_env').exists():
29+
return
30+
31+
local['virtualenv'][python.PY_ENV]()
32+
33+
with python.in_env() as python_env:
34+
python_env.run('pip install nodeenv')
35+
python_env.run('nodeenv {0}'.format(NODE_ENV))
36+
37+
with in_env(python_env) as node_env:
38+
node_env.run('npm install -g')
439

540

641
def run_hook(hook, file_args):
7-
raise NotImplementedError
42+
with python.in_env() as py_env:
43+
with in_env(py_env) as node_env:
44+
return helpers.run_hook(node_env, hook, file_args)

pre_commit/languages/python.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

2-
import contexlib
2+
import contextlib
33
from plumbum import local
4+
from pre_commit.languages import helpers
45

56
PY_ENV = 'py_env'
67

@@ -9,22 +10,11 @@ class PythonEnv(object):
910
def __init__(self):
1011
self.env_prefix = '. {0}/bin/activate &&'.format(PY_ENV)
1112

12-
def run(self, cmd):
13-
return local['bash']['-c', ' '.join([self.env_prefix, cmd])]()
13+
def run(self, cmd, **kwargs):
14+
return local['bash']['-c', ' '.join([self.env_prefix, cmd])].run(**kwargs)
1415

1516

16-
NODE_ENV = 'node_env'
17-
18-
class NodeEnv(object):
19-
def __init__(self, py_env):
20-
self.py_env = py_env
21-
self.env_prefix = '. {0}/bin/activate &&'.format(NODE_ENV)
22-
23-
def run(self, cmd):
24-
return self.py_env.run(' '.join(self.env_prefix, cmd))
25-
26-
27-
@contexlib.contextmanager
17+
@contextlib.contextmanager
2818
def in_env():
2919
yield PythonEnv()
3020

@@ -44,6 +34,4 @@ def install_environment():
4434
def run_hook(hook, file_args):
4535
# TODO: batch filenames
4636
with in_env() as env:
47-
env = env
48-
# MAGIC
49-
pass
37+
return helpers.run_hook(env, hook, file_args)

0 commit comments

Comments
 (0)