Skip to content

Commit 37545bf

Browse files
committed
chore: add pytest hook to pre-commit + improve executor logging
Signed-off-by: Samuel Amen Ague <ague.samuel27@gmail.com>
1 parent 60e1c3e commit 37545bf

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

.pre-commit-config.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,16 @@ repos:
44
hooks:
55
- id: ruff
66
args: [--fix]
7-
- id: ruff-format
7+
- id: ruff-format
8+
9+
- repo: local
10+
hooks:
11+
- id: run-tests
12+
name: Run tests with pytest
13+
entry: python -m pytest
14+
language: system
15+
pass_filenames: false
16+
always_run: true
17+
env:
18+
QT_QPA_PLATFORM: minimal
19+
args: ["-q", "--tb=no", "tests/"]

pycompiler_ark/Core/utils/executor.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ class ExecutionResult:
4646
name: str = ""
4747

4848

49+
def _emit_log(log_callback: Optional[Callable[[str], None]], message: str) -> None:
50+
"""Emit a log line via callback if one was provided."""
51+
if log_callback is None:
52+
return
53+
try:
54+
log_callback(message)
55+
except Exception:
56+
pass
57+
58+
4959
def _check_stop(stop_requested: Optional[Callable[[], bool]]) -> bool:
5060
"""Return True if the caller requested a stop."""
5161
if stop_requested is None:
@@ -89,21 +99,28 @@ def executor(
8999
task_name = name or getattr(func, "__name__", repr(func))
90100

91101
if _check_stop(stop_requested):
92-
output.info(log_callback, f"Cancelled before start: {task_name}")
102+
msg = f"Cancelled before start: {task_name}"
103+
_emit_log(log_callback, msg)
104+
output.info(msg)
93105
return ExecutionResult(
94106
success=False,
95107
error="Execution cancelled before start",
96108
name=task_name,
97109
)
98110

99-
output.info(log_callback, f"Start: {task_name}")
111+
msg = f"Start: {task_name}"
112+
_emit_log(log_callback, msg)
113+
output.info(msg)
100114
start = time.perf_counter()
101115

102116
try:
103117
value = func(*args, **kwargs)
104118
duration_ms = (time.perf_counter() - start) * 1000.0
105-
output.success(
119+
_emit_log(
106120
log_callback,
121+
f"Success: {task_name} ({duration_ms:.1f} ms)",
122+
)
123+
output.success(
107124
f" {task_name} ({duration_ms:.1f} ms)",
108125
)
109126
return ExecutionResult(
@@ -115,8 +132,11 @@ def executor(
115132
except Exception as exc:
116133
duration_ms = (time.perf_counter() - start) * 1000.0
117134
error_message = str(exc)
118-
output.error(
135+
_emit_log(
119136
log_callback,
137+
f"Failure: {task_name} - {error_message}",
138+
)
139+
output.error(
120140
f" {task_name} - {error_message}",
121141
)
122142
if not catch_exceptions:

0 commit comments

Comments
 (0)