/[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.12 - (show annotations) (download)
Sat Jul 27 11:16:48 2013 UTC (16 months, 3 weeks ago) by mgorny
Branch: MAIN
Changes since 1.11: +6 -18 lines
Use PYTHON_PKG_DEP for generating deps.

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.11 2013/05/10 22:03:30 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
118 [[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]"
119
120 PYTHON_DEPS=
121 local i PYTHON_PKG_DEP
122 for i in "${_PYTHON_ALL_IMPLS[@]}"; do
123 has "${i}" "${PYTHON_COMPAT[@]}" || continue
124
125 python_export "${i}" PYTHON_PKG_DEP
126
127 PYTHON_DEPS="${PYTHON_PKG_DEP} ${PYTHON_DEPS}"
128 done
129 PYTHON_DEPS="|| ( ${PYTHON_DEPS})"
130 }
131 _python_build_set_globals
132
133 # @ECLASS-VARIABLE: PYTHON_USEDEP
134 # @DESCRIPTION:
135 # An eclass-generated USE-dependency string for the currently tested
136 # implementation. It is set locally for python_check_deps() call.
137 #
138 # The generate USE-flag list is compatible with packages using python-r1,
139 # python-single-r1 and python-distutils-ng eclasses. It must not be used
140 # on packages using python.eclass.
141 #
142 # Example use:
143 # @CODE
144 # python_check_deps() {
145 # has_version "dev-python/foo[${PYTHON_USEDEP}]"
146 # }
147 # @CODE
148 #
149 # Example value:
150 # @CODE
151 # python_targets_python2_7(-)?,python_single_target_python2_7(+)?
152 # @CODE
153
154 # @FUNCTION: _python_EPYTHON_supported
155 # @USAGE: <epython>
156 # @INTERNAL
157 # @DESCRIPTION:
158 # Check whether the specified implementation is supported by package
159 # (specified in PYTHON_COMPAT). Calls python_check_deps() if declared.
160 _python_EPYTHON_supported() {
161 debug-print-function ${FUNCNAME} "${@}"
162
163 local EPYTHON=${1}
164 local i=${EPYTHON/./_}
165
166 case "${i}" in
167 python*|jython*)
168 ;;
169 pypy-c*)
170 i=${i/-c/}
171 ;;
172 *)
173 ewarn "Invalid EPYTHON: ${EPYTHON}"
174 return 1
175 ;;
176 esac
177
178 if has "${i}" "${PYTHON_COMPAT[@]}"; then
179 local PYTHON_PKG_DEP
180 python_export "${i}" PYTHON_PKG_DEP
181 if ROOT=/ has_version "${PYTHON_PKG_DEP}"; then
182 if declare -f python_check_deps >/dev/null; then
183 local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)"
184 python_check_deps
185 return ${?}
186 fi
187
188 return 0
189 fi
190 elif ! has "${i}" "${_PYTHON_ALL_IMPLS[@]}"; then
191 ewarn "Invalid EPYTHON: ${EPYTHON}"
192 fi
193 return 1
194 }
195
196 # @FUNCTION: python-any-r1_pkg_setup
197 # @DESCRIPTION:
198 # Determine what the best installed (and supported) Python
199 # implementation is and set EPYTHON and PYTHON accordingly.
200 python-any-r1_pkg_setup() {
201 debug-print-function ${FUNCNAME} "${@}"
202
203 # first, try ${EPYTHON}... maybe it's good enough for us.
204 if [[ ${EPYTHON} ]]; then
205 if _python_EPYTHON_supported "${EPYTHON}"; then
206 python_export EPYTHON PYTHON
207 python_wrapper_setup
208 return
209 fi
210 fi
211
212 # then, try eselect-python
213 local variant i
214 for variant in '' '--python2' '--python3'; do
215 i=$(eselect python --show ${variant} 2>/dev/null)
216
217 if [[ ! ${i} ]]; then
218 # no eselect-python?
219 break
220 elif _python_EPYTHON_supported "${i}"; then
221 python_export "${i}" EPYTHON PYTHON
222 python_wrapper_setup
223 return
224 fi
225 done
226
227 # fallback to best installed impl.
228 local rev_impls=()
229 for i in "${_PYTHON_ALL_IMPLS[@]}"; do
230 if has "${i}" "${PYTHON_COMPAT[@]}"; then
231 rev_impls=( "${i}" "${rev_impls[@]}" )
232 fi
233 done
234
235 for i in "${rev_impls[@]}"; do
236 python_export "${i}" EPYTHON PYTHON
237 if _python_EPYTHON_supported "${EPYTHON}"; then
238 python_wrapper_setup
239 return
240 fi
241 done
242
243 eerror "No Python implementation found for the build. This is usually"
244 eerror "a bug in the ebuild. Please report it to bugs.gentoo.org"
245 eerror "along with the build log."
246 echo
247 die "No supported Python implementation installed."
248 }
249
250 _PYTHON_ANY_R1=1
251 fi

  ViewVC Help
Powered by ViewVC 1.1.20