diff --git a/scripts/pre_push_checks.sh b/scripts/pre_push_checks.sh index 3a06e59..6b64c77 100644 --- a/scripts/pre_push_checks.sh +++ b/scripts/pre_push_checks.sh @@ -20,10 +20,15 @@ case "$UNAME_S" in # It frequently leaves locked .exe files (WinError 5) and blocks hook cleanup. export PRE_COMMIT_HOME="${PRE_COMMIT_HOME:-$ROOT_DIR/.tmp/pre-commit-win}" mkdir -p "$PRE_COMMIT_HOME" + # Keep Black cache local to avoid AppData lock/permission errors. + export BLACK_CACHE_DIR="${BLACK_CACHE_DIR:-$ROOT_DIR/.tmp/black-cache}" + mkdir -p "$BLACK_CACHE_DIR" ;; *) export PRE_COMMIT_HOME="${PRE_COMMIT_HOME:-$ROOT_DIR/.tmp/pre-commit}" mkdir -p "$PRE_COMMIT_HOME" + export BLACK_CACHE_DIR="${BLACK_CACHE_DIR:-$ROOT_DIR/.tmp/black-cache}" + mkdir -p "$BLACK_CACHE_DIR" ;; esac @@ -114,6 +119,10 @@ run_pre_commit_safe() { # Avoid removing this block; without it, pre-push can hang/fail repeatedly on Windows. echo "[pre-push] WARN: pre-commit cache appears locked by another process; running cache reset + single retry." >&2 reset_cache + if [ -n "${BLACK_CACHE_DIR:-}" ] && [ -d "$BLACK_CACHE_DIR" ]; then + rm -rf "$BLACK_CACHE_DIR" 2>/dev/null || true + mkdir -p "$BLACK_CACHE_DIR" + fi pre-commit "$@" rm -f "$tmp_log" rm -f "$lower_log" diff --git a/scripts/precommit_black_single.sh b/scripts/precommit_black_single.sh index 8149537..b3664b3 100644 --- a/scripts/precommit_black_single.sh +++ b/scripts/precommit_black_single.sh @@ -1,6 +1,11 @@ #!/usr/bin/env bash set -euo pipefail +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +# Keep Black cache local to avoid AppData lock/permission errors on Windows. +export BLACK_CACHE_DIR="${BLACK_CACHE_DIR:-$ROOT_DIR/.tmp/black-cache}" +mkdir -p "$BLACK_CACHE_DIR" + if command -v python >/dev/null 2>&1; then # CRITICAL cross-platform guard: # WSL sometimes has only `python3`, while Windows shells usually expose `python`.