nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

python3{5,6}: Reintroduce bytecode determinism

Originally introduced in 8970a9c and 1531b5e, these patches were lost in
efbe87f when the CPython version files were merged, likely due to
CPython 3.7 not needing them anymore. These patches should remain
in-tree until CPython 3.5 and 3.6 support is dropped completely.

Found with the diffoscope ( https://diffoscope.org/ ).

authored by bb010g.com and committed by

Frederik Rietdijk 28ac3093 e53ade7d

+22 -2
+17
pkgs/development/interpreters/python/cpython/3.5/force_bytecode_determinism.patch
··· 1 + --- a/Lib/py_compile.py 2 + +++ b/Lib/py_compile.py 3 + @@ -139,3 +139,4 @@ 4 + source_stats = loader.path_stats(file) 5 + + source_mtime = 1 if 'DETERMINISTIC_BUILD' in os.environ else source_stats['mtime'] 6 + bytecode = importlib._bootstrap_external._code_to_bytecode( 7 + - code, source_stats['mtime'], source_stats['size']) 8 + + code, source_mtime, source_stats['size']) 9 + --- a/Lib/importlib/_bootstrap_external.py 10 + +++ b/Lib/importlib/_bootstrap_external.py 11 + @@ -485,5 +485,5 @@ 12 + if source_stats is not None: 13 + try: 14 + - source_mtime = int(source_stats['mtime']) 15 + + source_mtime = 1 16 + except KeyError: 17 + pass
+5 -2
pkgs/development/interpreters/python/cpython/default.nix
··· 87 87 # (since it will do a futile invocation of gcc (!) to find 88 88 # libuuid, slowing down program startup a lot). 89 89 (./. + "/${sourceVersion.major}.${sourceVersion.minor}/no-ldconfig.patch") 90 + ] ++ optionals (isPy35 || isPy36) [ 91 + # Determinism: Write null timestamps when compiling python files. 92 + ./3.5/force_bytecode_determinism.patch 90 93 ] ++ optionals isPy35 [ 91 94 # Backports support for LD_LIBRARY_PATH from 3.6 92 95 ./3.5/ld_library_path.patch ··· 171 168 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -msse2" 172 169 export MACOSX_DEPLOYMENT_TARGET=10.6 173 170 '' + optionalString (isPy3k && pythonOlder "3.7") '' 174 - # Determinism: The interpreter is patched to write null timestamps when compiling python files. 175 - # This way python does not try to update them when we freeze timestamps in nix store. 171 + # Determinism: The interpreter is patched to write null timestamps when compiling Python files 172 + # so Python doesn't try to update the bytecode when seeing frozen timestamps in Nix's store. 176 173 export DETERMINISTIC_BUILD=1; 177 174 '' + optionalString stdenv.hostPlatform.isMusl '' 178 175 export NIX_CFLAGS_COMPILE+=" -DTHREAD_STACK_SIZE=0x100000"