mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Implement concurrent execution of individual hooks
This commit is contained in:
parent
1f1cd2bc39
commit
ba5e27e4ec
15 changed files with 104 additions and 14 deletions
|
|
@ -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),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue