From 7bc9c63c9da678a7e6fceb095d56c634afd22c56 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Sun, 15 Dec 2019 18:09:03 +0000 Subject: gentoo resync : 15.12.2019 --- eclass/distutils-r1.eclass | 190 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 183 insertions(+), 7 deletions(-) (limited to 'eclass/distutils-r1.eclass') diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass index e2cd076d4148..fae25ea8a5ec 100644 --- a/eclass/distutils-r1.eclass +++ b/eclass/distutils-r1.eclass @@ -77,9 +77,23 @@ esac # to be exported. It must be run in order for the eclass functions # to function properly. +# @ECLASS-VARIABLE: DISTUTILS_USE_SETUPTOOLS +# @PRE_INHERIT +# @DESCRIPTION: +# Controls adding dev-python/setuptools dependency. The allowed values +# are: +# +# - no -- do not add the dependency (pure distutils package) +# - bdepend -- add it to BDEPEND (the default) +# - rdepend -- add it to BDEPEND+RDEPEND (when using entry_points) +# +# This variable is effective only if DISTUTILS_OPTIONAL is disabled. +# It needs to be set before the inherit line. +: ${DISTUTILS_USE_SETUPTOOLS:=bdepend} + if [[ ! ${_DISTUTILS_R1} ]]; then -[[ ${EAPI} == [45] ]] && inherit eutils +[[ ${EAPI} == [456] ]] && inherit eutils [[ ${EAPI} == [56] ]] && inherit xdg-utils inherit multiprocessing toolchain-funcs @@ -97,15 +111,35 @@ fi if [[ ! ${_DISTUTILS_R1} ]]; then -if [[ ! ${DISTUTILS_OPTIONAL} ]]; then - RDEPEND=${PYTHON_DEPS} +_distutils_set_globals() { + local rdep=${PYTHON_DEPS} + local bdep=${rdep} + + case ${DISTUTILS_USE_SETUPTOOLS} in + no) + ;; + bdepend) + bdep+=" dev-python/setuptools[${PYTHON_USEDEP}]" + ;; + rdepend) + bdep+=" dev-python/setuptools[${PYTHON_USEDEP}]" + rdep+=" dev-python/setuptools[${PYTHON_USEDEP}]" + ;; + *) + die "Invalid DISTUTILS_USE_SETUPTOOLS=${DISTUTILS_USE_SETUPTOOLS}" + ;; + esac + + RDEPEND=${rdep} if [[ ${EAPI} != [56] ]]; then - BDEPEND=${PYTHON_DEPS} + BDEPEND=${bdep} else - DEPEND=${PYTHON_DEPS} + DEPEND=${bdep} fi REQUIRED_USE=${PYTHON_REQUIRED_USE} -fi +} +[[ ! ${DISTUTILS_OPTIONAL} ]] && _distutils_set_globals +unset -f _distutils_set_globals # @ECLASS-VARIABLE: PATCHES # @DEFAULT_UNSET @@ -232,6 +266,102 @@ fi # } # @CODE +# @FUNCTION: distutils_enable_sphinx +# @USAGE: [--no-autodoc | ...] +# @DESCRIPTION: +# Set up IUSE, BDEPEND, python_check_deps() and python_compile_all() for +# building HTML docs via dev-python/sphinx. python_compile_all() will +# append to HTML_DOCS if docs are enabled. +# +# This helper is meant for the most common case, that is a single Sphinx +# subdirectory with standard layout, building and installing HTML docs +# behind USE=doc. It assumes it's the only consumer of the three +# aforementioned functions. If you need to use a custom implemention, +# you can't use it. +# +# If your package uses additional Sphinx plugins, they should be passed +# (without PYTHON_USEDEP) as . The function will take care +# of setting appropriate any-of dep and python_check_deps(). +# +# If no plugin packages are specified, the eclass will still utilize +# any-r1 API to support autodoc (documenting source code). +# If the package uses neither autodoc nor additional plugins, you should +# pass --no-autodoc to disable this API and simplify the resulting code. +# +# This function must be called in global scope. Take care not to +# overwrite the variables set by it. If you need to extend +# python_compile_all(), you can call the original implementation +# as sphinx_compile_all. +distutils_enable_sphinx() { + debug-print-function ${FUNCNAME} "${@}" + [[ ${#} -ge 1 ]] || die "${FUNCNAME} takes at least one arg: " + + _DISTUTILS_SPHINX_SUBDIR=${1} + shift + _DISTUTILS_SPHINX_PLUGINS=( "${@}" ) + + local deps autodoc=1 d + for d; do + if [[ ${d} == --no-autodoc ]]; then + autodoc= + else + deps+=" + ${d}[\${PYTHON_USEDEP}]" + fi + done + + if [[ ! ${autodoc} && -n ${deps} ]]; then + die "${FUNCNAME}: do not pass --no-autodoc if external plugins are used" + fi + if [[ ${autodoc} ]]; then + deps="$(python_gen_any_dep " + dev-python/sphinx[\${PYTHON_USEDEP}] + ${deps}")" + + python_check_deps() { + use doc || return 0 + local p + for p in dev-python/sphinx "${_DISTUTILS_SPHINX_PLUGINS[@]}"; do + has_version "${p}[${PYTHON_USEDEP}]" || return 1 + done + } + else + deps="dev-python/sphinx" + fi + + sphinx_compile_all() { + use doc || return + + local confpy=${_DISTUTILS_SPHINX_SUBDIR}/conf.py + [[ -f ${confpy} ]] || + die "${confpy} not found, distutils_enable_sphinx call wrong" + + if [[ ${_DISTUTILS_SPHINX_PLUGINS[0]} == --no-autodoc ]]; then + if grep -F -q 'sphinx.ext.autodoc' "${confpy}"; then + die "distutils_enable_sphinx: --no-autodoc passed but sphinx.ext.autodoc found in ${confpy}" + fi + else + if ! grep -F -q 'sphinx.ext.autodoc' "${confpy}"; then + die "distutils_enable_sphinx: sphinx.ext.autodoc not found in ${confpy}, pass --no-autodoc" + fi + fi + + build_sphinx "${_DISTUTILS_SPHINX_SUBDIR}" + } + python_compile_all() { sphinx_compile_all; } + + IUSE+=" doc" + if [[ ${EAPI} == [56] ]]; then + DEPEND+=" doc? ( ${deps} )" + else + BDEPEND+=" doc? ( ${deps} )" + fi + + # we need to ensure successful return in case we're called last, + # otherwise Portage may wrongly assume sourcing failed + return 0 +} + # @FUNCTION: distutils_enable_tests # @USAGE: # @DESCRIPTION: @@ -241,6 +371,7 @@ fi # # - nose: nosetests (dev-python/nose) # - pytest: dev-python/pytest +# - setup.py: setup.py test (no deps included) # - unittest: for built-in Python unittest module # # This function is meant as a helper for common use cases, and it only @@ -268,6 +399,11 @@ distutils_enable_tests() { pytest -vv || die "Tests fail with ${EPYTHON}" } ;; + setup.py) + python_test() { + esetup.py test --verbose + } + ;; unittest) python_test() { "${EPYTHON}" -m unittest discover -v || @@ -293,6 +429,41 @@ distutils_enable_tests() { return 0 } +# @FUNCTION: _distutils-r1_verify_use_setuptools +# @INTERNAL +# @DESCRIPTION: +# Check setup.py for signs that DISTUTILS_USE_SETUPTOOLS have been set +# incorrectly. +_distutils_verify_use_setuptools() { + [[ ${DISTUTILS_OPTIONAL} ]] && return + + # ok, those are cheap greps. we can try toimprove them if we hit + # false positives. + local expected=no + if [[ ${CATEGORY}/${PN} == dev-python/setuptools ]]; then + # as a special case, setuptools provides itself ;-) + : + elif grep -E -q -s '(from|import)\s+setuptools' setup.py; then + if grep -E -q -s 'entry_points\s+=' setup.py; then + expected=rdepend + else + expected=bdepend + fi + fi + + if [[ ${DISTUTILS_USE_SETUPTOOLS} != ${expected} ]]; then + if [[ ! ${_DISTUTILS_SETUPTOOLS_WARNED} ]]; then + _DISTUTILS_SETUPTOOLS_WARNED=1 + local def= + [[ ${DISTUTILS_USE_SETUPTOOLS} == bdepend ]] && def=' (default?)' + + eqawarn "DISTUTILS_USE_SETUPTOOLS value is probably incorrect" + eqawarn " value: DISTUTILS_USE_SETUPTOOLS=${DISTUTILS_USE_SETUPTOOLS}${def}" + eqawarn " expected: DISTUTILS_USE_SETUPTOOLS=${expected}" + fi + fi +} + # @FUNCTION: esetup.py # @USAGE: [...] # @DESCRIPTION: @@ -315,6 +486,7 @@ esetup.py() { [[ ${EAPI} != [45] ]] && die_args+=( -n ) [[ ${BUILD_DIR} ]] && _distutils-r1_create_setup_cfg + _distutils_verify_use_setuptools set -- "${EPYTHON:-python}" setup.py "${mydistutilsargs[@]}" "${@}" @@ -719,7 +891,11 @@ distutils-r1_run_phase() { debug-print-function ${FUNCNAME} "${@}" if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then - if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then + # only force BUILD_DIR if implementation is explicitly enabled + # for building; any-r1 API may select one that is not + # https://bugs.gentoo.org/701506 + if [[ ! ${DISTUTILS_SINGLE_IMPL} ]] && + has "${EPYTHON/./_}" ${PYTHON_TARGETS}; then cd "${BUILD_DIR}" || die fi local BUILD_DIR=${BUILD_DIR}/build -- cgit v1.2.3