2020-03-17 21:29:47 +00:00
|
|
|
# Clean up __init__.py's found in namespace directories
|
|
|
|
echo "Sourcing python-namespaces-hook"
|
|
|
|
|
|
|
|
pythonNamespacesHook() {
|
|
|
|
echo "Executing pythonNamespacesHook"
|
|
|
|
|
|
|
|
for namespace in ${pythonNamespaces[@]}; do
|
|
|
|
echo "Enforcing PEP420 namespace: ${namespace}"
|
|
|
|
|
|
|
|
# split namespace into segments. "azure.mgmt" -> "azure mgmt"
|
|
|
|
IFS='.' read -ra pathSegments <<< $namespace
|
|
|
|
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
|
|
|
|
for pathSegment in ${pathSegments[@]}; do
|
|
|
|
constructedPath=${constructedPath}/${pathSegment}
|
|
|
|
pathToRemove=${constructedPath}/__init__.py
|
2020-11-20 18:51:07 +00:00
|
|
|
pycachePath=${constructedPath}/__pycache__/
|
2020-03-17 21:29:47 +00:00
|
|
|
|
2020-11-20 18:51:07 +00:00
|
|
|
# remove __init__.py
|
2020-03-17 21:29:47 +00:00
|
|
|
if [ -f "$pathToRemove" ]; then
|
2020-11-20 18:51:07 +00:00
|
|
|
rm -v "$pathToRemove"
|
2020-03-17 21:29:47 +00:00
|
|
|
fi
|
|
|
|
|
2021-11-29 21:51:20 +00:00
|
|
|
# remove ${pname}-${version}-${python-interpeter}-nspkg.pth
|
2021-11-30 17:13:52 +00:00
|
|
|
#
|
|
|
|
# Still need to check that parent directory exists in the
|
|
|
|
# event of a "meta-package" package, which will just install
|
|
|
|
# other packages, but not produce anything in site-packages
|
|
|
|
# besides meta information
|
|
|
|
if [ -d "${constructedPath}/../" -a -z ${dontRemovePth-} ]; then
|
2021-11-29 21:51:20 +00:00
|
|
|
# .pth files are located in the parent directory of a module
|
|
|
|
@findutils@/bin/find ${constructedPath}/../ -name '*-nspkg.pth' -exec rm -v "{}" +
|
|
|
|
fi
|
|
|
|
|
2020-11-20 18:51:07 +00:00
|
|
|
# remove __pycache__/ entry, can be interpreter specific. E.g. __init__.cpython-38.pyc
|
|
|
|
# use null characters to perserve potential whitespace in filepath
|
2020-11-26 21:51:05 +00:00
|
|
|
if [ -d "$pycachePath" ]; then
|
|
|
|
@findutils@/bin/find "$pycachePath" -name '__init__*' -exec rm -v "{}" +
|
|
|
|
fi
|
2020-03-17 21:29:47 +00:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Finished executing pythonNamespacesHook"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then
|
|
|
|
postFixupHooks+=(pythonNamespacesHook)
|
|
|
|
fi
|
|
|
|
|