From 912aaaa9cfc9449feabb4239276cfd5c09628638 Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Thu, 2 Mar 2023 23:35:00 +0800 Subject: [PATCH] python: Unset Python environment variables This will prevent the user's environment variables from affecting host Python, removing the need to manually override these variables. It is also not necessary to set PYTHONPATH (when not working on target Python packages) because the given directories are already included in Python's search path by default. Signed-off-by: Jeffery To (cherry picked from commit 6ef46bb9194b5d3f5fc17471d8869bcae729d215) --- lang/python/python3-host.mk | 50 +++++++++++++++++++++++++++++++--- lang/python/python3-package.mk | 1 - 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lang/python/python3-host.mk b/lang/python/python3-host.mk index 9366b78d9e..fa3d3ace37 100644 --- a/lang/python/python3-host.mk +++ b/lang/python/python3-host.mk @@ -12,6 +12,51 @@ python3_mk_path:=$(dir $(lastword $(MAKEFILE_LIST))) include $(python3_mk_path)python3-version.mk +# Unset environment variables + +# https://docs.python.org/3/using/cmdline.html#environment-variables +unexport \ + PYTHONHOME \ + PYTHONPATH \ + PYTHONSAFEPATH \ + PYTHONPLATLIBDIR \ + PYTHONSTARTUP \ + PYTHONOPTIMIZE \ + PYTHONBREAKPOINT \ + PYTHONDEBUG \ + PYTHONINSPECT \ + PYTHONUNBUFFERED \ + PYTHONVERBOSE \ + PYTHONCASEOK \ + PYTHONDONTWRITEBYTECODE \ + PYTHONPYCACHEPREFIX \ + PYTHONHASHSEED \ + PYTHONINTMAXSTRDIGITS \ + PYTHONIOENCODING \ + PYTHONNOUSERSITE \ + PYTHONUSERBASE \ + PYTHONEXECUTABLE \ + PYTHONWARNINGS \ + PYTHONFAULTHANDLER \ + PYTHONTRACEMALLOC \ + PYTHONPROFILEIMPORTTIME \ + PYTHONASYNCIODEBUG \ + PYTHONMALLOC \ + PYTHONMALLOCSTATS \ + PYTHONLEGACYWINDOWSFSENCODING \ + PYTHONLEGACYWINDOWSSTDIO \ + PYTHONCOERCECLOCALE \ + PYTHONDEVMODE \ + PYTHONUTF8 \ + PYTHONWARNDEFAULTENCODING \ + PYTHONNODEBUGRANGES + +# https://docs.python.org/3/using/cmdline.html#debug-mode-variables +unexport \ + PYTHONTHREADDEBUG \ + PYTHONDUMPREFS \ + PYTHONDUMPREFSFILE + HOST_PYTHON3_DIR:=$(STAGING_DIR_HOSTPKG) HOST_PYTHON3_INC_DIR:=$(HOST_PYTHON3_DIR)/include/python$(PYTHON3_VERSION) HOST_PYTHON3_LIB_DIR:=$(HOST_PYTHON3_DIR)/lib/python$(PYTHON3_VERSION) @@ -31,10 +76,7 @@ HOST_PYTHON3_VARS = \ LDSHARED="$(HOSTCC) -shared" \ CFLAGS="$(HOST_CFLAGS)" \ CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON3_INC_DIR)" \ - LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON3_VERSION) -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib" \ - PYTHONPATH="$(HOST_PYTHON3PATH)" \ - PYTHONDONTWRITEBYTECODE=0 \ - PYTHONOPTIMIZE="" + LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON3_VERSION) -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib" # $(1) => directory of python script # $(2) => python script and its arguments diff --git a/lang/python/python3-package.mk b/lang/python/python3-package.mk index c2617f69ce..4b5698c393 100644 --- a/lang/python/python3-package.mk +++ b/lang/python/python3-package.mk @@ -42,7 +42,6 @@ PYTHON3_VARS = \ __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \ PYTHONPATH="$(PYTHON3PATH)" \ PYTHONDONTWRITEBYTECODE=1 \ - PYTHONOPTIMIZE="" \ _python_sysroot="$(STAGING_DIR)" \ _python_prefix="/usr" \ _python_exec_prefix="/usr" -- 2.30.2