#!/usr/bin/env bash1# This script uses pep8 / autopep8 to find Python style errors2# or even fixes them.3# Usage: ./codestyle.sh or ./codestyle.sh [path/to/python/file ...]45# Note: When using this codestyle fixing utility, don't forget that it6# might introduce a lot of changes. That could be hard to merge!78# increased line length. might get shorter in time ... for now even ignored9#ARGS='--max-line-length=120 --ignore=E501'10# E271 multiple spaces after keyword11# E272 multiple spaces before keyword12# E703 statement ends with a semicolon13# E713 test for membership should be ‘not in’14# E714 test for object identity should be ‘is not’15# E722 do not use bare except, specify exception instead16ARGS='--select=E271,E272,E703,E713,E714,E722'1718SAGE_COMMAND=$SAGE19if [[ "$SAGE_COMMAND" == "" ]]; then20SAGE_COMMAND=sage21fi22echo "Using Sage command $SAGE_COMMAND"2324# WARN: we set the aggressive flag25AUTOPEP="$SAGE_COMMAND -python -m autopep8 -i --aggressive $ARGS"26CODESTYLE="$SAGE_COMMAND -python -m pycodestyle $ARGS"2728if [ -n "$1" ]; then29$AUTOPEP "$@"30else31cd `dirname "$0"`32find lmfdb -iname '*.py' | xargs $CODESTYLE33fi343536