@@ -340,6 +340,17 @@ _python_export() {
340
340
fi
341
341
debug-print " ${FUNCNAME} : PYTHON = ${PYTHON} "
342
342
;;
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
+ ;;
343
354
PYTHON_SITEDIR)
344
355
[[ -n ${PYTHON} ]] || die " PYTHON needs to be set for ${var} to be exported, or requested before it"
345
356
PYTHON_SITEDIR=$(
@@ -482,6 +493,18 @@ _python_export() {
482
493
done
483
494
}
484
495
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
+
485
508
# @FUNCTION: python_get_sitedir
486
509
# @USAGE: [<impl>]
487
510
# @DESCRIPTION:
@@ -1337,6 +1360,15 @@ _python_check_occluded_packages() {
1337
1360
# Specifies the number of jobs for parallel (pytest-xdist) test runs.
1338
1361
# When unset, defaults to -j from MAKEOPTS, or the current nproc.
1339
1362
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
+
1340
1372
# @FUNCTION: epytest
1341
1373
# @USAGE: [<args>...]
1342
1374
# @DESCRIPTION:
@@ -1448,10 +1480,10 @@ epytest() {
1448
1480
for x in " ${EPYTEST_IGNORE[@]} " ; do
1449
1481
args+=( --ignore " ${x} " )
1450
1482
done
1451
- set -- " ${EPYTHON} " -m pytest " ${args[@]} " " ${@ } "
1483
+ set -- " ${EPYTHON} " -m pytest " ${args[@]} " " ${@ } " ${EPYTEST_FLAGS}
1452
1484
1453
1485
echo " ${@ } " >&2
1454
- " ${@ } " || die -n " pytest failed with ${EPYTHON} "
1486
+ " ${@ } "
1455
1487
local ret=${?}
1456
1488
1457
1489
# remove common temporary directories left over by pytest plugins
@@ -1462,6 +1494,7 @@ epytest() {
1462
1494
find " ${BUILD_DIR} " -name ' *-pytest-*.pyc' -delete || die
1463
1495
fi
1464
1496
1497
+ [[ ${ret} -ne 0 ]] && die -n " pytest failed with ${EPYTHON} "
1465
1498
return ${ret}
1466
1499
}
1467
1500
@@ -1550,4 +1583,38 @@ python_has_version() {
1550
1583
return 0
1551
1584
}
1552
1585
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
+
1553
1620
fi
0 commit comments