Created
November 5, 2019 17:37
-
-
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
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 | |
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