Support restricting accepted implementation list for python_setup.
authorMichał Górny <mgorny@gentoo.org>
Tue, 13 Jan 2015 21:34:22 +0000 (21:34 +0000)
committerMichał Górny <mgorny@gentoo.org>
Tue, 13 Jan 2015 21:34:22 +0000 (21:34 +0000)
eclass/ChangeLog
eclass/python-r1.eclass

index d4dc9d5e628bb263f7b813fb7497788d13689902..15e5a93b77e1a516c23fba39f8e10bca1336927a 100644 (file)
@@ -1,6 +1,9 @@
 # ChangeLog for eclass directory
 # Copyright 1999-2015 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1507 2015/01/12 23:17:14 polynomial-c Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1508 2015/01/13 21:34:22 mgorny Exp $
+
+  13 Jan 2015; Michał Górny <mgorny@gentoo.org> python-r1.eclass:
+  Support restricting accepted implementation list for python_setup.
 
   12 Jan 2015; Lars Wendler <polynomial-c@gentoo.org> autotools.eclass:
   Attempt to fix bug #536428.
index 713167d4c038f73c177a683b32b6c73aa4ac8fe9..c0c066359c98b11b19405a34127db945a9f2d382 100644 (file)
@@ -1,6 +1,6 @@
-# Copyright 1999-2014 Gentoo Foundation
+# Copyright 1999-2015 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.82 2014/12/28 22:45:47 mgorny Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.83 2015/01/13 21:34:22 mgorny Exp $
 
 # @ECLASS: python-r1
 # @MAINTAINER:
@@ -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
 }