diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2016-08-11 10:31:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-11 10:31:43 -0700 |
commit | cd6c370303ae6411c32eff311b315031fe244547 (patch) | |
tree | 17ff41907e166077e509dba8356a00ff1a7b69aa | |
parent | e6a122417aee3dbb0f83c92d23a408a855b07c40 (diff) | |
parent | 87d0a7c3156070316ca28f356ef97c8208236fab (diff) | |
download | spack-cd6c370303ae6411c32eff311b315031fe244547.tar.gz spack-cd6c370303ae6411c32eff311b315031fe244547.tar.bz2 spack-cd6c370303ae6411c32eff311b315031fe244547.tar.xz spack-cd6c370303ae6411c32eff311b315031fe244547.zip |
Merge pull request #1480 from adamjstewart/features/run-flake8
Various improvements to run-flake8
-rwxr-xr-x | share/spack/qa/run-flake8 | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/share/spack/qa/run-flake8 b/share/spack/qa/run-flake8 index c59bfc9490..e41cd0d471 100755 --- a/share/spack/qa/run-flake8 +++ b/share/spack/qa/run-flake8 @@ -2,11 +2,6 @@ # # This script runs source code style checks on Spack. # -# It should be executed from the top-level directory of the repo, -# e.g.: -# -# share/spack/qa/run-flake8 -# # To run it, you'll need to have the Python flake8 installed locally. # PYTHONPATH=./lib/spack:$PYTHONPATH @@ -17,11 +12,33 @@ if [[ ! $flake8 ]]; then exit 1 fi -# Check if changed files are flake8 conformant [framework] -changed=$(git diff --name-only --find-renames develop... | grep '.py$') +# Move to Spack root; allows script to be run from anywhere +cd "$(dirname "$0")/../../.." + +# 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')) + +# Ensure that each file in the array is unique +changed=($(printf '%s\n' "${changed[@]}" | sort -u)) + +function cleanup { + # Restore original package files after modifying them. + for file in "${changed[@]}"; do + if [[ -e "${file}.sbak~" ]]; then + mv "${file}.sbak~" "${file}" + fi + done +} + +# Cleanup temporary files upon exit or when script is killed +trap cleanup EXIT SIGINT SIGTERM # Add approved style exemptions to the changed packages. -for file in $changed; do +for file in "${changed[@]}"; do # Make a backup to restore later cp "$file" "$file.sbak~" @@ -47,29 +64,21 @@ for file in $changed; do perl -i -pe 's/^(.*(https?|file)\:.*)$/\1 # NOQA: ignore=E501/' $file done -return_code=0 -if [[ $changed ]]; then +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 "${changed[@]}" | perl -pe 's/^/ /;s/ +/\n /g' echo ======================================================= - if flake8 --format pylint $changed; then + if flake8 --format pylint "${changed[@]}"; then echo "Flake8 checks were clean." else echo "Flake8 found errors." - return_code=1 + exit 1 fi else echo No core framework files modified. fi -# Restore original package files after modifying them. -for file in $changed; do - if [[ -e "${file}.sbak~" ]]; then - mv "${file}.sbak~" "${file}" - fi -done - -exit $return_code +exit 0 |