at 22.05-pre 1.5 kB view raw
1# Clean up __init__.py's found in namespace directories 2echo "Sourcing python-namespaces-hook" 3 4pythonNamespacesHook() { 5 echo "Executing pythonNamespacesHook" 6 7 for namespace in ${pythonNamespaces[@]}; do 8 echo "Enforcing PEP420 namespace: ${namespace}" 9 10 # split namespace into segments. "azure.mgmt" -> "azure mgmt" 11 IFS='.' read -ra pathSegments <<< $namespace 12 constructedPath=$out/@pythonSitePackages@ 13 14 # Need to remove the __init__.py at each namespace level 15 # E.g `azure/__init__.py` and `azure/mgmt/__init__.py` 16 # The __pycache__ entry also needs to be removed 17 for pathSegment in ${pathSegments[@]}; do 18 constructedPath=${constructedPath}/${pathSegment} 19 pathToRemove=${constructedPath}/__init__.py 20 pycachePath=${constructedPath}/__pycache__/ 21 22 # remove __init__.py 23 if [ -f "$pathToRemove" ]; then 24 rm -v "$pathToRemove" 25 fi 26 27 # remove __pycache__/ entry, can be interpreter specific. E.g. __init__.cpython-38.pyc 28 # use null characters to perserve potential whitespace in filepath 29 if [ -d "$pycachePath" ]; then 30 @findutils@/bin/find "$pycachePath" -name '__init__*' -exec rm -v "{}" + 31 fi 32 done 33 done 34 35 echo "Finished executing pythonNamespacesHook" 36} 37 38if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then 39 postFixupHooks+=(pythonNamespacesHook) 40fi 41