/[gentoo-x86]/eclass/python-any-r1.eclass
Gentoo

Contents of /eclass/python-any-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations) (download)
Tue Sep 24 19:53:06 2013 UTC (13 months ago) by mgorny
Branch: MAIN
Changes since 1.13: +62 -1 lines
Introduce python_gen_any_dep to generate any-of dependencies matching python_check_deps() code.

1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/python-any-r1.eclass,v 1.13 2013/08/01 12:49:42 mgorny Exp $
4
5 # @ECLASS: python-any-r1
6 # @MAINTAINER:
7 # Python team <python@gentoo.org>
8 # @AUTHOR:
9 # Author: Michał Górny <mgorny@gentoo.org>
10 # Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
11 # @BLURB: An eclass for packages having build-time dependency on Python.
12 # @DESCRIPTION:
13 # A minimal eclass for packages which need any Python interpreter
14 # installed without a need for explicit choice and invariability.
15 # This usually involves packages requiring Python at build-time
16 # but having no other relevance to it.
17 #
18 # This eclass provides a minimal PYTHON_DEPS variable with a dependency
19 # string on any of the supported Python implementations. It also exports
20 # pkg_setup() which finds the best supported implementation and sets it
21 # as the active one.
22 #
23 # Optionally, you can define a python_check_deps() function. It will
24 # be called by the eclass with EPYTHON set to each matching Python
25 # implementation and it is expected to check whether the implementation
26 # fulfills the package requirements. You can use the locally exported
27 # PYTHON_USEDEP to check USE-dependencies of relevant packages. It
28 # should return a true value (0) if the Python implementation fulfills
29 # the requirements, a false value (non-zero) otherwise.
30 #
31 # Please note that python-any-r1 will always inherit python-utils-r1
32 # as well. Thus, all the functions defined there can be used in the
33 # packages using python-any-r1, and there is no need ever to inherit
34 # both.
35 #
36 # For more information, please see the python-r1 Developer's Guide:
37 # http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
38
39 case "${EAPI:-0}" in
40 0|1|2|3|4|5)
41 # EAPI=4 needed by python-r1
42 ;;
43 *)
44 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
45 ;;
46 esac
47
48 if [[ ! ${_PYTHON_ANY_R1} ]]; then
49
50 if [[ ${_PYTHON_R1} ]]; then
51 die 'python-any-r1.eclass can not be used with python-r1.eclass.'
52 elif [[ ${_PYTHON_SINGLE_R1} ]]; then
53 die 'python-any-r1.eclass can not be used with python-single-r1.eclass.'
54 fi
55
56 inherit python-utils-r1
57
58 fi
59
60 EXPORT_FUNCTIONS pkg_setup
61
62 if [[ ! ${_PYTHON_ANY_R1} ]]; then
63
64 # @ECLASS-VARIABLE: PYTHON_COMPAT
65 # @REQUIRED
66 # @DESCRIPTION:
67 # This variable contains a list of Python implementations the package
68 # supports. It must be set before the `inherit' call. It has to be
69 # an array.
70 #
71 # Example:
72 # @CODE
73 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
74 # @CODE
75 if ! declare -p PYTHON_COMPAT &>/dev/null; then
76 die 'PYTHON_COMPAT not declared.'
77 fi
78
79 # @ECLASS-VARIABLE: PYTHON_REQ_USE
80 # @DEFAULT_UNSET
81 # @DESCRIPTION:
82 # The list of USEflags required to be enabled on the Python
83 # implementations, formed as a USE-dependency string. It should be valid
84 # for all implementations in PYTHON_COMPAT, so it may be necessary to
85 # use USE defaults.
86 #
87 # Example:
88 # @CODE
89 # PYTHON_REQ_USE="gdbm,ncurses(-)?"
90 # @CODE
91 #
92 # It will cause the Python dependencies to look like:
93 # @CODE
94 # || ( dev-lang/python:X.Y[gdbm,ncurses(-)?] ... )
95 # @CODE
96
97 # @ECLASS-VARIABLE: PYTHON_DEPS
98 # @DESCRIPTION:
99 # This is an eclass-generated Python dependency string for all
100 # implementations listed in PYTHON_COMPAT.
101 #
102 # Any of the supported interpreters will satisfy the dependency.
103 #
104 # Example use:
105 # @CODE
106 # DEPEND="${RDEPEND}
107 # ${PYTHON_DEPS}"
108 # @CODE
109 #
110 # Example value:
111 # @CODE
112 # || ( dev-lang/python:2.7[gdbm]
113 # dev-lang/python:2.6[gdbm] )
114 # @CODE
115
116 _python_build_set_globals() {
117 local usestr i PYTHON_PKG_DEP
118 [[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]"
119
120 # check for invalid PYTHON_COMPAT
121 for i in "${PYTHON_COMPAT[@]}"; do
122 # the function simply dies on invalid impl
123 _python_impl_supported "${i}"
124 done
125
126 PYTHON_DEPS=
127 for i in "${_PYTHON_ALL_IMPLS[@]}"; do
128 has "${i}" "${PYTHON_COMPAT[@]}" || continue
129
130 python_export "${i}" PYTHON_PKG_DEP
131
132 PYTHON_DEPS="${PYTHON_PKG_DEP} ${PYTHON_DEPS}"
133 done
134 PYTHON_DEPS="|| ( ${PYTHON_DEPS})"
135 }
136 _python_build_set_globals
137
138 # @ECLASS-VARIABLE: PYTHON_USEDEP
139 # @DESCRIPTION:
140 # An eclass-generated USE-dependency string for the currently tested
141 # implementation. It is set locally for python_check_deps() call.
142 #
143 # The generate USE-flag list is compatible with packages using python-r1,
144 # python-single-r1 and python-distutils-ng eclasses. It must not be used
145 # on packages using python.eclass.
146 #
147 # Example use:
148 # @CODE
149 # python_check_deps() {
150 # has_version "dev-python/foo[${PYTHON_USEDEP}]"
151 # }
152 # @CODE
153 #
154 # Example value:
155 # @CODE
156 # python_targets_python2_7(-)?,python_single_target_python2_7(+)?
157 # @CODE
158
159 # @FUNCTION: python_gen_any_dep
160 # @USAGE: <dependency-block>
161 # @DESCRIPTION:
162 # Generate an any-of dependency that enforces a version match between
163 # the Python interpreter and Python packages. <dependency-block> needs
164 # to list one or more dependencies with verbatim '${PYTHON_USEDEP}'
165 # references (quoted!) that will get expanded inside the function.
166 #
167 # This should be used along with an appropriate python_check_deps()
168 # that checks which of the any-of blocks were matched.
169 #
170 # Example use:
171 # @CODE
172 # DEPEND="$(python_gen_any_dep '
173 # dev-python/foo[${PYTHON_USEDEP}]
174 # || ( dev-python/bar[${PYTHON_USEDEP}]
175 # dev-python/baz[${PYTHON_USEDEP}] )')"
176 #
177 # python_check_deps() {
178 # has_version "dev-python/foo[${PYTHON_USEDEP}]" \
179 # && { has_version "dev-python/bar[${PYTHON_USEDEP}]" \
180 # || has_version "dev-python/baz[${PYTHON_USEDEP}]"; }
181 # }
182 # @CODE
183 #
184 # Example value:
185 # @CODE
186 # || (
187 # (
188 # dev-lang/python:2.7
189 # dev-python/foo[python_targets_python2_7(-)?,python_single_target_python2_7(+)?]
190 # || ( dev-python/bar[python_targets_python2_7(-)?,python_single_target_python2_7(+)?]
191 # dev-python/baz[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] )
192 # )
193 # (
194 # dev-lang/python:2.6
195 # dev-python/foo[python_targets_python2_6(-)?,python_single_target_python2_6(+)?]
196 # || ( dev-python/bar[python_targets_python2_6(-)?,python_single_target_python2_6(+)?]
197 # dev-python/baz[python_targets_python2_6(-)?,python_single_target_python2_6(+)?] )
198 # )
199 # )
200 # @CODE
201 python_gen_any_dep() {
202 debug-print-function ${FUNCNAME} "${@}"
203
204 local depstr=${1}
205 [[ ${depstr} ]] || die "No dependency string provided"
206
207 local PYTHON_PKG_DEP out=
208 for i in "${_PYTHON_ALL_IMPLS[@]}"; do
209 has "${i}" "${PYTHON_COMPAT[@]}" || continue
210
211 local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)"
212 python_export "${i}" PYTHON_PKG_DEP
213
214 local i_depstr=${depstr//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
215 out="( ${PYTHON_PKG_DEP} ${i_depstr} ) ${out}"
216 done
217 echo "|| ( ${out})"
218 }
219
220 # @FUNCTION: _python_EPYTHON_supported
221 # @USAGE: <epython>
222 # @INTERNAL
223 # @DESCRIPTION:
224 # Check whether the specified implementation is supported by package
225 # (specified in PYTHON_COMPAT). Calls python_check_deps() if declared.
226 _python_EPYTHON_supported() {
227 debug-print-function ${FUNCNAME} "${@}"
228
229 local EPYTHON=${1}
230 local i=${EPYTHON/./_}
231
232 case "${i}" in
233 python*|jython*)
234 ;;
235 pypy-c*)
236 i=${i/-c/}
237 ;;
238 *)
239 ewarn "Invalid EPYTHON: ${EPYTHON}"
240 return 1
241 ;;
242 esac
243
244 if has "${i}" "${PYTHON_COMPAT[@]}"; then
245 local PYTHON_PKG_DEP
246 python_export "${i}" PYTHON_PKG_DEP
247 if ROOT=/ has_version "${PYTHON_PKG_DEP}"; then
248 if declare -f python_check_deps >/dev/null; then
249 local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)"
250 python_check_deps
251 return ${?}
252 fi
253
254 return 0
255 fi
256 elif ! has "${i}" "${_PYTHON_ALL_IMPLS[@]}"; then
257 ewarn "Invalid EPYTHON: ${EPYTHON}"
258 fi
259 return 1
260 }
261
262 # @FUNCTION: python-any-r1_pkg_setup
263 # @DESCRIPTION:
264 # Determine what the best installed (and supported) Python
265 # implementation is and set EPYTHON and PYTHON accordingly.
266 python-any-r1_pkg_setup() {
267 debug-print-function ${FUNCNAME} "${@}"
268
269 # first, try ${EPYTHON}... maybe it's good enough for us.
270 if [[ ${EPYTHON} ]]; then
271 if _python_EPYTHON_supported "${EPYTHON}"; then
272 python_export EPYTHON PYTHON
273 python_wrapper_setup
274 return
275 fi
276 fi
277
278 # then, try eselect-python
279 local variant i
280 for variant in '' '--python2' '--python3'; do
281 i=$(eselect python --show ${variant} 2>/dev/null)
282
283 if [[ ! ${i} ]]; then
284 # no eselect-python?
285 break
286 elif _python_EPYTHON_supported "${i}"; then
287 python_export "${i}" EPYTHON PYTHON
288 python_wrapper_setup
289 return
290 fi
291 done
292
293 # fallback to best installed impl.
294 local rev_impls=()
295 for i in "${_PYTHON_ALL_IMPLS[@]}"; do
296 if has "${i}" "${PYTHON_COMPAT[@]}"; then
297 rev_impls=( "${i}" "${rev_impls[@]}" )
298 fi
299 done
300
301 for i in "${rev_impls[@]}"; do
302 python_export "${i}" EPYTHON PYTHON
303 if _python_EPYTHON_supported "${EPYTHON}"; then
304 python_wrapper_setup
305 return
306 fi
307 done
308
309 eerror "No Python implementation found for the build. This is usually"
310 eerror "a bug in the ebuild. Please report it to bugs.gentoo.org"
311 eerror "along with the build log."
312 echo
313 die "No supported Python implementation installed."
314 }
315
316 _PYTHON_ANY_R1=1
317 fi

  ViewVC Help
Powered by ViewVC 1.1.20