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 , dontWrapPythonPrograms ? false
# Skip setting the PYTHONNOUSERSITE environment variable in wrapped programs # Skip setting the PYTHONNOUSERSITE environment variable in wrapped programs
, skipNoUserSite ? false , permitUserSite ? false
# Remove bytecode from bin folder. # Remove bytecode from bin folder.
# When a Python script has the extension `.py`, bytecode is generated # 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; installCheckInputs = checkInputs;
postFixup = lib.optionalString (!dontWrapPythonPrograms) '' postFixup = lib.optionalString (!dontWrapPythonPrograms) ''
${if skipNoUserSite then "export SKIPNOUSERSITE=1" else ""}
wrapPythonPrograms wrapPythonPrograms
'' + lib.optionalString removeBinBytecode '' '' + lib.optionalString removeBinBytecode ''
if [ -d "$out/bin" ]; then if [ -d "$out/bin" ]; then

View File

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

View File

@ -3,6 +3,7 @@
, extraOutputsToInstall ? [] , extraOutputsToInstall ? []
, postBuild ? "" , postBuild ? ""
, ignoreCollisions ? false , ignoreCollisions ? false
, permitUserSite ? false
, requiredPythonModules , requiredPythonModules
# Wrap executables with the given argument. # Wrap executables with the given argument.
, makeWrapperArgs ? [] , makeWrapperArgs ? []
@ -34,7 +35,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 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
fi fi
done done