nixpkgs/pkgs/development/interpreters/python/hooks/python-recompile-bytecode-hook.sh
Frederik Rietdijk 818cf7827b buildPythonPackage: recompile bytecode for reproducibility
Due to a change in pip the unpacked wheels are no longer reproducible.
We recompile the bytecode to cleanup this error.
https://github.com/NixOS/nixpkgs/issues/81441
2020-06-13 10:36:28 +02:00

25 lines
805 B
Bash

# 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