/[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.19 - (show annotations) (download)
Sat Jul 4 15:26:17 2015 UTC (3 years, 9 months ago) by floppym
Branch: MAIN
CVS Tags: HEAD
Changes since 1.18: +4 -4 lines
Replace links to python-r1 dev guide with links to the wiki.

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

  ViewVC Help
Powered by ViewVC 1.1.20