Skip to content

Commit

Permalink
pre-commit: run optional doctests before commit
Browse files Browse the repository at this point in the history
 * 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
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -54,6 +54,12 @@ repos:
entry: scripts/check-pylint
language: script
types: [file, python]
- id: doctest
name: Doctests
entry: scripts/run-doctests
language: script
types: [file, python]
verbose: true
- id: futurize
name: Check futurize
entry: scripts/check-futurize
Expand Down
39 changes: 39 additions & 0 deletions scripts/run-doctests
@@ -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

0 comments on commit 0e1b0d8

Please sign in to comment.