mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #26 from pre-commit/performance_test
Performance test
This commit is contained in:
commit
dd004c2ee5
2 changed files with 30 additions and 23 deletions
|
|
@ -1,17 +1,25 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
from plumbum import local
|
from plumbum import local
|
||||||
from plumbum.machines.session import ShellSession
|
|
||||||
from pre_commit.languages import helpers
|
|
||||||
|
|
||||||
|
from pre_commit.languages import helpers
|
||||||
from pre_commit.languages import python
|
from pre_commit.languages import python
|
||||||
|
|
||||||
|
|
||||||
NODE_ENV = 'node_env'
|
NODE_ENV = 'node_env'
|
||||||
|
|
||||||
|
|
||||||
|
class NodeEnv(object):
|
||||||
|
def __init__(self, py_env):
|
||||||
|
self.py_env = py_env
|
||||||
|
self.env_prefix = '. {0}/bin/activate &&'.format(NODE_ENV)
|
||||||
|
|
||||||
|
def run(self, cmd, **kwargs):
|
||||||
|
return self.py_env.run(' '.join([self.env_prefix, cmd]), **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def in_env():
|
def in_env(py_env):
|
||||||
with ShellSession(local['bash'].popen()) as env:
|
yield NodeEnv(py_env)
|
||||||
env.run('. {0}/bin/activate'.format(NODE_ENV))
|
|
||||||
yield env
|
|
||||||
|
|
||||||
|
|
||||||
def install_environment():
|
def install_environment():
|
||||||
|
|
@ -20,21 +28,17 @@ def install_environment():
|
||||||
if local.path('node_env').exists():
|
if local.path('node_env').exists():
|
||||||
return
|
return
|
||||||
|
|
||||||
# Install a virtualenv
|
|
||||||
local['virtualenv'][python.PY_ENV]()
|
local['virtualenv'][python.PY_ENV]()
|
||||||
|
|
||||||
with python.in_env() as python_env:
|
with python.in_env() as python_env:
|
||||||
python_env.run('pip install nodeenv')
|
python_env.run('pip install nodeenv')
|
||||||
|
python_env.run('nodeenv {0}'.format(NODE_ENV))
|
||||||
|
|
||||||
print "Creating nodeenv"
|
with in_env(python_env) as node_env:
|
||||||
local['nodeenv'][NODE_ENV]()
|
|
||||||
print "Done nodeenv"
|
|
||||||
|
|
||||||
with in_env() as node_env:
|
|
||||||
node_env.run('npm install -g')
|
node_env.run('npm install -g')
|
||||||
|
|
||||||
|
|
||||||
def run_hook(hook, file_args):
|
def run_hook(hook, file_args):
|
||||||
with python.in_env():
|
with python.in_env() as py_env:
|
||||||
with in_env() as node_env:
|
with in_env(py_env) as node_env:
|
||||||
return helpers.run_hook(node_env, hook, file_args)
|
return helpers.run_hook(node_env, hook, file_args)
|
||||||
|
|
@ -1,34 +1,37 @@
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
from plumbum import local
|
from plumbum import local
|
||||||
from plumbum.machines.session import ShellSession
|
|
||||||
from pre_commit.languages import helpers
|
from pre_commit.languages import helpers
|
||||||
|
|
||||||
PY_ENV = 'py_env'
|
PY_ENV = 'py_env'
|
||||||
|
|
||||||
|
|
||||||
|
class PythonEnv(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.env_prefix = '. {0}/bin/activate &&'.format(PY_ENV)
|
||||||
|
|
||||||
|
def run(self, cmd, **kwargs):
|
||||||
|
return local['bash']['-c', ' '.join([self.env_prefix, cmd])].run(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def in_env():
|
def in_env():
|
||||||
with ShellSession(local['bash'].popen()) as env:
|
yield PythonEnv()
|
||||||
env.run('source {0}/bin/activate'.format(PY_ENV))
|
|
||||||
yield 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
|
# Return immediately if we already have a virtualenv
|
||||||
if local.path('py_env').exists():
|
if local.path(PY_ENV).exists():
|
||||||
return
|
return
|
||||||
|
|
||||||
# Install a virtualenv
|
# Install a virtualenv
|
||||||
local['virtualenv'][PY_ENV]()
|
local['virtualenv'][PY_ENV]()
|
||||||
|
|
||||||
with in_env() as env:
|
with in_env() as env:
|
||||||
# Run their setup.py
|
|
||||||
env.run('pip install .')
|
env.run('pip install .')
|
||||||
|
|
||||||
|
|
||||||
def run_hook(hook, file_args):
|
def run_hook(hook, file_args):
|
||||||
|
# TODO: batch filenames
|
||||||
with in_env() as env:
|
with in_env() as env:
|
||||||
# TODO: batch filenames
|
return helpers.run_hook(env, hook, file_args)
|
||||||
return helpers.run_hook(env, hook, file_args)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue