···11# Clean up __init__.py's found in namespace directories
22+# shellcheck shell=bash
33+24echo "Sourcing python-namespaces-hook"
3546pythonNamespacesHook() {
57 echo "Executing pythonNamespacesHook"
6877- for namespace in ${pythonNamespaces[@]}; do
99+ # Python namespaces names are Python identifiers, which must not contain spaces.
1010+ # See https://docs.python.org/3/reference/lexical_analysis.html
1111+ # shellcheck disable=SC2048
1212+ for namespace in ${pythonNamespaces[*]-}; do
813 echo "Enforcing PEP420 namespace: ${namespace}"
9141015 # split namespace into segments. "azure.mgmt" -> "azure mgmt"
1111- IFS='.' read -ra pathSegments <<<$namespace
1616+ IFS='.' read -ra pathSegments <<<"$namespace"
1717+ # shellcheck disable=SC2154
1218 constructedPath=$out/@pythonSitePackages@
13191420 # Need to remove the __init__.py at each namespace level
1521 # E.g `azure/__init__.py` and `azure/mgmt/__init__.py`
1622 # The __pycache__ entry also needs to be removed
1717- for pathSegment in ${pathSegments[@]}; do
2323+ for pathSegment in "${pathSegments[@]}"; do
1824 constructedPath=${constructedPath}/${pathSegment}
1925 pathToRemove=${constructedPath}/__init__.py
2026 pycachePath=${constructedPath}/__pycache__/
···3036 # event of a "meta-package" package, which will just install
3137 # other packages, but not produce anything in site-packages
3238 # besides meta information
3333- if [ -d "${constructedPath}/../" -a -z ${dontRemovePth-} ]; then
3939+ if [[ -d "${constructedPath}/../" ]] && [[ -z "${dontRemovePth-}" ]]; then
3440 # .pth files are located in the parent directory of a module
3535- @findutils@/bin/find ${constructedPath}/../ -name '*-nspkg.pth' -exec rm -v "{}" +
4141+ @findutils@/bin/find "${constructedPath}/../" -name '*-nspkg.pth' -exec rm -v "{}" +
3642 fi
37433844 # remove __pycache__/ entry, can be interpreter specific. E.g. __init__.cpython-38.pyc
···4652 echo "Finished executing pythonNamespacesHook"
4753}
48544949-if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then
5555+if [[ -z "${dontUsePythonNamespacesHook-}" ]] && [[ -n "${pythonNamespaces-}" ]]; then
5056 postFixupHooks+=(pythonNamespacesHook)
5157fi