From f5d9dd30509548a4a22dadba66dc1799e7140724 Mon Sep 17 00:00:00 2001 From: Jonathan Ringer Date: Fri, 20 Nov 2020 10:51:07 -0800 Subject: [PATCH] python/hooks/pythonNamespaces: fix __pycache__ logic --- .../interpreters/python/hooks/default.nix | 3 ++- .../python/hooks/python-namespaces-hook.sh | 13 ++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix index 456aea4c5d8..1a64c79232b 100644 --- a/pkgs/development/interpreters/python/hooks/default.nix +++ b/pkgs/development/interpreters/python/hooks/default.nix @@ -5,6 +5,7 @@ , disabledIf , isPy3k , ensureNewerSourcesForZipFilesHook +, findutils }: let @@ -94,7 +95,7 @@ in rec { makeSetupHook { name = "python-namespaces-hook.sh"; substitutions = { - inherit pythonSitePackages; + inherit pythonSitePackages findutils; }; } ./python-namespaces-hook.sh) {}; diff --git a/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh b/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh index 50f21819d17..ebc94e076c8 100644 --- a/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh +++ b/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh @@ -17,17 +17,16 @@ pythonNamespacesHook() { for pathSegment in ${pathSegments[@]}; do constructedPath=${constructedPath}/${pathSegment} pathToRemove=${constructedPath}/__init__.py - pycachePath=${constructedPath}/__pycache__/__init__* + pycachePath=${constructedPath}/__pycache__/ + # remove __init__.py if [ -f "$pathToRemove" ]; then - echo "Removing $pathToRemove" - rm "$pathToRemove" + rm -v "$pathToRemove" fi - if [ -f "$pycachePath" ]; then - echo "Removing $pycachePath" - rm "$pycachePath" - fi + # remove __pycache__/ entry, can be interpreter specific. E.g. __init__.cpython-38.pyc + # use null characters to perserve potential whitespace in filepath + @findutils@/bin/find $pycachePath -name '__init__*' -print0 | xargs -0 rm -v done done