Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pre-commit: run optional doctests before commit
* Any error will not prevent the commit but will warn the developer. This is being done due to livestatus package import problems in some packages. Change-Id: I9cbad5d9762bfdf4e16918a66921842ec7cfa04c
- Loading branch information
Christoph Rauch
committed
Feb 19, 2020
1 parent
35f8efb
commit 0e1b0d8
Showing
2 changed files
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
# | ||
# This file is for execution by the pre-commit framework. | ||
# | ||
source "$(dirname $0)/lib-precommit" | ||
|
||
# Filter out all tests/* and tests-py3/* files. | ||
declare -a FILES | ||
|
||
for param in "$@"; do | ||
if [[ "$param" == tests* ]]; then | ||
continue | ||
fi | ||
FILES+=($param) | ||
done | ||
|
||
NUM_PARAM=${#FILES[@]} | ||
|
||
if [ "$NUM_PARAM" == "0" ]; then | ||
echo No files to check. >&2 | ||
exit 0 | ||
fi | ||
|
||
REPO_PATH="$(git rev-parse --show-toplevel)" | ||
PIPENV="$REPO_PATH/scripts/run-pipenv" | ||
|
||
printf -v files " %s" ${FILES[@]} | ||
PYTHON2_FILES=$(python_files 2 "$files") | ||
PYTHON3_FILES=$(python_files 3 "$files") | ||
|
||
if [ ! -z "$PYTHON2_FILES" ]; then | ||
$PIPENV 2 run python -m doctest $PYTHON2_FILES | ||
fi | ||
|
||
if [ ! -z "$PYTHON3_FILES" ]; then | ||
$PIPENV 3 run python -m doctest $PYTHON3_FILES | ||
fi | ||
|
||
exit 0 |