/[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.15 - (show annotations) (download)
Wed Jan 30 10:42:25 2013 UTC (17 months, 3 weeks ago) by mgorny
Branch: MAIN
Changes since 1.14: +3 -3 lines
Use (-) USE-defaults to reduce issues from removing flags.

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.14 2013/01/21 19:28:16 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 _python_single_set_globals() {
137 local impls=()
138
139 PYTHON_DEPS=
140 local i PYTHON_PKG_DEP
141 for i in "${PYTHON_COMPAT[@]}"; do
142 _python_impl_supported "${i}" || continue
143
144 # The chosen targets need to be in PYTHON_TARGETS as well.
145 # This is in order to enforce correct dependencies on packages
146 # supporting multiple implementations.
147 #REQUIRED_USE+=" python_single_target_${i}? ( python_targets_${i} )"
148
149 python_export "${i}" PYTHON_PKG_DEP
150 PYTHON_DEPS+="python_single_target_${i}? ( ${PYTHON_PKG_DEP} ) "
151
152 impls+=( "${i}" )
153 done
154
155 if [[ ${#impls[@]} -eq 0 ]]; then
156 die "No supported implementation in PYTHON_COMPAT."
157 fi
158
159 local flags_mt=( "${impls[@]/#/python_targets_}" )
160 local flags=( "${impls[@]/#/python_single_target_}" )
161
162 local optflags=${flags_mt[@]/%/(-)?}
163 optflags+=,${flags[@]/%/(+)?}
164
165 IUSE="${flags_mt[*]} ${flags[*]}"
166 #REQUIRED_USE="|| ( ${flags_mt[*]} ) ^^ ( ${flags[*]} )"
167 PYTHON_USEDEP=${optflags// /,}
168
169 # 1) well, python-exec would suffice as an RDEP
170 # but no point in making this overcomplex, BDEP doesn't hurt anyone
171 # 2) python-exec should be built with all targets forced anyway
172 # but if new targets were added, we may need to force a rebuild
173 PYTHON_DEPS+="dev-python/python-exec[${PYTHON_USEDEP}]"
174 }
175 _python_single_set_globals
176
177 # @FUNCTION: python-single-r1_pkg_setup
178 # @DESCRIPTION:
179 # Determine what the selected Python implementation is and set EPYTHON
180 # and PYTHON accordingly.
181 python-single-r1_pkg_setup() {
182 debug-print-function ${FUNCNAME} "${@}"
183
184 unset EPYTHON
185
186 local impl
187 for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
188 if has "${impl}" "${PYTHON_COMPAT[@]}" \
189 && use "python_single_target_${impl}"
190 then
191 if [[ ${EPYTHON} ]]; then
192 eerror "Your PYTHON_SINGLE_TARGET setting lists more than a single Python"
193 eerror "implementation. Please set it to just one value. If you need"
194 eerror "to override the value for a single package, please use package.env"
195 eerror "or an equivalent solution (man 5 portage)."
196 echo
197 die "More than one implementation in PYTHON_SINGLE_TARGET."
198 fi
199
200 if ! use "python_targets_${impl}"; then
201 eerror "The implementation chosen as PYTHON_SINGLE_TARGET must be added"
202 eerror "to PYTHON_TARGETS as well. This is in order to ensure that"
203 eerror "dependencies are satisfied correctly. We're sorry"
204 eerror "for the inconvenience."
205 echo
206 die "Build target (${impl}) not in PYTHON_TARGETS."
207 fi
208
209 python_export "${impl}" EPYTHON PYTHON
210 fi
211 done
212
213 if [[ ! ${EPYTHON} ]]; then
214 eerror "No Python implementation selected for the build. Please set"
215 eerror "the PYTHON_SINGLE_TARGET variable in your make.conf to one"
216 eerror "of the following values:"
217 eerror
218 eerror "${PYTHON_COMPAT[@]}"
219 echo
220 die "No supported Python implementation in PYTHON_SINGLE_TARGET."
221 fi
222 }
223
224 # @FUNCTION: python_fix_shebang
225 # @USAGE: <path>...
226 # @DESCRIPTION:
227 # Replace the shebang in Python scripts with the current Python
228 # implementation (EPYTHON). If a directory is passed, works recursively
229 # on all Python scripts.
230 #
231 # Only files having a 'python' shebang will be modified; other files
232 # will be skipped. If a script has a complete shebang matching
233 # the chosen interpreter version, it is left unmodified. If a script has
234 # a complete shebang matching other version, the command dies.
235 python_fix_shebang() {
236 debug-print-function ${FUNCNAME} "${@}"
237
238 [[ ${1} ]] || die "${FUNCNAME}: no paths given"
239 [[ ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)"
240
241 local path f
242 for path; do
243 while IFS= read -r -d '' f; do
244 local shebang=$(head -n 1 "${f}")
245
246 case "${shebang}" in
247 '#!'*${EPYTHON}*)
248 debug-print "${FUNCNAME}: in file ${f#${D}}"
249 debug-print "${FUNCNAME}: shebang matches EPYTHON: ${shebang}"
250 ;;
251 '#!'*python[23].[0123456789]*|'#!'*pypy-c*|'#!'*jython*)
252 debug-print "${FUNCNAME}: in file ${f#${D}}"
253 debug-print "${FUNCNAME}: incorrect specific shebang: ${shebang}"
254
255 die "${f#${D}} has a specific Python shebang not matching EPYTHON"
256 ;;
257 '#!'*python*)
258 debug-print "${FUNCNAME}: in file ${f#${D}}"
259 debug-print "${FUNCNAME}: rewriting shebang: ${shebang}"
260
261 einfo "Fixing shebang in ${f#${D}}"
262 _python_rewrite_shebang "${f}"
263 esac
264 done < <(find "${path}" -type f -print0)
265 done
266 }
267
268 _PYTHON_SINGLE_R1=1
269 fi

  ViewVC Help
Powered by ViewVC 1.1.20