Implement concurrent execution of individual hooks

This commit is contained in:
Chris Kuehl 2018-10-20 13:05:55 -07:00 committed by Chris Kuehl
parent 1f1cd2bc39
commit ba5e27e4ec
15 changed files with 104 additions and 14 deletions

View file

@ -97,4 +97,8 @@ def run_hook(prefix, hook, file_args): # pragma: windows no cover
entry_tag = ('--entrypoint', entry_exe, docker_tag(prefix))
cmd = docker_cmd() + entry_tag + cmd_rest
return xargs(cmd, file_args)
return xargs(
cmd,
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -16,4 +16,8 @@ install_environment = helpers.no_install
def run_hook(prefix, hook, file_args): # pragma: windows no cover
assert_docker_available()
cmd = docker_cmd() + helpers.to_cmd(hook)
return xargs(cmd, file_args)
return xargs(
cmd,
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -81,4 +81,8 @@ def install_environment(prefix, version, additional_dependencies):
def run_hook(prefix, hook, file_args):
with in_env(prefix):
return xargs(helpers.to_cmd(hook), file_args)
return xargs(
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -1,5 +1,6 @@
from __future__ import unicode_literals
import multiprocessing
import shlex
from pre_commit.util import cmd_output
@ -45,3 +46,11 @@ def basic_healthy(prefix, language_version):
def no_install(prefix, version, additional_dependencies):
raise AssertionError('This type is not installable')
def target_concurrency(hook):
if hook['require_serial']:
return 1
else:
# TODO: something smart!
return multiprocessing.cpu_count()

View file

@ -71,4 +71,8 @@ def install_environment(prefix, version, additional_dependencies):
def run_hook(prefix, hook, file_args):
with in_env(prefix, hook['language_version']):
return xargs(helpers.to_cmd(hook), file_args)
return xargs(
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -127,7 +127,11 @@ def py_interface(_dir, _make_venv):
def run_hook(prefix, hook, file_args):
with in_env(prefix, hook['language_version']):
return xargs(helpers.to_cmd(hook), file_args)
return xargs(
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)
def install_environment(prefix, version, additional_dependencies):
additional_dependencies = tuple(additional_dependencies)

View file

@ -126,4 +126,8 @@ def install_environment(
def run_hook(prefix, hook, file_args): # pragma: windows no cover
with in_env(prefix, hook['language_version']):
return xargs(helpers.to_cmd(hook), file_args)
return xargs(
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -91,4 +91,8 @@ def install_environment(prefix, version, additional_dependencies):
def run_hook(prefix, hook, file_args):
with in_env(prefix):
return xargs(helpers.to_cmd(hook), file_args)
return xargs(
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -13,4 +13,8 @@ install_environment = helpers.no_install
def run_hook(prefix, hook, file_args):
cmd = helpers.to_cmd(hook)
cmd = (prefix.path(cmd[0]),) + cmd[1:]
return xargs(cmd, file_args)
return xargs(
cmd,
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -53,4 +53,8 @@ def install_environment(
def run_hook(prefix, hook, file_args): # pragma: windows no cover
with in_env(prefix):
return xargs(helpers.to_cmd(hook), file_args)
return xargs(
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -11,4 +11,8 @@ install_environment = helpers.no_install
def run_hook(prefix, hook, file_args):
return xargs(helpers.to_cmd(hook), file_args)
return xargs(
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)