Add bash scripts style checking for IPA

Updated file tox.ini allows to check code style in all ".sh" files
included in Ironic Python Agent. Checking can be invoked by calling either
"tox" or "tox -e pep8".

Change-Id: Ie76605737c7db10a064f2aebfda388372a4c0591
Closes-Bug: #1625215
This commit is contained in:
OpenStack Proposal Bot 2016-11-04 14:08:31 +00:00 committed by John L. Villalovos
parent 3ebffd0e42
commit c40575e4e0
8 changed files with 85 additions and 62 deletions

@ -8,7 +8,7 @@ testtools>=1.4.0 # MIT
python-subunit>=0.0.18 # Apache-2.0/BSD python-subunit>=0.0.18 # Apache-2.0/BSD
oslotest>=1.10.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0
os-testr>=0.8.0 # Apache-2.0 os-testr>=0.8.0 # Apache-2.0
bashate>=0.2 # Apache-2.0
# Doc requirements # Doc requirements
doc8 # Apache-2.0 doc8 # Apache-2.0
sphinx!=1.3b1,<1.4,>=1.2.1 # BSD sphinx!=1.3b1,<1.4,>=1.2.1 # BSD

@ -17,8 +17,7 @@ trap "rm -rf $TEMPDIR" EXIT
tools/config/generate_sample.sh -b ./ -p ${PROJECT_NAME} -o ${TEMPDIR} tools/config/generate_sample.sh -b ./ -p ${PROJECT_NAME} -o ${TEMPDIR}
if ! diff -u ${TEMPDIR}/${CFGFILE_NAME} ${CFGFILE} if ! diff -u ${TEMPDIR}/${CFGFILE_NAME} ${CFGFILE} ; then
then
echo "${0##*/}: ${PROJECT_NAME}.conf.sample is not up to date." echo "${0##*/}: ${PROJECT_NAME}.conf.sample is not up to date."
echo "${0##*/}: Please run ${0%%${0##*/}}generate_sample.sh." echo "${0##*/}: Please run ${0%%${0##*/}}generate_sample.sh."
exit 1 exit 1

@ -7,7 +7,10 @@ print_hint() {
PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:m:l:o: \ PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:m:l:o: \
--long help,base-dir:,package-name:,output-dir:,module:,library: -- "$@") --long help,base-dir:,package-name:,output-dir:,module:,library: -- "$@")
if [ $? != 0 ] ; then print_hint ; exit 1 ; fi if [ $? != 0 ] ; then
print_hint ;
exit 1
fi
eval set -- "$PARSED_OPTIONS" eval set -- "$PARSED_OPTIONS"
@ -57,30 +60,25 @@ while true; do
done done
BASEDIR=${BASEDIR:-`pwd`} BASEDIR=${BASEDIR:-`pwd`}
if ! [ -d $BASEDIR ] if ! [ -d $BASEDIR ] ; then
then
echo "${0##*/}: missing project base directory" >&2 ; print_hint ; exit 1 echo "${0##*/}: missing project base directory" >&2 ; print_hint ; exit 1
elif [[ $BASEDIR != /* ]] elif [[ $BASEDIR != /* ]] ; then
then
BASEDIR=$(cd "$BASEDIR" && pwd) BASEDIR=$(cd "$BASEDIR" && pwd)
fi fi
PACKAGENAME=${PACKAGENAME:-${BASEDIR##*/}} PACKAGENAME=${PACKAGENAME:-${BASEDIR##*/}}
PACKAGENAME=`echo $PACKAGENAME | tr - _` PACKAGENAME=`echo $PACKAGENAME | tr - _`
TARGETDIR=$BASEDIR/$PACKAGENAME TARGETDIR=$BASEDIR/$PACKAGENAME
if ! [ -d $TARGETDIR ] if ! [ -d $TARGETDIR ] ; then
then
echo "${0##*/}: invalid project package name" >&2 ; print_hint ; exit 1 echo "${0##*/}: invalid project package name" >&2 ; print_hint ; exit 1
fi fi
OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc} OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc}
# NOTE(bnemec): Some projects put their sample config in etc/, # NOTE(bnemec): Some projects put their sample config in etc/,
# some in etc/$PACKAGENAME/ # some in etc/$PACKAGENAME/
if [ -d $OUTPUTDIR/$PACKAGENAME ] if [ -d $OUTPUTDIR/$PACKAGENAME ] ; then
then
OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME
elif ! [ -d $OUTPUTDIR ] elif ! [ -d $OUTPUTDIR ] ; then
then
echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2 echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2
exit 1 exit 1
fi fi
@ -91,8 +89,7 @@ FILES=$(find $TARGETDIR -type f -name "*.py" ! -path "*/tests/*" ! -path "*/nova
-exec grep -l "Opt(" {} + | sed -e "s/^$BASEDIRESC\///g" | sort -u) -exec grep -l "Opt(" {} + | sed -e "s/^$BASEDIRESC\///g" | sort -u)
RC_FILE="`dirname $0`/oslo.config.generator.rc" RC_FILE="`dirname $0`/oslo.config.generator.rc"
if test -r "$RC_FILE" if test -r "$RC_FILE" ; then
then
source "$RC_FILE" source "$RC_FILE"
fi fi

23
tools/run_bashate.sh Executable file

@ -0,0 +1,23 @@
#!/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# Ignoring E003(Indent not multiple of 4)
# Ignoring E006(Line longer than 79 characters)
find "$@" -not \( -type d -name .?\* -prune \) \
-type f \
\( \
-name \*.sh \
\) \
-print0 | xargs -0 bashate -v -iE003,E006 -eE005,E042

@ -26,8 +26,12 @@ setenv =
commands = ostestr {posargs} commands = ostestr {posargs}
[testenv:pep8] [testenv:pep8]
whitelist_externals = bash
commands = commands =
flake8 {posargs:ironic_python_agent imagebuild} flake8 {posargs:ironic_python_agent imagebuild}
# Run bashate during pep8 runs to ensure violations are caught by
# the check and gate queues.
{toxinidir}/tools/run_bashate.sh {toxinidir}
doc8 doc/source README.rst doc8 doc/source README.rst
[testenv:cover] [testenv:cover]