From be471469156b5a4fb6d5a0c9c82607a316136393 Mon Sep 17 00:00:00 2001 From: Sylvain Herlédan Date: Thu, 16 Jul 2026 22:54:53 +0200 Subject: Code linting. --- python_install.sh | 69 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/python_install.sh b/python_install.sh index cf17cde..495a11d 100755 --- a/python_install.sh +++ b/python_install.sh @@ -7,26 +7,33 @@ set -o nounset set -o errexit set -o pipefail -readonly PROGNAME="$(basename "${0}")"; -readonly PROGDIR="$(readlink -f "$(dirname "${0}")")"; -readonly ARGS="${@}"; +readonly ARGS=( "${@}" ); -readonly PYTHON_VERSION_PATH="$(mktemp)"; -readonly PIP_INSTALL_SCRIPT="$(mktemp)"; +readonly PYTHON_VERSION_PATH; +PYTHON_VERSION_PATH="$(mktemp)"; +readonly PIP_INSTALL_SCRIPT; +PIP_INSTALL_SCRIPT="$(mktemp)"; +# Don't warn about unreachable commands in this function (called via trap, +# which shellcheck fails to detect) +# shellcheck disable=SC2317 cleanup() { local rc=$?; # Keep original return code + trap - INT TERM EXIT + rm -f "${PYTHON_VERSION_PATH}" rm -f "${PIP_INSTALL_SCRIPT}" - exit ${rc} + exit "${rc}" } get_python_version() { - local python="${1}"; shift; - local version_path="${1}"; shift; + local python; + python="${1}"; shift; + local version_path; + version_path="${1}"; shift; # Redirecting stderr to stdout is necessary because older versions # of Python printed to stderr @@ -37,12 +44,15 @@ get_python_version() venv_install_method() { - local python="${1}"; shift; - local env_dir="${1}"; shift; + local python; + python="${1}"; shift; + local env_dir; + env_dir="${1}"; shift; "${python}" -m venv "${env_dir}" set +o nounset + # shellcheck disable=SC1091 # Don't warn about not following sourced files source "${env_dir}/bin/activate" set -o nounset @@ -55,10 +65,12 @@ venv_install_method() pip_install_method() { - local python="${1}"; shift; - local env_dir="${1}"; shift; - local version="${1:-}"; shift; - local opts=''; + local python; + python="${1}"; shift; + local env_dir: + env_dir="${1}"; shift; + local version; + version="${1:-}"; shift; [ -n "${version}" ] && version="/${version}" wget "https://bootstrap.pypa.io/pip${version}/get-pip.py" \ @@ -80,15 +92,19 @@ install_environment() { get_python_version "${python}" "${PYTHON_VERSION_PATH}" - local major="$(cat "${PYTHON_VERSION_PATH}" | cut -d. -f1)"; - local minor="$(cat "${PYTHON_VERSION_PATH}" | cut -d. -f2)"; - local num=$((${minor} + 10 * ${major})); + local major; + major="$(cut -d. -f1 "${PYTHON_VERSION_PATH}")"; + local minor; + minor="$(cut -d. -f2 "${PYTHON_VERSION_PATH}")"; + local num; + num=$((minor + 10 * major)); if [ ${num} -gt 33 ]; then set +o errexit - "${python}" -m ensurepip --help 2>&1 >/dev/null - local rc=$? + "${python}" -m ensurepip --help >/dev/null 2>&1 + local rc; + rc=$? set -o errexit if [ 0 -eq ${rc} ]; @@ -116,11 +132,15 @@ EOF install_virtualenv() { - local python="${1}"; shift; - local env_dir="${1}"; shift; - local _pkg_dir="$(find "${env_dir}/lib" -mindepth 2 -maxdepth 2 \ + local python; + python="${1}"; shift; + local env_dir; + env_dir="${1}"; shift; + local _pkg_dir; + _pkg_dir="$(find "${env_dir}/lib" -mindepth 2 -maxdepth 2 \ -name "site-packages")"; - local pkg_dir="$(readlink -f "${_pkg_dir}")"; + local pkg_dir; + pkg_dir="$(readlink -f "${_pkg_dir}")"; echo "Install virtual env" @@ -153,9 +173,8 @@ main() install_environment "${python}" "${env_dir}" - trap - INT TERM EXIT echo 'Environment ready' } -main ${ARGS} +main "${ARGS[@]}" exit 0 -- cgit v1.3.1