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:
parent
c9793b81b8
commit
bd47c5721f
@ -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.
|
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.
|
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 site
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
paths = os.environ.pop('NIX_PYTHONPATH', None)
|
paths = os.environ.pop('NIX_PYTHONPATH', None)
|
||||||
if paths:
|
if paths:
|
||||||
functools.reduce(lambda k, p: site.addsitedir(p, k), paths.split(':'), site._init_pathinfo())
|
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
|
||||||
|
@ -14,6 +14,7 @@ let
|
|||||||
env = let
|
env = let
|
||||||
paths = requiredPythonModules (extraLibs ++ [ python ] ) ;
|
paths = requiredPythonModules (extraLibs ++ [ python ] ) ;
|
||||||
pythonPath = "${placeholder "out"}/${python.sitePackages}";
|
pythonPath = "${placeholder "out"}/${python.sitePackages}";
|
||||||
|
pythonExecutable = "${placeholder "out"}/bin/${python.executable}";
|
||||||
in buildEnv {
|
in buildEnv {
|
||||||
name = "${python.name}-env";
|
name = "${python.name}-env";
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ let
|
|||||||
if [ -f "$prg" ]; then
|
if [ -f "$prg" ]; then
|
||||||
rm -f "$out/bin/$prg"
|
rm -f "$out/bin/$prg"
|
||||||
if [ -x "$prg" ]; then
|
if [ -x "$prg" ]; then
|
||||||
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONPATH ${pythonPath} ${if permitUserSite then "" else ''--set PYTHONNOUSERSITE "true"''} ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
|
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONEXECUTABLE ${pythonExecutable} --set NIX_PYTHONPATH ${pythonPath} ${if permitUserSite then "" else ''--set PYTHONNOUSERSITE "true"''} ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user