Created
February 11, 2017 19:38
-
-
Save benoit-pierre/671eacd6222d0e8ac53eb1f31594cffd to your computer and use it in GitHub Desktop.
monitor tracked Python files, and run tests on change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
runtests() | |
{ | |
./setup.py --quiet test -- "$@" | |
} | |
source_dirs() | |
{ | |
git ls-files '*.py' | sed -ne '/\(^\|\/\)\([^\/]*\.py\)$/{s//\1/;s/^$/./;p}' | sort -u | |
} | |
is_tracked() | |
{ | |
git ls-files --error-unmatch "$@" &>/dev/null | |
} | |
monitor_inotify() | |
{ | |
inotifywait --monitor --event CLOSE_WRITE --format '%w%f' "$@" | |
} | |
monitor_fswatch() | |
{ | |
fswatch --event AttributeModified "$@" | |
} | |
runtests "$@" | |
monitor_fswatch $(source_dirs) | sed --unbuffered -ne '/\.py$/p' | while read file | |
do | |
if is_tracked "$file" | |
then | |
echo "$file changed" | |
runtests "$@" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment