From bab7ef307cb11e2d2dc9b9ddf2d1de68f220ed45 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Tue, 10 Sep 2024 17:22:09 +0800 Subject: [PATCH] pythonImportsCheckHook: lint with ShellCheck --- .../python/hooks/python-imports-check-hook.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkgs/development/interpreters/python/hooks/python-imports-check-hook.sh b/pkgs/development/interpreters/python/hooks/python-imports-check-hook.sh index 2788a947fe95..c3c758d6a902 100644 --- a/pkgs/development/interpreters/python/hooks/python-imports-check-hook.sh +++ b/pkgs/development/interpreters/python/hooks/python-imports-check-hook.sh @@ -1,23 +1,28 @@ +# shellcheck shell=bash + # Setup hook for checking whether Python imports succeed echo "Sourcing python-imports-check-hook.sh" pythonImportsCheckPhase() { echo "Executing pythonImportsCheckPhase" - if [ -n "${pythonImportsCheck[*]-}" ]; then + if [[ -n "${pythonImportsCheck[*]-}" ]]; then echo "Check whether the following modules can be imported: ${pythonImportsCheck[*]}" # shellcheck disable=SC2154 pythonImportsCheckOutput="$out" - if [ -n "${python-}" ]; then + if [[ -n "${python-}" ]]; then echo "Using python specific output \$python for imports check" pythonImportsCheckOutput=$python fi export PYTHONPATH="$pythonImportsCheckOutput/@pythonSitePackages@:$PYTHONPATH" + # Python modules and namespaces names are Python identifiers, which must not contain spaces. + # See https://docs.python.org/3/reference/lexical_analysis.html + # shellcheck disable=SC2048,SC2086 (cd "$pythonImportsCheckOutput" && @pythonCheckInterpreter@ -c 'import sys; import importlib; list(map(lambda mod: importlib.import_module(mod), sys.argv[1:]))' ${pythonImportsCheck[*]}) fi } -if [ -z "${dontUsePythonImportsCheck-}" ]; then +if [[ -z "${dontUsePythonImportsCheck-}" ]]; then echo "Using pythonImportsCheckPhase" appendToVar preDistPhases pythonImportsCheckPhase fi