/[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.2 - (show annotations) (download)
Fri Dec 7 18:00:08 2012 UTC (2 years ago) by mgorny
Branch: MAIN
Changes since 1.1: +55 -2 lines
Respect user preferences in python-any-r1 (EPYTHON, eselect-python).

1 # Copyright 1999-2012 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.1 2012/12/01 09:29:24 mgorny Exp $
4
5 # @ECLASS: python-any-r1
6 # @MAINTAINER:
7 # Michał Górny <mgorny@gentoo.org>
8 # Python herd <python@gentoo.org>
9 # @AUTHOR:
10 # Author: Michał Górny <mgorny@gentoo.org>
11 # Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
12 # @BLURB: An eclass for packages having build-time dependency on Python.
13 # @DESCRIPTION:
14 # A minimal eclass for packages which need any Python interpreter
15 # installed without a need for explicit choice and invariability.
16 # This usually involves packages requiring Python at build-time
17 # but having no other relevance to it.
18 #
19 # This eclass provides a minimal PYTHON_DEPS variable with a dependency
20 # string on any of the supported Python implementations. It also exports
21 # pkg_setup() which finds the best supported implementation and sets it
22 # as the active one.
23 #
24 # Please note that python-any-r1 will always inherit python-utils-r1
25 # as well. Thus, all the functions defined there can be used in the
26 # packages using python-any-r1, and there is no need ever to inherit
27 # both.
28 #
29 # For more information, please see the python-r1 Developer's Guide:
30 # http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
31
32 case "${EAPI:-0}" in
33 0|1|2|3|4|5)
34 # EAPI=4 needed by python-r1
35 ;;
36 *)
37 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
38 ;;
39 esac
40
41 if [[ ! ${_PYTHON_ANY_R1} ]]; then
42
43 if [[ ${_PYTHON_R1} ]]; then
44 die 'python-any-r1.eclass can not be used with python-r1.eclass.'
45 elif [[ ${_PYTHON_SINGLE_R1} ]]; then
46 die 'python-any-r1.eclass can not be used with python-single-r1.eclass.'
47 fi
48
49 inherit python-utils-r1
50
51 fi
52
53 EXPORT_FUNCTIONS pkg_setup
54
55 if [[ ! ${_PYTHON_ANY_R1} ]]; then
56
57 # @ECLASS-VARIABLE: PYTHON_COMPAT
58 # @REQUIRED
59 # @DESCRIPTION:
60 # This variable contains a list of Python implementations the package
61 # supports. It must be set before the `inherit' call. It has to be
62 # an array.
63 #
64 # Example:
65 # @CODE
66 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
67 # @CODE
68 if ! declare -p PYTHON_COMPAT &>/dev/null; then
69 die 'PYTHON_COMPAT not declared.'
70 fi
71
72 # @ECLASS-VARIABLE: PYTHON_REQ_USE
73 # @DEFAULT_UNSET
74 # @DESCRIPTION:
75 # The list of USEflags required to be enabled on the Python
76 # implementations, formed as a USE-dependency string. It should be valid
77 # for all implementations in PYTHON_COMPAT, so it may be necessary to
78 # use USE defaults.
79 #
80 # Example:
81 # @CODE
82 # PYTHON_REQ_USE="gdbm,ncurses(-)?"
83 # @CODE
84 #
85 # It will cause the Python dependencies to look like:
86 # @CODE
87 # || ( dev-lang/python:X.Y[gdbm,ncurses(-)?] ... )
88 # @CODE
89
90 # @ECLASS-VARIABLE: PYTHON_DEPS
91 # @DESCRIPTION:
92 # This is an eclass-generated Python dependency string for all
93 # implementations listed in PYTHON_COMPAT.
94 #
95 # Any of the supported interpreters will satisfy the dependency.
96 #
97 # Example use:
98 # @CODE
99 # DEPEND="${RDEPEND}
100 # ${PYTHON_DEPS}"
101 # @CODE
102 #
103 # Example value:
104 # @CODE
105 # || ( dev-lang/python:2.7[gdbm]
106 # dev-lang/python:2.6[gdbm] )
107 # @CODE
108
109 _python_build_set_globals() {
110 local usestr
111 [[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]"
112
113 PYTHON_DEPS=
114 local i
115 for i in "${_PYTHON_ALL_IMPLS[@]}"; do
116 if has "${i}" "${PYTHON_COMPAT[@]}"
117 then
118 local d
119 case ${i} in
120 python*)
121 d='dev-lang/python';;
122 jython*)
123 d='dev-java/jython';;
124 pypy*)
125 d='dev-python/pypy';;
126 *)
127 die "Invalid implementation: ${i}"
128 esac
129
130 local v=${i##*[a-z]}
131 PYTHON_DEPS="${d}:${v/_/.}${usestr} ${PYTHON_DEPS}"
132 fi
133 done
134 PYTHON_DEPS="|| ( ${PYTHON_DEPS})"
135 }
136 _python_build_set_globals
137
138 # @FUNCTION: _python_impl_supported
139 # @USAGE: <epython>
140 # @INTERNAL
141 # @DESCRIPTION:
142 # Check whether the specified implementation is supported by package
143 # (specified in PYTHON_COMPAT).
144 _python_impl_supported() {
145 debug-print-function ${FUNCNAME} "${@}"
146
147 local i=${1/./_}
148
149 case "${i}" in
150 python*|jython*)
151 ;;
152 pypy-c*)
153 i=${i/-c/}
154 ;;
155 *)
156 ewarn "Invalid EPYTHON: ${EPYTHON}"
157 ;;
158 esac
159
160 if has "${i}" "${PYTHON_COMPAT[@]}"; then
161 return 0
162 elif ! has "${i}" "${_PYTHON_ALL_IMPLS[@]}"; then
163 ewarn "Invalid EPYTHON: ${EPYTHON}"
164 fi
165 return 1
166 }
167
168 # @FUNCTION: python-any-r1_pkg_setup
169 # @DESCRIPTION:
170 # Determine what the best installed (and supported) Python
171 # implementation is and set EPYTHON and PYTHON accordingly.
172 python-any-r1_pkg_setup() {
173 debug-print-function ${FUNCNAME} "${@}"
174
175 # first, try ${EPYTHON}... maybe it's good enough for us.
176 if [[ ${EPYTHON} ]]; then
177 if _python_impl_supported "${EPYTHON}"; then
178 python_export EPYTHON PYTHON
179 return
180 fi
181 fi
182
183 # then, try eselect-python
184 local variant i
185 for variant in '' '--python2' '--python3'; do
186 i=$(eselect python --show ${variant} 2>/dev/null)
187
188 if [[ ! ${i} ]]; then
189 # no eselect-python?
190 break
191 elif _python_impl_supported "${i}"; then
192 python_export "${i}" EPYTHON PYTHON
193 return
194 fi
195 done
196
197 # fallback to best installed impl.
198 local rev_impls=()
199 for i in "${_PYTHON_ALL_IMPLS[@]}"; do
200 if has "${i}" "${PYTHON_COMPAT[@]}"; then
201 rev_impls=( "${i}" "${rev_impls[@]}" )
202 fi
203 done
204
205 for i in "${rev_impls[@]}"; do
206 local d
207 case "${i}" in
208 python*)
209 d='dev-lang/python';;
210 jython*)
211 d='dev-java/jython';;
212 pypy*)
213 d='dev-python/pypy';;
214 *)
215 die "Invalid implementation: ${i}"
216 esac
217 local v=${i##*[a-z]}
218
219 if has_version "${d}:${v/_/.}${usestr}"; then
220 python_export "${i}" EPYTHON PYTHON
221 break
222 fi
223 done
224 }
225
226 _PYTHON_ANY_R1=1
227 fi

  ViewVC Help
Powered by ViewVC 1.1.20