Skip to content

Commit f721305

Browse files
committed
Add a progress bar
1 parent 8f86f8f commit f721305

13 files changed

Lines changed: 48 additions & 27 deletions

File tree

pre_commit/commands/run.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,29 @@ def _run_single_hook(hook, repo, args, skips, cols):
103103

104104
# Print the hook and the dots first in case the hook takes hella long to
105105
# run.
106-
output.write(get_hook_message(
106+
msg, num_dots = get_hook_message(
107107
_hook_msg_start(hook, args.verbose), end_len=6, cols=cols,
108-
))
108+
)
109+
output.write(msg)
109110
sys.stdout.flush()
110111

111112
diff_before = cmd_output(
112113
'git', 'diff', '--no-ext-diff', retcode=None, encoding=None,
113114
)
115+
dots_printed = [0]
116+
def report_progress(progress):
117+
dots_to_print = int(round(num_dots * progress))
118+
119+
for _ in range(dots_to_print - dots_printed[0]):
120+
sys.stdout.write('.')
121+
sys.stdout.flush()
122+
123+
dots_printed[0] = dots_to_print
124+
114125
retcode, stdout, stderr = repo.run_hook(
115126
hook,
116127
tuple(filenames) if hook['pass_filenames'] else (),
128+
report_progress,
117129
)
118130
diff_after = cmd_output(
119131
'git', 'diff', '--no-ext-diff', retcode=None, encoding=None,

pre_commit/languages/docker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def install_environment(
7777
os.mkdir(directory)
7878

7979

80-
def run_hook(repo_cmd_runner, hook, file_args): # pragma: windows no cover
80+
def run_hook(repo_cmd_runner, hook, file_args, report_progress): # pragma: windows no cover
8181
assert_docker_available()
8282
# Rebuild the docker image in case it has gone missing, as many people do
8383
# automated cleanup of docker images.
@@ -96,4 +96,4 @@ def run_hook(repo_cmd_runner, hook, file_args): # pragma: windows no cover
9696
docker_tag(repo_cmd_runner),
9797
) + cmd_rest
9898

99-
return xargs(cmd, file_args)
99+
return xargs(cmd, file_args, report_progress)

pre_commit/languages/golang.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ def install_environment(repo_cmd_runner, version, additional_dependencies):
7070
rmtree(repo_cmd_runner.path(directory, 'pkg'))
7171

7272

73-
def run_hook(repo_cmd_runner, hook, file_args):
73+
def run_hook(repo_cmd_runner, hook, file_args, report_progress):
7474
with in_env(repo_cmd_runner):
75-
return xargs(helpers.to_cmd(hook), file_args)
75+
return xargs(helpers.to_cmd(hook), file_args, report_progress)

pre_commit/languages/node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ def install_environment(
6161
)
6262

6363

64-
def run_hook(repo_cmd_runner, hook, file_args): # pragma: windows no cover
64+
def run_hook(repo_cmd_runner, hook, file_args, report_progress): # pragma: windows no cover
6565
with in_env(repo_cmd_runner, hook['language_version']):
66-
return xargs(helpers.to_cmd(hook), file_args)
66+
return xargs(helpers.to_cmd(hook), file_args, report_progress)

pre_commit/languages/pcre.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def install_environment(repo_cmd_runner, version, additional_dependencies):
1717
raise AssertionError('Cannot install pcre repo.')
1818

1919

20-
def run_hook(repo_cmd_runner, hook, file_args):
20+
def run_hook(repo_cmd_runner, hook, file_args, report_progress):
2121
# For PCRE the entry is the regular expression to match
2222
cmd = (GREP, '-H', '-n', '-P') + tuple(hook['args']) + (hook['entry'],)
2323

2424
# Grep usually returns 0 for matches, and nonzero for non-matches so we
2525
# negate it here.
26-
return xargs(cmd, file_args, negate=True)
26+
return xargs(cmd, file_args, report_progress, negate=True)

pre_commit/languages/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ def install_environment(repo_cmd_runner, version, additional_dependencies):
130130
)
131131

132132

133-
def run_hook(repo_cmd_runner, hook, file_args):
133+
def run_hook(repo_cmd_runner, hook, file_args, report_progress):
134134
with in_env(repo_cmd_runner, hook['language_version']):
135-
return xargs(helpers.to_cmd(hook), file_args)
135+
return xargs(helpers.to_cmd(hook), file_args, report_progress)

pre_commit/languages/ruby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ def install_environment(
130130
)
131131

132132

133-
def run_hook(repo_cmd_runner, hook, file_args): # pragma: windows no cover
133+
def run_hook(repo_cmd_runner, hook, file_args, report_progress): # pragma: windows no cover
134134
with in_env(repo_cmd_runner, hook['language_version']):
135-
return xargs(helpers.to_cmd(hook), file_args)
135+
return xargs(helpers.to_cmd(hook), file_args, report_progress)

pre_commit/languages/script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def install_environment(repo_cmd_runner, version, additional_dependencies):
1414
raise AssertionError('Cannot install script repo.')
1515

1616

17-
def run_hook(repo_cmd_runner, hook, file_args):
17+
def run_hook(repo_cmd_runner, hook, file_args, report_progress):
1818
cmd = helpers.to_cmd(hook)
1919
cmd = (repo_cmd_runner.prefix_dir + cmd[0],) + cmd[1:]
20-
return xargs(cmd, file_args)
20+
return xargs(cmd, file_args, report_progress)

pre_commit/languages/swift.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ def install_environment(
5050
))
5151

5252

53-
def run_hook(repo_cmd_runner, hook, file_args): # pragma: windows no cover
53+
def run_hook(repo_cmd_runner, hook, file_args, report_progress): # pragma: windows no cover
5454
with in_env(repo_cmd_runner):
55-
return xargs(helpers.to_cmd(hook), file_args)
55+
return xargs(helpers.to_cmd(hook), file_args, report_progress)

pre_commit/languages/system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ def install_environment(repo_cmd_runner, version, additional_dependencies):
1414
raise AssertionError('Cannot install system repo.')
1515

1616

17-
def run_hook(repo_cmd_runner, hook, file_args):
18-
return xargs(helpers.to_cmd(hook), file_args)
17+
def run_hook(repo_cmd_runner, hook, file_args, report_progress):
18+
return xargs(helpers.to_cmd(hook), file_args, report_progress)

0 commit comments

Comments
 (0)