forked from scipy/scipy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Flake8 no longer handles patches, so instead apply to entire files (see PyCQA/flake8#1760) - Rename `tools/lint_diff.py` to `tools/lint.py` - Files can be obtained either via diffing against a branch, or by specifying them manually - `tools/pre-commit-hook.sh` is a pre-commit hook that utilizes `tools/lint.py` but only lints staged changes - Update contributor guidelines to point to pre-commit hook See also the discussion at scipy#15489
- Loading branch information
Showing
5 changed files
with
106 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
# | ||
# Pre-commit linting hook. | ||
# | ||
# Install from root of repository with: | ||
# | ||
# ln -s tools/pre-commit-hook.sh .git/hooks/pre-commit | ||
|
||
# store names of files that were staged | ||
mapfile -d '' changed < <(git diff --cached --name-only -z --diff-filter=ACMR -- '*.py') | ||
|
||
# create a temporary copy of what would get committed, without unstaged modifications | ||
# (e.g., only certain changes in a file may have been committed) | ||
GIT_DIR=${GIT_DIR:-.git} | ||
workdir=$GIT_DIR/.pre-commit-workdir | ||
fakecommit=$(git commit-tree -p HEAD $(git write-tree) -m ...) | ||
|
||
if ! [[ -d $workdir ]]; then | ||
git clone -qns "$GIT_DIR" "$workdir" || exit | ||
fi | ||
|
||
unset "${!GIT_@}" | ||
cd "$workdir" | ||
git checkout -q $fakecommit | ||
|
||
# run linter(s); if any fail, remember that, and set an overall hook failure status | ||
ret=0 | ||
|
||
# Run lint.py from the scipy source tree | ||
../../tools/lint.py --files "${changed[@]}" || ret=1 | ||
|
||
if [[ $ret -ne 0 ]]; then | ||
echo "!! Linting failed; please make fixes, \`git add\` files, and re-commit." | ||
fi | ||
exit $ret |