zulip/tools/clean-repo

21 lines
535 B
Plaintext
Raw Normal View History

#!/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")/.."
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
find . -name "__pycache__" -prune -exec rm -rf {} \;