Python: add sitecustomize.py, listen to NIX_PYTHONPATH

This commit adds a Nix-specific module that recursively adds paths that
are on `NIX_PYTHONPATH` to `sys.path`. In order to process possible
`.pth` files `site.addsitedir` is used.

The paths listed in `PYTHONPATH` are added to `sys.path` afterwards, but
they will be added before the entries we add here and thus take
precedence.

The reason for adding support for this environment variable is that we
can set it in a wrapper without breaking support for `PYTHONPATH`.
This commit is contained in:
Frederik Rietdijk
2017-05-22 11:01:00 +02:00
committed by Frederik Rietdijk
parent 02afb228e2
commit 46409b5c32
5 changed files with 33 additions and 0 deletions

View File

@@ -221,6 +221,9 @@ in with passthru; stdenv.mkDerivation {
find $out/lib/python*/config-* -type f -print -exec nuke-refs -e $out '{}' +
find $out/lib -name '_sysconfigdata*.py*' -print -exec nuke-refs -e $out '{}' +
# Include a sitecustomize.py file
cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
# Determinism: rebuild all bytecode
# We exclude lib2to3 because that's Python 2 code which fails
# We rebuild three times, once for each optimization level