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

Diff of /eclass/python.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.84 Revision 1.104
1# Copyright 1999-2010 Gentoo Foundation 1# Copyright 1999-2010 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.84 2010/01/11 16:07:23 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.104 2010/10/25 11:54:19 arfrever Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# python@gentoo.org 7# Gentoo Python Project <python@gentoo.org>
8# @BLURB: A utility eclass that should be inherited by anything that deals with Python or Python modules. 8# @BLURB: Eclass for Python packages
9# @DESCRIPTION: 9# @DESCRIPTION:
10# Some useful functions for dealing with Python. 10# The python eclass contains miscellaneous, useful functions for Python packages.
11 11
12inherit multilib 12inherit multilib
13 13
14if ! has "${EAPI:-0}" 0 1 2; then 14if ! has "${EAPI:-0}" 0 1 2 3; then
15 die "API of python.eclass in EAPI=\"${EAPI}\" not established" 15 die "API of python.eclass in EAPI=\"${EAPI}\" not established"
16fi 16fi
17 17
18_CPYTHON2_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
19_CPYTHON3_SUPPORTED_ABIS=(3.0 3.1 3.2)
20_JYTHON_SUPPORTED_ABIS=(2.5-jython)
21_PYTHON_SUPPORTED_ABIS=(${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]})
22
23# ================================================================================================
24# ===================================== HANDLING OF METADATA =====================================
25# ================================================================================================
26
27_python_set_IUSE() {
28 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI
29
30 _PYTHON_ABIS_USE_FLAGS=""
31 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
32
33 for PYTHON_ABI in "${_PYTHON_SUPPORTED_ABIS[@]}"; do
34 support_ABI="1"
35 while read restricted_ABI; do
36 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
37 support_ABI="0"
38 break
39 fi
40 done <<< "${restricted_ABIs}"
41 [[ "${support_ABI}" == "1" ]] && _PYTHON_ABIS_USE_FLAGS+="${_PYTHON_ABIS_USE_FLAGS:+ }python_abis_${PYTHON_ABI}"
42 done
43
44 IUSE="${_PYTHON_ABIS_USE_FLAGS}"
45}
46
47if ! has "${EAPI:-0}" 0 1 2 3 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
48 _python_set_IUSE
49fi
50unset -f _python_set_IUSE
51
52# @ECLASS-VARIABLE: PYTHON_DEPEND
53# @DESCRIPTION:
54# Specification of dependency on dev-lang/python.
55# Syntax:
56# PYTHON_DEPEND: [[!]USE_flag? ]<version_components_group>[ version_components_group]
57# version_components_group: <major_version[:[minimal_version][:maximal_version]]>
58# major_version: <2|3|*>
59# minimal_version: <minimal_major_version.minimal_minor_version>
60# maximal_version: <maximal_major_version.maximal_minor_version>
61
62_python_parse_PYTHON_DEPEND() {
63 local major_version maximal_version minimal_version python_all="0" python_maximal_version python_minimal_version python_versions=() python2="0" python2_maximal_version python2_minimal_version python3="0" python3_maximal_version python3_minimal_version USE_flag= version_components_group version_components_group_regex version_components_groups
64
65 version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
66 version_components_groups="${PYTHON_DEPEND}"
67
68 if [[ "${version_components_groups}" =~ ^((\!)?[[:alnum:]_-]+\?\ )?${version_components_group_regex}(\ ${version_components_group_regex})?$ ]]; then
69 if [[ "${version_components_groups}" =~ ^(\!)?[[:alnum:]_-]+\? ]]; then
70 USE_flag="${version_components_groups%\? *}"
71 version_components_groups="${version_components_groups#* }"
72 fi
73 if [[ "${version_components_groups}" =~ ("*".*" "|" *"|^2.*\ (2|\*)|^3.*\ (3|\*)) ]]; then
74 die "Invalid syntax of PYTHON_DEPEND: Incorrectly specified groups of versions"
75 fi
76
77 version_components_groups="${version_components_groups// /$'\n'}"
78 while read version_components_group; do
79 major_version="${version_components_group:0:1}"
80 minimal_version="${version_components_group:2}"
81 minimal_version="${minimal_version%:*}"
82 maximal_version="${version_components_group:$((3 + ${#minimal_version}))}"
83
84 if [[ "${major_version}" =~ ^(2|3)$ ]]; then
85 if [[ -n "${minimal_version}" && "${major_version}" != "${minimal_version:0:1}" ]]; then
86 die "Invalid syntax of PYTHON_DEPEND: Minimal version '${minimal_version}' not in specified group of versions"
87 fi
88 if [[ -n "${maximal_version}" && "${major_version}" != "${maximal_version:0:1}" ]]; then
89 die "Invalid syntax of PYTHON_DEPEND: Maximal version '${maximal_version}' not in specified group of versions"
90 fi
91 fi
92
93 if [[ "${major_version}" == "2" ]]; then
94 python2="1"
95 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}")
96 python2_minimal_version="${minimal_version}"
97 python2_maximal_version="${maximal_version}"
98 elif [[ "${major_version}" == "3" ]]; then
99 python3="1"
100 python_versions=("${_CPYTHON3_SUPPORTED_ABIS[@]}")
101 python3_minimal_version="${minimal_version}"
102 python3_maximal_version="${maximal_version}"
103 else
104 python_all="1"
105 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}")
106 python_minimal_version="${minimal_version}"
107 python_maximal_version="${maximal_version}"
108 fi
109
110 if [[ -n "${minimal_version}" ]] && ! has "${minimal_version}" "${python_versions[@]}"; then
111 die "Invalid syntax of PYTHON_DEPEND: Unrecognized minimal version '${minimal_version}'"
112 fi
113 if [[ -n "${maximal_version}" ]] && ! has "${maximal_version}" "${python_versions[@]}"; then
114 die "Invalid syntax of PYTHON_DEPEND: Unrecognized maximal version '${maximal_version}'"
115 fi
116
117 if [[ -n "${minimal_version}" && -n "${maximal_version}" && "${minimal_version}" > "${maximal_version}" ]]; then
118 die "Invalid syntax of PYTHON_DEPEND: Minimal version '${minimal_version}' greater than maximal version '${maximal_version}'"
119 fi
120 done <<< "${version_components_groups}"
121
122 _PYTHON_ATOMS=()
123
124 _append_accepted_versions_range() {
125 local accepted_version="0" i
126 for ((i = "${#python_versions[@]}"; i >= 0; i--)); do
127 if [[ "${python_versions[${i}]}" == "${python_maximal_version}" ]]; then
128 accepted_version="1"
129 fi
130 if [[ "${accepted_version}" == "1" ]]; then
131 _PYTHON_ATOMS+=("=dev-lang/python-${python_versions[${i}]}*")
132 fi
133 if [[ "${python_versions[${i}]}" == "${python_minimal_version}" ]]; then
134 accepted_version="0"
135 fi
136 done
137 }
138
139 if [[ "${python_all}" == "1" ]]; then
140 if [[ -z "${python_minimal_version}" && -z "${python_maximal_version}" ]]; then
141 _PYTHON_ATOMS+=("dev-lang/python")
142 else
143 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}")
144 python_minimal_version="${python_minimal_version:-${python_versions[0]}}"
145 python_maximal_version="${python_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
146 _append_accepted_versions_range
147 fi
148 else
149 if [[ "${python3}" == "1" ]]; then
150 if [[ -z "${python3_minimal_version}" && -z "${python3_maximal_version}" ]]; then
151 _PYTHON_ATOMS+=("=dev-lang/python-3*")
152 else
153 python_versions=("${_CPYTHON3_SUPPORTED_ABIS[@]}")
154 python_minimal_version="${python3_minimal_version:-${python_versions[0]}}"
155 python_maximal_version="${python3_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
156 _append_accepted_versions_range
157 fi
158 fi
159 if [[ "${python2}" == "1" ]]; then
160 if [[ -z "${python2_minimal_version}" && -z "${python2_maximal_version}" ]]; then
161 _PYTHON_ATOMS+=("=dev-lang/python-2*")
162 else
163 python_versions=("${_CPYTHON2_SUPPORTED_ABIS[@]}")
164 python_minimal_version="${python2_minimal_version:-${python_versions[0]}}"
165 python_maximal_version="${python2_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
166 _append_accepted_versions_range
167 fi
168 fi
169 fi
170
171 unset -f _append_accepted_versions_range
172
173 if [[ "${#_PYTHON_ATOMS[@]}" -gt 1 ]]; then
174 DEPEND+="${DEPEND:+ }${USE_flag}${USE_flag:+? ( }|| ( ${_PYTHON_ATOMS[@]} )${USE_flag:+ )}"
175 RDEPEND+="${RDEPEND:+ }${USE_flag}${USE_flag:+? ( }|| ( ${_PYTHON_ATOMS[@]} )${USE_flag:+ )}"
176 else
177 DEPEND+="${DEPEND:+ }${USE_flag}${USE_flag:+? ( }${_PYTHON_ATOMS[@]}${USE_flag:+ )}"
178 RDEPEND+="${RDEPEND:+ }${USE_flag}${USE_flag:+? ( }${_PYTHON_ATOMS[@]}${USE_flag:+ )}"
179 fi
180 else
181 die "Invalid syntax of PYTHON_DEPEND"
182 fi
183}
184
185DEPEND=">=app-admin/eselect-python-20091230"
186RDEPEND="${DEPEND}"
187
188if [[ -n "${PYTHON_DEPEND}" ]]; then
189 _python_parse_PYTHON_DEPEND
190else
191 _PYTHON_ATOMS=("dev-lang/python")
192fi
193unset -f _python_parse_PYTHON_DEPEND
194
18if [[ -n "${NEED_PYTHON}" ]]; then 195if [[ -n "${NEED_PYTHON}" ]]; then
19 PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" 196 eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
20 DEPEND="${PYTHON_ATOM}" 197 die "NEED_PYTHON variable is banned"
21 RDEPEND="${DEPEND}"
22else
23 PYTHON_ATOM="dev-lang/python"
24fi 198fi
25 199
26DEPEND+=" >=app-admin/eselect-python-20090804" 200# @ECLASS-VARIABLE: PYTHON_USE_WITH
27
28__python_eclass_test() {
29 __python_version_extract 2.3
30 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
31 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
32 __python_version_extract 2.3.4
33 echo -n "2.3.4 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
34 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
35 __python_version_extract 2.3.5
36 echo -n "2.3.5 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
37 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
38 __python_version_extract 2.4
39 echo -n "2.4 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
40 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
41 __python_version_extract 2.5b3
42 echo -n "2.5b3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
43 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
44}
45
46# @FUNCTION: python_version
47# @DESCRIPTION: 201# @DESCRIPTION:
48# Run without arguments and it will export the version of python 202# Set this to a space separated list of USE flags the Python slot in use must be built with.
49# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR 203
50__python_version_extract() { 204# @ECLASS-VARIABLE: PYTHON_USE_WITH_OR
51 local verstr=$1 205# @DESCRIPTION:
52 export PYVER_MAJOR=${verstr:0:1} 206# Set this to a space separated list of USE flags of which one must be turned on for the slot in use.
53 export PYVER_MINOR=${verstr:2:1} 207
54 if [[ ${verstr:3:1} == . ]]; then 208# @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT
55 export PYVER_MICRO=${verstr:4} 209# @DESCRIPTION:
210# Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or
211# PYTHON_USE_WITH_OR atoms conditional under a USE flag.
212
213if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
214 _PYTHON_USE_WITH_ATOMS_ARRAY=()
215 if [[ -n "${PYTHON_USE_WITH}" ]]; then
216 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
217 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH// /,}]")
218 done
219 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
220 for _USE_flag in ${PYTHON_USE_WITH_OR}; do
221 for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
222 _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
223 done
224 done
225 unset _USE_flag
226 fi
227 if [[ "${#_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" -gt 1 ]]; then
228 _PYTHON_USE_WITH_ATOMS="|| ( ${_PYTHON_USE_WITH_ATOMS_ARRAY[@]} )"
229 else
230 _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}"
231 fi
232 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
233 _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )"
234 fi
235 DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
236 RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
237 unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
56 fi 238fi
57 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
58}
59 239
60python_version() { 240unset _PYTHON_ATOMS
61 [[ -n "${PYVER}" ]] && return 0
62 local tmpstr
63 python=${python:-/usr/bin/python}
64 tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
65 export PYVER_ALL="${tmpstr#Python }"
66 __python_version_extract $PYVER_ALL
67}
68 241
69# @FUNCTION: PYTHON 242# @FUNCTION: python_abi_depend
70# @USAGE: [-2] [-3] [--ABI] [-A|--active] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> 243# @USAGE: [-e|--exclude-ABIs Python_ABIs] [-i|--include-ABIs Python_ABIs] [--] <dependency_atom> [dependency_atoms]
71# @DESCRIPTION: 244# @DESCRIPTION:
72# Get Python interpreter filename for specified Python ABI. If Python_ABI argument 245# Print dependency atoms with USE dependencies for Python ABIs added.
73# is ommitted, then PYTHON_ABI environment variable must be set and is used. 246# If --exclude-ABIs option is specified, then Python ABIs matching its argument are not used.
74# If -2 option is specified, then active version of Python 2 is used. 247# If --include-ABIs option is specified, then only Python ABIs matching its argument are used.
75# If -3 option is specified, then active version of Python 3 is used.
76# If --active option is specified, then active version of Python is used.
77# Active version of Python can be set by python_set_active_version().
78# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
79# -2, -3, --active and --final-ABI options and Python_ABI argument cannot be specified simultaneously.
80# If --ABI option is specified, then only specified Python ABI is printed instead of
81# Python interpreter filename.
82# --ABI and --absolute-path options cannot be specified simultaneously. 248# --exclude-ABIs and --include-ABIs options cannot be specified simultaneously.
83PYTHON() { 249python_abi_depend() {
84 local ABI_output="0" absolute_path_output="0" active="0" final_ABI="0" python2="0" python3="0" slot= 250 local atom atom_index atoms=() exclude_ABIs="0" excluded_ABI excluded_ABIs include_ABIs="0" included_ABI included_ABIs support_ABI USE_dependencies USE_flag USE_flag_index USE_flags=()
251
252 if has "${EAPI:-0}" 0 1 2 3; then
253 die "${FUNCNAME}() cannot be used in this EAPI"
254 fi
255
256 if [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
257 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
258 fi
85 259
86 while (($#)); do 260 while (($#)); do
87 case "$1" in 261 case "$1" in
88 -2) 262 -e|--exclude-ABIs)
89 python2="1" 263 exclude_ABIs="1"
264 excluded_ABIs="${2// /$'\n'}"
265 shift
90 ;; 266 ;;
91 -3)
92 python3="1"
93 ;;
94 --ABI)
95 ABI_output="1"
96 ;;
97 -A|--active)
98 active="1"
99 ;;
100 -a|--absolute-path)
101 absolute_path_output="1"
102 ;;
103 -f|--final-ABI) 267 -i|--include-ABIs)
104 final_ABI="1" 268 include_ABIs="1"
269 included_ABIs="${2// /$'\n'}"
270 shift
105 ;; 271 ;;
106 --) 272 --)
273 shift
107 break 274 break
108 ;; 275 ;;
109 -*) 276 -*)
110 die "${FUNCNAME}(): Unrecognized option '$1'" 277 die "${FUNCNAME}(): Unrecognized option '$1'"
111 ;; 278 ;;
114 ;; 281 ;;
115 esac 282 esac
116 shift 283 shift
117 done 284 done
118 285
119 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then 286 if [[ "${exclude_ABIs}" == "1" && "${include_ABIs}" == "1" ]]; then
120 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" 287 die "${FUNCNAME}(): '--exclude-ABIs' and '--include-ABIs' options cannot be specified simultaneously"
121 fi
122
123 if [[ "$((${python2} + ${python3} + ${active} + ${final_ABI}))" -gt 1 ]]; then
124 die "${FUNCNAME}(): '-2', '-3', '--active' or '--final-ABI' options cannot be specified simultaneously"
125 fi 288 fi
126 289
127 if [[ "$#" -eq 0 ]]; then 290 if [[ "$#" -eq 0 ]]; then
291 die "${FUNCNAME}(): Missing dependency atoms"
292 fi
293
294 atoms=("$@")
295
296 if [[ "${exclude_ABIs}" == "0" && "${include_ABIs}" == "0" ]]; then
297 USE_dependencies="$(printf ",%s?" ${_PYTHON_ABIS_USE_FLAGS})"
298 USE_dependencies="${USE_dependencies#,}"
299
300 for atom_index in "${!atoms[@]}"; do
301 atom="${atoms[${atom_index}]}"
302
303 if [[ "${atom}" == *"["*"]" ]]; then
304 echo -n "${atom%]},"
305 else
306 echo -n "${atom}["
307 fi
308 echo -n "${USE_dependencies}]"
309
310 if [[ "${atom_index}" -ne $((${#atoms[@]} - 1)) ]]; then
311 echo -n " "
312 fi
313 done
314 else
128 if [[ "${active}" == "1" ]]; then 315 if [[ "${exclude_ABIs}" == "1" ]]; then
129 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 316 for USE_flag in ${_PYTHON_ABIS_USE_FLAGS}; do
130 die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python" 317 while read excluded_ABI; do
318 support_ABI="1"
319 if [[ "${USE_flag}" == python_abis_${excluded_ABI} ]]; then
320 support_ABI="0"
321 break
131 fi 322 fi
132 slot="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" 323 done <<< "${excluded_ABIs}"
324 [[ "${support_ABI}" == "1" ]] && USE_flags+=("${USE_flag}")
325 done
133 elif [[ "${final_ABI}" == "1" ]]; then 326 elif [[ "${include_ABIs}" == "1" ]]; then
134 validate_PYTHON_ABIS 327 for USE_flag in ${_PYTHON_ABIS_USE_FLAGS}; do
135 slot="${PYTHON_ABIS##* }" 328 while read included_ABI; do
136 elif [[ "${python2}" == "1" ]]; then 329 support_ABI="0"
137 slot="$(eselect python show --python2)" 330 if [[ "${USE_flag}" == python_abis_${included_ABI} ]]; then
138 if [[ -z "${slot}" ]]; then 331 support_ABI="1"
139 die "${FUNCNAME}(): Active Python 2 interpreter not set" 332 break
140 elif [[ "${slot}" != "python2."* ]]; then
141 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
142 fi 333 fi
143 slot="${slot#python}" 334 done <<< "${included_ABIs}"
144 elif [[ "${python3}" == "1" ]]; then 335 [[ "${support_ABI}" == "1" ]] && USE_flags+=("${USE_flag}")
145 slot="$(eselect python show --python3)" 336 done
146 if [[ -z "${slot}" ]]; then
147 die "${FUNCNAME}(): Active Python 3 interpreter not set"
148 elif [[ "${slot}" != "python3."* ]]; then
149 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
150 fi
151 slot="${slot#python}"
152 elif [[ -n "${PYTHON_ABI}" ]]; then
153 slot="${PYTHON_ABI}"
154 else 337 else
155 die "${FUNCNAME}(): Invalid usage" 338 die "${FUNCNAME}(): Internal error"
339 fi
340
341 for USE_flag_index in "${!USE_flags[@]}"; do
342 USE_flag="${USE_flags[${USE_flag_index}]}"
343 USE_dependencies="${USE_flag}"
344
345 echo -n "${USE_flag}? ( "
346
347 for atom_index in "${!atoms[@]}"; do
348 atom="${atoms[${atom_index}]}"
349
350 if [[ "${atom}" == *"["*"]" ]]; then
351 echo -n "${atom%]},"
352 else
353 echo -n "${atom}["
354 fi
355 echo -n "${USE_dependencies}]"
356
357 if [[ "${atom_index}" -ne $((${#atoms[@]} - 1)) ]]; then
358 echo -n " "
359 fi
360 done
361
362 echo -n " )"
363
364 if [[ "${USE_flag_index}" -ne $((${#USE_flags[@]} - 1)) ]]; then
365 echo -n " "
156 fi 366 fi
157 elif [[ "$#" -eq 1 ]]; then 367 done
158 if [[ "${active}" == "1" ]]; then
159 die "${FUNCNAME}(): '--active' option and Python ABI cannot be specified simultaneously"
160 fi 368 fi
161 if [[ "${final_ABI}" == "1" ]]; then
162 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
163 fi
164 if [[ "${python2}" == "1" ]]; then
165 die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously"
166 fi
167 if [[ "${python3}" == "1" ]]; then
168 die "${FUNCNAME}(): '-3' option and Python ABI cannot be specified simultaneously"
169 fi
170 slot="$1"
171 else
172 die "${FUNCNAME}(): Invalid usage"
173 fi
174
175 if [[ "${ABI_output}" == "1" ]]; then
176 echo -n "${slot}"
177 return
178 elif [[ "${absolute_path_output}" == "1" ]]; then
179 echo -n "/usr/bin/python${slot}"
180 else
181 echo -n "python${slot}"
182 fi
183
184 if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then
185 echo -n "-${ABI}"
186 fi
187} 369}
370
371# ================================================================================================
372# =================================== MISCELLANEOUS FUNCTIONS ====================================
373# ================================================================================================
188 374
189_python_implementation() { 375_python_implementation() {
190 if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then 376 if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
191 return 0 377 return 0
378 elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
379 return 0
192 else 380 else
193 return 1 381 return 1
194 fi 382 fi
195} 383}
196 384
197# @FUNCTION: python_set_active_version 385_python_package_supporting_installation_for_multiple_python_abis() {
198# @USAGE: <Python_ABI|2|3> 386 if [[ "${EBUILD_PHASE}" == "depend" ]]; then
199# @DESCRIPTION: 387 die "${FUNCNAME}() cannot be used in global scope"
200# Set active version of Python.
201python_set_active_version() {
202 if [[ "$#" -ne "1" ]]; then
203 die "${FUNCNAME}() requires 1 argument"
204 fi
205
206 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
207 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
208 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
209 fi 388 fi
210 export EPYTHON="$(PYTHON "$1")" 389
211 elif [[ "$1" == "2" ]]; then 390 if has "${EAPI:-0}" 0 1 2 3 4; then
212 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then 391 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
213 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" 392 return 0
214 fi
215 export EPYTHON="$(PYTHON -2)"
216 elif [[ "$1" == "3" ]]; then
217 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
218 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
219 fi
220 export EPYTHON="$(PYTHON -3)"
221 else 393 else
222 die "${FUNCNAME}(): Unrecognized argument '$1'" 394 return 1
223 fi 395 fi
224 396 else
225 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, 397 die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
226 # so it does not need to be exported to subprocesses. 398 fi
227 PYTHON_ABI="${EPYTHON#python}"
228 PYTHON_ABI="${PYTHON_ABI%%-*}"
229} 399}
230 400
231unset PYTHON_ABIS 401_python_abi-specific_local_scope() {
232unset PYTHON_ABIS_SANITY_CHECKS 402 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
403}
233 404
234# @FUNCTION: validate_PYTHON_ABIS 405_python_initialize_prefix_variables() {
235# @DESCRIPTION: 406 if has "${EAPI:-0}" 0 1 2; then
236# Ensure that PYTHON_ABIS variable has valid value. 407 if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
237validate_PYTHON_ABIS() { 408 EROOT="${ROOT%/}${EPREFIX}/"
238 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable.
239 if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
240 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
241 fi 409 fi
410 if [[ -n "${D}" && -z "${ED}" ]]; then
411 ED="${D%/}${EPREFIX}/"
412 fi
413 fi
414}
242 415
416unset PYTHON_SANITY_CHECKS_EXECUTED PYTHON_SKIP_SANITY_CHECKS
417
418_python_initial_sanity_checks() {
419 if [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
243 # Ensure that /usr/bin/python and /usr/bin/python-config are valid. 420 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
244 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then 421 if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
245 eerror "'/usr/bin/python' is not valid symlink." 422 eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
246 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." 423 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
247 die "'/usr/bin/python' is not valid symlink" 424 die "'${EPREFIX}/usr/bin/python' is not valid symlink"
248 fi 425 fi
249 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then 426 if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
250 eerror "'/usr/bin/python-config' is not valid script" 427 eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
251 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." 428 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
252 die "'/usr/bin/python-config' is not valid script" 429 die "'${EPREFIX}/usr/bin/python-config' is not valid script"
253 fi 430 fi
431 fi
432}
254 433
255 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5. 434_python_final_sanity_checks() {
435 if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
436 local PYTHON_ABI="${PYTHON_ABI}"
437 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
438 # Ensure that appropriate version of Python is installed.
439 if ! has_version "$(python_get_implementational_package)"; then
440 die "$(python_get_implementational_package) is not installed"
441 fi
442
443 # Ensure that EPYTHON variable is respected.
444 if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
445 eerror "Path to 'python': '$(type -p python)'"
446 eerror "ABI: '${ABI}'"
447 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
448 eerror "EPYTHON: '$(PYTHON)'"
449 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
450 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
451 die "'python' does not respect EPYTHON variable"
452 fi
453 done
454 fi
455 PYTHON_SANITY_CHECKS_EXECUTED="1"
456}
457
458# @ECLASS-VARIABLE: PYTHON_COLORS
459# @DESCRIPTION:
460# User-configurable colored output.
461PYTHON_COLORS="${PYTHON_COLORS:-0}"
462
463_python_set_color_variables() {
464 if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
465 _BOLD=$'\e[1m'
466 _RED=$'\e[1;31m'
467 _GREEN=$'\e[1;32m'
468 _BLUE=$'\e[1;34m'
469 _CYAN=$'\e[1;36m'
470 _NORMAL=$'\e[0m'
471 else
472 _BOLD=
473 _RED=
474 _GREEN=
475 _BLUE=
476 _CYAN=
477 _NORMAL=
478 fi
479}
480
481unset PYTHON_PKG_SETUP_EXECUTED
482
483_python_check_python_pkg_setup_execution() {
484 [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return
485
486 if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
487 die "python_pkg_setup() not called"
488 fi
489}
490
491# @FUNCTION: python_pkg_setup
492# @DESCRIPTION:
493# Perform sanity checks and initialize environment.
494#
495# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
496# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
497#
498# This function can be used only in pkg_setup() phase.
499python_pkg_setup() {
500 # Check if phase is pkg_setup().
501 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
502
503 if [[ "$#" -ne 0 ]]; then
504 die "${FUNCNAME}() does not accept arguments"
505 fi
506
507 if _python_package_supporting_installation_for_multiple_python_abis; then
508 _python_calculate_PYTHON_ABIS
509 export EPYTHON="$(PYTHON -f)"
510 else
511 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
512 fi
513
514 if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
515 if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
516 if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
517 use ${PYTHON_USE_WITH_OPT#!} && return
518 else
519 use !${PYTHON_USE_WITH_OPT} && return
520 fi
521 fi
522
523 python_pkg_setup_check_USE_flags() {
524 local python_atom USE_flag
525 python_atom="$(python_get_implementational_package)"
526
527 for USE_flag in ${PYTHON_USE_WITH}; do
528 if ! has_version "${python_atom}[${USE_flag}]"; then
529 eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
530 die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
531 fi
532 done
533
534 for USE_flag in ${PYTHON_USE_WITH_OR}; do
535 if has_version "${python_atom}[${USE_flag}]"; then
536 return
537 fi
538 done
539
540 if [[ ${PYTHON_USE_WITH_OR} ]]; then
541 eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
542 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
543 fi
544 }
545
546 if _python_package_supporting_installation_for_multiple_python_abis; then
547 PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags
548 else
549 python_pkg_setup_check_USE_flags
550 fi
551
552 unset -f python_pkg_setup_check_USE_flags
553 fi
554
555 PYTHON_PKG_SETUP_EXECUTED="1"
556}
557
558if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then
559 EXPORT_FUNCTIONS pkg_setup
560fi
561
562# @FUNCTION: python_convert_shebangs
563# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
564# @DESCRIPTION:
565# Convert shebangs in specified files. Directories can be specified only with --recursive option.
566python_convert_shebangs() {
567 _python_check_python_pkg_setup_execution
568
569 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
570
571 while (($#)); do
572 case "$1" in
573 -r|--recursive)
574 recursive="1"
575 ;;
576 -q|--quiet)
577 quiet="1"
578 ;;
579 -x|--only-executables)
580 only_executables="1"
581 ;;
582 --)
583 shift
584 break
585 ;;
586 -*)
587 die "${FUNCNAME}(): Unrecognized option '$1'"
588 ;;
589 *)
590 break
591 ;;
592 esac
593 shift
594 done
595
596 if [[ "$#" -eq 0 ]]; then
597 die "${FUNCNAME}(): Missing Python version and files or directories"
598 elif [[ "$#" -eq 1 ]]; then
599 die "${FUNCNAME}(): Missing files or directories"
600 fi
601
602 python_version="$1"
603 shift
604
605 for argument in "$@"; do
606 if [[ ! -e "${argument}" ]]; then
607 die "${FUNCNAME}(): '${argument}' does not exist"
608 elif [[ -f "${argument}" ]]; then
609 files+=("${argument}")
610 elif [[ -d "${argument}" ]]; then
611 if [[ "${recursive}" == "1" ]]; then
612 while read -d $'\0' -r file; do
613 files+=("${file}")
614 done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
615 else
616 die "${FUNCNAME}(): '${argument}' is not a regular file"
617 fi
618 else
619 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
620 fi
621 done
622
623 for file in "${files[@]}"; do
624 file="${file#./}"
625 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
626
627 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
628 [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
629
630 if [[ "${quiet}" == "0" ]]; then
631 einfo "Converting shebang in '${file}'"
632 fi
633
634 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
635
636 # Delete potential whitespace after "#!".
637 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
638 fi
639 done
640}
641
642# @FUNCTION: python_clean_installation_image
643# @USAGE: [-q|--quiet]
644# @DESCRIPTION:
645# Delete needless files in installation image.
646python_clean_installation_image() {
647 _python_check_python_pkg_setup_execution
648 _python_initialize_prefix_variables
649
650 local file files=() quiet="0"
651
652 # Check if phase is src_install().
653 [[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase"
654
655 while (($#)); do
656 case "$1" in
657 -q|--quiet)
658 quiet="1"
659 ;;
660 -*)
661 die "${FUNCNAME}(): Unrecognized option '$1'"
662 ;;
663 *)
664 die "${FUNCNAME}(): Invalid usage"
665 ;;
666 esac
667 shift
668 done
669
670 while read -d $'\0' -r file; do
671 files+=("${file}")
672 done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0)
673
674 if [[ "${#files[@]}" -gt 0 ]]; then
675 if [[ "${quiet}" == "0" ]]; then
676 ewarn "Deleting byte-compiled Python modules needlessly generated by build system:"
677 fi
678 for file in "${files[@]}"; do
679 if [[ "${quiet}" == "0" ]]; then
680 ewarn " ${file}"
681 fi
682 rm -f "${file}"
683
684 # Delete empty __pycache__ directories.
685 if [[ "${file%/*}" == *"/__pycache__" ]]; then
686 rmdir "${file%/*}" 2> /dev/null
687 fi
688 done
689 fi
690
691 python_clean_sitedirs() {
692 if [[ -d "${ED}$(python_get_sitedir)" ]]; then
693 find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
694 fi
695 }
696 if _python_package_supporting_installation_for_multiple_python_abis; then
697 python_execute_function -q python_clean_sitedirs
698 else
699 python_clean_sitedirs
700 fi
701
702 unset -f python_clean_sitedirs
703}
704
705# ================================================================================================
706# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============
707# ================================================================================================
708
709# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
710# @DESCRIPTION:
711# Set this in EAPI <= 4 to indicate that current package supports installation for
712# multiple Python ABIs.
713
714# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
715# @DESCRIPTION:
716# Set this to export phase functions for the following ebuild phases:
717# src_prepare, src_configure, src_compile, src_test, src_install.
718if ! has "${EAPI:-0}" 0 1; then
719 python_src_prepare() {
720 _python_check_python_pkg_setup_execution
721
722 if ! _python_package_supporting_installation_for_multiple_python_abis; then
723 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
724 fi
725
726 if [[ "$#" -ne 0 ]]; then
727 die "${FUNCNAME}() does not accept arguments"
728 fi
729
730 python_copy_sources
731 }
732
733 for python_default_function in src_configure src_compile src_test src_install; do
734 eval "python_${python_default_function}() {
735 _python_check_python_pkg_setup_execution
736
737 if ! _python_package_supporting_installation_for_multiple_python_abis; then
738 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
739 fi
740
741 python_execute_function -d -s -- \"\$@\"
742 }"
743 done
744 unset python_default_function
745
746 if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
747 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
748 fi
749fi
750
751if has "${EAPI:-0}" 0 1 2 3; then
752 unset PYTHON_ABIS
753fi
754
755_python_calculate_PYTHON_ABIS() {
756 if ! _python_package_supporting_installation_for_multiple_python_abis; then
757 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
758 fi
759
760 _python_initial_sanity_checks
761
256 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 762 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then
257 local PYTHON_ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS= 763 local PYTHON_ABI restricted_ABI restricted_ABIs support_ABI supported_PYTHON_ABIS
258 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" 764
259 python2_supported_versions="2.4 2.5 2.6 2.7" 765 restricted_ABIs="${RESTRICT_PYTHON_ABIS// /$'\n'}"
260 python3_supported_versions="3.0 3.1 3.2"
261 766
262 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then 767 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
263 local python2_enabled="0" python3_enabled="0" 768 local cpython_enabled="0"
264 769
265 if [[ -z "${USE_PYTHON}" ]]; then 770 if [[ -z "${USE_PYTHON}" ]]; then
266 die "USE_PYTHON variable is empty" 771 die "USE_PYTHON variable is empty"
267 fi 772 fi
268 773
269 for PYTHON_ABI in ${USE_PYTHON}; do 774 for PYTHON_ABI in ${USE_PYTHON}; do
270 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 775 if ! has "${PYTHON_ABI}" ${_PYTHON_SUPPORTED_ABIS[@]}; then
271 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" 776 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
272 fi 777 fi
273 778
274 if has "${PYTHON_ABI}" ${python2_supported_versions}; then 779 if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then
275 python2_enabled="1" 780 cpython_enabled="1"
276 fi
277 if has "${PYTHON_ABI}" ${python3_supported_versions}; then
278 python3_enabled="1"
279 fi 781 fi
280 782
281 support_ABI="1" 783 support_ABI="1"
282 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 784 while read restricted_ABI; do
283 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 785 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
284 support_ABI="0" 786 support_ABI="0"
285 break 787 break
286 fi 788 fi
287 done 789 done <<< "${restricted_ABIs}"
288 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" 790 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
289 done 791 done
290 792
291 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 793 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
292 die "USE_PYTHON variable does not enable any version of Python supported by ${CATEGORY}/${PF}" 794 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
293 fi 795 fi
294 796
295 if [[ "${python2_enabled}" == "0" ]]; then 797 if [[ "${cpython_enabled}" == "0" ]]; then
296 ewarn "USE_PYTHON variable does not enable any version of Python 2. This configuration is unsupported." 798 die "USE_PYTHON variable does not enable any CPython ABI"
297 fi
298 if [[ "${python3_enabled}" == "0" ]]; then
299 ewarn "USE_PYTHON variable does not enable any version of Python 3. This configuration is unsupported."
300 fi 799 fi
301 else 800 else
302 local python_version python2_version= python3_version= support_python_major_version 801 local python_version python2_version= python3_version= support_python_major_version
303 802
803 if ! has_version "dev-lang/python"; then
804 die "${FUNCNAME}(): 'dev-lang/python' is not installed"
805 fi
806
304 python_version="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" 807 python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
305 808
306 if has_version "=dev-lang/python-2*"; then 809 if has_version "=dev-lang/python-2*"; then
307 if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then 810 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
308 die "'/usr/bin/python2' is not valid symlink" 811 die "'${EPREFIX}/usr/bin/python2' is not valid symlink"
309 fi 812 fi
310 813
311 python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" 814 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
312 815
313 for PYTHON_ABI in ${python2_supported_versions}; do 816 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
314 support_python_major_version="1" 817 support_python_major_version="1"
315 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 818 while read restricted_ABI; do
316 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 819 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
317 support_python_major_version="0" 820 support_python_major_version="0"
318 fi 821 fi
319 done 822 done <<< "${restricted_ABIs}"
320 [[ "${support_python_major_version}" == "1" ]] && break 823 [[ "${support_python_major_version}" == "1" ]] && break
321 done 824 done
322 if [[ "${support_python_major_version}" == "1" ]]; then 825 if [[ "${support_python_major_version}" == "1" ]]; then
323 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 826 while read restricted_ABI; do
324 if [[ "${python2_version}" == ${restricted_ABI} ]]; then 827 if [[ "${python2_version}" == ${restricted_ABI} ]]; then
325 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}" 828 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}"
326 fi 829 fi
327 done 830 done <<< "${restricted_ABIs}"
328 else 831 else
329 python2_version="" 832 python2_version=""
330 fi 833 fi
331 fi 834 fi
332 835
333 if has_version "=dev-lang/python-3*"; then 836 if has_version "=dev-lang/python-3*"; then
334 if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then 837 if [[ "$(readlink "${EPREFIX}/usr/bin/python3")" != "python3."* ]]; then
335 die "'/usr/bin/python3' is not valid symlink" 838 die "'${EPREFIX}/usr/bin/python3' is not valid symlink"
336 fi 839 fi
337 840
338 python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" 841 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
339 842
340 for PYTHON_ABI in ${python3_supported_versions}; do 843 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do
341 support_python_major_version="1" 844 support_python_major_version="1"
342 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 845 while read restricted_ABI; do
343 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then 846 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
344 support_python_major_version="0" 847 support_python_major_version="0"
345 fi 848 fi
346 done 849 done <<< "${restricted_ABIs}"
347 [[ "${support_python_major_version}" == "1" ]] && break 850 [[ "${support_python_major_version}" == "1" ]] && break
348 done 851 done
349 if [[ "${support_python_major_version}" == "1" ]]; then 852 if [[ "${support_python_major_version}" == "1" ]]; then
350 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 853 while read restricted_ABI; do
351 if [[ "${python3_version}" == ${restricted_ABI} ]]; then 854 if [[ "${python3_version}" == ${restricted_ABI} ]]; then
352 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}" 855 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}"
353 fi 856 fi
354 done 857 done <<< "${restricted_ABIs}"
355 else 858 else
356 python3_version="" 859 python3_version=""
357 fi 860 fi
358 fi 861 fi
359 862
360 if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then 863 if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then
361 eerror "Python wrapper is configured incorrectly or /usr/bin/python2 symlink" 864 eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink"
362 eerror "is set incorrectly. Use \`eselect python\` to fix configuration." 865 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
363 die "Incorrect configuration of Python" 866 die "Incorrect configuration of Python"
364 fi 867 fi
365 if [[ -n "${python3_version}" && "${python_version}" == "3."* && "${python_version}" != "${python3_version}" ]]; then 868 if [[ -n "${python3_version}" && "${python_version}" == "3."* && "${python_version}" != "${python3_version}" ]]; then
366 eerror "Python wrapper is configured incorrectly or /usr/bin/python3 symlink" 869 eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python3' symlink"
367 eerror "is set incorrectly. Use \`eselect python\` to fix configuration." 870 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
368 die "Incorrect configuration of Python" 871 die "Incorrect configuration of Python"
369 fi 872 fi
370 873
371 PYTHON_ABIS="${python2_version} ${python3_version}" 874 PYTHON_ABIS="${python2_version} ${python3_version}"
372 PYTHON_ABIS="${PYTHON_ABIS# }" 875 PYTHON_ABIS="${PYTHON_ABIS# }"
373 export PYTHON_ABIS="${PYTHON_ABIS% }" 876 export PYTHON_ABIS="${PYTHON_ABIS% }"
374 fi 877 fi
375 fi 878 fi
376 879
377 if ! _python_implementation && [[ "$(declare -p PYTHON_ABIS_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_ABIS_SANITY_CHECKS="* ]]; then 880 _python_final_sanity_checks
378 local PYTHON_ABI 881}
379 for PYTHON_ABI in ${PYTHON_ABIS}; do 882
380 # Ensure that appropriate version of Python is installed. 883_python_prepare_flags() {
381 if ! has_version "dev-lang/python:${PYTHON_ABI}"; then 884 local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable
382 die "dev-lang/python:${PYTHON_ABI} is not installed" 885
886 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
887 eval "_PYTHON_SAVED_${variable}=\"\${!variable}\""
888 for prefix in PYTHON_USER_ PYTHON_; do
889 if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
890 eval "array=(\"\${${prefix}${variable}[@]}\")"
891 for element in "${array[@]}"; do
892 if [[ "${element}" =~ ^([[:alnum:]]|\.|-|\*|\[|\])+\ (\+|-)\ .+ ]]; then
893 pattern="${element%% *}"
894 element="${element#* }"
895 operator="${element%% *}"
896 flags="${element#* }"
897 if [[ "${PYTHON_ABI}" == ${pattern} ]]; then
898 if [[ "${operator}" == "+" ]]; then
899 eval "export ${variable}+=\"\${variable:+ }${flags}\""
900 elif [[ "${operator}" == "-" ]]; then
901 flags="${flags// /$'\n'}"
902 old_value="${!variable// /$'\n'}"
903 new_value=""
904 while read old_flag; do
905 while read deleted_flag; do
906 if [[ "${old_flag}" == ${deleted_flag} ]]; then
907 continue 2
908 fi
909 done <<< "${flags}"
910 new_value+="${new_value:+ }${old_flag}"
911 done <<< "${old_value}"
912 eval "export ${variable}=\"\${new_value}\""
913 fi
914 fi
915 else
916 die "Element '${element}' of ${prefix}${variable} array has invalid syntax"
383 fi 917 fi
384 918 done
385 # Ensure that EPYTHON variable is respected. 919 elif [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
386 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then 920 die "${prefix}${variable} should be indexed array"
387 eerror "python: '$(type -p python)'"
388 eerror "ABI: '${ABI}'"
389 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
390 eerror "EPYTHON: '$(PYTHON)'"
391 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
392 eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')'"
393 die "'python' does not respect EPYTHON variable"
394 fi 921 fi
395 done 922 done
396 PYTHON_ABIS_SANITY_CHECKS="1"
397 fi
398}
399
400# @FUNCTION: python_copy_sources
401# @USAGE: [--no-link] [--] [directory]
402# @DESCRIPTION:
403# Copy unpacked sources of given package for each Python ABI.
404python_copy_sources() {
405 local dir dirs=() no_link="0" PYTHON_ABI
406
407 while (($#)); do
408 case "$1" in
409 --no-link)
410 no_link="1"
411 ;;
412 --)
413 break
414 ;;
415 -*)
416 die "${FUNCNAME}(): Unrecognized option '$1'"
417 ;;
418 *)
419 break
420 ;;
421 esac
422 shift
423 done
424
425 if [[ "$#" -eq 0 ]]; then
426 if [[ "${WORKDIR}" == "${S}" ]]; then
427 die "${FUNCNAME}() cannot be used"
428 fi
429 dirs="${S}"
430 else
431 dirs="$@"
432 fi
433
434 validate_PYTHON_ABIS
435 for PYTHON_ABI in ${PYTHON_ABIS}; do
436 for dir in "${dirs[@]}"; do
437 if [[ "${no_link}" == "1" ]]; then
438 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
439 else
440 cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
441 fi
442 done 923 done
443 done
444} 924}
445 925
446# @FUNCTION: python_set_build_dir_symlink 926_python_restore_flags() {
447# @USAGE: [directory="build"] 927 local variable
448# @DESCRIPTION:
449# Create build directory symlink.
450python_set_build_dir_symlink() {
451 local dir="$1"
452 928
453 [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set" 929 for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
454 [[ -z "${dir}" ]] && dir="build" 930 eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\""
455 931 unset _PYTHON_SAVED_${variable}
456 # Do not delete preexistent directories. 932 done
457 rm -f "${dir}" || die "Deletion of '${dir}' failed"
458 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
459} 933}
460 934
461# @FUNCTION: python_execute_function 935# @FUNCTION: python_execute_function
462# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] 936# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [-f|--final-ABI] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments]
463# @DESCRIPTION: 937# @DESCRIPTION:
464# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 938# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
465# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 939# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
466python_execute_function() { 940python_execute_function() {
467 local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir= 941 _python_check_python_pkg_setup_execution
942
943 if ! _python_package_supporting_installation_for_multiple_python_abis; then
944 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
945 fi
946
947 _python_set_color_variables
948
949 local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" return_code separate_build_dirs="0" source_dir=
468 950
469 while (($#)); do 951 while (($#)); do
470 case "$1" in 952 case "$1" in
471 --action-message) 953 --action-message)
472 action_message_template="$2" 954 action_message_template="$2"
477 ;; 959 ;;
478 --failure-message) 960 --failure-message)
479 failure_message_template="$2" 961 failure_message_template="$2"
480 shift 962 shift
481 ;; 963 ;;
964 -f|--final-ABI)
965 final_ABI="1"
966 ;;
482 --nonfatal) 967 --nonfatal)
483 nonfatal="1" 968 nonfatal="1"
484 ;; 969 ;;
485 -q|--quiet) 970 -q|--quiet)
486 quiet="1" 971 quiet="1"
491 --source-dir) 976 --source-dir)
492 source_dir="$2" 977 source_dir="$2"
493 shift 978 shift
494 ;; 979 ;;
495 --) 980 --)
981 shift
496 break 982 break
497 ;; 983 ;;
498 -*) 984 -*)
499 die "${FUNCNAME}(): Unrecognized option '$1'" 985 die "${FUNCNAME}(): Unrecognized option '$1'"
500 ;; 986 ;;
518 1004
519 if [[ -z "$(type -t "${function}")" ]]; then 1005 if [[ -z "$(type -t "${function}")" ]]; then
520 die "${FUNCNAME}(): '${function}' function is not defined" 1006 die "${FUNCNAME}(): '${function}' function is not defined"
521 fi 1007 fi
522 else 1008 else
523 if [[ "$#" -ne "0" ]]; then
524 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
525 fi
526 if has "${EAPI:-0}" 0 1; then 1009 if has "${EAPI:-0}" 0 1; then
527 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI" 1010 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
528 fi 1011 fi
529 1012
530 if [[ "${EBUILD_PHASE}" == "configure" ]]; then 1013 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
531 if has "${EAPI}" 2 3; then 1014 if has "${EAPI}" 2 3; then
532 python_default_function() { 1015 python_default_function() {
533 econf 1016 econf "$@"
534 } 1017 }
535 else 1018 else
536 python_default_function() { 1019 python_default_function() {
537 nonfatal econf 1020 nonfatal econf "$@"
538 } 1021 }
539 fi 1022 fi
540 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then 1023 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
541 python_default_function() { 1024 python_default_function() {
542 emake 1025 emake "$@"
543 } 1026 }
544 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 1027 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
545 python_default_function() { 1028 python_default_function() {
546 if emake -j1 -n check &> /dev/null; then 1029 if emake -j1 -n check &> /dev/null; then
547 emake -j1 check 1030 emake -j1 check "$@"
548 elif emake -j1 -n test &> /dev/null; then 1031 elif emake -j1 -n test &> /dev/null; then
549 emake -j1 test 1032 emake -j1 test "$@"
550 fi 1033 fi
551 } 1034 }
552 elif [[ "${EBUILD_PHASE}" == "install" ]]; then 1035 elif [[ "${EBUILD_PHASE}" == "install" ]]; then
553 python_default_function() { 1036 python_default_function() {
554 emake DESTDIR="${D}" install 1037 emake DESTDIR="${D}" install "$@"
555 } 1038 }
556 else 1039 else
557 die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase" 1040 die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase"
558 fi 1041 fi
559 function="python_default_function" 1042 function="python_default_function"
1043 fi
1044
1045 # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function().
1046 if _python_abi-specific_local_scope; then
1047 die "${FUNCNAME}(): Invalid call stack"
560 fi 1048 fi
561 1049
562 if [[ "${quiet}" == "0" ]]; then 1050 if [[ "${quiet}" == "0" ]]; then
563 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" 1051 [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
564 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" 1052 [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
571 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" 1059 [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation"
572 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" 1060 [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation"
573 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" 1061 [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation"
574 fi 1062 fi
575 1063
576 local RED GREEN BLUE NORMAL 1064 _python_calculate_PYTHON_ABIS
577 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then 1065 if [[ "${final_ABI}" == "1" ]]; then
578 RED=$'\e[1;31m' 1066 iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
579 GREEN=$'\e[1;32m'
580 BLUE=$'\e[1;34m'
581 NORMAL=$'\e[0m'
582 else 1067 else
583 RED= 1068 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
584 GREEN=
585 BLUE=
586 NORMAL=
587 fi 1069 fi
588
589 validate_PYTHON_ABIS
590 for PYTHON_ABI in ${PYTHON_ABIS}; do 1070 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1071 _python_prepare_flags
1072
591 if [[ "${quiet}" == "0" ]]; then 1073 if [[ "${quiet}" == "0" ]]; then
592 if [[ -n "${action_message_template}" ]]; then 1074 if [[ -n "${action_message_template}" ]]; then
593 action_message="$(eval echo -n "${action_message_template}")" 1075 eval "action_message=\"${action_message_template}\""
594 else 1076 else
595 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." 1077 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
596 fi 1078 fi
597 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" 1079 echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
598 fi 1080 fi
599 1081
600 if [[ "${separate_build_dirs}" == "1" ]]; then 1082 if [[ "${separate_build_dirs}" == "1" ]]; then
601 if [[ -n "${source_dir}" ]]; then 1083 if [[ -n "${source_dir}" ]]; then
602 export BUILDDIR="${S}/${source_dir}-${PYTHON_ABI}" 1084 export BUILDDIR="${S}/${source_dir}-${PYTHON_ABI}"
616 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 1098 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
617 else 1099 else
618 EPYTHON="$(PYTHON)" "${function}" "$@" 1100 EPYTHON="$(PYTHON)" "${function}" "$@"
619 fi 1101 fi
620 1102
621 if [[ "$?" != "0" ]]; then 1103 return_code="$?"
1104
1105 _python_restore_flags
1106
1107 if [[ "${return_code}" -ne 0 ]]; then
622 if [[ -n "${failure_message_template}" ]]; then 1108 if [[ -n "${failure_message_template}" ]]; then
623 failure_message="$(eval echo -n "${failure_message_template}")" 1109 eval "failure_message=\"${failure_message_template}\""
624 else 1110 else
625 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" 1111 failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
626 fi 1112 fi
627 1113
628 if [[ "${nonfatal}" == "1" ]]; then 1114 if [[ "${nonfatal}" == "1" ]]; then
629 if [[ "${quiet}" == "0" ]]; then 1115 if [[ "${quiet}" == "0" ]]; then
630 ewarn "${RED}${failure_message}${NORMAL}" 1116 ewarn "${failure_message}"
631 fi 1117 fi
632 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 1118 elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
633 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then 1119 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
634 local enabled_PYTHON_ABIS= other_PYTHON_ABI 1120 local enabled_PYTHON_ABIS= other_PYTHON_ABI
635 for other_PYTHON_ABI in ${PYTHON_ABIS}; do 1121 for other_PYTHON_ABI in ${PYTHON_ABIS}; do
636 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}" 1122 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}"
637 done 1123 done
638 export PYTHON_ABIS="${enabled_PYTHON_ABIS}" 1124 export PYTHON_ABIS="${enabled_PYTHON_ABIS}"
639 fi 1125 fi
640 if [[ "${quiet}" == "0" ]]; then 1126 if [[ "${quiet}" == "0" ]]; then
641 ewarn "${RED}${failure_message}${NORMAL}" 1127 ewarn "${failure_message}"
642 fi 1128 fi
643 if [[ -z "${PYTHON_ABIS}" ]]; then 1129 if [[ -z "${PYTHON_ABIS}" ]]; then
644 die "${function}() function failed with all enabled versions of Python" 1130 die "${function}() function failed with all enabled Python ABIs"
645 fi 1131 fi
646 else 1132 else
647 die "${failure_message}" 1133 die "${failure_message}"
648 fi 1134 fi
649 fi 1135 fi
678 if [[ "${default_function}" == "1" ]]; then 1164 if [[ "${default_function}" == "1" ]]; then
679 unset -f python_default_function 1165 unset -f python_default_function
680 fi 1166 fi
681} 1167}
682 1168
683# @FUNCTION: python_convert_shebangs 1169# @FUNCTION: python_copy_sources
684# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] 1170# @USAGE: <directory="${S}"> [directory]
685# @DESCRIPTION: 1171# @DESCRIPTION:
686# Convert shebangs in specified files. Directories can be specified only with --recursive option. 1172# Copy unpacked sources of current package to separate build directory for each Python ABI.
687python_convert_shebangs() { 1173python_copy_sources() {
688 local argument file files=() only_executables="0" python_version quiet="0" recursive="0" 1174 _python_check_python_pkg_setup_execution
689 1175
690 while (($#)); do 1176 if ! _python_package_supporting_installation_for_multiple_python_abis; then
691 case "$1" in 1177 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
692 -r|--recursive) 1178 fi
693 recursive="1" 1179
694 ;; 1180 local dir dirs=() PYTHON_ABI
695 -q|--quiet)
696 quiet="1"
697 ;;
698 -x|--only-executables)
699 only_executables="1"
700 ;;
701 --)
702 break
703 ;;
704 -*)
705 die "${FUNCNAME}(): Unrecognized option '$1'"
706 ;;
707 *)
708 break
709 ;;
710 esac
711 shift
712 done
713 1181
714 if [[ "$#" -eq 0 ]]; then 1182 if [[ "$#" -eq 0 ]]; then
715 die "${FUNCNAME}(): Missing Python version and files or directories" 1183 if [[ "${WORKDIR}" == "${S}" ]]; then
716 elif [[ "$#" -eq 1 ]]; then 1184 die "${FUNCNAME}() cannot be used with current value of S variable"
717 die "${FUNCNAME}(): Missing files or directories"
718 fi
719
720 python_version="$1"
721 shift
722
723 for argument in "$@"; do
724 if [[ ! -e "${argument}" ]]; then
725 die "${FUNCNAME}(): '${argument}' does not exist"
726 elif [[ -f "${argument}" ]]; then
727 files+=("${argument}")
728 elif [[ -d "${argument}" ]]; then
729 if [[ "${recursive}" == "1" ]]; then
730 if [[ "${only_executables}" == "1" ]]; then
731 files+=($(find "${argument}" -perm /111 -type f))
732 else
733 files+=($(find "${argument}" -type f))
734 fi
735 else
736 die "${FUNCNAME}(): '${argument}' is not a regular file"
737 fi 1185 fi
1186 dirs=("${S%/}")
738 else 1187 else
739 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory" 1188 dirs=("$@")
740 fi 1189 fi
1190
1191 _python_calculate_PYTHON_ABIS
1192 for PYTHON_ABI in ${PYTHON_ABIS}; do
1193 for dir in "${dirs[@]}"; do
1194 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
741 done 1195 done
742
743 for file in "${files[@]}"; do
744 file="${file#./}"
745 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
746
747 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
748 if [[ "${quiet}" == "0" ]]; then
749 einfo "Converting shebang in '${file}'"
750 fi
751 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
752
753 # Delete potential whitespace after "#!".
754 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
755 fi
756 done 1196 done
757} 1197}
758 1198
759# @FUNCTION: python_generate_wrapper_scripts 1199# @FUNCTION: python_generate_wrapper_scripts
760# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] 1200# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files]
761# @DESCRIPTION: 1201# @DESCRIPTION:
762# Generate wrapper scripts. Existing files are overwritten only with --force option. 1202# Generate wrapper scripts. Existing files are overwritten only with --force option.
763# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1203# If --respect-EPYTHON option is specified, then generated wrapper scripts will
764# respect EPYTHON variable at run time. 1204# respect EPYTHON variable at run time.
765python_generate_wrapper_scripts() { 1205python_generate_wrapper_scripts() {
1206 _python_check_python_pkg_setup_execution
1207
1208 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1209 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1210 fi
1211
1212 _python_initialize_prefix_variables
1213
766 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python2_supported_versions python3_enabled="0" python3_supported_versions respect_EPYTHON="0" 1214 local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0"
767 python2_supported_versions="2.4 2.5 2.6 2.7"
768 python3_supported_versions="3.0 3.1 3.2"
769 1215
770 while (($#)); do 1216 while (($#)); do
771 case "$1" in 1217 case "$1" in
772 -E|--respect-EPYTHON) 1218 -E|--respect-EPYTHON)
773 respect_EPYTHON="1" 1219 respect_EPYTHON="1"
777 ;; 1223 ;;
778 -q|--quiet) 1224 -q|--quiet)
779 quiet="1" 1225 quiet="1"
780 ;; 1226 ;;
781 --) 1227 --)
1228 shift
782 break 1229 break
783 ;; 1230 ;;
784 -*) 1231 -*)
785 die "${FUNCNAME}(): Unrecognized option '$1'" 1232 die "${FUNCNAME}(): Unrecognized option '$1'"
786 ;; 1233 ;;
793 1240
794 if [[ "$#" -eq 0 ]]; then 1241 if [[ "$#" -eq 0 ]]; then
795 die "${FUNCNAME}(): Missing arguments" 1242 die "${FUNCNAME}(): Missing arguments"
796 fi 1243 fi
797 1244
798 validate_PYTHON_ABIS 1245 _python_calculate_PYTHON_ABIS
799 for PYTHON_ABI in ${python2_supported_versions}; do 1246 for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do
800 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1247 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
801 python2_enabled="1" 1248 python2_enabled="1"
802 fi 1249 fi
803 done 1250 done
804 for PYTHON_ABI in ${python3_supported_versions}; do 1251 for PYTHON_ABI in "${_CPYTHON3_SUPPORTED_ABIS[@]}"; do
805 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then 1252 if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
806 python3_enabled="1" 1253 python3_enabled="1"
807 fi 1254 fi
808 done 1255 done
809 1256
821 if [[ -f "${file}" && "${force}" == "0" ]]; then 1268 if [[ -f "${file}" && "${force}" == "0" ]]; then
822 die "${FUNCNAME}(): '$1' already exists" 1269 die "${FUNCNAME}(): '$1' already exists"
823 fi 1270 fi
824 1271
825 if [[ "${quiet}" == "0" ]]; then 1272 if [[ "${quiet}" == "0" ]]; then
826 einfo "Generating '${file#${D%/}}' wrapper script" 1273 einfo "Generating '${file#${ED%/}}' wrapper script"
827 fi 1274 fi
828 1275
829 cat << EOF > "${file}" 1276 cat << EOF > "${file}"
830#!/usr/bin/env python 1277#!/usr/bin/env python
831# Gentoo '${file##*/}' wrapper script 1278# Gentoo '${file##*/}' wrapper script generated by python_generate_wrapper_scripts()
832 1279
833import os 1280import os
834import re 1281import re
835import subprocess 1282import subprocess
836import sys 1283import sys
837 1284
838EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") 1285EPYTHON_re = re.compile(r"^python(\d+\.\d+)$")
1286python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)")
1287python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
839 1288
840EOF 1289EOF
841 if [[ "$?" != "0" ]]; then 1290 if [[ "$?" != "0" ]]; then
842 die "${FUNCNAME}(): Generation of '$1' failed" 1291 die "${FUNCNAME}(): Generation of '$1' failed"
843 fi 1292 fi
851 else: 1300 else:
852 sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON) 1301 sys.stderr.write("EPYTHON variable has unrecognized value '%s'\n" % EPYTHON)
853 sys.exit(1) 1302 sys.exit(1)
854else: 1303else:
855 try: 1304 try:
856 eselect_process = subprocess.Popen(["/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) 1305 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
857 if eselect_process.wait() != 0: 1306 if eselect_process.wait() != 0:
858 raise ValueError 1307 raise ValueError
859 except (OSError, ValueError): 1308 except (OSError, ValueError):
860 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 1309 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
861 sys.exit(1) 1310 sys.exit(1)
862 1311
863 eselect_output = eselect_process.stdout.read() 1312 EPYTHON = eselect_process.stdout.read()
864 if not isinstance(eselect_output, str): 1313 if not isinstance(EPYTHON, str):
865 # Python 3 1314 # Python 3
866 eselect_output = eselect_output.decode() 1315 EPYTHON = EPYTHON.decode()
1316 EPYTHON = EPYTHON.rstrip("\n")
867 1317
868 EPYTHON_matched = EPYTHON_re.match(eselect_output) 1318 EPYTHON_matched = EPYTHON_re.match(EPYTHON)
869 if EPYTHON_matched: 1319 if EPYTHON_matched:
870 PYTHON_ABI = EPYTHON_matched.group(1) 1320 PYTHON_ABI = EPYTHON_matched.group(1)
871 else: 1321 else:
872 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output) 1322 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
873 sys.exit(1) 1323 sys.exit(1)
874EOF 1324EOF
875 if [[ "$?" != "0" ]]; then 1325 if [[ "$?" != "0" ]]; then
876 die "${FUNCNAME}(): Generation of '$1' failed" 1326 die "${FUNCNAME}(): Generation of '$1' failed"
877 fi 1327 fi
878 else 1328 else
879 cat << EOF >> "${file}" 1329 cat << EOF >> "${file}"
880try: 1330try:
881 eselect_process = subprocess.Popen(["/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE) 1331 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
882 if eselect_process.wait() != 0: 1332 if eselect_process.wait() != 0:
883 raise ValueError 1333 raise ValueError
884except (OSError, ValueError): 1334except (OSError, ValueError):
885 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") 1335 sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
886 sys.exit(1) 1336 sys.exit(1)
887 1337
888eselect_output = eselect_process.stdout.read() 1338EPYTHON = eselect_process.stdout.read()
889if not isinstance(eselect_output, str): 1339if not isinstance(EPYTHON, str):
890 # Python 3 1340 # Python 3
891 eselect_output = eselect_output.decode() 1341 EPYTHON = EPYTHON.decode()
1342EPYTHON = EPYTHON.rstrip("\n")
892 1343
893EPYTHON_matched = EPYTHON_re.match(eselect_output) 1344EPYTHON_matched = EPYTHON_re.match(EPYTHON)
894if EPYTHON_matched: 1345if EPYTHON_matched:
895 PYTHON_ABI = EPYTHON_matched.group(1) 1346 PYTHON_ABI = EPYTHON_matched.group(1)
896else: 1347else:
897 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output) 1348 sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON)
898 sys.exit(1) 1349 sys.exit(1)
899EOF 1350EOF
900 if [[ "$?" != "0" ]]; then 1351 if [[ "$?" != "0" ]]; then
901 die "${FUNCNAME}(): Generation of '$1' failed" 1352 die "${FUNCNAME}(): Generation of '$1' failed"
902 fi 1353 fi
903 fi 1354 fi
904 cat << EOF >> "${file}" 1355 cat << EOF >> "${file}"
905 1356
1357wrapper_script_path = os.path.realpath(sys.argv[0])
1358target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
906os.environ["PYTHON_PROCESS_NAME"] = sys.argv[0] 1359os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
907target_executable = "%s-%s" % (os.path.realpath(sys.argv[0]), PYTHON_ABI) 1360os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
1361os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
908if not os.path.exists(target_executable): 1362if not os.path.exists(target_executable_path):
909 sys.stderr.write("'%s' does not exist\n" % target_executable) 1363 sys.stderr.write("'%s' does not exist\n" % target_executable_path)
910 sys.exit(1) 1364 sys.exit(1)
911 1365
1366target_executable = open(target_executable_path, "rb")
1367target_executable_first_line = target_executable.readline()
1368if not isinstance(target_executable_first_line, str):
1369 # Python 3
1370 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
1371
1372python_shebang_matched = python_shebang_re.match(target_executable_first_line)
1373target_executable.close()
1374
1375if python_shebang_matched:
1376 try:
1377 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
1378 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
1379 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
1380 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
1381 if python_verification_process.wait() != 0:
1382 raise ValueError
1383
1384 python_verification_output = python_verification_process.stdout.read()
1385 if not isinstance(python_verification_output, str):
1386 # Python 3
1387 python_verification_output = python_verification_output.decode()
1388
1389 if not python_verification_output_re.match(python_verification_output):
1390 raise ValueError
1391
1392 os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv)
1393 except:
1394 pass
1395 if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ:
1396 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
1397
912os.execv(target_executable, sys.argv) 1398os.execv(target_executable_path, sys.argv)
913EOF 1399EOF
914 if [[ "$?" != "0" ]]; then 1400 if [[ "$?" != "0" ]]; then
915 die "${FUNCNAME}(): Generation of '$1' failed" 1401 die "${FUNCNAME}(): Generation of '$1' failed"
916 fi 1402 fi
917 fperms +x "${file#${D%/}}" || die "fperms '${file}' failed" 1403 fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
918 done 1404 done
919} 1405}
920 1406
921# @ECLASS-VARIABLE: PYTHON_USE_WITH 1407# ================================================================================================
922# @DESCRIPTION: 1408# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
923# Set this to a space separated list of use flags 1409# ================================================================================================
924# the python slot in use must be built with.
925 1410
926# @ECLASS-VARIABLE: PYTHON_USE_WITH_OR 1411unset EPYTHON PYTHON_ABI
927# @DESCRIPTION:
928# Set this to a space separated list of use flags
929# of which one must be turned on for the slot of
930# in use.
931 1412
932# @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT 1413# @FUNCTION: python_set_active_version
1414# @USAGE: <CPython_ABI|2|3>
933# @DESCRIPTION: 1415# @DESCRIPTION:
934# Set this if you need to make either PYTHON_USE_WITH or 1416# Set specified version of CPython as active version of Python.
935# PYTHON_USE_WITH_OR atoms conditional under a use flag. 1417#
1418# This function can be used only in pkg_setup() phase.
1419python_set_active_version() {
1420 # Check if phase is pkg_setup().
1421 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
936 1422
937# @FUNCTION: python_pkg_setup 1423 if _python_package_supporting_installation_for_multiple_python_abis; then
938# @DESCRIPTION: 1424 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
939# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 1425 fi
940# are respected. Only exported if one of those variables is set.
941if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
942 python_pkg_setup() {
943 python_pkg_setup_fail() {
944 eerror "${1}"
945 die "${1}"
946 }
947 1426
948 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return 1427 if [[ "$#" -ne 1 ]]; then
1428 die "${FUNCNAME}() requires 1 argument"
1429 fi
949 1430
950 python_pkg_setup_check_USE_flags() { 1431 _python_initial_sanity_checks
951 local pyatom use 1432
952 if [[ -n "${PYTHON_ABI}" ]]; then 1433 if [[ -z "${PYTHON_ABI}" ]]; then
953 pyatom="dev-lang/python:${PYTHON_ABI}" 1434 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
954 else 1435 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
955 pyatom="dev-lang/python:$(PYTHON -A --ABI)" 1436 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
956 fi
957
958 for use in ${PYTHON_USE_WITH}; do
959 if ! has_version "${pyatom}[${use}]"; then
960 python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
961 fi 1437 fi
962 done 1438 export EPYTHON="$(PYTHON "$1")"
963 1439 elif [[ "$1" == "2" ]]; then
964 for use in ${PYTHON_USE_WITH_OR}; do 1440 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
965 if has_version "${pyatom}[${use}]"; then 1441 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
966 return
967 fi 1442 fi
968 done 1443 export EPYTHON="$(PYTHON -2)"
969 1444 elif [[ "$1" == "3" ]]; then
970 if [[ ${PYTHON_USE_WITH_OR} ]]; then 1445 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
971 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" 1446 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
972 fi 1447 fi
973 } 1448 export EPYTHON="$(PYTHON -3)"
974
975 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
976 python_execute_function -q python_pkg_setup_check_USE_flags
977 else 1449 else
978 python_pkg_setup_check_USE_flags 1450 die "${FUNCNAME}(): Unrecognized argument '$1'"
1451 fi
1452
1453 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
1454 # so it does not need to be exported to subprocesses.
1455 PYTHON_ABI="${EPYTHON#python}"
1456 PYTHON_ABI="${PYTHON_ABI%%-*}"
1457 fi
1458
1459 _python_final_sanity_checks
1460
1461 # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
1462 PYTHON_REQUESTED_ACTIVE_VERSION="$1"
1463}
1464
1465# @FUNCTION: python_need_rebuild
1466# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1467# switching of active version of Python.
1468python_need_rebuild() {
1469 _python_check_python_pkg_setup_execution
1470
1471 if _python_package_supporting_installation_for_multiple_python_abis; then
1472 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1473 fi
1474
1475 if [[ "$#" -ne 0 ]]; then
1476 die "${FUNCNAME}() does not accept arguments"
1477 fi
1478
1479 export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
1480}
1481
1482# ================================================================================================
1483# ======================================= GETTER FUNCTIONS =======================================
1484# ================================================================================================
1485
1486_PYTHON_ABI_EXTRACTION_COMMAND='import platform
1487import sys
1488sys.stdout.write(".".join(str(x) for x in sys.version_info[:2]))
1489if platform.system()[:4] == "Java":
1490 sys.stdout.write("-jython")'
1491
1492_python_get_implementation() {
1493 if [[ "$#" -ne 1 ]]; then
1494 die "${FUNCNAME}() requires 1 argument"
1495 fi
1496
1497 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
1498 echo "CPython"
1499 elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
1500 echo "Jython"
1501 else
1502 die "${FUNCNAME}(): Unrecognized Python ABI '$1'"
1503 fi
1504}
1505
1506# @FUNCTION: PYTHON
1507# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}">
1508# @DESCRIPTION:
1509# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument
1510# is ommitted, then PYTHON_ABI environment variable must be set and is used.
1511# If -2 option is specified, then active version of Python 2 is used.
1512# If -3 option is specified, then active version of Python 3 is used.
1513# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1514# -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously.
1515# If --ABI option is specified, then only specified Python ABI is printed instead of
1516# filename of Python interpreter.
1517# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
1518# --ABI and --absolute-path options cannot be specified simultaneously.
1519PYTHON() {
1520 _python_check_python_pkg_setup_execution
1521
1522 local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0"
1523
1524 while (($#)); do
1525 case "$1" in
1526 -2)
1527 python2="1"
1528 ;;
1529 -3)
1530 python3="1"
1531 ;;
1532 --ABI)
1533 ABI_output="1"
1534 ;;
1535 -a|--absolute-path)
1536 absolute_path_output="1"
1537 ;;
1538 -f|--final-ABI)
1539 final_ABI="1"
1540 ;;
1541 --)
1542 shift
1543 break
1544 ;;
1545 -*)
1546 die "${FUNCNAME}(): Unrecognized option '$1'"
1547 ;;
1548 *)
1549 break
1550 ;;
1551 esac
1552 shift
1553 done
1554
1555 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
1556 die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously"
1557 fi
1558
1559 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
1560 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
1561 fi
1562
1563 if [[ "$#" -eq 0 ]]; then
1564 if [[ "${final_ABI}" == "1" ]]; then
1565 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1566 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
979 fi 1567 fi
1568 _python_calculate_PYTHON_ABIS
1569 PYTHON_ABI="${PYTHON_ABIS##* }"
1570 elif [[ "${python2}" == "1" ]]; then
1571 PYTHON_ABI="$(eselect python show --python2 --ABI)"
1572 if [[ -z "${PYTHON_ABI}" ]]; then
1573 die "${FUNCNAME}(): Active version of Python 2 not set"
1574 elif [[ "${PYTHON_ABI}" != "2."* ]]; then
1575 die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
1576 fi
1577 elif [[ "${python3}" == "1" ]]; then
1578 PYTHON_ABI="$(eselect python show --python3 --ABI)"
1579 if [[ -z "${PYTHON_ABI}" ]]; then
1580 die "${FUNCNAME}(): Active version of Python 3 not set"
1581 elif [[ "${PYTHON_ABI}" != "3."* ]]; then
1582 die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
1583 fi
1584 elif _python_package_supporting_installation_for_multiple_python_abis; then
1585 if ! _python_abi-specific_local_scope; then
1586 die "${FUNCNAME}() should be used in ABI-specific local scope"
1587 fi
1588 else
1589 PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
1590 if [[ -z "${PYTHON_ABI}" ]]; then
1591 die "${FUNCNAME}(): Failure of extraction of locally active version of Python"
1592 fi
1593 fi
1594 elif [[ "$#" -eq 1 ]]; then
1595 if [[ "${final_ABI}" == "1" ]]; then
1596 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
1597 fi
1598 if [[ "${python2}" == "1" ]]; then
1599 die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously"
1600 fi
1601 if [[ "${python3}" == "1" ]]; then
1602 die "${FUNCNAME}(): '-3' option and Python ABI cannot be specified simultaneously"
1603 fi
1604 PYTHON_ABI="$1"
1605 else
1606 die "${FUNCNAME}(): Invalid usage"
1607 fi
1608
1609 if [[ "${ABI_output}" == "1" ]]; then
1610 echo -n "${PYTHON_ABI}"
1611 return
1612 else
1613 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1614 python_interpreter="python${PYTHON_ABI}"
1615 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1616 python_interpreter="jython-${PYTHON_ABI%-jython}"
1617 fi
1618
1619 if [[ "${absolute_path_output}" == "1" ]]; then
1620 echo -n "${EPREFIX}/usr/bin/${python_interpreter}"
1621 else
1622 echo -n "${python_interpreter}"
1623 fi
1624 fi
1625
1626 if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then
1627 echo -n "-${ABI}"
1628 fi
1629}
1630
1631# @FUNCTION: python_get_implementation
1632# @USAGE: [-f|--final-ABI]
1633# @DESCRIPTION:
1634# Print name of Python implementation.
1635# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1636python_get_implementation() {
1637 _python_check_python_pkg_setup_execution
1638
1639 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1640
1641 while (($#)); do
1642 case "$1" in
1643 -f|--final-ABI)
1644 final_ABI="1"
1645 ;;
1646 -*)
1647 die "${FUNCNAME}(): Unrecognized option '$1'"
1648 ;;
1649 *)
1650 die "${FUNCNAME}(): Invalid usage"
1651 ;;
1652 esac
1653 shift
1654 done
1655
1656 if [[ "${final_ABI}" == "1" ]]; then
1657 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1658 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1659 fi
1660 PYTHON_ABI="$(PYTHON -f --ABI)"
1661 else
1662 if _python_package_supporting_installation_for_multiple_python_abis; then
1663 if ! _python_abi-specific_local_scope; then
1664 die "${FUNCNAME}() should be used in ABI-specific local scope"
1665 fi
1666 else
1667 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1668 fi
1669 fi
1670
1671 echo "$(_python_get_implementation "${PYTHON_ABI}")"
1672}
1673
1674# @FUNCTION: python_get_implementational_package
1675# @USAGE: [-f|--final-ABI]
1676# @DESCRIPTION:
1677# Print category, name and slot of package providing Python implementation.
1678# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1679python_get_implementational_package() {
1680 _python_check_python_pkg_setup_execution
1681
1682 local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
1683
1684 while (($#)); do
1685 case "$1" in
1686 -f|--final-ABI)
1687 final_ABI="1"
1688 ;;
1689 -*)
1690 die "${FUNCNAME}(): Unrecognized option '$1'"
1691 ;;
1692 *)
1693 die "${FUNCNAME}(): Invalid usage"
1694 ;;
1695 esac
1696 shift
1697 done
1698
1699 if [[ "${final_ABI}" == "1" ]]; then
1700 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1701 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1702 fi
1703 PYTHON_ABI="$(PYTHON -f --ABI)"
1704 else
1705 if _python_package_supporting_installation_for_multiple_python_abis; then
1706 if ! _python_abi-specific_local_scope; then
1707 die "${FUNCNAME}() should be used in ABI-specific local scope"
1708 fi
1709 else
1710 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1711 fi
1712 fi
1713
1714 if [[ "${EAPI:-0}" == "0" ]]; then
1715 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1716 echo "=dev-lang/python-${PYTHON_ABI}*"
1717 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1718 echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
1719 fi
1720 else
1721 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1722 echo "dev-lang/python:${PYTHON_ABI}"
1723 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1724 echo "dev-java/jython:${PYTHON_ABI%-jython}"
1725 fi
1726 fi
1727}
1728
1729# @FUNCTION: python_get_includedir
1730# @USAGE: [-b|--base-path] [-f|--final-ABI]
1731# @DESCRIPTION:
1732# Print path to Python include directory.
1733# If --base-path option is specified, then path not prefixed with "/" is printed.
1734# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1735python_get_includedir() {
1736 _python_check_python_pkg_setup_execution
1737
1738 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1739
1740 while (($#)); do
1741 case "$1" in
1742 -b|--base-path)
1743 base_path="1"
1744 ;;
1745 -f|--final-ABI)
1746 final_ABI="1"
1747 ;;
1748 -*)
1749 die "${FUNCNAME}(): Unrecognized option '$1'"
1750 ;;
1751 *)
1752 die "${FUNCNAME}(): Invalid usage"
1753 ;;
1754 esac
1755 shift
1756 done
1757
1758 if [[ "${base_path}" == "0" ]]; then
1759 prefix="/"
1760 fi
1761
1762 if [[ "${final_ABI}" == "1" ]]; then
1763 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1764 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1765 fi
1766 PYTHON_ABI="$(PYTHON -f --ABI)"
1767 else
1768 if _python_package_supporting_installation_for_multiple_python_abis; then
1769 if ! _python_abi-specific_local_scope; then
1770 die "${FUNCNAME}() should be used in ABI-specific local scope"
1771 fi
1772 else
1773 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1774 fi
1775 fi
1776
1777 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1778 echo "${prefix}usr/include/python${PYTHON_ABI}"
1779 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1780 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include"
1781 fi
1782}
1783
1784# @FUNCTION: python_get_libdir
1785# @USAGE: [-b|--base-path] [-f|--final-ABI]
1786# @DESCRIPTION:
1787# Print path to Python library directory.
1788# If --base-path option is specified, then path not prefixed with "/" is printed.
1789# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1790python_get_libdir() {
1791 _python_check_python_pkg_setup_execution
1792
1793 local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1794
1795 while (($#)); do
1796 case "$1" in
1797 -b|--base-path)
1798 base_path="1"
1799 ;;
1800 -f|--final-ABI)
1801 final_ABI="1"
1802 ;;
1803 -*)
1804 die "${FUNCNAME}(): Unrecognized option '$1'"
1805 ;;
1806 *)
1807 die "${FUNCNAME}(): Invalid usage"
1808 ;;
1809 esac
1810 shift
1811 done
1812
1813 if [[ "${base_path}" == "0" ]]; then
1814 prefix="/"
1815 fi
1816
1817 if [[ "${final_ABI}" == "1" ]]; then
1818 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1819 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1820 fi
1821 PYTHON_ABI="$(PYTHON -f --ABI)"
1822 else
1823 if _python_package_supporting_installation_for_multiple_python_abis; then
1824 if ! _python_abi-specific_local_scope; then
1825 die "${FUNCNAME}() should be used in ABI-specific local scope"
1826 fi
1827 else
1828 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1829 fi
1830 fi
1831
1832 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1833 echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}"
1834 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1835 echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib"
1836 fi
1837}
1838
1839# @FUNCTION: python_get_sitedir
1840# @USAGE: [-b|--base-path] [-f|--final-ABI]
1841# @DESCRIPTION:
1842# Print path to Python site-packages directory.
1843# If --base-path option is specified, then path not prefixed with "/" is printed.
1844# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1845python_get_sitedir() {
1846 _python_check_python_pkg_setup_execution
1847
1848 local final_ABI="0" options=()
1849
1850 while (($#)); do
1851 case "$1" in
1852 -b|--base-path)
1853 options+=("$1")
1854 ;;
1855 -f|--final-ABI)
1856 final_ABI="1"
1857 options+=("$1")
1858 ;;
1859 -*)
1860 die "${FUNCNAME}(): Unrecognized option '$1'"
1861 ;;
1862 *)
1863 die "${FUNCNAME}(): Invalid usage"
1864 ;;
1865 esac
1866 shift
1867 done
1868
1869 if [[ "${final_ABI}" == "1" ]]; then
1870 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1871 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1872 fi
1873 else
1874 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
1875 die "${FUNCNAME}() should be used in ABI-specific local scope"
1876 fi
1877 fi
1878
1879 echo "$(python_get_libdir "${options[@]}")/site-packages"
1880}
1881
1882# @FUNCTION: python_get_library
1883# @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option]
1884# @DESCRIPTION:
1885# Print path to Python library.
1886# If --base-path option is specified, then path not prefixed with "/" is printed.
1887# If --linker-option is specified, then "-l${library}" linker option is printed.
1888# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1889python_get_library() {
1890 _python_check_python_pkg_setup_execution
1891
1892 local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}"
1893
1894 while (($#)); do
1895 case "$1" in
1896 -b|--base-path)
1897 base_path="1"
1898 ;;
1899 -f|--final-ABI)
1900 final_ABI="1"
1901 ;;
1902 -l|--linker-option)
1903 linker_option="1"
1904 ;;
1905 -*)
1906 die "${FUNCNAME}(): Unrecognized option '$1'"
1907 ;;
1908 *)
1909 die "${FUNCNAME}(): Invalid usage"
1910 ;;
1911 esac
1912 shift
1913 done
1914
1915 if [[ "${base_path}" == "0" ]]; then
1916 prefix="/"
1917 fi
1918
1919 if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
1920 die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously"
1921 fi
1922
1923 if [[ "${final_ABI}" == "1" ]]; then
1924 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1925 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1926 fi
1927 PYTHON_ABI="$(PYTHON -f --ABI)"
1928 else
1929 if _python_package_supporting_installation_for_multiple_python_abis; then
1930 if ! _python_abi-specific_local_scope; then
1931 die "${FUNCNAME}() should be used in ABI-specific local scope"
1932 fi
1933 else
1934 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1935 fi
1936 fi
1937
1938 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
1939 if [[ "${linker_option}" == "1" ]]; then
1940 echo "-lpython${PYTHON_ABI}"
1941 else
1942 echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)"
1943 fi
1944 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
1945 die "${FUNCNAME}(): Jython does not have shared library"
1946 fi
1947}
1948
1949# @FUNCTION: python_get_version
1950# @USAGE: [-f|--final-ABI] [--full] [--major] [--minor] [--micro]
1951# @DESCRIPTION:
1952# Print Python version.
1953# --full, --major, --minor and --micro options cannot be specified simultaneously.
1954# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
1955# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
1956python_get_version() {
1957 _python_check_python_pkg_setup_execution
1958
1959 local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command
1960
1961 while (($#)); do
1962 case "$1" in
1963 -f|--final-ABI)
1964 final_ABI="1"
1965 ;;
1966 --full)
1967 full="1"
1968 ;;
1969 --major)
1970 major="1"
1971 ;;
1972 --minor)
1973 minor="1"
1974 ;;
1975 --micro)
1976 micro="1"
1977 ;;
1978 -*)
1979 die "${FUNCNAME}(): Unrecognized option '$1'"
1980 ;;
1981 *)
1982 die "${FUNCNAME}(): Invalid usage"
1983 ;;
1984 esac
1985 shift
1986 done
1987
1988 if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
1989 die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
1990 fi
1991
1992 if [[ "${full}" == "1" ]]; then
1993 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))"
1994 elif [[ "${major}" == "1" ]]; then
1995 python_command="from sys import version_info; print(version_info[0])"
1996 elif [[ "${minor}" == "1" ]]; then
1997 python_command="from sys import version_info; print(version_info[1])"
1998 elif [[ "${micro}" == "1" ]]; then
1999 python_command="from sys import version_info; print(version_info[2])"
2000 else
2001 if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
2002 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2003 echo "${PYTHON_ABI}"
2004 elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2005 echo "${PYTHON_ABI%-jython}"
2006 fi
2007 return
2008 fi
2009 python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
2010 fi
2011
2012 if [[ "${final_ABI}" == "1" ]]; then
2013 if ! _python_package_supporting_installation_for_multiple_python_abis; then
2014 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2015 fi
2016 "$(PYTHON -f)" -c "${python_command}"
2017 else
2018 if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
2019 die "${FUNCNAME}() should be used in ABI-specific local scope"
2020 fi
2021 "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
2022 fi
2023}
2024
2025# ================================================================================================
2026# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
2027# ================================================================================================
2028
2029# @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY
2030# @DESCRIPTION:
2031# User-configurable verbosity of tests of Python modules.
2032# Supported values: 0, 1, 2, 3, 4.
2033PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}"
2034
2035_python_test_hook() {
2036 if [[ "$#" -ne 1 ]]; then
2037 die "${FUNCNAME}() requires 1 argument"
2038 fi
2039
2040 if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then
2041 "${FUNCNAME[3]}_$1_hook"
2042 fi
2043}
2044
2045# @FUNCTION: python_execute_nosetests
2046# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
2047# @DESCRIPTION:
2048# Execute nosetests for all enabled Python ABIs.
2049# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
2050# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
2051python_execute_nosetests() {
2052 _python_check_python_pkg_setup_execution
2053 _python_set_color_variables
2054
2055 local PYTHONPATH_template= separate_build_dirs=
2056
2057 while (($#)); do
2058 case "$1" in
2059 -P|--PYTHONPATH)
2060 PYTHONPATH_template="$2"
2061 shift
2062 ;;
2063 -s|--separate-build-dirs)
2064 separate_build_dirs="1"
2065 ;;
2066 --)
2067 shift
2068 break
2069 ;;
2070 -*)
2071 die "${FUNCNAME}(): Unrecognized option '$1'"
2072 ;;
2073 *)
2074 break
2075 ;;
2076 esac
2077 shift
2078 done
2079
2080 python_test_function() {
2081 local evaluated_PYTHONPATH
2082
2083 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2084
2085 _python_test_hook pre
2086
2087 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2088 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
2089 PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
2090 else
2091 echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
2092 nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
2093 fi
2094
2095 _python_test_hook post
980 } 2096 }
2097 if _python_package_supporting_installation_for_multiple_python_abis; then
2098 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2099 else
2100 if [[ -n "${separate_build_dirs}" ]]; then
2101 die "${FUNCNAME}(): Invalid usage"
2102 fi
2103 python_test_function "$@" || die "Testing failed"
2104 fi
981 2105
982 EXPORT_FUNCTIONS pkg_setup 2106 unset -f python_test_function
2107}
983 2108
984 if [[ -n "${PYTHON_USE_WITH}" ]]; then 2109# @FUNCTION: python_execute_py.test
985 PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" 2110# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
986 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then 2111# @DESCRIPTION:
987 PYTHON_USE_WITH_ATOM="|| ( " 2112# Execute py.test for all enabled Python ABIs.
988 for use in ${PYTHON_USE_WITH_OR}; do 2113# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
989 PYTHON_USE_WITH_ATOM+=" ${PYTHON_ATOM}[${use}]" 2114# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
2115python_execute_py.test() {
2116 _python_check_python_pkg_setup_execution
2117 _python_set_color_variables
2118
2119 local PYTHONPATH_template= separate_build_dirs=
2120
2121 while (($#)); do
2122 case "$1" in
2123 -P|--PYTHONPATH)
2124 PYTHONPATH_template="$2"
2125 shift
2126 ;;
2127 -s|--separate-build-dirs)
2128 separate_build_dirs="1"
2129 ;;
2130 --)
2131 shift
2132 break
2133 ;;
2134 -*)
2135 die "${FUNCNAME}(): Unrecognized option '$1'"
2136 ;;
2137 *)
2138 break
2139 ;;
2140 esac
2141 shift
990 done 2142 done
991 unset use 2143
992 PYTHON_USE_WITH_ATOM+=" )" 2144 python_test_function() {
2145 local evaluated_PYTHONPATH
2146
2147 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2148
2149 _python_test_hook pre
2150
2151 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2152 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
2153 PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?"
2154 else
2155 echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL}
2156 py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?"
993 fi 2157 fi
994 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
995 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )"
996 fi
997 DEPEND+=" ${PYTHON_USE_WITH_ATOM}"
998 RDEPEND+=" ${PYTHON_USE_WITH_ATOM}"
999fi
1000 2158
1001# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS 2159 _python_test_hook post
1002# @DESCRIPTION:
1003# Set this to define default functions for the following ebuild phases:
1004# src_prepare, src_configure, src_compile, src_test, src_install.
1005if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then
1006 python_src_prepare() {
1007 python_copy_sources
1008 } 2160 }
2161 if _python_package_supporting_installation_for_multiple_python_abis; then
2162 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2163 else
2164 if [[ -n "${separate_build_dirs}" ]]; then
2165 die "${FUNCNAME}(): Invalid usage"
2166 fi
2167 python_test_function "$@" || die "Testing failed"
2168 fi
1009 2169
1010 for python_default_function in src_configure src_compile src_test src_install; do
1011 eval "python_${python_default_function}() { python_execute_function -d -s; }"
1012 done
1013 unset python_default_function 2170 unset -f python_test_function
2171}
1014 2172
1015 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 2173# @FUNCTION: python_execute_trial
2174# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
2175# @DESCRIPTION:
2176# Execute trial for all enabled Python ABIs.
2177# In ebuilds of packages supporting installation for multiple Python ABIs, this function
2178# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
2179python_execute_trial() {
2180 _python_check_python_pkg_setup_execution
2181 _python_set_color_variables
2182
2183 local PYTHONPATH_template= separate_build_dirs=
2184
2185 while (($#)); do
2186 case "$1" in
2187 -P|--PYTHONPATH)
2188 PYTHONPATH_template="$2"
2189 shift
2190 ;;
2191 -s|--separate-build-dirs)
2192 separate_build_dirs="1"
2193 ;;
2194 --)
2195 shift
2196 break
2197 ;;
2198 -*)
2199 die "${FUNCNAME}(): Unrecognized option '$1'"
2200 ;;
2201 *)
2202 break
2203 ;;
2204 esac
2205 shift
2206 done
2207
2208 python_test_function() {
2209 local evaluated_PYTHONPATH
2210
2211 eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
2212
2213 _python_test_hook pre
2214
2215 if [[ -n "${evaluated_PYTHONPATH}" ]]; then
2216 echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
2217 PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
2218 else
2219 echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
2220 trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
2221 fi
2222
2223 _python_test_hook post
2224 }
2225 if _python_package_supporting_installation_for_multiple_python_abis; then
2226 python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
2227 else
2228 if [[ -n "${separate_build_dirs}" ]]; then
2229 die "${FUNCNAME}(): Invalid usage"
2230 fi
2231 python_test_function "$@" || die "Testing failed"
1016fi 2232 fi
2233
2234 unset -f python_test_function
2235}
2236
2237# ================================================================================================
2238# ======================= FUNCTIONS FOR HANDLING OF BYTE-COMPILED MODULES ========================
2239# ================================================================================================
2240
2241# @FUNCTION: python_enable_pyc
2242# @DESCRIPTION:
2243# Tell Python to automatically recompile modules to .pyc/.pyo if the
2244# timestamps/version stamps have changed.
2245python_enable_pyc() {
2246 _python_check_python_pkg_setup_execution
2247
2248 if [[ "$#" -ne 0 ]]; then
2249 die "${FUNCNAME}() does not accept arguments"
2250 fi
2251
2252 unset PYTHONDONTWRITEBYTECODE
2253}
1017 2254
1018# @FUNCTION: python_disable_pyc 2255# @FUNCTION: python_disable_pyc
1019# @DESCRIPTION: 2256# @DESCRIPTION:
1020# Tell Python not to automatically recompile modules to .pyc/.pyo 2257# Tell Python not to automatically recompile modules to .pyc/.pyo
1021# even if the timestamps/version stamps do not match. This is done 2258# even if the timestamps/version stamps do not match. This is done
1022# to protect sandbox. 2259# to protect sandbox.
1023python_disable_pyc() { 2260python_disable_pyc() {
2261 _python_check_python_pkg_setup_execution
2262
2263 if [[ "$#" -ne 0 ]]; then
2264 die "${FUNCNAME}() does not accept arguments"
2265 fi
2266
1024 export PYTHONDONTWRITEBYTECODE="1" 2267 export PYTHONDONTWRITEBYTECODE="1"
1025} 2268}
1026 2269
1027# @FUNCTION: python_enable_pyc 2270_python_clean_compiled_modules() {
1028# @DESCRIPTION: 2271 _python_initialize_prefix_variables
1029# Tell Python to automatically recompile modules to .pyc/.pyo if the 2272 _python_set_color_variables
1030# timestamps/version stamps have changed.
1031python_enable_pyc() {
1032 unset PYTHONDONTWRITEBYTECODE
1033}
1034 2273
1035# @FUNCTION: python_need_rebuild 2274 [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
1036# @DESCRIPTION: Run without arguments, specifies that the package should be
1037# rebuilt after a python upgrade.
1038# Do not use this function in ebuilds of packages supporting installation
1039# for multiple versions of Python.
1040python_need_rebuild() {
1041 export PYTHON_NEED_REBUILD="$(PYTHON -A --ABI)"
1042}
1043 2275
1044# @FUNCTION: python_get_includedir 2276 local base_module_name compiled_file compiled_files=() dir path py_file root
1045# @DESCRIPTION: 2277
1046# Run without arguments, returns the Python include directory. 2278 # Strip trailing slash from EROOT.
1047python_get_includedir() { 2279 root="${EROOT%/}"
1048 if [[ -n "${PYTHON_ABI}" ]]; then 2280
1049 echo "/usr/include/python${PYTHON_ABI}" 2281 for path in "$@"; do
1050 else 2282 compiled_files=()
1051 echo "/usr/include/python$(PYTHON -A --ABI)" 2283 if [[ -d "${path}" ]]; then
2284 while read -d $'\0' -r compiled_file; do
2285 compiled_files+=("${compiled_file}")
2286 done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
2287
2288 if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
2289 # Delete empty child directories.
2290 find "${path}" -type d | sort -r | while read -r dir; do
2291 if rmdir "${dir}" 2> /dev/null; then
2292 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2293 fi
2294 done
2295 fi
2296 elif [[ "${path}" == *.py ]]; then
2297 base_module_name="${path##*/}"
2298 base_module_name="${base_module_name%.py}"
2299 if [[ -d "${path%/*}/__pycache__" ]]; then
2300 while read -d $'\0' -r compiled_file; do
2301 compiled_files+=("${compiled_file}")
2302 done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0)
2303 fi
2304 compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class")
1052 fi 2305 fi
1053}
1054 2306
1055# @FUNCTION: python_get_libdir 2307 for compiled_file in "${compiled_files[@]}"; do
1056# @DESCRIPTION: 2308 [[ ! -f "${compiled_file}" ]] && continue
1057# Run without arguments, returns the Python library directory. 2309 dir="${compiled_file%/*}"
1058python_get_libdir() { 2310 dir="${dir##*/}"
1059 if [[ -n "${PYTHON_ABI}" ]]; then 2311 if [[ "${compiled_file}" == *.py[co] ]]; then
1060 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 2312 if [[ "${dir}" == "__pycache__" ]]; then
2313 base_module_name="${compiled_file##*/}"
2314 base_module_name="${base_module_name%.*py[co]}"
2315 base_module_name="${base_module_name%.*}"
2316 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
2317 else
2318 py_file="${compiled_file%[co]}"
2319 fi
2320 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2321 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2322 else
2323 [[ -f "${py_file}" ]] && continue
2324 fi
2325 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}"
2326 rm -f "${compiled_file%[co]}"[co]
2327 elif [[ "${compiled_file}" == *\$py.class ]]; then
2328 if [[ "${dir}" == "__pycache__" ]]; then
2329 base_module_name="${compiled_file##*/}"
2330 base_module_name="${base_module_name%\$py.class}"
2331 py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
2332 else
2333 py_file="${compiled_file%\$py.class}"
2334 fi
2335 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
2336 [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
2337 else
2338 [[ -f "${py_file}" ]] && continue
2339 fi
2340 echo "${_BLUE}<<< ${compiled_file}${_NORMAL}"
2341 rm -f "${compiled_file}"
1061 else 2342 else
1062 echo "/usr/$(get_libdir)/python$(PYTHON -A --ABI)" 2343 die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
1063 fi 2344 fi
1064}
1065 2345
1066# @FUNCTION: python_get_sitedir 2346 # Delete empty parent directories.
1067# @DESCRIPTION: 2347 dir="${compiled_file%/*}"
1068# Run without arguments, returns the Python site-packages directory. 2348 while [[ "${dir}" != "${root}" ]]; do
1069python_get_sitedir() { 2349 if rmdir "${dir}" 2> /dev/null; then
1070 echo "$(python_get_libdir)/site-packages" 2350 echo "${_CYAN}<<< ${dir}${_NORMAL}"
2351 else
2352 break
2353 fi
2354 dir="${dir%/*}"
2355 done
2356 done
2357 done
1071} 2358}
1072 2359
1073# @FUNCTION: python_tkinter_exists
1074# @DESCRIPTION:
1075# Run without arguments, checks if python was compiled with Tkinter
1076# support. If not, prints an error message and dies.
1077python_tkinter_exists() {
1078 if ! python -c "import Tkinter" >/dev/null 2>&1; then
1079 eerror "You need to recompile python with Tkinter support."
1080 eerror "Try adding: 'dev-lang/python tk'"
1081 eerror "in to /etc/portage/package.use"
1082 echo
1083 die "missing tkinter support with installed python"
1084 fi
1085}
1086
1087# @FUNCTION: python_mod_exists 2360# @FUNCTION: python_mod_optimize
1088# @USAGE: <module> 2361# @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories]
1089# @DESCRIPTION: 2362# @DESCRIPTION:
1090# Run with the module name as an argument. it will check if a 2363# Byte-compile specified Python modules.
1091# python module is installed and loadable. it will return 2364# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
1092# TRUE(0) if the module exists, and FALSE(1) if the module does
1093# not exist.
1094# 2365#
1095# Example:
1096# if python_mod_exists gtk; then
1097# echo "gtk support enabled"
1098# fi
1099python_mod_exists() {
1100 [[ "$1" ]] || die "${FUNCNAME} requires an argument!"
1101 python -c "import $1" &>/dev/null
1102}
1103
1104# @FUNCTION: python_mod_compile
1105# @USAGE: <file> [more files ...]
1106# @DESCRIPTION:
1107# Given filenames, it will pre-compile the module's .pyc and .pyo.
1108# This function should only be run in pkg_postinst()
1109#
1110# Example:
1111# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
1112#
1113python_mod_compile() {
1114 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1115 die "${FUNCNAME}() cannot be used in this EAPI"
1116 fi
1117
1118 local f myroot myfiles=()
1119
1120 # Check if phase is pkg_postinst()
1121 [[ ${EBUILD_PHASE} != postinst ]] &&\
1122 die "${FUNCNAME} should only be run in pkg_postinst()"
1123
1124 # strip trailing slash
1125 myroot="${ROOT%/}"
1126
1127 # respect ROOT
1128 for f in "$@"; do
1129 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
1130 done
1131
1132 if ((${#myfiles[@]})); then
1133 "$(PYTHON -A)" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
1134 "$(PYTHON -A)" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
1135 else
1136 ewarn "No files to compile!"
1137 fi
1138}
1139
1140# @FUNCTION: python_mod_optimize
1141# @USAGE: [options] [directory|file]
1142# @DESCRIPTION:
1143# If no arguments supplied, it will recompile not recursively all modules
1144# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages).
1145#
1146# If supplied with arguments, it will recompile all modules recursively
1147# in the supplied directory.
1148# This function should only be run in pkg_postinst(). 2366# This function can be used only in pkg_postinst() phase.
1149#
1150# Options passed to this function are passed to compileall.py.
1151#
1152# Example:
1153# python_mod_optimize ctypesgencore
1154python_mod_optimize() { 2367python_mod_optimize() {
2368 _python_check_python_pkg_setup_execution
2369 _python_initialize_prefix_variables
2370
1155 # Check if phase is pkg_postinst(). 2371 # Check if phase is pkg_postinst().
1156 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME} should only be run in pkg_postinst()" 2372 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
1157 2373
2374 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2375 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
2376 local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=()
2377
2378 if _python_package_supporting_installation_for_multiple_python_abis; then
1158 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2379 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
1159 local dir file options=() other_dirs=() other_files=() PYTHON_ABI return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() 2380 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2381 fi
2382 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2383 else
2384 if has "${EAPI:-0}" 0 1 2 3; then
2385 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
2386 else
2387 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2388 fi
2389 fi
1160 2390
1161 # Strip trailing slash from ROOT. 2391 # Strip trailing slash from EROOT.
1162 root="${ROOT%/}" 2392 root="${EROOT%/}"
1163 2393
1164 # Respect ROOT and options passed to compileall.py.
1165 while (($#)); do 2394 while (($#)); do
1166 case "$1" in 2395 case "$1" in
2396 --allow-evaluated-non-sitedir-paths)
2397 allow_evaluated_non_sitedir_paths="1"
2398 ;;
1167 -l|-f|-q) 2399 -l|-f|-q)
1168 options+=("$1") 2400 options+=("$1")
1169 ;; 2401 ;;
1170 -d|-x) 2402 -d|-x)
1171 options+=("$1" "$2") 2403 options+=("$1" "$2")
1172 shift 2404 shift
1173 ;; 2405 ;;
2406 --)
2407 shift
2408 break
2409 ;;
1174 -*) 2410 -*)
1175 ewarn "${FUNCNAME}: Ignoring compile option $1" 2411 die "${FUNCNAME}(): Unrecognized option '$1'"
1176 ;; 2412 ;;
1177 *) 2413 *)
1178 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1179 die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories"
1180 elif [[ "$1" =~ ^/ ]]; then
1181 if [[ -d "${root}/$1" ]]; then
1182 other_dirs+=("${root}/$1")
1183 elif [[ -f "${root}/$1" ]]; then
1184 other_files+=("${root}/$1")
1185 elif [[ -e "${root}/$1" ]]; then
1186 ewarn "'${root}/$1' is not a file or a directory!"
1187 else
1188 ewarn "'${root}/$1' does not exist!"
1189 fi
1190 else
1191 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do
1192 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
1193 site_packages_dirs+=("$1")
1194 break 2414 break
1195 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
1196 site_packages_files+=("$1")
1197 break
1198 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
1199 ewarn "'$1' is not a file or a directory!"
1200 else
1201 ewarn "'$1' does not exist!"
1202 fi
1203 done
1204 fi
1205 ;; 2415 ;;
1206 esac 2416 esac
1207 shift 2417 shift
1208 done 2418 done
1209 2419
2420 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2421 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2422 fi
2423
2424 if [[ "$#" -eq 0 ]]; then
2425 die "${FUNCNAME}(): Missing files or directories"
2426 fi
2427
2428 while (($#)); do
2429 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2430 die "${FUNCNAME}(): Invalid argument '$1'"
2431 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
2432 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
2433 elif [[ "$1" =~ ^/ ]]; then
2434 if _python_package_supporting_installation_for_multiple_python_abis; then
2435 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2436 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2437 fi
2438 if [[ "$1" != *\$* ]]; then
2439 die "${FUNCNAME}(): '$1' has invalid syntax"
2440 fi
2441 if [[ "$1" == *.py ]]; then
2442 evaluated_files+=("$1")
2443 else
2444 evaluated_dirs+=("$1")
2445 fi
2446 else
2447 if [[ -d "${root}$1" ]]; then
2448 other_dirs+=("${root}$1")
2449 elif [[ -f "${root}$1" ]]; then
2450 other_files+=("${root}$1")
2451 elif [[ -e "${root}$1" ]]; then
2452 eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
2453 else
2454 eerror "${FUNCNAME}(): '${root}$1' does not exist"
2455 fi
2456 fi
2457 else
2458 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2459 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
2460 site_packages_dirs+=("$1")
2461 break
2462 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
2463 site_packages_files+=("$1")
2464 break
2465 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
2466 eerror "${FUNCNAME}(): '$1' is not a regular file or a directory"
2467 else
2468 eerror "${FUNCNAME}(): '$1' does not exist"
2469 fi
2470 done
2471 fi
2472 shift
2473 done
2474
1210 # Set additional options. 2475 # Set additional options.
1211 options+=("-q") 2476 options+=("-q")
1212 2477
1213 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do 2478 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1214 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 2479 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
1215 return_code="0" 2480 return_code="0"
1216 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" 2481 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1217 if ((${#site_packages_dirs[@]})); then 2482 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
1218 for dir in "${site_packages_dirs[@]}"; do 2483 for dir in "${site_packages_dirs[@]}"; do
1219 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") 2484 dirs+=("${root}$(python_get_sitedir)/${dir}")
1220 done 2485 done
2486 for dir in "${evaluated_dirs[@]}"; do
2487 eval "dirs+=(\"\${root}${dir}\")"
2488 done
1221 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 2489 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" || return_code="1"
2490 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1222 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" 2491 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
1223 fi 2492 fi
1224 if ((${#site_packages_files[@]})); then 2493 _python_clean_compiled_modules "${dirs[@]}"
2494 fi
2495 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
1225 for file in "${site_packages_files[@]}"; do 2496 for file in "${site_packages_files[@]}"; do
1226 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") 2497 files+=("${root}$(python_get_sitedir)/${file}")
1227 done 2498 done
2499 for file in "${evaluated_files[@]}"; do
2500 eval "files+=(\"\${root}${file}\")"
2501 done
1228 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 2502 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" || return_code="1"
2503 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1229 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" 2504 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${files[@]}" &> /dev/null || return_code="1"
2505 fi
2506 _python_clean_compiled_modules "${files[@]}"
1230 fi 2507 fi
1231 eend "${return_code}" 2508 eend "${return_code}"
1232 fi 2509 fi
1233 unset site_packages_absolute_dirs site_packages_absolute_files 2510 unset dirs files
1234 done 2511 done
1235 2512
1236 # Do not use PYTHON_ABI in next calls to python_get_libdir(). 2513 if _python_package_supporting_installation_for_multiple_python_abis; then
2514 # Restore previous value of PYTHON_ABI.
2515 if [[ -n "${previous_PYTHON_ABI}" ]]; then
2516 PYTHON_ABI="${previous_PYTHON_ABI}"
2517 else
1237 unset PYTHON_ABI 2518 unset PYTHON_ABI
2519 fi
2520 fi
1238 2521
1239 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 2522 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
1240 return_code="0" 2523 return_code="0"
1241 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python $(PYTHON -A --ABI)" 2524 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)"
1242 if ((${#other_dirs[@]})); then 2525 if ((${#other_dirs[@]})); then
1243 "$(PYTHON -A)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 2526 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
2527 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1244 "$(PYTHON -A)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 2528 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
2529 fi
2530 _python_clean_compiled_modules "${other_dirs[@]}"
1245 fi 2531 fi
1246 if ((${#other_files[@]})); then 2532 if ((${#other_files[@]})); then
1247 "$(PYTHON -A)" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 2533 "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
2534 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
1248 "$(PYTHON -A)" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 2535 "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
2536 fi
2537 _python_clean_compiled_modules "${other_files[@]}"
1249 fi 2538 fi
1250 eend "${return_code}" 2539 eend "${return_code}"
1251 fi 2540 fi
1252 else 2541 else
2542 # Deprecated part of python_mod_optimize()
2543 # ewarn
2544 # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
2545 # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01."
2546 # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2547 # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2548 # ewarn
2549
1253 local myroot mydirs=() myfiles=() myopts=() return_code="0" 2550 local myroot mydirs=() myfiles=() myopts=() return_code="0"
1254 2551
1255 # strip trailing slash 2552 # strip trailing slash
1256 myroot="${ROOT%/}" 2553 myroot="${EROOT%/}"
1257 2554
1258 # respect ROOT and options passed to compileall.py 2555 # respect EROOT and options passed to compileall.py
1259 while (($#)); do 2556 while (($#)); do
1260 case "$1" in 2557 case "$1" in
1261 -l|-f|-q) 2558 -l|-f|-q)
1262 myopts+=("$1") 2559 myopts+=("$1")
1263 ;; 2560 ;;
1264 -d|-x) 2561 -d|-x)
1265 myopts+=("$1" "$2") 2562 myopts+=("$1" "$2")
1266 shift 2563 shift
1267 ;; 2564 ;;
2565 --)
2566 shift
2567 break
2568 ;;
1268 -*) 2569 -*)
1269 ewarn "${FUNCNAME}: Ignoring compile option $1" 2570 die "${FUNCNAME}(): Unrecognized option '$1'"
1270 ;; 2571 ;;
1271 *) 2572 *)
1272 if [[ -d "${myroot}"/$1 ]]; then 2573 break
1273 mydirs+=("${myroot}/$1")
1274 elif [[ -f "${myroot}"/$1 ]]; then
1275 # Files are passed to python_mod_compile which is ROOT-aware
1276 myfiles+=("$1")
1277 elif [[ -e "${myroot}/$1" ]]; then
1278 ewarn "${myroot}/$1 is not a file or directory!"
1279 else
1280 ewarn "${myroot}/$1 does not exist!"
1281 fi
1282 ;; 2574 ;;
1283 esac 2575 esac
1284 shift 2576 shift
1285 done 2577 done
1286 2578
2579 if [[ "$#" -eq 0 ]]; then
2580 die "${FUNCNAME}(): Missing files or directories"
2581 fi
2582
2583 while (($#)); do
2584 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2585 die "${FUNCNAME}(): Invalid argument '$1'"
2586 elif [[ -d "${myroot}/${1#/}" ]]; then
2587 mydirs+=("${myroot}/${1#/}")
2588 elif [[ -f "${myroot}/${1#/}" ]]; then
2589 myfiles+=("${myroot}/${1#/}")
2590 elif [[ -e "${myroot}/${1#/}" ]]; then
2591 eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
2592 else
2593 eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
2594 fi
2595 shift
2596 done
2597
1287 # set additional opts 2598 # set additional opts
1288 myopts+=(-q) 2599 myopts+=(-q)
1289 2600
1290 ebegin "Compilation and optimization of Python modules for Python $(PYTHON -A --ABI)" 2601 PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
2602
2603 ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
1291 if ((${#mydirs[@]})); then 2604 if ((${#mydirs[@]})); then
1292 "$(PYTHON -A)" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" 2605 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1"
1293 "$(PYTHON -A)" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 2606 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
2607 _python_clean_compiled_modules "${mydirs[@]}"
1294 fi 2608 fi
1295 2609
1296 if ((${#myfiles[@]})); then 2610 if ((${#myfiles[@]})); then
2611 "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1"
2612 "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1"
1297 python_mod_compile "${myfiles[@]}" 2613 _python_clean_compiled_modules "${myfiles[@]}"
1298 fi 2614 fi
1299 2615
1300 eend "${return_code}" 2616 eend "${return_code}"
1301 fi 2617 fi
1302} 2618}
1303 2619
1304# @FUNCTION: python_mod_cleanup 2620# @FUNCTION: python_mod_cleanup
1305# @USAGE: [directory|file] 2621# @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories]
1306# @DESCRIPTION: 2622# @DESCRIPTION:
1307# Run with optional arguments, where arguments are Python modules. If none given, 2623# Delete orphaned byte-compiled Python modules corresponding to specified Python modules.
1308# it will look in /usr/lib/python[0-9].[0-9].
1309# 2624#
1310# It will recursively scan all compiled Python modules in the directories and
1311# determine if they are orphaned (i.e. their corresponding .py files are missing.)
1312# If they are, then it will remove their corresponding .pyc and .pyo files.
1313#
1314# This function should only be run in pkg_postrm(). 2625# This function can be used only in pkg_postrm() phase.
1315python_mod_cleanup() { 2626python_mod_cleanup() {
1316 local path py_file PYTHON_ABI SEARCH_PATH=() root 2627 _python_check_python_pkg_setup_execution
2628 _python_initialize_prefix_variables
2629
2630 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
1317 2631
1318 # Check if phase is pkg_postrm(). 2632 # Check if phase is pkg_postrm().
1319 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME} should only be run in pkg_postrm()" 2633 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
1320 2634
2635 if _python_package_supporting_installation_for_multiple_python_abis; then
2636 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2637 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2638 fi
2639 iterated_PYTHON_ABIS="${PYTHON_ABIS}"
2640 else
2641 if has "${EAPI:-0}" 0 1 2 3; then
2642 iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
2643 else
2644 iterated_PYTHON_ABIS="${PYTHON_ABI}"
2645 fi
2646 fi
2647
1321 # Strip trailing slash from ROOT. 2648 # Strip trailing slash from EROOT.
1322 root="${ROOT%/}" 2649 root="${EROOT%/}"
1323 2650
1324 if (($#)); then 2651 while (($#)); do
1325 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 2652 case "$1" in
2653 --allow-evaluated-non-sitedir-paths)
2654 allow_evaluated_non_sitedir_paths="1"
2655 ;;
2656 --)
2657 shift
2658 break
2659 ;;
2660 -*)
2661 die "${FUNCNAME}(): Unrecognized option '$1'"
2662 ;;
2663 *)
2664 break
2665 ;;
2666 esac
2667 shift
2668 done
2669
2670 if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
2671 die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2672 fi
2673
2674 if [[ "$#" -eq 0 ]]; then
2675 die "${FUNCNAME}(): Missing files or directories"
2676 fi
2677
2678 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
1326 while (($#)); do 2679 while (($#)); do
2680 if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
2681 die "${FUNCNAME}(): Invalid argument '$1'"
1327 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 2682 elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1328 die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories" 2683 die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
1329 elif [[ "$1" =~ ^/ ]]; then 2684 elif [[ "$1" =~ ^/ ]]; then
1330 SEARCH_PATH+=("${root}/${1#/}") 2685 if _python_package_supporting_installation_for_multiple_python_abis; then
2686 if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
2687 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2688 fi
2689 if [[ "$1" != *\$* ]]; then
2690 die "${FUNCNAME}(): '$1' has invalid syntax"
2691 fi
2692 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2693 eval "search_paths+=(\"\${root}$1\")"
2694 done
1331 else 2695 else
1332 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do 2696 search_paths+=("${root}$1")
1333 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1")
1334 done
1335 fi
1336 shift
1337 done
1338 else
1339 SEARCH_PATH=("${@#/}")
1340 SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}")
1341 fi
1342 else
1343 local dir sitedir
1344 for dir in "${root}"/usr/lib*; do
1345 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
1346 for sitedir in "${dir}"/python*/site-packages; do
1347 if [[ -d "${sitedir}" ]]; then
1348 SEARCH_PATH+=("${sitedir}")
1349 fi 2697 fi
2698 else
2699 for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
2700 search_paths+=("${root}$(python_get_sitedir)/$1")
1350 done 2701 done
1351 fi 2702 fi
2703 shift
1352 done 2704 done
1353 fi
1354
1355 local BLUE CYAN NORMAL
1356 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
1357 BLUE=$'\e[1;34m'
1358 CYAN=$'\e[1;36m'
1359 NORMAL=$'\e[0m'
1360 else 2705 else
1361 BLUE= 2706 # Deprecated part of python_mod_cleanup()
1362 CYAN= 2707 # ewarn
1363 NORMAL= 2708 # ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
1364 fi 2709 # ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-06-01."
2710 # ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
2711 # ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
2712 # ewarn
1365 2713
1366 for path in "${SEARCH_PATH[@]}"; do 2714 search_paths=("${@#/}")
1367 if [[ -d "${path}" ]]; then 2715 search_paths=("${search_paths[@]/#/${root}/}")
1368 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do
1369 py_file="${REPLY%[co]}"
1370 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
1371 einfo "${BLUE}<<< ${py_file}[co]${NORMAL}"
1372 rm -f "${py_file}"[co]
1373 done
1374
1375 # Attempt to delete directories, which may be empty.
1376 find "${path}" -type d | sort -r | while read -r dir; do
1377 rmdir "${dir}" 2>/dev/null && einfo "${CYAN}<<< ${dir}${NORMAL}"
1378 done
1379 elif [[ "${path}" == *.py && ! -f "${path}" && (-f "${path}c" || -f "${path}o") ]]; then
1380 einfo "${BLUE}<<< ${path}[co]${NORMAL}"
1381 rm -f "${path}"[co]
1382 fi 2716 fi
1383 done 2717
2718 _python_clean_compiled_modules "${search_paths[@]}"
1384} 2719}
2720
2721# ================================================================================================
2722# ===================================== DEPRECATED FUNCTIONS =====================================
2723# ================================================================================================
2724
2725# Scheduled for deletion on 2011-01-01.
2726python_version() {
2727 eerror "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables."
2728 die "${FUNCNAME}() is banned"
2729}
2730
2731# Scheduled for deletion on 2011-01-01.
2732python_mod_exists() {
2733 eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()."
2734 die "${FUNCNAME}() is banned"
2735}
2736
2737# Scheduled for deletion on 2011-01-01.
2738python_tkinter_exists() {
2739 eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()."
2740 die "${FUNCNAME}() is banned"
2741}
2742
2743# Scheduled for deletion on 2011-04-01.
2744python_mod_compile() {
2745 eerror "Use python_mod_optimize() instead of ${FUNCNAME}()."
2746 die "${FUNCNAME}() is banned"
2747}

Legend:
Removed from v.1.84  
changed lines
  Added in v.1.104

  ViewVC Help
Powered by ViewVC 1.1.20