Skip to content

Instantly share code, notes, and snippets.

@xyntrix
Created November 5, 2019 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyntrix/72c0676c97e27123e5bd2ad414785387 to your computer and use it in GitHub Desktop.
Save xyntrix/72c0676c97e27123e5bd2ad414785387 to your computer and use it in GitHub Desktop.
run a flake8 lint test + command every time a .py file is written: the world's smallest/laziest py test
#!/bin/sh
if [ -z "${PYCMD}" ]; then
echo "# You can set the command to run like so:"
echo "# export PYCMD=\"python36 example.py\""
echo
fi
# where to set up the file event watch, default: present dir and
# recursive
WORKPATH="-r -m ."
# where to set py include/class scan path, default: present dir
export PYTHONPATH="$(pwd)"
echo "# Watching: ${WORKPATH}"
echo "# Include base: ${PYTHONPATH}"
echo "# Run command (PYCMD): ${PYCMD}"
echo
inotifywait -e close_write,moved_to,create ${WORKPATH} | while read -r directory events filename; do
if [[ "${filename}" == *".py" ]] && [[ "${events}" == *"CLOSE_WRITE"* ]]; then
echo
echo "### event: ${events}, for ${directory}${filename}"
flake8 ${directory}${filename}
if [ $? -ne 0 ]; then
echo "# Terrible. Go fix it."
else
if [ ! -z "${PYCMD}" ]; then
${PYCMD}
if [ $? -ne 0 ]; then
echo "# You have failed."
fi
fi
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment