Skip to content
Permalink
Browse files

python modules: linting script and pre-commit hook

 * to check the consistency of omd/packages/python3?-modules
   execute scripts/check-omd-python-modules
 * if changed and pre-commit is installed, it will be checked
   automatically when committing

Change-Id: I645a627cac17a7e47ba14fa6d619d7c6362641d1
  • Loading branch information
smokey42 committed Jan 14, 2020
1 parent 5c68bf3 commit d5a1b5ba6dc1c8d6fd030bf87a053c835d6ec0ab
Showing with 38 additions and 0 deletions.
  1. +6 −0 .pre-commit-config.yaml
  2. +32 −0 scripts/check-omd-python-modules
@@ -37,6 +37,12 @@ repos:
entry: scripts/check-yapf -i
language: script
types: [file, python]
- id: omd-python-modules
name: Check Python modules in OMD
entry: scripts/check-omd-python-modules
language: script
files: omd/packages/python3?-modules
types: [file]
- id: pylint
name: Check pylint
entry: scripts/check-pylint
@@ -0,0 +1,32 @@
#!/bin/bash
#
# This script checks that the Python modules and the corresponding
# makefiles are in sync.
#
# It will fail when:
# - a module exists which is not referenced
# - a module is referenced in the makefile which does not exist
#
# This is done for both Python2 and Python3 modules.
#
# The Pipfiles are not checked.
#

REPO_PATH="$(git rev-parse --show-toplevel)"

PYTHON_MODULES=$REPO_PATH/omd/packages/python-modules
PYTHON3_MODULES=$REPO_PATH/omd/packages/python3-modules

STATUS=0

pushd $PYTHON_MODULES > /dev/null
awk '/^ *PYTHON_MODULES_LIST *\+=/ { if (system("test -f src/" $3)) { missing = 1; print $3 " missing in python-modules/src directory" } } END { if (missing) { exit 1 }}' python-modules.make || STATUS=$?
ls -1 src | grep -E -v "download|README" | xargs -n 1 -i{} awk '/^ *PYTHON_MODULES_LIST *\+= *{}/ { found = 1 } END { if (!found) { print "{} not in python-modules.make"; exit 1 } }' python-modules.make || STATUS=$?
popd > /dev/null

pushd $PYTHON3_MODULES > /dev/null
awk '/^ *PYTHON3_MODULES_LIST *\+=/ { if (system("test -f src/" $3)) { missing = 1; print $3 " missing in python3-modules/src directory" } } END { if (missing) { exit 1 }}' python3-modules.make || STATUS=$?
ls -1 src | grep -E -v "download|README" | xargs -n 1 -i{} awk '/^ *PYTHON3_MODULES_LIST *\+= *{}/ { found = 1 } END { if (!found) { print "{} not in python3-modules.make"; exit 1 } }' python3-modules.make || STATUS=$?
popd > /dev/null

exit $STATUS

0 comments on commit d5a1b5b

Please sign in to comment.
You can’t perform that action at this time.