/[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.18 - (show annotations) (download)
Tue May 21 01:31:02 2013 UTC (2 years ago) by floppym
Branch: MAIN
Changes since 1.17: +24 -3 lines
Set PYTHON_REQUIRED_USE, and add it to REQUIRED_USE in distutils-r1.

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

  ViewVC Help
Powered by ViewVC 1.1.20