Skip to content
This repository was archived by the owner on Jul 2, 2026. It is now read-only.

Commit dbc193c

Browse files
committed
fix: mypy default target + kubeconform empty-batch graceful exit
- mypy: detect when caller's args contain no path target and default to `.`, so a bare `id: mypy` no longer fails with "Missing target module, package, files, or command." Consumers can still pass an explicit target via args. - kubeconform: when every input file gets filtered out (e.g. a batch of only Helm values.yaml + Chart.yaml — neither manifests nor chart templates), exit 0 instead of falling through to a no-arg kubeconform call that blocks reading from stdin and emits "failing to read data from stdin".
1 parent 1295415 commit dbc193c

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

hooks/kubeconform/run.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ if ((${#plain_files[@]} > 0)); then
121121
fi
122122
fi
123123

124+
# All inputs were filtered out (e.g. values.yaml + Chart.yaml only — no manifests
125+
# and no chart templates). Nothing to validate; exit 0 instead of falling
126+
# through to a kubeconform invocation that would block reading from stdin.
124127
if ((${#chart_roots[@]} == 0 && ${#plain_files[@]} == 0)); then
125-
exec "${bin_path}" "${flags[@]}"
128+
exit 0
126129
fi
127130

128131
exit "${status}"

hooks/mypy/run.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,34 @@
22
# mypy — Python static type checker (category: toolchain wrapper).
33
# Prefers `uv run mypy` when uv is available; falls back to `python -m mypy`.
44
# If neither is on PATH, prints a skip warning and exits 0.
5+
#
6+
# pre-commit / prek invoke this with `pass_filenames: false`, so $@ is just the
7+
# `args:` from .pre-commit-hooks.yaml. If the caller's args don't include any
8+
# target path, mypy refuses to run with "Missing target module, package, files,
9+
# or command." We default to `.` so a bare `id: mypy` works out of the box.
510
set -euo pipefail
611

7-
if command -v uv >/dev/null 2>&1; then
12+
# Detect whether $@ contains a path-like target (anything that isn't a flag).
13+
has_target=0
14+
for arg in "$@"; do
15+
case "${arg}" in
16+
-*) ;;
17+
*) has_target=1; break ;;
18+
esac
19+
done
20+
if ((has_target == 0)); then
21+
set -- "$@" "."
22+
fi
23+
24+
if command -v uv > /dev/null 2>&1; then
825
exec uv run mypy "$@"
926
fi
1027

11-
if command -v python >/dev/null 2>&1; then
28+
if command -v python > /dev/null 2>&1; then
1229
exec python -m mypy "$@"
1330
fi
1431

15-
if command -v python3 >/dev/null 2>&1; then
32+
if command -v python3 > /dev/null 2>&1; then
1633
exec python3 -m mypy "$@"
1734
fi
1835

0 commit comments

Comments
 (0)