at 23.11-beta 2.1 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 ${pname}-${version}-${python-interpeter}-nspkg.pth 28 # 29 # Still need to check that parent directory exists in the 30 # event of a "meta-package" package, which will just install 31 # other packages, but not produce anything in site-packages 32 # besides meta information 33 if [ -d "${constructedPath}/../" -a -z ${dontRemovePth-} ]; then 34 # .pth files are located in the parent directory of a module 35 @findutils@/bin/find ${constructedPath}/../ -name '*-nspkg.pth' -exec rm -v "{}" + 36 fi 37 38 # remove __pycache__/ entry, can be interpreter specific. E.g. __init__.cpython-38.pyc 39 # use null characters to perserve potential whitespace in filepath 40 if [ -d "$pycachePath" ]; then 41 @findutils@/bin/find "$pycachePath" -name '__init__*' -exec rm -v "{}" + 42 fi 43 done 44 done 45 46 echo "Finished executing pythonNamespacesHook" 47} 48 49if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then 50 postFixupHooks+=(pythonNamespacesHook) 51fi 52