From 4db38596c8bf22077faf23076cc83f8edd69b00f Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 13 Mar 2014 23:55:02 -0700 Subject: [PATCH] Attempt to improve performance by eliminating a sleep call --- pre_commit/languages/python.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py index 77819d1f..c2d49cf9 100644 --- a/pre_commit/languages/python.py +++ b/pre_commit/languages/python.py @@ -1,18 +1,9 @@ -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() # Return immediately if we already have a virtualenv @@ -21,16 +12,14 @@ def install_environment(): # Install a virtualenv local['virtualenv'][PY_ENV]() - - with in_env() as env: - # Run their setup.py - env.run('pip install .') + local['bash']['-c', 'source {0}/bin/activate && pip install .'.format(PY_ENV)]() 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, - ) \ No newline at end of file + # TODO: batch filenames + return local['bash'][ + '-c', ' '.join( + ['source {0}/bin/activate &&'.format(PY_ENV)] + + [hook['entry']] + hook.get('args', []) + list(file_args) + ) + ].run() \ No newline at end of file