Skip to content

Commit f21257c

Browse files
committed
WIP: progress dots
Based on @chriskuehl's branch here: - chriskuehl@f721305
1 parent 4bd6529 commit f21257c

File tree

15 files changed

+69
-31
lines changed

15 files changed

+69
-31
lines changed

pre_commit/commands/run.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,25 @@ def _run_single_hook(classifier, hook, args, skips, cols, use_color):
110110

111111
# Print the hook and the dots first in case the hook takes hella long to
112112
# run.
113-
output.write(
114-
get_hook_message(
115-
_hook_msg_start(hook, args.verbose), end_len=6, cols=cols,
116-
),
113+
msg, num_dots = get_hook_message(
114+
_hook_msg_start(hook, args.verbose), end_len=6, cols=cols,
117115
)
116+
output.write(msg)
118117
sys.stdout.flush()
119118

119+
dots_printed = [0]
120+
121+
def progress(perc):
122+
dots_to_print = int(round(num_dots * perc))
123+
124+
sys.stdout.write('.' * (dots_to_print - dots_printed[0]))
125+
sys.stdout.flush()
126+
127+
dots_printed[0] = dots_to_print
128+
120129
diff_before = cmd_output_b('git', 'diff', '--no-ext-diff', retcode=None)
121130
filenames = tuple(filenames) if hook.pass_filenames else ()
122-
retcode, out = hook.run(filenames, use_color)
131+
retcode, out = hook.run(filenames, use_color, progress)
123132
diff_after = cmd_output_b('git', 'diff', '--no-ext-diff', retcode=None)
124133

125134
file_modifications = diff_before != diff_after

pre_commit/languages/all.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@
3838
# version - A version specified in the hook configuration or 'default'.
3939
# """
4040
#
41-
# def run_hook(hook, file_args, color):
41+
# def run_hook(hook, file_args, color, progress):
4242
# """Runs a hook and returns the returncode and output of running that
4343
# hook.
4444
#
4545
# Args:
4646
# hook - `Hook`
4747
# file_args - The files to be run
4848
# color - whether the hook should be given a pty (when supported)
49+
# progress - report progress as a float percentage
4950
#
5051
# Returns:
5152
# (returncode, output)

pre_commit/languages/docker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def docker_cmd(): # pragma: windows no cover
9595
)
9696

9797

98-
def run_hook(hook, file_args, color): # pragma: windows no cover
98+
def run_hook(hook, file_args, color, progress): # pragma: windows no cover
9999
assert_docker_available()
100100
# Rebuild the docker image in case it has gone missing, as many people do
101101
# automated cleanup of docker images.
@@ -106,4 +106,6 @@ def run_hook(hook, file_args, color): # pragma: windows no cover
106106

107107
entry_tag = ('--entrypoint', entry_exe, docker_tag(hook.prefix))
108108
cmd = docker_cmd() + entry_tag + cmd_rest
109-
return helpers.run_xargs(hook, cmd, file_args, color=color)
109+
return helpers.run_xargs(
110+
hook, cmd, file_args, color=color, progress=progress,
111+
)

pre_commit/languages/docker_image.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
install_environment = helpers.no_install
1313

1414

15-
def run_hook(hook, file_args, color): # pragma: windows no cover
15+
def run_hook(hook, file_args, color, progress): # pragma: windows no cover
1616
assert_docker_available()
1717
cmd = docker_cmd() + hook.cmd
18-
return helpers.run_xargs(hook, cmd, file_args, color=color)
18+
return helpers.run_xargs(
19+
hook, cmd, file_args, color=color, progress=progress,
20+
)

pre_commit/languages/golang.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def install_environment(prefix, version, additional_dependencies):
8181
rmtree(pkgdir)
8282

8383

84-
def run_hook(hook, file_args, color):
84+
def run_hook(hook, file_args, color, progress):
8585
with in_env(hook.prefix):
86-
return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
86+
return helpers.run_xargs(
87+
hook, hook.cmd, file_args, color=color, progress=progress,
88+
)

pre_commit/languages/node.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def install_environment(
7878
)
7979

8080

81-
def run_hook(hook, file_args, color): # pragma: windows no cover
81+
def run_hook(hook, file_args, color, progress): # pragma: windows no cover
8282
with in_env(hook.prefix, hook.language_version):
83-
return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
83+
return helpers.run_xargs(
84+
hook, hook.cmd, file_args, color=color, progress=progress,
85+
)

pre_commit/languages/python.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ def healthy(prefix, language_version):
151151
)
152152
return retcode == 0
153153

154-
def run_hook(hook, file_args, color):
154+
def run_hook(hook, file_args, color, progress):
155155
with in_env(hook.prefix, hook.language_version):
156-
return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
156+
return helpers.run_xargs(
157+
hook, hook.cmd, file_args, color=color, progress=progress,
158+
)
157159

158160
def install_environment(prefix, version, additional_dependencies):
159161
additional_dependencies = tuple(additional_dependencies)

pre_commit/languages/ruby.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def install_environment(
124124
)
125125

126126

127-
def run_hook(hook, file_args, color): # pragma: windows no cover
127+
def run_hook(hook, file_args, color, progress): # pragma: windows no cover
128128
with in_env(hook.prefix, hook.language_version):
129-
return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
129+
return helpers.run_xargs(
130+
hook, hook.cmd, file_args, color=color, progress=progress,
131+
)

pre_commit/languages/rust.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def install_environment(prefix, version, additional_dependencies):
8989
)
9090

9191

92-
def run_hook(hook, file_args, color):
92+
def run_hook(hook, file_args, color, progress):
9393
with in_env(hook.prefix):
94-
return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
94+
return helpers.run_xargs(
95+
hook, hook.cmd, file_args, color=color, progress=progress,
96+
)

pre_commit/languages/script.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
install_environment = helpers.no_install
1010

1111

12-
def run_hook(hook, file_args, color):
12+
def run_hook(hook, file_args, color, progress):
1313
cmd = hook.cmd
1414
cmd = (hook.prefix.path(cmd[0]),) + cmd[1:]
15-
return helpers.run_xargs(hook, cmd, file_args, color=color)
15+
return helpers.run_xargs(
16+
hook, cmd, file_args, color=color, progress=progress,
17+
)

0 commit comments

Comments
 (0)