Skip to content
Snippets Groups Projects
Commit 1edfc821 authored by Adam J. Stewart's avatar Adam J. Stewart
Browse files

Run flake8 checks on changed uncommitted files

parent e6a12241
No related branches found
No related tags found
No related merge requests found
...@@ -17,11 +17,18 @@ if [[ ! $flake8 ]]; then ...@@ -17,11 +17,18 @@ if [[ ! $flake8 ]]; then
exit 1 exit 1
fi fi
# Check if changed files are flake8 conformant [framework] # Add changed files that have been committed since branching off of develop
changed=$(git diff --name-only --find-renames develop... | grep '.py$') 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))
# Add approved style exemptions to the changed packages. # Add approved style exemptions to the changed packages.
for file in $changed; do for file in "${changed[@]}"; do
# Make a backup to restore later # Make a backup to restore later
cp "$file" "$file.sbak~" cp "$file" "$file.sbak~"
...@@ -48,14 +55,14 @@ for file in $changed; do ...@@ -48,14 +55,14 @@ for file in $changed; do
done done
return_code=0 return_code=0
if [[ $changed ]]; then if [[ "${changed[@]}" ]]; then
echo ======================================================= echo =======================================================
echo flake8: running flake8 code checks on spack. echo flake8: running flake8 code checks on spack.
echo echo
echo Modified files: echo Modified files:
echo $changed | perl -pe 's/^/ /;s/ +/\n /g' echo "${changed[@]}" | perl -pe 's/^/ /;s/ +/\n /g'
echo ======================================================= echo =======================================================
if flake8 --format pylint $changed; then if flake8 --format pylint "${changed[@]}"; then
echo "Flake8 checks were clean." echo "Flake8 checks were clean."
else else
echo "Flake8 found errors." echo "Flake8 found errors."
...@@ -66,7 +73,7 @@ else ...@@ -66,7 +73,7 @@ else
fi fi
# Restore original package files after modifying them. # Restore original package files after modifying them.
for file in $changed; do for file in "${changed[@]}"; do
if [[ -e "${file}.sbak~" ]]; then if [[ -e "${file}.sbak~" ]]; then
mv "${file}.sbak~" "${file}" mv "${file}.sbak~" "${file}"
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment