/[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.11 - (show annotations) (download)
Fri May 10 22:03:30 2013 UTC (18 months, 1 week ago) by mgorny
Branch: MAIN
Changes since 1.10: +4 -4 lines
Consistently create ${EPYTHON} subdir for Python wrappers. Fixes conflict between Python & vala wrappers, bug #469312.

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

  ViewVC Help
Powered by ViewVC 1.1.20