Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve hook duration timing #3029

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pre_commit/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _run_single_hook(

if not hook.pass_filenames:
filenames = ()
time_before = time.time()
time_before = time.monotonic()
language = languages[hook.language]
with language.in_env(hook.prefix, hook.language_version):
retcode, out = language.run_hook(
Expand All @@ -199,7 +199,7 @@ def _run_single_hook(
require_serial=hook.require_serial,
color=use_color,
)
duration = round(time.time() - time_before, 2) or 0
duration = round(time.monotonic() - time_before, 2) or 0
diff_after = _get_diff()

# if the hook makes changes, fail the commit
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def test_verbose_duration(cap_out, store, in_git_dir, t1, t2, expected):
write_config('.', {'repo': 'meta', 'hooks': [{'id': 'identity'}]})
cmd_output('git', 'add', '.')
opts = run_opts(verbose=True)
with mock.patch.object(time, 'time', side_effect=(t1, t2)):
with mock.patch.object(time, 'monotonic', side_effect=(t1, t2)):
ret, printed = _do_run(cap_out, store, str(in_git_dir), opts)
assert ret == 0
assert expected in printed
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/try_repo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _run_try_repo(tempdir_factory, **kwargs):


def test_try_repo_repo_only(cap_out, tempdir_factory):
with mock.patch.object(time, 'time', return_value=0.0):
with mock.patch.object(time, 'monotonic', return_value=0.0):
_run_try_repo(tempdir_factory, verbose=True)
start, config, rest = _get_out(cap_out)
assert start == ''
Expand Down