Created
December 19, 2019 09:36
-
-
Save league55/f117601d1782e77a10b0f0a9eb0f0e8f to your computer and use it in GitHub Desktop.
Flake8 for python code linting. Script takes into account diff with develop branch.
This file contains hidden or 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
PROJECT_DIR=$1 | |
#now we need to act from a project source directory to have vsc in place | |
pushd ${PROJECT_DIR} | |
#we never push directly to develop and we want to run linter only on feature branches | |
#skip when on master branch as well | |
curr_branch_name=$(git rev-parse --abbrev-ref HEAD) | |
if [ "${curr_branch_name}" = "origin/develop" ] || [ "${curr_branch_name}" = "origin/master" ]; then | |
echo "Skipping linter for ${curr_branch_name}." | |
exit 0 | |
fi | |
# Creating temporary directory and new virtual environment not to mess things | |
TMP_DIR=$(mktemp -d) | |
virtualenv -p python3 ${TMP_DIR} >> /dev/null | |
source ${TMP_DIR}/bin/activate >> /dev/null | |
# installing flake8-awesome which includes flake8 and a bunch of extension plugins | |
pip install flake8-awesome >> /dev/null | |
#take diff between current branch and develop branch and pass them as an input to flake8 --diff | |
git diff origin/develop -- "*.py" | flake8 --diff --ignore E402,E731,E501 --max-line-length=99 | |
deactivate | |
rm -rf ${TMP_DIR} | |
echo "Linting OK" | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment