mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
Attempt to improve performance by eliminating a sleep call
This commit is contained in:
parent
da8c435e9c
commit
4db38596c8
1 changed files with 8 additions and 19 deletions
|
|
@ -1,18 +1,9 @@
|
||||||
|
|
||||||
import contextlib
|
|
||||||
from plumbum import local
|
from plumbum import local
|
||||||
from plumbum.machines.session import ShellSession
|
|
||||||
|
|
||||||
PY_ENV = 'py_env'
|
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():
|
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
|
||||||
|
|
@ -21,16 +12,14 @@ def install_environment():
|
||||||
|
|
||||||
# Install a virtualenv
|
# Install a virtualenv
|
||||||
local['virtualenv'][PY_ENV]()
|
local['virtualenv'][PY_ENV]()
|
||||||
|
local['bash']['-c', 'source {0}/bin/activate && pip install .'.format(PY_ENV)]()
|
||||||
with in_env() as env:
|
|
||||||
# Run their setup.py
|
|
||||||
env.run('pip install .')
|
|
||||||
|
|
||||||
|
|
||||||
def run_hook(hook, file_args):
|
def run_hook(hook, file_args):
|
||||||
with in_env() as env:
|
|
||||||
# TODO: batch filenames
|
# TODO: batch filenames
|
||||||
return env.run(
|
return local['bash'][
|
||||||
' '.join([hook['entry']] + hook.get('args', []) + list(file_args)),
|
'-c', ' '.join(
|
||||||
retcode=None,
|
['source {0}/bin/activate &&'.format(PY_ENV)] +
|
||||||
|
[hook['entry']] + hook.get('args', []) + list(file_args)
|
||||||
)
|
)
|
||||||
|
].run()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue