summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2021-04-10 07:08:52 +0000
committerSam James <sam@gentoo.org>2021-04-10 07:08:52 +0000
commit576b06627578c9846b2b265085c13509692ea49f (patch)
tree28acd11308528b36183ee413bb0acca3ca010071 /eclass/python-utils-r1.eclass
parentsys-apps/portage: clena up EAPI 5 version (2.3.100-r1) (diff)
downloadprefix-576b06627578c9846b2b265085c13509692ea49f.tar.gz
prefix-576b06627578c9846b2b265085c13509692ea49f.tar.bz2
prefix-576b06627578c9846b2b265085c13509692ea49f.zip
python-utils-r1.eclass: sync with ::gentoo
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'eclass/python-utils-r1.eclass')
-rw-r--r--eclass/python-utils-r1.eclass304
1 files changed, 81 insertions, 223 deletions
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 1b1f6b4d4b..88b258a7f6 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1,4 +1,4 @@
-# Copyright 1999-2020 Gentoo Authors
+# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: python-utils-r1.eclass
@@ -7,7 +7,7 @@
# @AUTHOR:
# Author: Michał Górny <mgorny@gentoo.org>
# Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
-# @SUPPORTED_EAPIS: 5 6 7
+# @SUPPORTED_EAPIS: 6 7
# @BLURB: Utility functions for packages with Python parts.
# @DESCRIPTION:
# A utility eclass providing functions to query Python implementations,
@@ -19,9 +19,12 @@
# For more information, please see the Python Guide:
# https://dev.gentoo.org/~mgorny/python-guide/
+# NOTE: When dropping support for EAPIs here, we need to update
+# metadata/install-qa-check.d/60python-pyc
+# See bug #704286, bug #781878
case "${EAPI:-0}" in
- [0-4]) die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;;
- [5-7]) ;;
+ [0-5]) die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;;
+ [6-7]) ;;
*) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
esac
@@ -31,7 +34,6 @@ fi
if [[ ! ${_PYTHON_UTILS_R1} ]]; then
-[[ ${EAPI} == 5 ]] && inherit eutils multilib
inherit toolchain-funcs
# @ECLASS-VARIABLE: _PYTHON_ALL_IMPLS
@@ -40,8 +42,7 @@ inherit toolchain-funcs
# All supported Python implementations, most preferred last.
_PYTHON_ALL_IMPLS=(
pypy3
- python2_7
- python3_6 python3_7 python3_8 python3_9
+ python3_7 python3_8 python3_9
)
readonly _PYTHON_ALL_IMPLS
@@ -52,8 +53,8 @@ readonly _PYTHON_ALL_IMPLS
_PYTHON_HISTORICAL_IMPLS=(
jython2_7
pypy pypy1_{8,9} pypy2_0
- python2_{5,6}
- python3_{1,2,3,4,5}
+ python2_{5..7}
+ python3_{1..6}
)
readonly _PYTHON_HISTORICAL_IMPLS
@@ -69,38 +70,6 @@ readonly _PYTHON_HISTORICAL_IMPLS
# which can involve revisions of this eclass that support a different
# set of Python implementations.
-# @FUNCTION: _python_impl_supported
-# @USAGE: <impl>
-# @INTERNAL
-# @DESCRIPTION:
-# Check whether the implementation <impl> (PYTHON_COMPAT-form)
-# is still supported.
-#
-# Returns 0 if the implementation is valid and supported. If it is
-# unsupported, returns 1 -- and the caller should ignore the entry.
-# If it is invalid, dies with an appopriate error messages.
-_python_impl_supported() {
- debug-print-function ${FUNCNAME} "${@}"
-
- [[ ${#} -eq 1 ]] || die "${FUNCNAME}: takes exactly 1 argument (impl)."
-
- local impl=${1}
-
- # keep in sync with _PYTHON_ALL_IMPLS!
- # (not using that list because inline patterns shall be faster)
- case "${impl}" in
- python2_7|python3_[6789]|pypy3)
- return 0
- ;;
- jython2_7|pypy|pypy1_[89]|pypy2_0|python2_[56]|python3_[12345])
- return 1
- ;;
- *)
- [[ ${PYTHON_COMPAT_NO_STRICT} ]] && return 1
- die "Invalid implementation in PYTHON_COMPAT: ${impl}"
- esac
-}
-
# @FUNCTION: _python_verify_patterns
# @USAGE: <pattern>...
# @INTERNAL
@@ -149,10 +118,26 @@ _python_set_impls() {
if [[ $(declare -p PYTHON_COMPAT) != "declare -a"* ]]; then
die 'PYTHON_COMPAT must be an array.'
fi
- for i in "${PYTHON_COMPAT[@]}"; do
- # trigger validity checks
- _python_impl_supported "${i}"
- done
+ if [[ ! ${PYTHON_COMPAT_NO_STRICT} ]]; then
+ for i in "${PYTHON_COMPAT[@]}"; do
+ # check for incorrect implementations
+ # we're using pattern matching as an optimization
+ # please keep them in sync with _PYTHON_ALL_IMPLS
+ # and _PYTHON_HISTORICAL_IMPLS
+ case ${i} in
+ jython2_7|pypy|pypy1_[89]|pypy2_0|pypy3|python2_[5-7]|python3_[1-9])
+ ;;
+ *)
+ if has "${i}" "${_PYTHON_ALL_IMPLS[@]}" \
+ "${_PYTHON_HISTORICAL_IMPLS[@]}"
+ then
+ die "Mis-synced patterns in _python_set_impls: missing ${i}"
+ else
+ die "Invalid implementation in PYTHON_COMPAT: ${i}"
+ fi
+ esac
+ done
+ fi
local supp=() unsupp=()
@@ -165,7 +150,13 @@ _python_set_impls() {
done
if [[ ! ${supp[@]} ]]; then
- die "No supported implementation in PYTHON_COMPAT."
+ # special-case python2_7 for python-any-r1
+ if [[ ${_PYTHON_ALLOW_PY27} ]] && has python2_7 "${PYTHON_COMPAT[@]}"
+ then
+ supp+=( python2_7 )
+ else
+ die "No supported implementation in PYTHON_COMPAT."
+ fi
fi
if [[ ${_PYTHON_SUPPORTED_IMPLS[@]} ]]; then
@@ -636,6 +627,7 @@ python_optimize() {
local PYTHON=${PYTHON}
[[ ${PYTHON} ]] || _python_export PYTHON
+ [[ -x ${PYTHON} ]] || die "PYTHON (${PYTHON}) is not executable"
# default to sys.path
if [[ ${#} -eq 0 ]]; then
@@ -950,8 +942,6 @@ _python_wrapper_setup() {
[[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON specified."
if [[ ! -x ${workdir}/bin/python ]]; then
- _python_check_dead_variables
-
mkdir -p "${workdir}"/{bin,pkgconfig} || die
# Clean up, in case we were supposed to do a cheap update.
@@ -1058,16 +1048,8 @@ python_is_python3() {
python_is_installed() {
local impl=${1:-${EPYTHON}}
[[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON"
- local hasv_args=()
-
- case ${EAPI} in
- 5|6)
- hasv_args+=( --host-root )
- ;;
- *)
- hasv_args+=( -b )
- ;;
- esac
+ local hasv_args=( -b )
+ [[ ${EAPI} == 6 ]] && hasv_args=( --host-root )
local PYTHON_PKG_DEP
_python_export "${impl}" PYTHON_PKG_DEP
@@ -1214,17 +1196,14 @@ python_fix_shebang() {
done < <(find -H "${path}" -type f -print0 || die)
if [[ ! ${any_fixed} ]]; then
- local cmd=eerror
- [[ ${EAPI} == 5 ]] && cmd=eqawarn
-
- "${cmd}" "QA warning: ${FUNCNAME}, ${path#${D%/}} did not match any fixable files."
+ eerror "QA error: ${FUNCNAME}, ${path#${D%/}} did not match any fixable files."
if [[ ${any_correct} ]]; then
- "${cmd}" "All files have ${EPYTHON} shebang already."
+ eerror "All files have ${EPYTHON} shebang already."
else
- "${cmd}" "There are no Python files in specified directory."
+ eerror "There are no Python files in specified directory."
fi
- [[ ${cmd} == eerror ]] && die "${FUNCNAME} did not match any fixable files (QA warning fatal in EAPI ${EAPI})"
+ die "${FUNCNAME} did not match any fixable files"
fi
done
}
@@ -1321,172 +1300,51 @@ build_sphinx() {
HTML_DOCS+=( "${dir}/_build/html/." )
}
-# -- python.eclass functions --
-
-_python_check_dead_variables() {
- local v
-
- for v in PYTHON_DEPEND PYTHON_USE_WITH{,_OR,_OPT} {RESTRICT,SUPPORT}_PYTHON_ABIS
- do
- if [[ ${!v} ]]; then
- die "${v} is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#Ebuild_head"
- fi
- done
-
- for v in PYTHON_{CPPFLAGS,CFLAGS,CXXFLAGS,LDFLAGS}
- do
- if [[ ${!v} ]]; then
- die "${v} is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#PYTHON_CFLAGS"
- fi
- done
-
- for v in PYTHON_TESTS_RESTRICTED_ABIS PYTHON_EXPORT_PHASE_FUNCTIONS \
- PYTHON_VERSIONED_{SCRIPTS,EXECUTABLES} PYTHON_NONVERSIONED_EXECUTABLES
- do
- if [[ ${!v} ]]; then
- die "${v} is invalid for python-r1 suite"
- fi
- done
-
- for v in DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES DISTUTILS_SETUP_FILES \
- DISTUTILS_GLOBAL_OPTIONS DISTUTILS_SRC_TEST PYTHON_MODNAME
- do
- if [[ ${!v} ]]; then
- die "${v} is invalid for distutils-r1, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#${v}"
- fi
- done
-
- if [[ ${DISTUTILS_DISABLE_TEST_DEPENDENCY} ]]; then
- die "${v} is invalid for distutils-r1, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#DISTUTILS_SRC_TEST"
- fi
-
- # python.eclass::progress
- for v in PYTHON_BDEPEND PYTHON_MULTIPLE_ABIS PYTHON_ABI_TYPE \
- PYTHON_RESTRICTED_ABIS PYTHON_TESTS_FAILURES_TOLERANT_ABIS \
- PYTHON_CFFI_MODULES_GENERATION_COMMANDS
- do
- if [[ ${!v} ]]; then
- die "${v} is invalid for python-r1 suite"
- fi
- done
-}
-
-python_pkg_setup() {
- die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#pkg_setup"
-}
-
-python_convert_shebangs() {
- die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#python_convert_shebangs"
-}
-
-python_clean_py-compile_files() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_clean_installation_image() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_execute_function() {
- die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#python_execute_function"
-}
-
-python_generate_wrapper_scripts() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_merge_intermediate_installation_images() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_set_active_version() {
- die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#pkg_setup"
-}
-
-python_need_rebuild() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-PYTHON() {
- die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#.24.28PYTHON.29.2C_.24.7BEPYTHON.7D"
-}
-
-python_get_implementation() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_get_implementational_package() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_get_libdir() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_get_library() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_get_version() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_get_implementation_and_version() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_execute_nosetests() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_execute_py.test() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_execute_trial() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_enable_pyc() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_disable_pyc() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
-
-python_mod_optimize() {
- die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#Python_byte-code_compilation"
-}
-
-python_mod_cleanup() {
- die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#Python_byte-code_compilation"
-}
+# @FUNCTION: epytest
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Run pytest, passing the standard set of pytest options, followed
+# by user-specified options.
+#
+# This command dies on failure and respects nonfatal.
+epytest() {
+ debug-print-function ${FUNCNAME} "${@}"
-# python.eclass::progress
+ [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context"
-python_abi_depend() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
+ local args=(
+ # verbose progress reporting and tracebacks
+ -vv
+ # list all non-passed tests in the summary for convenience
+ # (includes failures, skips, xfails...)
+ -ra
+ # print local variables in tracebacks, useful for debugging
+ -l
+ )
+ set -- "${EPYTHON}" -m pytest "${args[@]}" "${@}"
-python_install_executables() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
+ echo "${@}" >&2
+ "${@}" || die -n "pytest failed with ${EPYTHON}"
+ return ${?}
}
-python_get_extension_module_suffix() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
+# @FUNCTION: eunittest
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Run unit tests using dev-python/unittest-or-fail, passing the standard
+# set of options, followed by user-specified options.
+#
+# This command dies on failure and respects nonfatal.
+eunittest() {
+ debug-print-function ${FUNCNAME} "${@}"
-python_byte-compile_modules() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
+ [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context"
-python_clean_byte-compiled_modules() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
-}
+ set -- "${EPYTHON}" -m unittest_or_fail discover -v "${@}"
-python_generate_cffi_modules() {
- die "${FUNCNAME}() is invalid for python-r1 suite"
+ echo "${@}" >&2
+ "${@}" || die -n "Tests failed with ${EPYTHON}"
+ return ${?}
}
_PYTHON_UTILS_R1=1