Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/codestyle.sh
1127 views
1
#!/usr/bin/env bash
2
# This script uses pep8 / autopep8 to find Python style errors
3
# or even fixes them.
4
# Usage: ./codestyle.sh or ./codestyle.sh [path/to/python/file ...]
5
6
# Note: When using this codestyle fixing utility, don't forget that it
7
# might introduce a lot of changes. That could be hard to merge!
8
9
# increased line length. might get shorter in time ... for now even ignored
10
#ARGS='--max-line-length=120 --ignore=E501'
11
# E271 multiple spaces after keyword
12
# E272 multiple spaces before keyword
13
# E703 statement ends with a semicolon
14
# E713 test for membership should be ‘not in’
15
# E714 test for object identity should be ‘is not’
16
# E722 do not use bare except, specify exception instead
17
ARGS='--select=E271,E272,E703,E713,E714,E722'
18
19
SAGE_COMMAND=$SAGE
20
if [[ "$SAGE_COMMAND" == "" ]]; then
21
SAGE_COMMAND=sage
22
fi
23
echo "Using Sage command $SAGE_COMMAND"
24
25
# WARN: we set the aggressive flag
26
AUTOPEP="$SAGE_COMMAND -python -m autopep8 -i --aggressive $ARGS"
27
CODESTYLE="$SAGE_COMMAND -python -m pycodestyle $ARGS"
28
29
if [ -n "$1" ]; then
30
$AUTOPEP "$@"
31
else
32
cd `dirname "$0"`
33
find lmfdb -iname '*.py' | xargs $CODESTYLE
34
fi
35
36