about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2020-04-27 21:04:56 +0000
committerAlyssa Ross <hi@alyssa.is>2020-04-27 21:04:56 +0000
commita4e6c7d26af697f4346cacb7ab18dcd7fcfc056e (patch)
tree47950e79183035018882419c4eff5047d1537b99 /nixpkgs/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh
parent5b00523fb58512232b819a301c4309f579c7f09c (diff)
parent22a3bf9fb9edad917fb6cd1066d58b5e426ee975 (diff)
downloadnixlib-a4e6c7d26af697f4346cacb7ab18dcd7fcfc056e.tar
nixlib-a4e6c7d26af697f4346cacb7ab18dcd7fcfc056e.tar.gz
nixlib-a4e6c7d26af697f4346cacb7ab18dcd7fcfc056e.tar.bz2
nixlib-a4e6c7d26af697f4346cacb7ab18dcd7fcfc056e.tar.lz
nixlib-a4e6c7d26af697f4346cacb7ab18dcd7fcfc056e.tar.xz
nixlib-a4e6c7d26af697f4346cacb7ab18dcd7fcfc056e.tar.zst
nixlib-a4e6c7d26af697f4346cacb7ab18dcd7fcfc056e.zip
Merge commit '22a3bf9fb9edad917fb6cd1066d58b5e426ee975'
Diffstat (limited to 'nixpkgs/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh')
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh b/nixpkgs/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh
new file mode 100644
index 000000000000..50f21819d176
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh
@@ -0,0 +1,40 @@
+# 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
+            pycachePath=${constructedPath}/__pycache__/__init__*
+
+            if [ -f "$pathToRemove" ]; then
+                echo "Removing $pathToRemove"
+                rm "$pathToRemove"
+            fi
+
+            if [ -f "$pycachePath" ]; then
+                echo "Removing $pycachePath"
+                rm "$pycachePath"
+            fi
+        done
+    done
+
+    echo "Finished executing pythonNamespacesHook"
+}
+
+if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then
+    postFixupHooks+=(pythonNamespacesHook)
+fi
+