/[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.13 - (show annotations) (download)
Tue Jan 8 20:18:38 2013 UTC (20 months, 1 week ago) by mgorny
Branch: MAIN
Changes since 1.12: +10 -8 lines
Fix the PYTHON_SINGLE_TARGET validity check.

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

  ViewVC Help
Powered by ViewVC 1.1.20