Skip to content

Commit ff7f7d4

Browse files
committed
eclass/python-utils-r1: sync with gx86
Signed-off-by: Fabian Groffen <[email protected]>
1 parent 03176f2 commit ff7f7d4

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

eclass/python-utils-r1.eclass

+69-2
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,17 @@ _python_export() {
340340
fi
341341
debug-print "${FUNCNAME}: PYTHON = ${PYTHON}"
342342
;;
343+
PYTHON_STDLIB)
344+
[[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
345+
PYTHON_STDLIB=$(
346+
"${PYTHON}" - "${EPREFIX}/usr" <<-EOF || die
347+
import sys, sysconfig
348+
print(sysconfig.get_path("stdlib", vars={"installed_base": sys.argv[1]}))
349+
EOF
350+
)
351+
export PYTHON_STDLIB
352+
debug-print "${FUNCNAME}: PYTHON_STDLIB = ${PYTHON_STDLIB}"
353+
;;
343354
PYTHON_SITEDIR)
344355
[[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
345356
PYTHON_SITEDIR=$(
@@ -482,6 +493,18 @@ _python_export() {
482493
done
483494
}
484495

496+
# @FUNCTION: python_get_stdlib
497+
# @USAGE: [<impl>]
498+
# @DESCRIPTION:
499+
# Obtain and print the 'stdlib' path for the given implementation. If no
500+
# implementation is provided, ${EPYTHON} will be used.
501+
python_get_stdlib() {
502+
debug-print-function ${FUNCNAME} "${@}"
503+
504+
_python_export "${@}" PYTHON_STDLIB
505+
echo "${PYTHON_STDLIB}"
506+
}
507+
485508
# @FUNCTION: python_get_sitedir
486509
# @USAGE: [<impl>]
487510
# @DESCRIPTION:
@@ -1337,6 +1360,15 @@ _python_check_occluded_packages() {
13371360
# Specifies the number of jobs for parallel (pytest-xdist) test runs.
13381361
# When unset, defaults to -j from MAKEOPTS, or the current nproc.
13391362

1363+
# @ECLASS_VARIABLE: EPYTEST_FLAGS
1364+
# @USER_VARIABLE
1365+
# @DEFAULT_UNSET
1366+
# @DESCRIPTION:
1367+
# Additional flags to pass to pytest. This is intended to be set
1368+
# in the environment when debugging packages (options such as -x or -s
1369+
# are useful here), rather than globally. It must not be set
1370+
# in ebuilds.
1371+
13401372
# @FUNCTION: epytest
13411373
# @USAGE: [<args>...]
13421374
# @DESCRIPTION:
@@ -1448,10 +1480,10 @@ epytest() {
14481480
for x in "${EPYTEST_IGNORE[@]}"; do
14491481
args+=( --ignore "${x}" )
14501482
done
1451-
set -- "${EPYTHON}" -m pytest "${args[@]}" "${@}"
1483+
set -- "${EPYTHON}" -m pytest "${args[@]}" "${@}" ${EPYTEST_FLAGS}
14521484

14531485
echo "${@}" >&2
1454-
"${@}" || die -n "pytest failed with ${EPYTHON}"
1486+
"${@}"
14551487
local ret=${?}
14561488

14571489
# remove common temporary directories left over by pytest plugins
@@ -1462,6 +1494,7 @@ epytest() {
14621494
find "${BUILD_DIR}" -name '*-pytest-*.pyc' -delete || die
14631495
fi
14641496

1497+
[[ ${ret} -ne 0 ]] && die -n "pytest failed with ${EPYTHON}"
14651498
return ${ret}
14661499
}
14671500

@@ -1550,4 +1583,38 @@ python_has_version() {
15501583
return 0
15511584
}
15521585

1586+
# @FUNCTION: _python_sanity_checks
1587+
# @INTERNAL
1588+
# @DESCRIPTION:
1589+
# Perform additional environment sanity checks.
1590+
_python_sanity_checks() {
1591+
debug-print-function ${FUNCNAME} "${@}"
1592+
1593+
[[ ${_PYTHON_SANITY_CHECKED} ]] && return
1594+
1595+
if [[ -v PYTHONPATH ]]; then
1596+
local x paths=()
1597+
mapfile -d ':' -t paths <<<${PYTHONPATH}
1598+
1599+
for x in "${paths[@]}"; do
1600+
if [[ ${x} != /* ]]; then
1601+
eerror "Relative path found in PYTHONPATH:"
1602+
eerror
1603+
eerror " PYTHONPATH=${PYTHONPATH@Q}"
1604+
eerror
1605+
eerror "This is guaranteed to cause random breakage. Please make sure that"
1606+
eerror "your PYTHONPATH contains absolute paths only (and only if necessary)."
1607+
eerror "Note that empty values (including ':' at either end and an empty"
1608+
eerror "PYTHONPATH) count as the current directory. If no PYTHONPATH"
1609+
eerror "is intended, it needs to be unset instead."
1610+
die "Relative paths in PYTHONPATH are forbidden: ${x@Q}"
1611+
fi
1612+
done
1613+
1614+
elog "PYTHONPATH=${PYTHONPATH@Q}"
1615+
fi
1616+
1617+
_PYTHON_SANITY_CHECKED=1
1618+
}
1619+
15531620
fi

0 commit comments

Comments
 (0)