Add flag to disable PYTHONNOUSERSITE for wrapped binaries in python environments

This commit is contained in:
Tom McLaughlin 2018-12-06 15:18:59 -08:00
parent 0045164b15
commit a3f24daa7b
3 changed files with 4 additions and 4 deletions

View File

@ -47,7 +47,7 @@
, dontWrapPythonPrograms ? false
# Skip setting the PYTHONNOUSERSITE environment variable in wrapped programs
, skipNoUserSite ? false
, permitUserSite ? false
# Remove bytecode from bin folder.
# When a Python script has the extension `.py`, bytecode is generated
@ -96,7 +96,6 @@ let self = toPythonModule (python.stdenv.mkDerivation (builtins.removeAttrs attr
installCheckInputs = checkInputs;
postFixup = lib.optionalString (!dontWrapPythonPrograms) ''
${if skipNoUserSite then "export SKIPNOUSERSITE=1" else ""}
wrapPythonPrograms
'' + lib.optionalString removeBinBytecode ''
if [ -d "$out/bin" ]; then

View File

@ -75,7 +75,7 @@ wrapPythonProgramsIn() {
--prefix PATH ':' "$program_PATH"
)
if [ -z "$SKIPNOUSERSITE" ]; then
if [ -z "$permitUserSite" ]; then
wrap_args+=(--set PYTHONNOUSERSITE "true")
fi

View File

@ -3,6 +3,7 @@
, extraOutputsToInstall ? []
, postBuild ? ""
, ignoreCollisions ? false
, permitUserSite ? false
, requiredPythonModules
# Wrap executables with the given argument.
, makeWrapperArgs ? []
@ -34,7 +35,7 @@ let
if [ -f "$prg" ]; then
rm -f "$out/bin/$prg"
if [ -x "$prg" ]; then
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out" --set PYTHONNOUSERSITE "true" ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out" ${if permitUserSite then "" else ''--set PYTHONNOUSERSITE "true"''} ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
fi
fi
done