Skip to content

Commit

Permalink
ENH: print subhook execution times (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Mar 7, 2024
1 parent ee94c54 commit 359331f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/compwa_policy/utilities/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import sys
import time
from typing import Callable, TypeVar

import attr
Expand Down Expand Up @@ -32,11 +33,19 @@ def __call__(
) -> T | None:
"""Execute a function and collect any `.PrecommitError` exceptions."""
try:
return function(*args, **kwargs)
start_time = time.time()
result = function(*args, **kwargs)
end_time = time.time()
execution_time = end_time - start_time
if execution_time > 0.1: # noqa: PLR2004
function_name = f"{function.__module__}.{function.__name__}"
print(f"{execution_time:>7.2f} s {function_name}") # noqa: T201
except PrecommitError as exception:
error_message = str("\n".join(exception.args))
self.error_messages.append(error_message)
return None
self.error_messages.append(error_message)
return None
else:
return result

def finalize(self, exception: bool = True) -> int:
error_msg = self.merge_messages()
Expand Down

0 comments on commit 359331f

Please sign in to comment.