···
# Clean up __init__.py's found in namespace directories
2
+
# shellcheck shell=bash
echo "Sourcing python-namespaces-hook"
echo "Executing pythonNamespacesHook"
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
echo "Enforcing PEP420 namespace: ${namespace}"
# split namespace into segments. "azure.mgmt" -> "azure mgmt"
11
-
IFS='.' read -ra pathSegments <<<$namespace
16
+
IFS='.' read -ra pathSegments <<<"$namespace"
17
+
# shellcheck disable=SC2154
constructedPath=$out/@pythonSitePackages@
# Need to remove the __init__.py at each namespace level
# E.g `azure/__init__.py` and `azure/mgmt/__init__.py`
# The __pycache__ entry also needs to be removed
17
-
for pathSegment in ${pathSegments[@]}; do
23
+
for pathSegment in "${pathSegments[@]}"; do
constructedPath=${constructedPath}/${pathSegment}
pathToRemove=${constructedPath}/__init__.py
pycachePath=${constructedPath}/__pycache__/
···
# event of a "meta-package" package, which will just install
# other packages, but not produce anything in site-packages
# besides meta information
33
-
if [ -d "${constructedPath}/../" -a -z ${dontRemovePth-} ]; then
39
+
if [[ -d "${constructedPath}/../" ]] && [[ -z "${dontRemovePth-}" ]]; then
# .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 "{}" +
# remove __pycache__/ entry, can be interpreter specific. E.g. __init__.cpython-38.pyc
···
echo "Finished executing pythonNamespacesHook"
49
-
if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then
55
+
if [[ -z "${dontUsePythonNamespacesHook-}" ]] && [[ -n "${pythonNamespaces-}" ]]; then
postFixupHooks+=(pythonNamespacesHook)