zulip/tools/clean-repo

21 lines
535 B
Bash
Executable File

#!/usr/bin/env bash
set -e
# Remove .pyc files without corresponding .py files
# to prevent loading stale code.
#
# You can run it automatically on checkout:
#
# echo ./tools/clean-repo > .git/hooks/post-checkout
# chmod +x .git/hooks/post-checkout
cd "$(dirname "$0")/.."
find . -name "__pycache__" -prune -exec rm -rf {} \;
for i in $(find . -name "*.pyc"); do
pyfile="${i%.pyc}.py"
if [ ! -e "$pyfile" ]; then
echo "Removing "$i" because source file ("$pyfile") doesn't exist."
rm "$i"
fi
done