#!/usr/bin/env bash # Remove stray Python bytecode caches that may have leaked into tracked sources. # Usage: bash scripts/clean.sh set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${0}}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" TARGETS=("${PROJECT_ROOT}/src" "${PROJECT_ROOT}/tests") removed_any=false remove_pycache_dirs() { local target="$1" if [ -d "${target}" ]; then while IFS= read -r -d '' dir; do removed_any=true echo "Removing directory: ${dir#${PROJECT_ROOT}/}" rm -rf "${dir}" done < <(find "${target}" -type d -name "__pycache__" -print0) fi } remove_pyc_files() { local target="$1" if [ -d "${target}" ]; then while IFS= read -r -d '' file; do removed_any=true echo "Removing file: ${file#${PROJECT_ROOT}/}" rm -f "${file}" done < <(find "${target}" -type f \( -name "*.pyc" -o -name "*.pyo" -o -name "*.pyd" \) -print0) fi } for target in "${TARGETS[@]}"; do remove_pycache_dirs "${target}" remove_pyc_files "${target}" done if [ "${removed_any}" = false ]; then echo "No cached artefacts found under src/ or tests/." else echo "Source tree cleaned. Future commands should run via scripts/ to keep it tidy." fi