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

View File

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

View File

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

View File

@ -7,7 +7,10 @@ print_hint() {
PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:m:l:o: \
--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"
@ -57,30 +60,25 @@ while true; do
done
BASEDIR=${BASEDIR:-`pwd`}
if ! [ -d $BASEDIR ]
then
if ! [ -d $BASEDIR ] ; then
echo "${0##*/}: missing project base directory" >&2 ; print_hint ; exit 1
elif [[ $BASEDIR != /* ]]
then
elif [[ $BASEDIR != /* ]] ; then
BASEDIR=$(cd "$BASEDIR" && pwd)
fi
PACKAGENAME=${PACKAGENAME:-${BASEDIR##*/}}
PACKAGENAME=`echo $PACKAGENAME | tr - _`
TARGETDIR=$BASEDIR/$PACKAGENAME
if ! [ -d $TARGETDIR ]
then
if ! [ -d $TARGETDIR ] ; then
echo "${0##*/}: invalid project package name" >&2 ; print_hint ; exit 1
fi
OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc}
# NOTE(bnemec): Some projects put their sample config in etc/,
# some in etc/$PACKAGENAME/
if [ -d $OUTPUTDIR/$PACKAGENAME ]
then
if [ -d $OUTPUTDIR/$PACKAGENAME ] ; then
OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME
elif ! [ -d $OUTPUTDIR ]
then
elif ! [ -d $OUTPUTDIR ] ; then
echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2
exit 1
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)
RC_FILE="`dirname $0`/oslo.config.generator.rc"
if test -r "$RC_FILE"
then
if test -r "$RC_FILE" ; then
source "$RC_FILE"
fi

23
tools/run_bashate.sh Executable file
View 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

View File

@ -26,8 +26,12 @@ setenv =
commands = ostestr {posargs}
[testenv:pep8]
whitelist_externals = bash
commands =
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
[testenv:cover]