Skip to content

Instantly share code, notes, and snippets.

@benoit-pierre
Created February 11, 2017 19:38
Show Gist options
  • Save benoit-pierre/671eacd6222d0e8ac53eb1f31594cffd to your computer and use it in GitHub Desktop.
Save benoit-pierre/671eacd6222d0e8ac53eb1f31594cffd to your computer and use it in GitHub Desktop.
monitor tracked Python files, and run tests on change
#!/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