lol

pythonNamespacesHook: lint with ShellCheck

+12 -6
+12 -6
pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh
··· 1 1 # Clean up __init__.py's found in namespace directories 2 + # shellcheck shell=bash 3 + 2 4 echo "Sourcing python-namespaces-hook" 3 5 4 6 pythonNamespacesHook() { 5 7 echo "Executing pythonNamespacesHook" 6 8 7 - for namespace in ${pythonNamespaces[@]}; do 9 + # Python namespaces names are Python identifiers, which must not contain spaces. 10 + # See https://docs.python.org/3/reference/lexical_analysis.html 11 + # shellcheck disable=SC2048 12 + for namespace in ${pythonNamespaces[*]-}; do 8 13 echo "Enforcing PEP420 namespace: ${namespace}" 9 14 10 15 # split namespace into segments. "azure.mgmt" -> "azure mgmt" 11 - IFS='.' read -ra pathSegments <<<$namespace 16 + IFS='.' read -ra pathSegments <<<"$namespace" 17 + # shellcheck disable=SC2154 12 18 constructedPath=$out/@pythonSitePackages@ 13 19 14 20 # Need to remove the __init__.py at each namespace level 15 21 # E.g `azure/__init__.py` and `azure/mgmt/__init__.py` 16 22 # The __pycache__ entry also needs to be removed 17 - for pathSegment in ${pathSegments[@]}; do 23 + for pathSegment in "${pathSegments[@]}"; do 18 24 constructedPath=${constructedPath}/${pathSegment} 19 25 pathToRemove=${constructedPath}/__init__.py 20 26 pycachePath=${constructedPath}/__pycache__/ ··· 30 36 # event of a "meta-package" package, which will just install 31 37 # other packages, but not produce anything in site-packages 32 38 # besides meta information 33 - if [ -d "${constructedPath}/../" -a -z ${dontRemovePth-} ]; then 39 + if [[ -d "${constructedPath}/../" ]] && [[ -z "${dontRemovePth-}" ]]; then 34 40 # .pth files are located in the parent directory of a module 35 - @findutils@/bin/find ${constructedPath}/../ -name '*-nspkg.pth' -exec rm -v "{}" + 41 + @findutils@/bin/find "${constructedPath}/../" -name '*-nspkg.pth' -exec rm -v "{}" + 36 42 fi 37 43 38 44 # remove __pycache__/ entry, can be interpreter specific. E.g. __init__.cpython-38.pyc ··· 46 52 echo "Finished executing pythonNamespacesHook" 47 53 } 48 54 49 - if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then 55 + if [[ -z "${dontUsePythonNamespacesHook-}" ]] && [[ -n "${pythonNamespaces-}" ]]; then 50 56 postFixupHooks+=(pythonNamespacesHook) 51 57 fi