aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/pkgs/development/interpreters/python/hooks/python-recompile-bytecode-hook.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/interpreters/python/hooks/python-recompile-bytecode-hook.sh')
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/hooks/python-recompile-bytecode-hook.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/interpreters/python/hooks/python-recompile-bytecode-hook.sh b/nixpkgs/pkgs/development/interpreters/python/hooks/python-recompile-bytecode-hook.sh
new file mode 100644
index 00000000000..649d0c17ea0
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/hooks/python-recompile-bytecode-hook.sh
@@ -0,0 +1,24 @@
+# Setup hook for recompiling bytecode.
+# https://github.com/NixOS/nixpkgs/issues/81441
+echo "Sourcing python-recompile-bytecode-hook.sh"
+
+# Remove all bytecode from the $out output. Then, recompile only site packages folder
+# Note this effectively duplicates `python-remove-bin-bytecode`, but long-term
+# this hook should be removed again.
+
+pythonRecompileBytecodePhase () {
+ # TODO: consider other outputs than $out
+
+ items="$(find "$out" -name "@bytecodeName@")"
+ if [[ -n $items ]]; then
+ for pycache in $items; do
+ rm -rf "$pycache"
+ done
+ fi
+
+ find "$out"/@pythonSitePackages@ -name "*.py" -exec @pythonInterpreter@ -OO -m compileall @compileArgs@ {} +
+}
+
+if [ -z "${dontUsePythonRecompileBytecode-}" ]; then
+ postPhases+=" pythonRecompileBytecodePhase"
+fi