Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls
Date: Mon, 05 Jan 2015 18:18:51
Message-Id: 1420481910-13985-1-git-send-email-mgorny@gentoo.org
1 Allow limiting accepted implementations in python_setup. This allows
2 ebuilds to explicitly specify which implementations can be used to
3 perform specific tasks (e.g. doc build) rather than implicitly relying
4 on specific implementation preference order.
5
6 Example use case:
7
8 IUSE="doc"
9 RDEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
10 REQUIRED_USE="doc? ( || ( $(python_gen_useflags 'python2*') ) )"
11
12 So far, such ebuilds implicitly assumed Python 2 will be preferred over
13 Python 3, so if any version of Python 2 is enabled, python_setup will
14 use it.
15
16 With the new API, the src_configure() call could look like:
17
18 src_configure() {
19 #...
20
21 if use doc; then
22 python_setup 'python2*'
23 ./build_docs.py
24 fi
25 }
26
27 Therefore explicitly restricting the choice to Python 2.* independently
28 of eclass-defined implementation order/preference.
29 ---
30 eclass/python-r1.eclass | 45 ++++++++++++++++++++++++++++++++++++++++++---
31 1 file changed, 42 insertions(+), 3 deletions(-)
32
33 diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
34 index 713167d..0f73e3c 100644
35 --- a/eclass/python-r1.eclass
36 +++ b/eclass/python-r1.eclass
37 @@ -737,17 +737,56 @@ python_parallel_foreach_impl() {
38 }
39
40 # @FUNCTION: python_setup
41 +# @USAGE: [<impl-pattern>...]
42 # @DESCRIPTION:
43 -# Find the best (most preferred) Python implementation enabled
44 -# and set the Python build environment up for it.
45 +# Find the best (most preferred) Python implementation that is enabled
46 +# and matches at least one of the patterns passed (or '*' if no patterns
47 +# passed). Set the Python build environment up for that implementation.
48 #
49 # This function needs to be used when Python is being called outside
50 # of python_foreach_impl calls (e.g. for shared processes like doc
51 # building). python_foreach_impl sets up the build environment itself.
52 +#
53 +# If the specific commands support only a subset of Python
54 +# implementations, patterns need to be passed to restrict the allowed
55 +# implementations.
56 +#
57 +# Example:
58 +# @CODE
59 +# DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
60 +#
61 +# src_compile() {
62 +# #...
63 +# if use doc; then
64 +# python_setup 'python2*'
65 +# make doc
66 +# fi
67 +# }
68 +# @CODE
69 python_setup() {
70 debug-print-function ${FUNCNAME} "${@}"
71
72 - python_export_best
73 + local best_impl patterns=( "${@-*}" )
74 + _python_try_impl() {
75 + local pattern
76 + for pattern in "${patterns[@]}"; do
77 + if [[ ${EPYTHON} == ${pattern} ]]; then
78 + best_impl=${EPYTHON}
79 + fi
80 + done
81 + }
82 + python_foreach_impl _python_try_impl
83 +
84 + if [[ ! ${best_impl} ]]; then
85 + eerror "${FUNCNAME}: none of the enabled implementation matched the patterns."
86 + eerror " patterns: ${@-'(*)'}"
87 + eerror "Likely a REQUIRED_USE constraint (possibly USE-conditional) is missing."
88 + eerror " suggested: || ( \$(python_gen_useflags ${@}) )"
89 + eerror "(remember to quote all the patterns with '')"
90 + die "${FUNCNAME}: no enabled implementation satisfy requirements"
91 + fi
92 +
93 + python_export "${best_impl}" EPYTHON PYTHON
94 python_wrapper_setup
95 }
96
97 --
98 2.2.1

Replies