Allow limiting accepted implementations in python_setup. This allows
ebuilds to explicitly specify which implementations can be used to
perform specific tasks (e.g. doc build) rather than implicitly relying
on specific implementation preference order.
Example use case:
IUSE=doc
RDEPEND=doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )
REQUIRED_USE=doc? ( || ( $(python_gen_useflags 'python2*') ) )
So far, such ebuilds implicitly assumed Python 2 will be preferred over
Python 3, so if any version of Python 2 is enabled, python_setup will
use it.
With the new API, the src_configure() call could look like:
src_configure() {
#...
if use doc; then
python_setup 'python2*'
./build_docs.py
fi
}
Therefore explicitly restricting the choice to Python 2.* independently
of eclass-defined implementation order/preference.
---
eclass/python-r1.eclass | 45 ++---
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
index 713167d..0f73e3c 100644
--- a/eclass/python-r1.eclass
+++ b/eclass/python-r1.eclass
@@ -737,17 +737,56 @@ python_parallel_foreach_impl() {
}
# @FUNCTION: python_setup
+# @USAGE: [impl-pattern...]
# @DESCRIPTION:
-# Find the best (most preferred) Python implementation enabled
-# and set the Python build environment up for it.
+# Find the best (most preferred) Python implementation that is enabled
+# and matches at least one of the patterns passed (or '*' if no patterns
+# passed). Set the Python build environment up for that implementation.
#
# This function needs to be used when Python is being called outside
# of python_foreach_impl calls (e.g. for shared processes like doc
# building). python_foreach_impl sets up the build environment itself.
+#
+# If the specific commands support only a subset of Python
+# implementations, patterns need to be passed to restrict the allowed
+# implementations.
+#
+# Example:
+# @CODE
+# DEPEND=doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )
+#
+# src_compile() {
+# #...
+# if use doc; then
+# python_setup 'python2*'
+# make doc
+# fi
+# }
+# @CODE
python_setup() {
debug-print-function ${FUNCNAME} ${@}
- python_export_best
+ local best_impl patterns=( ${@-*} )
+ _python_try_impl() {
+ local pattern
+ for pattern in ${patterns[@]}; do
+ if [[ ${EPYTHON} == ${pattern} ]]; then
+ best_impl=${EPYTHON}
+ fi
+ done
+ }
+ python_foreach_impl _python_try_impl
+
+ if [[ ! ${best_impl} ]]; then
+ eerror ${FUNCNAME}: none of the enabled implementation matched
the patterns.
+ eerror patterns: ${@-'(*)'}
+ eerror Likely a REQUIRED_USE constraint (possibly
USE-conditional) is missing.
+ eerror suggested: || ( \$(python_gen_useflags ${@}) )
+ eerror (remember to quote all the patterns with '')
+ die ${FUNCNAME}: no enabled implementation satisfy
requirements
+ fi
+
+ python_export ${best_impl} EPYTHON PYTHON
python_wrapper_setup
}
--
2.2.1