at master 1.2 kB view raw
1# shellcheck shell=bash 2 3# Setup hook for checking whether Python imports succeed 4echo "Sourcing python-imports-check-hook.sh" 5 6pythonImportsCheckPhase() { 7 echo "Executing pythonImportsCheckPhase" 8 9 if [[ -n "${pythonImportsCheck[*]-}" ]]; then 10 echo "Check whether the following modules can be imported: ${pythonImportsCheck[*]}" 11 # shellcheck disable=SC2154 12 pythonImportsCheckOutput="$out" 13 if [[ -n "${python-}" ]]; then 14 echo "Using python specific output \$python for imports check" 15 pythonImportsCheckOutput=$python 16 fi 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 21 (cd "$pythonImportsCheckOutput" && @pythonCheckInterpreter@ -c 'import sys; import importlib; list(map(lambda mod: importlib.import_module(mod), sys.argv[1:]))' ${pythonImportsCheck[*]}) 22 fi 23} 24 25if [[ -z "${dontUsePythonImportsCheck-}" ]]; then 26 echo "Using pythonImportsCheckPhase" 27 appendToVar preDistPhases pythonImportsCheckPhase 28fi