summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2024-07-31 09:46:21 +0200
committerMichał Górny <mgorny@gentoo.org>2024-08-06 10:30:08 +0200
commit9b1ccc14f4a6e9b6c614a4c5f5d6ec15f6339d64 (patch)
tree2241118f1dad513cdbc46481fbbf311244e0886d /eclass/python-utils-r1.eclass
parentdistutils-r1.eclass: Fix disabling DISTUTILS_ALLOW_WHEEL_REUSE (diff)
downloadgentoo-9b1ccc14f4a6e9b6c614a4c5f5d6ec15f6339d64.tar.gz
gentoo-9b1ccc14f4a6e9b6c614a4c5f5d6ec15f6339d64.tar.bz2
gentoo-9b1ccc14f4a6e9b6c614a4c5f5d6ec15f6339d64.zip
python-utils-r1.eclass: Add a sanity check for PYTHONPATH
Add a sanity check that ensures that PYTHONPATH does not contain any relative paths. While at it, also explicitly warn about PYTHONPATH being set, so we know about it in build logs. Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass/python-utils-r1.eclass')
-rw-r--r--eclass/python-utils-r1.eclass34
1 files changed, 34 insertions, 0 deletions
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index c47565fa1db2..cc33a1c1bffd 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1544,4 +1544,38 @@ python_has_version() {
return 0
}
+# @FUNCTION: _python_sanity_checks
+# @INTERNAL
+# @DESCRIPTION:
+# Perform additional environment sanity checks.
+_python_sanity_checks() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ${_PYTHON_SANITY_CHECKED} ]] && return
+
+ if [[ -v PYTHONPATH ]]; then
+ local x paths=()
+ mapfile -d ':' -t paths <<<${PYTHONPATH}
+
+ for x in "${paths[@]}"; do
+ if [[ ${x} != /* ]]; then
+ eerror "Relative path found in PYTHONPATH:"
+ eerror
+ eerror " PYTHONPATH=${PYTHONPATH@Q}"
+ eerror
+ eerror "This is guaranteed to cause random breakage. Please make sure that"
+ eerror "your PYTHONPATH contains absolute paths only (and only if necessary)."
+ eerror "Note that empty values (including ':' at either end and an empty"
+ eerror "PYTHONPATH) count as the current directory. If no PYTHONPATH"
+ eerror "is intended, it needs to be unset instead."
+ die "Relative paths in PYTHONPATH are forbidden: ${x@Q}"
+ fi
+ done
+
+ elog "PYTHONPATH=${PYTHONPATH@Q}"
+ fi
+
+ _PYTHON_SANITY_CHECKED=1
+}
+
fi