Skip to content

Commit ba5e27e

Browse files
committed
Implement concurrent execution of individual hooks
1 parent 1f1cd2b commit ba5e27e

File tree

15 files changed

+104
-14
lines changed

15 files changed

+104
-14
lines changed

pre_commit/clientlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def _make_argparser(filenames_help):
5656
cfgv.Optional('language_version', cfgv.check_string, 'default'),
5757
cfgv.Optional('log_file', cfgv.check_string, ''),
5858
cfgv.Optional('minimum_pre_commit_version', cfgv.check_string, '0'),
59+
cfgv.Optional('require_serial', cfgv.check_bool, False),
5960
cfgv.Optional('stages', cfgv.check_array(cfgv.check_one_of(C.STAGES)), []),
6061
cfgv.Optional('verbose', cfgv.check_bool, False),
6162
)

pre_commit/languages/docker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,8 @@ def run_hook(prefix, hook, file_args): # pragma: windows no cover
9797

9898
entry_tag = ('--entrypoint', entry_exe, docker_tag(prefix))
9999
cmd = docker_cmd() + entry_tag + cmd_rest
100-
return xargs(cmd, file_args)
100+
return xargs(
101+
cmd,
102+
file_args,
103+
target_concurrency=helpers.target_concurrency(hook),
104+
)

pre_commit/languages/docker_image.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@
1616
def run_hook(prefix, hook, file_args): # pragma: windows no cover
1717
assert_docker_available()
1818
cmd = docker_cmd() + helpers.to_cmd(hook)
19-
return xargs(cmd, file_args)
19+
return xargs(
20+
cmd,
21+
file_args,
22+
target_concurrency=helpers.target_concurrency(hook),
23+
)

pre_commit/languages/golang.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,8 @@ def install_environment(prefix, version, additional_dependencies):
8181

8282
def run_hook(prefix, hook, file_args):
8383
with in_env(prefix):
84-
return xargs(helpers.to_cmd(hook), file_args)
84+
return xargs(
85+
helpers.to_cmd(hook),
86+
file_args,
87+
target_concurrency=helpers.target_concurrency(hook),
88+
)

pre_commit/languages/helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import unicode_literals
22

3+
import multiprocessing
34
import shlex
45

56
from pre_commit.util import cmd_output
@@ -45,3 +46,11 @@ def basic_healthy(prefix, language_version):
4546

4647
def no_install(prefix, version, additional_dependencies):
4748
raise AssertionError('This type is not installable')
49+
50+
51+
def target_concurrency(hook):
52+
if hook['require_serial']:
53+
return 1
54+
else:
55+
# TODO: something smart!
56+
return multiprocessing.cpu_count()

pre_commit/languages/node.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ def install_environment(prefix, version, additional_dependencies):
7171

7272
def run_hook(prefix, hook, file_args):
7373
with in_env(prefix, hook['language_version']):
74-
return xargs(helpers.to_cmd(hook), file_args)
74+
return xargs(
75+
helpers.to_cmd(hook),
76+
file_args,
77+
target_concurrency=helpers.target_concurrency(hook),
78+
)

pre_commit/languages/python.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ def healthy(prefix, language_version):
127127

128128
def run_hook(prefix, hook, file_args):
129129
with in_env(prefix, hook['language_version']):
130-
return xargs(helpers.to_cmd(hook), file_args)
130+
return xargs(
131+
helpers.to_cmd(hook),
132+
file_args,
133+
target_concurrency=helpers.target_concurrency(hook),
134+
)
131135

132136
def install_environment(prefix, version, additional_dependencies):
133137
additional_dependencies = tuple(additional_dependencies)

pre_commit/languages/ruby.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,8 @@ def install_environment(
126126

127127
def run_hook(prefix, hook, file_args): # pragma: windows no cover
128128
with in_env(prefix, hook['language_version']):
129-
return xargs(helpers.to_cmd(hook), file_args)
129+
return xargs(
130+
helpers.to_cmd(hook),
131+
file_args,
132+
target_concurrency=helpers.target_concurrency(hook),
133+
)

pre_commit/languages/rust.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ def install_environment(prefix, version, additional_dependencies):
9191

9292
def run_hook(prefix, hook, file_args):
9393
with in_env(prefix):
94-
return xargs(helpers.to_cmd(hook), file_args)
94+
return xargs(
95+
helpers.to_cmd(hook),
96+
file_args,
97+
target_concurrency=helpers.target_concurrency(hook),
98+
)

pre_commit/languages/script.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313
def run_hook(prefix, hook, file_args):
1414
cmd = helpers.to_cmd(hook)
1515
cmd = (prefix.path(cmd[0]),) + cmd[1:]
16-
return xargs(cmd, file_args)
16+
return xargs(
17+
cmd,
18+
file_args,
19+
target_concurrency=helpers.target_concurrency(hook),
20+
)

0 commit comments

Comments
 (0)