/[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.17 - (show annotations) (download)
Tue Apr 8 16:05:30 2014 UTC (3 months, 2 weeks ago) by mgorny
Branch: MAIN
CVS Tags: HEAD
Changes since 1.16: +3 -6 lines
Disable pypy2_0 and clean up after it.

1 # Copyright 1999-2014 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.16 2013/10/22 15:16:56 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*|pypy*)
234 ;;
235 *)
236 ewarn "Invalid EPYTHON: ${EPYTHON}"
237 return 1
238 ;;
239 esac
240
241 if has "${i}" "${PYTHON_COMPAT[@]}"; then
242 local PYTHON_PKG_DEP
243 python_export "${i}" PYTHON_PKG_DEP
244 if ROOT=/ has_version "${PYTHON_PKG_DEP}"; then
245 if declare -f python_check_deps >/dev/null; then
246 local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)"
247 python_check_deps
248 return ${?}
249 fi
250
251 return 0
252 fi
253 elif ! has "${i}" "${_PYTHON_ALL_IMPLS[@]}"; then
254 ewarn "Invalid EPYTHON: ${EPYTHON}"
255 fi
256 return 1
257 }
258
259 # @FUNCTION: python_setup
260 # @DESCRIPTION:
261 # Determine what the best installed (and supported) Python
262 # implementation is, and set the Python build environment up for it.
263 #
264 # This function will call python_check_deps() if defined.
265 python_setup() {
266 debug-print-function ${FUNCNAME} "${@}"
267
268 # first, try ${EPYTHON}... maybe it's good enough for us.
269 if [[ ${EPYTHON} ]]; then
270 if _python_EPYTHON_supported "${EPYTHON}"; then
271 python_export EPYTHON PYTHON
272 python_wrapper_setup
273 return
274 fi
275 fi
276
277 # then, try eselect-python
278 local variant i
279 for variant in '' '--python2' '--python3'; do
280 i=$(eselect python --show ${variant} 2>/dev/null)
281
282 if [[ ! ${i} ]]; then
283 # no eselect-python?
284 break
285 elif _python_EPYTHON_supported "${i}"; then
286 python_export "${i}" EPYTHON PYTHON
287 python_wrapper_setup
288 return
289 fi
290 done
291
292 # fallback to best installed impl.
293 local rev_impls=()
294 for i in "${_PYTHON_ALL_IMPLS[@]}"; do
295 if has "${i}" "${PYTHON_COMPAT[@]}"; then
296 rev_impls=( "${i}" "${rev_impls[@]}" )
297 fi
298 done
299
300 for i in "${rev_impls[@]}"; do
301 python_export "${i}" EPYTHON PYTHON
302 if _python_EPYTHON_supported "${EPYTHON}"; then
303 python_wrapper_setup
304 return
305 fi
306 done
307
308 eerror "No Python implementation found for the build. This is usually"
309 eerror "a bug in the ebuild. Please report it to bugs.gentoo.org"
310 eerror "along with the build log."
311 echo
312 die "No supported Python implementation installed."
313 }
314
315 # @FUNCTION: python-any-r1_pkg_setup
316 # @DESCRIPTION:
317 # Runs python_setup during from-source installs.
318 #
319 # In a binary package installs is a no-op. If you need Python in pkg_*
320 # phases of a binary package, call python_setup directly.
321 python-any-r1_pkg_setup() {
322 debug-print-function ${FUNCNAME} "${@}"
323
324 [[ ${MERGE_TYPE} != binary ]] && python_setup
325 }
326
327 _PYTHON_ANY_R1=1
328 fi

  ViewVC Help
Powered by ViewVC 1.1.20