/[gentoo-x86]/eclass/python-single-r1.eclass
Gentoo

Contents of /eclass/python-single-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (show annotations) (download)
Sat Nov 30 17:57:11 2013 UTC (12 months, 3 weeks ago) by floppym
Branch: MAIN
Changes since 1.24: +4 -2 lines
Depend on dev-lang/python-exec:0 if _PYTHON_WANT_PYTHON_EXEC2 is 0, bug 489646.

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-single-r1.eclass,v 1.24 2013/10/30 19:14:02 mgorny Exp $
4
5 # @ECLASS: python-single-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 Python packages not installed for multiple implementations.
12 # @DESCRIPTION:
13 # An extension of the python-r1 eclass suite for packages which
14 # don't support being installed for multiple Python implementations.
15 # This mostly includes tools embedding Python.
16 #
17 # This eclass extends the IUSE and REQUIRED_USE set by python-r1
18 # to request correct PYTHON_SINGLE_TARGET. It also replaces
19 # PYTHON_USEDEP and PYTHON_DEPS with a more suitable form.
20 #
21 # Please note that packages support multiple Python implementations
22 # (using python-r1 eclass) can not depend on packages not supporting
23 # them (using this eclass).
24 #
25 # Please note that python-single-r1 will always inherit python-utils-r1
26 # as well. Thus, all the functions defined there can be used
27 # in the packages using python-single-r1, and there is no need ever
28 # to inherit both.
29 #
30 # For more information, please see the python-r1 Developer's Guide:
31 # http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
32
33 case "${EAPI:-0}" in
34 0|1|2|3)
35 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
36 ;;
37 4|5)
38 # EAPI=4 is required for USE default deps on USE_EXPAND flags
39 ;;
40 *)
41 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
42 ;;
43 esac
44
45 if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
46
47 if [[ ${_PYTHON_R1} ]]; then
48 die 'python-single-r1.eclass can not be used with python-r1.eclass.'
49 elif [[ ${_PYTHON_ANY_R1} ]]; then
50 die 'python-single-r1.eclass can not be used with python-any-r1.eclass.'
51 fi
52
53 inherit python-utils-r1
54
55 fi
56
57 EXPORT_FUNCTIONS pkg_setup
58
59 if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
60
61 # @ECLASS-VARIABLE: PYTHON_COMPAT
62 # @REQUIRED
63 # @DESCRIPTION:
64 # This variable contains a list of Python implementations the package
65 # supports. It must be set before the `inherit' call. It has to be
66 # an array.
67 #
68 # Example:
69 # @CODE
70 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
71 # @CODE
72 if ! declare -p PYTHON_COMPAT &>/dev/null; then
73 die 'PYTHON_COMPAT not declared.'
74 fi
75
76 # @ECLASS-VARIABLE: PYTHON_REQ_USE
77 # @DEFAULT_UNSET
78 # @DESCRIPTION:
79 # The list of USEflags required to be enabled on the chosen Python
80 # implementations, formed as a USE-dependency string. It should be valid
81 # for all implementations in PYTHON_COMPAT, so it may be necessary to
82 # use USE defaults.
83 #
84 # This should be set before calling `inherit'.
85 #
86 # Example:
87 # @CODE
88 # PYTHON_REQ_USE="gdbm,ncurses(-)?"
89 # @CODE
90 #
91 # It will cause the Python dependencies to look like:
92 # @CODE
93 # python_single_target_pythonX_Y? ( dev-lang/python:X.Y[gdbm,ncurses(-)?] )
94 # @CODE
95
96 # @ECLASS-VARIABLE: PYTHON_DEPS
97 # @DESCRIPTION:
98 # This is an eclass-generated Python dependency string for all
99 # implementations listed in PYTHON_COMPAT.
100 #
101 # The dependency string is conditional on PYTHON_SINGLE_TARGET.
102 #
103 # Example use:
104 # @CODE
105 # RDEPEND="${PYTHON_DEPS}
106 # dev-foo/mydep"
107 # DEPEND="${RDEPEND}"
108 # @CODE
109 #
110 # Example value:
111 # @CODE
112 # dev-lang/python-exec:=
113 # python_single_target_python2_6? ( dev-lang/python:2.6[gdbm] )
114 # python_single_target_python2_7? ( dev-lang/python:2.7[gdbm] )
115 # @CODE
116
117 # @ECLASS-VARIABLE: PYTHON_USEDEP
118 # @DESCRIPTION:
119 # This is an eclass-generated USE-dependency string which can be used to
120 # depend on another Python package being built for the same Python
121 # implementations.
122 #
123 # The generate USE-flag list is compatible with packages using python-r1,
124 # python-single-r1 and python-distutils-ng eclasses. It must not be used
125 # on packages using python.eclass.
126 #
127 # Example use:
128 # @CODE
129 # RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
130 # @CODE
131 #
132 # Example value:
133 # @CODE
134 # python_targets_python2_7(-)?,python_single_target_python2_7(+)?
135 # @CODE
136
137 # @ECLASS-VARIABLE: PYTHON_REQUIRED_USE
138 # @DESCRIPTION:
139 # This is an eclass-generated required-use expression which ensures the following:
140 # 1. Exactly one PYTHON_SINGLE_TARGET value has been enabled.
141 # 2. The selected PYTHON_SINGLE_TARGET value is enabled in PYTHON_TARGETS.
142 #
143 # This expression should be utilized in an ebuild by including it in
144 # REQUIRED_USE, optionally behind a use flag.
145 #
146 # Example use:
147 # @CODE
148 # REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
149 # @CODE
150 #
151 # Example value:
152 # @CODE
153 # python_single_target_python2_6? ( python_targets_python2_6 )
154 # python_single_target_python2_7? ( python_targets_python2_7 )
155 # ^^ ( python_single_target_python2_6 python_single_target_python2_7 )
156 # @CODE
157
158 _python_single_set_globals() {
159 local impls=()
160
161 PYTHON_DEPS=
162 local i PYTHON_PKG_DEP
163 for i in "${PYTHON_COMPAT[@]}"; do
164 _python_impl_supported "${i}" || continue
165
166 # The chosen targets need to be in PYTHON_TARGETS as well.
167 # This is in order to enforce correct dependencies on packages
168 # supporting multiple implementations.
169 PYTHON_REQUIRED_USE+=" python_single_target_${i}? ( python_targets_${i} )"
170
171 python_export "${i}" PYTHON_PKG_DEP
172 PYTHON_DEPS+="python_single_target_${i}? ( ${PYTHON_PKG_DEP} ) "
173
174 impls+=( "${i}" )
175 done
176
177 if [[ ${#impls[@]} -eq 0 ]]; then
178 die "No supported implementation in PYTHON_COMPAT."
179 fi
180
181 local flags_mt=( "${impls[@]/#/python_targets_}" )
182 local flags=( "${impls[@]/#/python_single_target_}" )
183
184 local optflags=${flags_mt[@]/%/(-)?}
185 optflags+=,${flags[@]/%/(+)?}
186
187 IUSE="${flags_mt[*]} ${flags[*]}"
188 PYTHON_REQUIRED_USE+=" ^^ ( ${flags[*]} )"
189 PYTHON_USEDEP=${optflags// /,}
190
191 # 1) well, python-exec would suffice as an RDEP
192 # but no point in making this overcomplex, BDEP doesn't hurt anyone
193 # 2) python-exec should be built with all targets forced anyway
194 # but if new targets were added, we may need to force a rebuild
195 # 3) use whichever python-exec slot installed in EAPI 5. For EAPI 4,
196 # just fix :2 since := deps are not supported.
197 if [[ ${_PYTHON_WANT_PYTHON_EXEC2} == 0 ]]; then
198 PYTHON_DEPS+="dev-lang/python-exec:0[${PYTHON_USEDEP}]"
199 elif [[ ${EAPI} != 4 ]]; then
200 PYTHON_DEPS+="dev-lang/python-exec:=[${PYTHON_USEDEP}]"
201 else
202 PYTHON_DEPS+="dev-lang/python-exec:2[${PYTHON_USEDEP}]"
203 fi
204 }
205 _python_single_set_globals
206
207 # @FUNCTION: python_setup
208 # @DESCRIPTION:
209 # Determine what the selected Python implementation is and set
210 # the Python build environment up for it.
211 python_setup() {
212 debug-print-function ${FUNCNAME} "${@}"
213
214 unset EPYTHON
215
216 local impl
217 for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
218 if has "${impl}" "${PYTHON_COMPAT[@]}" \
219 && use "python_single_target_${impl}"
220 then
221 if [[ ${EPYTHON} ]]; then
222 eerror "Your PYTHON_SINGLE_TARGET setting lists more than a single Python"
223 eerror "implementation. Please set it to just one value. If you need"
224 eerror "to override the value for a single package, please use package.env"
225 eerror "or an equivalent solution (man 5 portage)."
226 echo
227 die "More than one implementation in PYTHON_SINGLE_TARGET."
228 fi
229
230 if ! use "python_targets_${impl}"; then
231 eerror "The implementation chosen as PYTHON_SINGLE_TARGET must be added"
232 eerror "to PYTHON_TARGETS as well. This is in order to ensure that"
233 eerror "dependencies are satisfied correctly. We're sorry"
234 eerror "for the inconvenience."
235 echo
236 die "Build target (${impl}) not in PYTHON_TARGETS."
237 fi
238
239 python_export "${impl}" EPYTHON PYTHON
240 python_wrapper_setup
241 fi
242 done
243
244 if [[ ! ${EPYTHON} ]]; then
245 eerror "No Python implementation selected for the build. Please set"
246 eerror "the PYTHON_SINGLE_TARGET variable in your make.conf to one"
247 eerror "of the following values:"
248 eerror
249 eerror "${PYTHON_COMPAT[@]}"
250 echo
251 die "No supported Python implementation in PYTHON_SINGLE_TARGET."
252 fi
253 }
254
255 # @FUNCTION: python-single-r1_pkg_setup
256 # @DESCRIPTION:
257 # Runs python_setup.
258 python-single-r1_pkg_setup() {
259 debug-print-function ${FUNCNAME} "${@}"
260
261 python_setup
262 }
263
264 # @FUNCTION: python_fix_shebang
265 # @USAGE: <path>...
266 # @DESCRIPTION:
267 # Replace the shebang in Python scripts with the current Python
268 # implementation (EPYTHON). If a directory is passed, works recursively
269 # on all Python scripts.
270 #
271 # Only files having a 'python' shebang will be modified; other files
272 # will be skipped. If a script has a complete shebang matching
273 # the chosen interpreter version, it is left unmodified. If a script has
274 # a complete shebang matching other version, the command dies.
275 python_fix_shebang() {
276 debug-print-function ${FUNCNAME} "${@}"
277
278 [[ ${1} ]] || die "${FUNCNAME}: no paths given"
279 [[ ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)"
280
281 local path f
282 for path; do
283 while IFS= read -r -d '' f; do
284 local shebang=$(head -n 1 "${f}")
285
286 case "${shebang}" in
287 '#!'*${EPYTHON}*)
288 debug-print "${FUNCNAME}: in file ${f#${D}}"
289 debug-print "${FUNCNAME}: shebang matches EPYTHON: ${shebang}"
290 ;;
291 '#!'*python[23].[0123456789]*|'#!'*pypy-c*|'#!'*jython*)
292 debug-print "${FUNCNAME}: in file ${f#${D}}"
293 debug-print "${FUNCNAME}: incorrect specific shebang: ${shebang}"
294
295 die "${f#${D}} has a specific Python shebang not matching EPYTHON"
296 ;;
297 '#!'*python*)
298 debug-print "${FUNCNAME}: in file ${f#${D}}"
299 debug-print "${FUNCNAME}: rewriting shebang: ${shebang}"
300
301 einfo "Fixing shebang in ${f#${D}}"
302 _python_rewrite_shebang "${f}"
303 esac
304 done < <(find "${path}" -type f -print0)
305 done
306 }
307
308 _PYTHON_SINGLE_R1=1
309 fi

  ViewVC Help
Powered by ViewVC 1.1.20