From 679f787a65bf4d8b3aa0c7931da7771bb0b8fb1e Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Mon, 22 Aug 2016 14:35:41 -0500 Subject: Add generic changed_files script --- share/spack/qa/changed_files | 31 +++++++++++++++++++++++++++++++ share/spack/qa/run-flake8-tests | 39 +++++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 16 deletions(-) create mode 100755 share/spack/qa/changed_files diff --git a/share/spack/qa/changed_files b/share/spack/qa/changed_files new file mode 100755 index 0000000000..9c60b3b20b --- /dev/null +++ b/share/spack/qa/changed_files @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# Description: +# Returns a list of changed files. +# +# Usage: +# changed_files [ ...] +# changed_files [ ...] +# changed_files ["*." ...] +# +# Options: +# Directories, files, or globs to search for changed files. +# + +# Move to root directory of Spack +# Allows script to be run from anywhere +SPACK_ROOT="$(dirname "$0")/../../.." +cd "$SPACK_ROOT" + +# Add changed files that have been committed since branching off of develop +changed=($(git diff --name-only --find-renames develop... -- "$@")) +# Add changed files that have been staged but not yet committed +changed+=($(git diff --name-only --find-renames --cached -- "$@")) +# Add changed files that are unstaged +changed+=($(git diff --name-only --find-renames -- "$@")) +# Add new files that are untracked +changed+=($(git ls-files --exclude-standard --other -- "$@")) + +# Return array +# Ensure that each file in the array is unique +printf '%s\n' "${changed[@]}" | sort -u diff --git a/share/spack/qa/run-flake8-tests b/share/spack/qa/run-flake8-tests index 9556b0d250..6c9f8968e2 100755 --- a/share/spack/qa/run-flake8-tests +++ b/share/spack/qa/run-flake8-tests @@ -1,31 +1,38 @@ #!/usr/bin/env bash # -# This script runs source code style checks on Spack. +# Description: +# Runs source code style checks on Spack. +# See $SPACK_ROOT/.flake8 for a list of +# approved exceptions. # -# To run it, you'll need to have the Python flake8 installed locally. +# Usage: +# 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. # -PYTHONPATH=./lib/spack:$PYTHONPATH +# Check for dependencies flake8="$(which flake8)" if [[ ! $flake8 ]]; then echo "ERROR: flake8 is required to run this script." exit 1 fi -# Move to Spack root; allows script to be run from anywhere -cd "$(dirname "$0")/../../.." +QA_DIR="$(dirname "$0")" +SPACK_ROOT="$QA_DIR/../../.." -# Add changed files that have been committed since branching off of develop -changed=($(git diff --name-only --find-renames develop... -- '*.py')) -# Add changed files that have been staged but not yet committed -changed+=($(git diff --name-only --find-renames --cached -- '*.py')) -# Add changed files that are unstaged -changed+=($(git diff --name-only --find-renames -- '*.py')) -# Add new files that are untracked -changed+=($(git ls-files --exclude-standard --other -- '*.py')) +# Move to root directory of Spack +# Allows script to be run from anywhere +SPACK_ROOT="$(dirname "$0")/../../.." +cd "$SPACK_ROOT" -# Ensure that each file in the array is unique -changed=($(printf '%s\n' "${changed[@]}" | sort -u)) +# Gather array of changed files +changed=($("$QA_DIR/changed_files" "*.py")) function cleanup { # Restore original package files after modifying them. @@ -80,7 +87,7 @@ if [[ "${changed[@]}" ]]; then exit 1 fi else - echo No core framework files modified. + echo No Python files were modified. fi exit 0 -- cgit v1.2.3-60-g2f50