From 6abbf81ef2f298e3221ff5e67a1f3c5f23958212 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Mon, 14 Dec 2020 13:26:14 +0000 Subject: gentoo resync : 14.12.2020 --- eclass/distutils-r1.eclass | 157 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 132 insertions(+), 25 deletions(-) (limited to 'eclass/distutils-r1.eclass') diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass index 25cb67b78a31..33c66c4872e5 100644 --- a/eclass/distutils-r1.eclass +++ b/eclass/distutils-r1.eclass @@ -378,7 +378,7 @@ distutils_enable_sphinx() { } # @FUNCTION: distutils_enable_tests -# @USAGE: +# @USAGE: [--install] # @DESCRIPTION: # Set up IUSE, RESTRICT, BDEPEND and python_test() for running tests # with the specified test runner. Also copies the current value @@ -389,6 +389,10 @@ distutils_enable_sphinx() { # - setup.py: setup.py test (no deps included) # - unittest: for built-in Python unittest module # +# Additionally, if --install is passed as the first parameter, +# 'distutils_install_for_testing --via-root' is called before running +# the test suite. +# # This function is meant as a helper for common use cases, and it only # takes care of basic setup. You still need to list additional test # dependencies manually. If you have uncommon use case, you should @@ -398,33 +402,71 @@ distutils_enable_sphinx() { # declared. Take care not to overwrite the variables set by it. distutils_enable_tests() { debug-print-function ${FUNCNAME} "${@}" - [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: test-runner" + local do_install= + case ${1} in + --install) + do_install=1 + shift + ;; + esac + + [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: test-runner" local test_pkg case ${1} in nose) test_pkg=">=dev-python/nose-1.3.7-r4" - python_test() { - nosetests -v || die "Tests fail with ${EPYTHON}" - } + if [[ ${do_install} ]]; then + python_test() { + distutils_install_for_testing --via-root + nosetests -v || die "Tests fail with ${EPYTHON}" + } + else + python_test() { + nosetests -v || die "Tests fail with ${EPYTHON}" + } + fi ;; pytest) test_pkg=">=dev-python/pytest-4.5.0" - python_test() { - pytest -vv || die "Tests fail with ${EPYTHON}" - } + if [[ ${do_install} ]]; then + python_test() { + distutils_install_for_testing --via-root + pytest -vv || die "Tests fail with ${EPYTHON}" + } + else + python_test() { + pytest -vv || die "Tests fail with ${EPYTHON}" + } + fi ;; setup.py) - python_test() { - nonfatal esetup.py test --verbose || - die "Tests fail with ${EPYTHON}" - } + if [[ ${do_install} ]]; then + python_test() { + distutils_install_for_testing --via-root + nonfatal esetup.py test --verbose || + die "Tests fail with ${EPYTHON}" + } + else + python_test() { + nonfatal esetup.py test --verbose || + die "Tests fail with ${EPYTHON}" + } + fi ;; unittest) - python_test() { - "${EPYTHON}" -m unittest discover -v || - die "Tests fail with ${EPYTHON}" - } + if [[ ${do_install} ]]; then + python_test() { + distutils_install_for_testing --via-root + "${EPYTHON}" -m unittest discover -v || + die "Tests fail with ${EPYTHON}" + } + else + python_test() { + "${EPYTHON}" -m unittest discover -v || + die "Tests fail with ${EPYTHON}" + } + fi ;; *) die "${FUNCNAME}: unsupported argument: ${1}" @@ -492,7 +534,7 @@ esetup.py() { } # @FUNCTION: distutils_install_for_testing -# @USAGE: [...] +# @USAGE: [--via-root|--via-home] [...] # @DESCRIPTION: # Install the package into a temporary location for running tests. # Update PYTHONPATH appropriately and set TEST_DIR to the test @@ -503,11 +545,19 @@ esetup.py() { # namespaces (and therefore proper install needs to be done to enforce # PYTHONPATH) or tests rely on the results of install command. # For most of the packages, tests built in BUILD_DIR are good enough. +# +# The function supports two install modes. The current default is +# the legacy --via-home mode. However, it has problems with newer +# versions of setuptools (50.3.0+). The --via-root mode generally +# works for these packages, and it will probably become the default +# in the future, once we test all affected packages. Please note +# that proper testing sometimes requires unmerging the package first. distutils_install_for_testing() { debug-print-function ${FUNCNAME} "${@}" # A few notes: - # 1) because of namespaces, we can't use 'install --root', + # 1) because of namespaces, we can't use 'install --root' + # (NB: this is probably no longer true with py3), # 2) 'install --home' is terribly broken on pypy, so we need # to override --install-lib and --install-scripts, # 3) non-root 'install' complains about PYTHONPATH and missing dirs, @@ -522,14 +572,39 @@ distutils_install_for_testing() { PATH=${bindir}:${PATH} PYTHONPATH=${libdir}:${PYTHONPATH} - local add_args=( - install - --home="${TEST_DIR}" - --install-lib="${libdir}" - --install-scripts="${bindir}" - ) + local install_method=home + case ${1} in + --via-home) + install_method=home + shift + ;; + --via-root) + install_method=root + shift + ;; + esac + + local -a add_args + case ${install_method} in + home) + add_args=( + install + --home="${TEST_DIR}" + --install-lib="${libdir}" + --install-scripts="${bindir}" + ) + mkdir -p "${libdir}" || die + ;; + root) + add_args=( + install + --root="${TEST_DIR}" + --install-lib=lib + --install-scripts=scripts + ) + ;; + esac - mkdir -p "${libdir}" || die esetup.py "${add_args[@]}" "${@}" } @@ -1118,34 +1193,66 @@ distutils-r1_src_install() { # -- distutils.eclass functions -- +# @FUNCTION: distutils_get_intermediate_installation_image +# @INTERNAL +# @DESCRIPTION: +# Die and warn when function from previous distutils is called distutils_get_intermediate_installation_image() { die "${FUNCNAME}() is invalid for distutils-r1" } +# @FUNCTION: distutils_src_unpack +# @INTERNAL +# @DESCRIPTION: +# Die and warn when function from previous distutils is called distutils_src_unpack() { die "${FUNCNAME}() is invalid for distutils-r1, and you don't want it in EAPI ${EAPI} anyway" } +# @FUNCTION: distutils_src_prepare +# @INTERNAL +# @DESCRIPTION: +# Die and warn when function from previous distutils is called distutils_src_prepare() { die "${FUNCNAME}() is invalid for distutils-r1, you probably want: ${FUNCNAME/_/-r1_}" } +# @FUNCTION: distutils_src_compile +# @INTERNAL +# @DESCRIPTION: +# Die and warn when function from previous distutils is called distutils_src_compile() { die "${FUNCNAME}() is invalid for distutils-r1, you probably want: ${FUNCNAME/_/-r1_}" } +# @FUNCTION: distutils_src_test +# @INTERNAL +# @DESCRIPTION: +# Die and warn when function from previous distutils is called distutils_src_test() { die "${FUNCNAME}() is invalid for distutils-r1, you probably want: ${FUNCNAME/_/-r1_}" } +# @FUNCTION: distutils_src_install +# @INTERNAL +# @DESCRIPTION: +# Die and warn when function from previous distutils is called distutils_src_install() { die "${FUNCNAME}() is invalid for distutils-r1, you probably want: ${FUNCNAME/_/-r1_}" } +# @FUNCTION: distutils_pkg_postinst +# @INTERNAL +# @DESCRIPTION: +# Die and warn when function from previous distutils is called distutils_pkg_postinst() { die "${FUNCNAME}() is invalid for distutils-r1, and pkg_postinst is unnecessary" } +# @FUNCTION: distutils_pkg_postrm +# @INTERNAL +# @DESCRIPTION: +# Die and warn when function from previous distutils is called distutils_pkg_postrm() { die "${FUNCNAME}() is invalid for distutils-r1, and pkg_postrm is unnecessary" } -- cgit v1.2.3