From 126c573abdd197bd2adaf025ef7066a73cf4d89b Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Tue, 21 Jan 2025 15:12:18 -0600 Subject: [PATCH] Update Python lint test The pki-lint script has been split into python-lint.py and python-flake8.py such that they can run independently. This way a failure in one test will not prevent the other test from running. --- .github/workflows/python-lint-test.yml | 8 ++- tests/bin/{pki-lint => python-flake8.py} | 13 +---- tests/bin/python-lint.py | 70 ++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 13 deletions(-) rename tests/bin/{pki-lint => python-flake8.py} (83%) create mode 100755 tests/bin/python-lint.py diff --git a/.github/workflows/python-lint-test.yml b/.github/workflows/python-lint-test.yml index e820d54bd62..a2f81ceb5c0 100644 --- a/.github/workflows/python-lint-test.yml +++ b/.github/workflows/python-lint-test.yml @@ -28,7 +28,13 @@ jobs: HOSTNAME: pki.example.com - name: Run Python lint + if: always() run: | docker exec pki pylint-3 --version + docker exec pki /usr/share/pki/tests/bin/python-lint.py + + - name: Run Python flake8 + if: always() + run: | docker exec pki python3-flake8 --version - docker exec pki /usr/share/pki/tests/bin/pki-lint + docker exec pki /usr/share/pki/tests/bin/python-flake8.py diff --git a/tests/bin/pki-lint b/tests/bin/python-flake8.py similarity index 83% rename from tests/bin/pki-lint rename to tests/bin/python-flake8.py index 2981605efc9..49f68abc99f 100755 --- a/tests/bin/pki-lint +++ b/tests/bin/python-flake8.py @@ -6,14 +6,12 @@ BIN_DIR=`dirname "$SCRIPT_PATH"` TESTS_DIR=`dirname "$BIN_DIR"` -RC_FILE="$TESTS_DIR/pylintrc" FLAKE8_CONFIG="$TESTS_DIR/tox.ini" usage() { echo "Usage: $SCRIPT_NAME [OPTIONS]" echo echo "Options:" - echo " --rcfile= pylint configuration (default: $RC_FILE)" echo " --config= flake8 configuration (default: $FLAKE8_CONFIG)" echo " -v,--verbose Run in verbose mode." echo " --debug Run in debug mode." @@ -29,9 +27,6 @@ LONG_OPTARG="${OPTARG#*=}" case $OPTARG in - rcfile=?*) - RC_FILE="$LONG_OPTARG" - ;; config?*) FLAKE8_CONFIG="$LONG_OPTARG" ;; @@ -42,7 +37,7 @@ '') break # "--" terminates argument processing ;; - rcfile* | config*) + config*) echo "ERROR: Missing argument for --$OPTARG option" >&2 exit 1 ;; @@ -70,12 +65,6 @@ SOURCES="$SOURCES `find /usr/share/pki/upgrade -name "*.py"`" SOURCES="$SOURCES `find /usr/share/pki/server/upgrade -name "*.py"`" -echo "Running pylint..." -pylint-3 \ - --rcfile=${RC_FILE} \ - $SOURCES - -echo "Running flake8..." python3-flake8 \ --config ${FLAKE8_CONFIG} \ $SOURCES diff --git a/tests/bin/python-lint.py b/tests/bin/python-lint.py new file mode 100755 index 00000000000..c4c6bbc508a --- /dev/null +++ b/tests/bin/python-lint.py @@ -0,0 +1,70 @@ +#! /bin/bash -e + +SCRIPT_PATH=`readlink -f "$0"` +SCRIPT_NAME=`basename "$SCRIPT_PATH"` + +BIN_DIR=`dirname "$SCRIPT_PATH"` +TESTS_DIR=`dirname "$BIN_DIR"` + +RC_FILE="$TESTS_DIR/pylintrc" + +usage() { + echo "Usage: $SCRIPT_NAME [OPTIONS]" + echo + echo "Options:" + echo " --rcfile= pylint configuration (default: $RC_FILE)" + echo " -v,--verbose Run in verbose mode." + echo " --debug Run in debug mode." + echo " --help Show help message." +} + +while getopts v-: arg ; do + case $arg in + v) + set -x + ;; + -) + LONG_OPTARG="${OPTARG#*=}" + + case $OPTARG in + rcfile=?*) + RC_FILE="$LONG_OPTARG" + ;; + help) + usage + exit + ;; + '') + break # "--" terminates argument processing + ;; + rcfile*) + echo "ERROR: Missing argument for --$OPTARG option" >&2 + exit 1 + ;; + *) + echo "ERROR: Illegal option --$OPTARG" >&2 + exit 1 + ;; + esac + ;; + \?) + exit 1 # getopts already reported the illegal option + ;; + esac +done + +PATHS=`python3 -Ic "import sys; print(' '.join(sys.path))"` +SOURCES="" + +for path in $PATHS; do + if [ -d $path/pki ]; then + SOURCES="$SOURCES `find $path/pki -name "*.py"`" + fi +done + +SOURCES="$SOURCES `find /usr/share/pki/upgrade -name "*.py"`" +SOURCES="$SOURCES `find /usr/share/pki/server/upgrade -name "*.py"`" + +pylint-3 \ + --rcfile=${RC_FILE} \ + $SOURCES