home · contact · privacy
Initial commit.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 17 Mar 2025 07:00:22 +0000 (08:00 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 17 Mar 2025 07:00:22 +0000 (08:00 +0100)
install.sh [new file with mode: 0755]
lintplom [new file with mode: 0755]

diff --git a/install.sh b/install.sh
new file mode 100755 (executable)
index 0000000..576ceef
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+PATH_LOCAL_BIN="${HOME}/.local/bin"
+mkdir -p "${PATH_LOCAL_BIN}"
+cp lintplom "${PATH_LOCAL_BIN}/"
diff --git a/lintplom b/lintplom
new file mode 100755 (executable)
index 0000000..9a4799c
--- /dev/null
+++ b/lintplom
@@ -0,0 +1,75 @@
+#!/bin/sh
+set -e
+
+# check existence of file, ensure absoluteness of path
+if [ "$?" -ne 1 ]; then
+    echo "usage: lintplom FILEPATH"
+    echo ""
+    echo "arguments:"
+    echo "  FILEPATH - source file to run Python linters against"
+    exit 1
+fi
+
+# check existence of file, ensure absoluteness of path
+TARGET="$1"
+if [ ! -f "$1" ]; then
+    echo "Must provide valid file path as argument."
+    exit 1
+fi
+if [ $(echo "${TARGET}" | cut -c1) != '/' ]; then
+    TARGET="$(pwd)/${TARGET}"
+fi
+
+# find closest parent directory with requirements listing, limit search to
+# directories below user directory
+if [ $(echo "${TARGET}" | cut -d'/' -f'1-3') != "${HOME}" ]; then
+    echo "Target outside user home directory."
+    exit 1
+fi
+FILE_REQS=requirements.txt
+DIR_REQS=
+cd "$(dirname ${TARGET})"
+while true; do
+    if [ "$(pwd)" = "${HOME}" ]; then
+       break
+    elif [ -f "${FILE_REQS}" ]; then
+        DIR_REQS="$(pwd)" 
+       break
+    fi
+    cd ..
+done
+
+# decide venv directory specific to directory found to hold requirements
+# listing, or if none found specific to user's home directory
+DIR_VENV_BASE=/tmp/venv_lintplom
+if [ -z "${DIR_REQS}" ]; then
+    DIR_VENV="${DIR_VENV_BASE}/_any/${HOME}"
+else
+    DIR_VENV="${DIR_VENV_BASE}${DIR_REQS}"
+fi
+
+# give some basic feedback
+echo "Linting ${TARGET} using venv environment at ${DIR_VENV} – but first, checking for and installing missing dependencies."
+if [ -z "${DIR_REQS}" ]; then
+    echo "(No ${FILE_REQS} found, so nothing to provide besides linters themselves.)"
+fi
+
+# ensure venv environment at result of previous decision, install reqs
+if [ ! -d "${DIR_VENV}" ]; then
+  python3 -m venv "${DIR_VENV}" 
+fi
+. "${DIR_VENV}/bin/activate"
+pip3 -q install flake8 pylint mypy
+. "${DIR_VENV}/bin/activate"
+if [ ! -z "${DIR_REQS}" ]; then
+    pip3 -q install -r "${DIR_REQS}/${FILE_REQS}"
+fi
+
+# run actual tests
+set +e
+echo "\n\n============================[ FLAKE results ]==================================\n"
+flake8 "${TARGET}"
+echo "\n\n============================[ PYLINT results ]=================================\n"
+pylint "${TARGET}"
+echo "\n\n============================[ MYPY results ]===================================\n"
+mypy "${TARGET}"