0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-14 14:10:33 +03:00

Python: introduce NIX_PYTHONEXECUTABLE in order to set sys.executable

This is needed in case of `python.buildEnv` to make sure sys.executable
does not point to the unwrapped executable.
This commit is contained in:
Frederik Rietdijk 2019-07-27 09:30:34 +02:00 committed by Frederik Rietdijk
parent c9793b81b8
commit bd47c5721f
2 changed files with 10 additions and 1 deletions

View file

@ -8,11 +8,19 @@ 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.
Note the `NIX_PYTHONPATH` environment variable is unset in order to prevent leakage.
Similarly, this module listens to the environment variable `NIX_PYTHONEXECUTABLE`
and sets `sys.executable` to its value.
"""
import site
import sys
import os
import functools
paths = os.environ.pop('NIX_PYTHONPATH', None)
if paths:
functools.reduce(lambda k, p: site.addsitedir(p, k), paths.split(':'), site._init_pathinfo())
executable = os.environ.pop('NIX_PYTHONEXECUTABLE', None)
if 'PYTHONEXECUTABLE' not in os.environ and executable:
sys.executable = executable