From 38d41acda4e55b9243b619f6dc1cf066310b0e52 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 18 Oct 2016 09:56:25 -0700 Subject: [PATCH] check_format: check Python style with pep8 Also continue checking for errors after a problem has been found. Change-Id: Iea37311e54f68fb6ba8c804ad4b2fb92d5238f36 Signed-off-by: Daniel Verkamp --- scripts/check_format.sh | 42 ++++++++++++++++++++----- scripts/rpc.py | 2 +- test/iscsi_tgt/rpc_config/rpc_config.py | 2 +- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/scripts/check_format.sh b/scripts/check_format.sh index 6563b19a2..689e7382e 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -6,6 +6,8 @@ cd $BASEDIR # exit on errors set -e +rc=0 + if hash astyle; then echo -n "Checking coding style..." rm -f astyle.log @@ -21,17 +23,43 @@ if hash astyle; then echo "Incorrect code style detected in one or more files." echo "The files have been automatically formatted." echo "Remember to add the files to your commit." - rm -f astyle.log - exit 1 + rc=1 + else + echo " OK" fi - echo " OK" rm -f astyle.log else echo "You do not have astyle installed so your code style is not being checked!" - exit 0 fi -git grep -I -l -e . -z | \ - xargs -0 -P8 -n1 scripts/eofnl +echo -n "Checking blank lines at end of file..." -exit 0 +if ! git grep -I -l -e . -z | \ + xargs -0 -P8 -n1 scripts/eofnl > eofnl.log; then + echo " Incorrect end-of-file formatting detected" + cat eofnl.log + rc=1 +else + echo " OK" +fi +rm -f eofnl.log + +if hash pep8; then + echo -n "Checking Python style..." + + PEP8_ARGS+=" --ignore=E302" # ignore 'E302 expected 2 blank lines, found 1' + PEP8_ARGS+=" --max-line-length=140" + + error=0 + git ls-files '*.py' | xargs -n1 pep8 $PEP8_ARGS > pep8.log || error=1 + if [ $error -ne 0 ]; then + echo " Python formatting errors detected" + cat pep8.log + rc=1 + else + echo " OK" + fi + rm -f pep8.log +fi + +exit $rc diff --git a/scripts/rpc.py b/scripts/rpc.py index 66bede70d..ceadc872a 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -371,7 +371,7 @@ Format: 'domain:device:function' etc Example: '0000:00:01.0'""") p.add_argument("-s", "--serial_number", help="""Valid if mode == Virtual. Format: 'sn' etc -Example: 'SPDK00000000000001'""", default='0000:00:01.0') +Example: 'SPDK00000000000001'""", default='0000:00:01.0') p.add_argument("-n", "--namespaces", help="""Whitespace-separated list of namespaces. Format: 'dev1 dev2 dev3' etc Example: 'Malloc0 Malloc1 Malloc2' diff --git a/test/iscsi_tgt/rpc_config/rpc_config.py b/test/iscsi_tgt/rpc_config/rpc_config.py index 4b0cd313c..e43ca22fc 100755 --- a/test/iscsi_tgt/rpc_config/rpc_config.py +++ b/test/iscsi_tgt/rpc_config/rpc_config.py @@ -401,7 +401,7 @@ def verify_add_nvme_bdev_rpc_methods(rpc_py): if out != '': ctrlr_address = "0000:{}".format(out.split(" ")[0]) output = rpc.construct_nvme_bdev(ctrlr_address) - if output.strip()=='': + if output.strip() == '': print "add nvme device passed first time" test_pass = 1 verify(test_pass == 1, 1, "add nvme device passed first time")