Add flag to disable PYTHONNOUSERSITE for wrapped python binaries

This commit is contained in:
Tom McLaughlin 2018-11-21 23:20:38 -07:00
parent 91047d75e1
commit 0045164b15
2 changed files with 8 additions and 1 deletions

View File

@ -46,6 +46,9 @@
# Skip wrapping of python programs altogether
, dontWrapPythonPrograms ? false
# Skip setting the PYTHONNOUSERSITE environment variable in wrapped programs
, skipNoUserSite ? false
# Remove bytecode from bin folder.
# When a Python script has the extension `.py`, bytecode is generated
# Typically, executables in bin have no extension, so no bytecode is generated.
@ -93,6 +96,7 @@ 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

@ -73,9 +73,12 @@ wrapPythonProgramsIn() {
# (see pkgs/build-support/setup-hooks/make-wrapper.sh)
local -a wrap_args=("$f"
--prefix PATH ':' "$program_PATH"
--set PYTHONNOUSERSITE "true"
)
if [ -z "$SKIPNOUSERSITE" ]; then
wrap_args+=(--set PYTHONNOUSERSITE "true")
fi
# Add any additional arguments provided by makeWrapperArgs
# argument to buildPythonPackage.
local -a user_args="($makeWrapperArgs)"