Only run unit tests when core Spack framework is modified

This commit is contained in:
Adam J. Stewart
2016-08-22 18:40:53 -05:00
parent d2d6c91b66
commit 1fc14fd7ed
4 changed files with 127 additions and 53 deletions

View File

@@ -9,23 +9,20 @@
# run-flake8-tests
#
# Notes:
# Requires flake8. Can be installed by running:
# `spack install py-flake8`
# or:
# `pip install flake8`
# and adding the bin directory to your PATH.
# Requires flake8.
#
# Check for dependencies
flake8="$(which flake8)"
if [[ ! $flake8 ]]; then
echo "ERROR: flake8 is required to run this script."
exit 1
fi
QA_DIR="$(dirname "$0")"
SPACK_ROOT="$QA_DIR/../../.."
# Array of dependencies
deps=(
flake8
)
# Check for dependencies
"$QA_DIR/check_dependencies" "${deps[@]}" || exit 1
# Move to root directory of Spack
# Allows script to be run from anywhere
cd "$SPACK_ROOT"
@@ -33,6 +30,12 @@ cd "$SPACK_ROOT"
# Gather array of changed files
changed=($("$QA_DIR/changed_files" "*.py"))
# Exit if no Python files were modified
if [[ ! "${changed[@]}" ]]; then
echo "No Python files were modified."
exit 0
fi
function cleanup {
# Restore original package files after modifying them.
for file in "${changed[@]}"; do
@@ -55,15 +58,15 @@ for file in "${changed[@]}"; do
#
if [[ $file = *package.py ]]; then
# Exempt lines with urls and descriptions from overlong line errors.
perl -i -pe 's/^(\s*homepage\s*=.*)$/\1 # NOQA: ignore=E501/' $file
perl -i -pe 's/^(\s*url\s*=.*)$/\1 # NOQA: ignore=E501/' $file
perl -i -pe 's/^(\s*version\(.*\).*)$/\1 # NOQA: ignore=E501/' $file
perl -i -pe 's/^(\s*variant\(.*\).*)$/\1 # NOQA: ignore=E501/' $file
perl -i -pe 's/^(\s*depends_on\(.*\).*)$/\1 # NOQA: ignore=E501/' $file
perl -i -pe 's/^(\s*extends\(.*\).*)$/\1 # NOQA: ignore=E501/' $file
perl -i -pe 's/^(\s*homepage\s*=.*)$/\1 # NOQA: ignore=E501/' "$file"
perl -i -pe 's/^(\s*url\s*=.*)$/\1 # NOQA: ignore=E501/' "$file"
perl -i -pe 's/^(\s*version\(.*\).*)$/\1 # NOQA: ignore=E501/' "$file"
perl -i -pe 's/^(\s*variant\(.*\).*)$/\1 # NOQA: ignore=E501/' "$file"
perl -i -pe 's/^(\s*depends_on\(.*\).*)$/\1 # NOQA: ignore=E501/' "$file"
perl -i -pe 's/^(\s*extends\(.*\).*)$/\1 # NOQA: ignore=E501/' "$file"
# Exempt '@when' decorated functions from redefinition errors.
perl -i -pe 's/^(\s*\@when\(.*\).*)$/\1 # NOQA: ignore=F811/' $file
perl -i -pe 's/^(\s*\@when\(.*\).*)$/\1 # NOQA: ignore=F811/' "$file"
fi
#
@@ -72,21 +75,15 @@ for file in "${changed[@]}"; do
perl -i -pe 's/^(.*(https?|file)\:.*)$/\1 # NOQA: ignore=E501/' $file
done
if [[ "${changed[@]}" ]]; then
echo =======================================================
echo flake8: running flake8 code checks on spack.
echo
echo Modified files:
echo "${changed[@]}" | perl -pe 's/^/ /;s/ +/\n /g'
echo =======================================================
if flake8 --format pylint "${changed[@]}"; then
echo "Flake8 checks were clean."
else
echo "Flake8 found errors."
exit 1
fi
echo =======================================================
echo flake8: running flake8 code checks on spack.
echo
echo Modified files:
echo "${changed[@]}" | perl -pe 's/^/ /;s/ +/\n /g'
echo =======================================================
if flake8 --format pylint "${changed[@]}"; then
echo "Flake8 checks were clean."
else
echo No Python files were modified.
echo "Flake8 found errors."
exit 1
fi
exit 0