lol

pythonImportsCheckHook: lint with ShellCheck

+8 -3
+8 -3
pkgs/development/interpreters/python/hooks/python-imports-check-hook.sh
··· 1 + # shellcheck shell=bash 2 + 1 3 # Setup hook for checking whether Python imports succeed 2 4 echo "Sourcing python-imports-check-hook.sh" 3 5 4 6 pythonImportsCheckPhase() { 5 7 echo "Executing pythonImportsCheckPhase" 6 8 7 - if [ -n "${pythonImportsCheck[*]-}" ]; then 9 + if [[ -n "${pythonImportsCheck[*]-}" ]]; then 8 10 echo "Check whether the following modules can be imported: ${pythonImportsCheck[*]}" 9 11 # shellcheck disable=SC2154 10 12 pythonImportsCheckOutput="$out" 11 - if [ -n "${python-}" ]; then 13 + if [[ -n "${python-}" ]]; then 12 14 echo "Using python specific output \$python for imports check" 13 15 pythonImportsCheckOutput=$python 14 16 fi 15 17 export PYTHONPATH="$pythonImportsCheckOutput/@pythonSitePackages@:$PYTHONPATH" 18 + # Python modules and namespaces names are Python identifiers, which must not contain spaces. 19 + # See https://docs.python.org/3/reference/lexical_analysis.html 20 + # shellcheck disable=SC2048,SC2086 16 21 (cd "$pythonImportsCheckOutput" && @pythonCheckInterpreter@ -c 'import sys; import importlib; list(map(lambda mod: importlib.import_module(mod), sys.argv[1:]))' ${pythonImportsCheck[*]}) 17 22 fi 18 23 } 19 24 20 - if [ -z "${dontUsePythonImportsCheck-}" ]; then 25 + if [[ -z "${dontUsePythonImportsCheck-}" ]]; then 21 26 echo "Using pythonImportsCheckPhase" 22 27 appendToVar preDistPhases pythonImportsCheckPhase 23 28 fi