/[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.5 - (show annotations) (download)
Wed Jan 2 21:12:44 2013 UTC (20 months, 3 weeks ago) by mgorny
Branch: MAIN
Changes since 1.4: +3 -4 lines
Remove myself from explicit maintainers, it is enough to assign the bugs to Python team.

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

  ViewVC Help
Powered by ViewVC 1.1.20