1# Setup hook for recompiling bytecode.
2# https://github.com/NixOS/nixpkgs/issues/81441
3echo "Sourcing python-recompile-bytecode-hook.sh"
4
5# Remove all bytecode from the $out output. Then, recompile only site packages folder
6# Note this effectively duplicates `python-remove-bin-bytecode`, but long-term
7# this hook should be removed again.
8
9pythonRecompileBytecodePhase() {
10 # TODO: consider other outputs than $out
11
12 items="$(find "$out" -name "@bytecodeName@")"
13 if [[ -n $items ]]; then
14 for pycache in $items; do
15 rm -rf "$pycache"
16 done
17 fi
18
19 find "$out"/@pythonSitePackages@ -name "*.py" -exec @pythonInterpreter@ -OO -m compileall @compileArgs@ {} +
20}
21
22if [ -z "${dontUsePythonRecompileBytecode-}" ]; then
23 appendToVar postPhases pythonRecompileBytecodePhase
24fi