testsAndMisc/meta/scripts/check_python_location.sh
Krzysztof kuhy Rudnicki 2e1e370c0f refactor: extract all inline Python from shell scripts into proper .py files
Move every multi-line python heredoc/`-c` block into a dedicated .py file so
ruff, mypy, pylint, bandit, and pytest can apply to it:
- linux_configuration/zsh/calc-live.zsh → python_pkg/live_calc/calc_eval.py (100% branch cov, 46 tests)
- meta/scripts/check_ai_evidence.sh → meta/scripts/validate_evidence.py
- meta/scripts/check_agent_contract.sh → meta/scripts/validate_contract.py
- phone_focus_mode/lib/monitor.sh → phone_focus_mode/lib/monitor_report.py
- phone_focus_mode/deploy.sh → phone_focus_mode/strip_workout_hosts.py
- linux_configuration/.../analyze_repo.sh → fast_count.py

Also: add zsh-syntax pre-commit hook (zsh -n); exclude zsh from shellcheck;
add tests for all 4 non-python_pkg helpers; update CLAUDE.md Shell Style with
the no-inline-Python rule.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 10:31:48 +02:00

45 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Check that all Python files are under python_pkg/.
# Exceptions: linux_configuration/, phone_focus_mode/, Bash/,
# and vendored/generated directories.
# Used as a pre-commit hook; receives staged file paths as arguments.
set -uo pipefail
errors=()
for file in "$@"; do
# Only check .py files
[[ "$file" != *.py ]] && continue
# Skip files already under python_pkg/
[[ "$file" == python_pkg/* ]] && continue
# Skip allowed directories (non-Python projects with some Python scripts)
case "$file" in
linux_configuration/*|phone_focus_mode/*|scripts/*|meta/scripts/*) continue ;;
esac
# Skip vendored/generated directories
skip=0
for part in /.venv/ /venv/ /__pycache__/ /build/ /dist/ /node_modules/ /.git/; do
case "/$file" in
*"$part"*) skip=1; break ;;
esac
done
[[ $skip -eq 1 ]] && continue
errors+=("$file")
done
if [[ ${#errors[@]} -gt 0 ]]; then
echo "ERROR: Python files must be under python_pkg/."
echo "The following files are in the wrong location:"
for err in "${errors[@]}"; do
echo " $err"
done
echo ""
echo "Move them with: git mv <file> python_pkg/<file>"
exit 1
fi