Gentoo Archives: gentoo-commits

From: Andreas Sturmlechner <asturm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/kde-sunset:master commit in: eclass/
Date: Wed, 12 Sep 2018 20:42:04
Message-Id: 1536784811.ffedd275d6bf9b9a3c9ff18c564d9f15b9b4b89e.asturm@gentoo
1 commit: ffedd275d6bf9b9a3c9ff18c564d9f15b9b4b89e
2 Author: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
3 AuthorDate: Wed Sep 12 20:40:11 2018 +0000
4 Commit: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
5 CommitDate: Wed Sep 12 20:40:11 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/kde-sunset.git/commit/?id=ffedd275
7
8 Import distutils.eclass, python.eclass from Gentoo ebuild repo
9
10 eclass/distutils.eclass | 599 +++++++++
11 eclass/python.eclass | 3167 +++++++++++++++++++++++++++++++++++++++++++++++
12 2 files changed, 3766 insertions(+)
13
14 diff --git a/eclass/distutils.eclass b/eclass/distutils.eclass
15 new file mode 100644
16 index 0000000..9e0b0b5
17 --- /dev/null
18 +++ b/eclass/distutils.eclass
19 @@ -0,0 +1,599 @@
20 +# Copyright 1999-2017 Gentoo Foundation
21 +# Distributed under the terms of the GNU General Public License v2
22 +
23 +# @DEAD
24 +# Removal on 2017-03-18.
25 +
26 +# @ECLASS: distutils.eclass
27 +# @MAINTAINER:
28 +# kde-sunset overlay maintainers
29 +# @BLURB: Eclass for packages with build systems using Distutils
30 +# @DESCRIPTION:
31 +# The distutils eclass defines phase functions for packages with build systems using Distutils.
32 +#
33 +# This eclass is DEPRECATED. Please use distutils-r1 instead.
34 +
35 +if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then
36 + inherit python
37 +fi
38 +
39 +inherit multilib
40 +
41 +case "${EAPI:-0}" in
42 + 6)
43 + die "${ECLASS}.eclass is banned in EAPI ${EAPI}"
44 + ;;
45 + 0|1)
46 + EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm
47 + ;;
48 + *)
49 + EXPORT_FUNCTIONS src_prepare src_compile src_install pkg_postinst pkg_postrm
50 + ;;
51 +esac
52 +
53 +if [[ -z "$(declare -p PYTHON_DEPEND 2> /dev/null)" ]]; then
54 + DEPEND="dev-lang/python"
55 + RDEPEND="${DEPEND}"
56 +fi
57 +
58 + if has "${EAPI:-0}" 0 1 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
59 + ewarn
60 + ewarn "\"${EBUILD}\":"
61 + ewarn "Deprecation Warning: Usage of distutils.eclass in packages supporting installation"
62 + ewarn "for multiple Python ABIs in EAPI <=1 is deprecated."
63 + ewarn "The ebuild should to be fixed. Please report a bug, if it has not been already reported."
64 + ewarn
65 + elif has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
66 + ewarn
67 + ewarn "\"${EBUILD}\":"
68 + ewarn "Deprecation Warning: Usage of distutils.eclass in packages not supporting installation"
69 + ewarn "for multiple Python ABIs in EAPI <=2 is deprecated."
70 + ewarn "The ebuild should to be fixed. Please report a bug, if it has not been already reported."
71 + ewarn
72 + fi
73 +
74 +# 'python' variable is deprecated. Use PYTHON() instead.
75 +if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
76 + python="python"
77 +else
78 + python="die"
79 +fi
80 +
81 +# @ECLASS-VARIABLE: DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES
82 +# @DESCRIPTION:
83 +# Set this to use separate source directories for each enabled version of Python.
84 +
85 +# @ECLASS-VARIABLE: DISTUTILS_SETUP_FILES
86 +# @DESCRIPTION:
87 +# Array of paths to setup files.
88 +# Syntax:
89 +# [current_working_directory|]path_to_setup_file
90 +
91 +# @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS
92 +# @DESCRIPTION:
93 +# Array of global options passed to setup files.
94 +# Syntax in EAPI <4:
95 +# global_option
96 +# Syntax in EAPI >=4:
97 +# Python_ABI_pattern global_option
98 +
99 +# @ECLASS-VARIABLE: DISTUTILS_SRC_TEST
100 +# @DESCRIPTION:
101 +# Type of test command used by distutils_src_test().
102 +# IUSE and DEPEND are automatically adjusted, unless DISTUTILS_DISABLE_TEST_DEPENDENCY is set.
103 +# Valid values:
104 +# setup.py
105 +# nosetests
106 +# py.test
107 +# trial [arguments]
108 +
109 +# @ECLASS-VARIABLE: DISTUTILS_DISABLE_TEST_DEPENDENCY
110 +# @DESCRIPTION:
111 +# Disable modification of IUSE and DEPEND caused by setting of DISTUTILS_SRC_TEST.
112 +
113 +if [[ -n "${DISTUTILS_SRC_TEST}" && ! "${DISTUTILS_SRC_TEST}" =~ ^(setup\.py|nosetests|py\.test|trial(\ .*)?)$ ]]; then
114 + die "'DISTUTILS_SRC_TEST' variable has unsupported value '${DISTUTILS_SRC_TEST}'"
115 +fi
116 +
117 +if [[ -z "${DISTUTILS_DISABLE_TEST_DEPENDENCY}" ]]; then
118 + if [[ "${DISTUTILS_SRC_TEST}" == "nosetests" ]]; then
119 + IUSE="test"
120 + DEPEND+="${DEPEND:+ }test? ( dev-python/nose )"
121 + elif [[ "${DISTUTILS_SRC_TEST}" == "py.test" ]]; then
122 + IUSE="test"
123 + DEPEND+="${DEPEND:+ }test? ( dev-python/pytest )"
124 + # trial requires an argument, which is usually equal to "${PN}".
125 + elif [[ "${DISTUTILS_SRC_TEST}" =~ ^trial(\ .*)?$ ]]; then
126 + IUSE="test"
127 + DEPEND+="${DEPEND:+ }test? ( dev-python/twisted-core )"
128 + fi
129 +fi
130 +
131 +if [[ -n "${DISTUTILS_SRC_TEST}" ]]; then
132 + EXPORT_FUNCTIONS src_test
133 +fi
134 +
135 +# Scheduled for deletion on 2011-06-01.
136 +if [[ -n "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" ]]; then
137 + eerror "Use PYTHON_NONVERSIONED_EXECUTABLES=(\".*\") instead of DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS variable."
138 + die "DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS variable is banned"
139 +fi
140 +
141 +# @ECLASS-VARIABLE: DOCS
142 +# @DESCRIPTION:
143 +# Additional documentation files installed by distutils_src_install().
144 +
145 +_distutils_get_build_dir() {
146 + if _python_package_supporting_installation_for_multiple_python_abis && [[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
147 + echo "build-${PYTHON_ABI}"
148 + else
149 + echo "build"
150 + fi
151 +}
152 +
153 +_distutils_get_PYTHONPATH() {
154 + if _python_package_supporting_installation_for_multiple_python_abis && [[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
155 + ls -d build-${PYTHON_ABI}/lib* 2> /dev/null
156 + else
157 + ls -d build/lib* 2> /dev/null
158 + fi
159 +}
160 +
161 +_distutils_hook() {
162 + if [[ "$#" -ne 1 ]]; then
163 + die "${FUNCNAME}() requires 1 argument"
164 + fi
165 + if [[ "$(type -t "distutils_src_${EBUILD_PHASE}_$1_hook")" == "function" ]]; then
166 + "distutils_src_${EBUILD_PHASE}_$1_hook"
167 + fi
168 +}
169 +
170 +_distutils_prepare_global_options() {
171 + local element option pattern
172 +
173 + if [[ -n "$(declare -p DISTUTILS_GLOBAL_OPTIONS 2> /dev/null)" && "$(declare -p DISTUTILS_GLOBAL_OPTIONS)" != "declare -a DISTUTILS_GLOBAL_OPTIONS="* ]]; then
174 + die "DISTUTILS_GLOBAL_OPTIONS should be indexed array"
175 + fi
176 +
177 + if has "${EAPI:-0}" 0 1 2 3; then
178 + _DISTUTILS_GLOBAL_OPTIONS=("${DISTUTILS_GLOBAL_OPTIONS[@]}")
179 + else
180 + _DISTUTILS_GLOBAL_OPTIONS=()
181 +
182 + for element in "${DISTUTILS_GLOBAL_OPTIONS[@]}"; do
183 + if [[ ! "${element}" =~ ^[^[:space:]]+\ . ]]; then
184 + die "Element '${element}' of DISTUTILS_GLOBAL_OPTIONS array has invalid syntax"
185 + fi
186 + pattern="${element%% *}"
187 + option="${element#* }"
188 + if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
189 + _DISTUTILS_GLOBAL_OPTIONS+=("${option}")
190 + fi
191 + done
192 + fi
193 +}
194 +
195 +_distutils_prepare_current_working_directory() {
196 + if [[ "$1" == *"|"*"|"* ]]; then
197 + die "Element '$1' of DISTUTILS_SETUP_FILES array has invalid syntax"
198 + fi
199 +
200 + if [[ "$1" == *"|"* ]]; then
201 + echo "${_BOLD}[${1%|*}]${_NORMAL}"
202 + pushd "${1%|*}" > /dev/null || die "Entering directory '${1%|*}' failed"
203 + fi
204 +}
205 +
206 +_distutils_restore_current_working_directory() {
207 + if [[ "$1" == *"|"* ]]; then
208 + popd > /dev/null || die "Leaving directory '${1%|*}' failed"
209 + fi
210 +}
211 +
212 +# @FUNCTION: distutils_src_unpack
213 +# @DESCRIPTION:
214 +# The distutils src_unpack function. This function is exported.
215 +distutils_src_unpack() {
216 + if ! has "${EAPI:-0}" 0 1; then
217 + die "${FUNCNAME}() cannot be used in this EAPI"
218 + fi
219 +
220 + if [[ "${EBUILD_PHASE}" != "unpack" ]]; then
221 + die "${FUNCNAME}() can be used only in src_unpack() phase"
222 + fi
223 +
224 + unpack ${A}
225 + cd "${S}"
226 +
227 + distutils_src_prepare
228 +}
229 +
230 +# @FUNCTION: distutils_src_prepare
231 +# @DESCRIPTION:
232 +# The distutils src_prepare function. This function is exported.
233 +distutils_src_prepare() {
234 + if ! has "${EAPI:-0}" 0 1 && [[ "${EBUILD_PHASE}" != "prepare" ]]; then
235 + die "${FUNCNAME}() can be used only in src_prepare() phase"
236 + fi
237 +
238 + _python_check_python_pkg_setup_execution
239 +
240 + local distribute_setup_existence="0" ez_setup_existence="0"
241 +
242 + if [[ "$#" -ne 0 ]]; then
243 + die "${FUNCNAME}() does not accept arguments"
244 + fi
245 +
246 + # Delete ez_setup files to prevent packages from installing Setuptools on their own.
247 + [[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1"
248 + rm -fr ez_setup*
249 + if [[ "${ez_setup_existence}" == "1" ]]; then
250 + echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py
251 + fi
252 +
253 + # Delete distribute_setup files to prevent packages from installing Distribute on their own.
254 + [[ -d distribute_setup || -f distribute_setup.py ]] && distribute_setup_existence="1"
255 + rm -fr distribute_setup*
256 + if [[ "${distribute_setup_existence}" == "1" ]]; then
257 + echo "def use_setuptools(*args, **kwargs): pass" > distribute_setup.py
258 + fi
259 +
260 + if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
261 + python_copy_sources
262 + fi
263 +}
264 +
265 +# @FUNCTION: distutils_src_compile
266 +# @DESCRIPTION:
267 +# The distutils src_compile function. This function is exported.
268 +# In ebuilds of packages supporting installation for multiple versions of Python, this function
269 +# calls distutils_src_compile_pre_hook() and distutils_src_compile_post_hook(), if they are defined.
270 +distutils_src_compile() {
271 + if [[ "${EBUILD_PHASE}" != "compile" ]]; then
272 + die "${FUNCNAME}() can be used only in src_compile() phase"
273 + fi
274 +
275 + _python_check_python_pkg_setup_execution
276 + _python_set_color_variables
277 +
278 + local setup_file
279 +
280 + if _python_package_supporting_installation_for_multiple_python_abis; then
281 + distutils_building() {
282 + _distutils_hook pre
283 +
284 + _distutils_prepare_global_options
285 +
286 + for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
287 + _distutils_prepare_current_working_directory "${setup_file}"
288 +
289 + echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "$(_distutils_get_build_dir)" "$@"${_NORMAL}
290 + "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "$(_distutils_get_build_dir)" "$@" || return "$?"
291 +
292 + _distutils_restore_current_working_directory "${setup_file}"
293 + done
294 +
295 + _distutils_hook post
296 + }
297 + python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_building "$@"
298 + unset -f distutils_building
299 + else
300 + _distutils_prepare_global_options
301 +
302 + for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
303 + _distutils_prepare_current_working_directory "${setup_file}"
304 +
305 + echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"${_NORMAL}
306 + "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || die "Building failed"
307 +
308 + _distutils_restore_current_working_directory "${setup_file}"
309 + done
310 + fi
311 +}
312 +
313 +_distutils_src_test_hook() {
314 + if [[ "$#" -ne 1 ]]; then
315 + die "${FUNCNAME}() requires 1 arguments"
316 + fi
317 +
318 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
319 + return
320 + fi
321 +
322 + if [[ "$(type -t "distutils_src_test_pre_hook")" == "function" ]]; then
323 + eval "python_execute_$1_pre_hook() {
324 + distutils_src_test_pre_hook
325 + }"
326 + fi
327 +
328 + if [[ "$(type -t "distutils_src_test_post_hook")" == "function" ]]; then
329 + eval "python_execute_$1_post_hook() {
330 + distutils_src_test_post_hook
331 + }"
332 + fi
333 +}
334 +
335 +# @FUNCTION: distutils_src_test
336 +# @DESCRIPTION:
337 +# The distutils src_test function. This function is exported, when DISTUTILS_SRC_TEST variable is set.
338 +# In ebuilds of packages supporting installation for multiple versions of Python, this function
339 +# calls distutils_src_test_pre_hook() and distutils_src_test_post_hook(), if they are defined.
340 +distutils_src_test() {
341 + if [[ "${EBUILD_PHASE}" != "test" ]]; then
342 + die "${FUNCNAME}() can be used only in src_test() phase"
343 + fi
344 +
345 + _python_check_python_pkg_setup_execution
346 + _python_set_color_variables
347 +
348 + local arguments setup_file
349 +
350 + if [[ "${DISTUTILS_SRC_TEST}" == "setup.py" ]]; then
351 + if _python_package_supporting_installation_for_multiple_python_abis; then
352 + distutils_testing() {
353 + _distutils_hook pre
354 +
355 + _distutils_prepare_global_options
356 +
357 + for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
358 + _distutils_prepare_current_working_directory "${setup_file}"
359 +
360 + echo ${_BOLD}PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") test "$@"${_NORMAL}
361 + PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") test "$@" || return "$?"
362 +
363 + _distutils_restore_current_working_directory "${setup_file}"
364 + done
365 +
366 + _distutils_hook post
367 + }
368 + python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_testing "$@"
369 + unset -f distutils_testing
370 + else
371 + _distutils_prepare_global_options
372 +
373 + for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
374 + _distutils_prepare_current_working_directory "${setup_file}"
375 +
376 + echo ${_BOLD}PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" test "$@"${_NORMAL}
377 + PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" test "$@" || die "Testing failed"
378 +
379 + _distutils_restore_current_working_directory "${setup_file}"
380 + done
381 + fi
382 + elif [[ "${DISTUTILS_SRC_TEST}" == "nosetests" ]]; then
383 + _distutils_src_test_hook nosetests
384 +
385 + python_execute_nosetests -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- "$@"
386 + elif [[ "${DISTUTILS_SRC_TEST}" == "py.test" ]]; then
387 + _distutils_src_test_hook py.test
388 +
389 + python_execute_py.test -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- "$@"
390 + # trial requires an argument, which is usually equal to "${PN}".
391 + elif [[ "${DISTUTILS_SRC_TEST}" =~ ^trial(\ .*)?$ ]]; then
392 + if [[ "${DISTUTILS_SRC_TEST}" == "trial "* ]]; then
393 + arguments="${DISTUTILS_SRC_TEST#trial }"
394 + else
395 + arguments="${PN}"
396 + fi
397 +
398 + _distutils_src_test_hook trial
399 +
400 + python_execute_trial -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- ${arguments} "$@"
401 + else
402 + die "'DISTUTILS_SRC_TEST' variable has unsupported value '${DISTUTILS_SRC_TEST}'"
403 + fi
404 +}
405 +
406 +# @FUNCTION: distutils_src_install
407 +# @DESCRIPTION:
408 +# The distutils src_install function. This function is exported.
409 +# In ebuilds of packages supporting installation for multiple versions of Python, this function
410 +# calls distutils_src_install_pre_hook() and distutils_src_install_post_hook(), if they are defined.
411 +# It also installs some standard documentation files (AUTHORS, Change*, CHANGELOG, CONTRIBUTORS,
412 +# KNOWN_BUGS, MAINTAINERS, NEWS, README*, TODO).
413 +distutils_src_install() {
414 + if [[ "${EBUILD_PHASE}" != "install" ]]; then
415 + die "${FUNCNAME}() can be used only in src_install() phase"
416 + fi
417 +
418 + _python_check_python_pkg_setup_execution
419 + _python_initialize_prefix_variables
420 + _python_set_color_variables
421 +
422 + local default_docs doc line nspkg_pth_file nspkg_pth_files=() setup_file
423 +
424 + if _python_package_supporting_installation_for_multiple_python_abis; then
425 + distutils_installation() {
426 + _distutils_hook pre
427 +
428 + _distutils_prepare_global_options
429 +
430 + for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
431 + _distutils_prepare_current_working_directory "${setup_file}"
432 +
433 + echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") install --no-compile --root="${T}/images/${PYTHON_ABI}" "$@"${_NORMAL}
434 + "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") install --no-compile --root="${T}/images/${PYTHON_ABI}" "$@" || return "$?"
435 +
436 + _distutils_restore_current_working_directory "${setup_file}"
437 + done
438 +
439 + _distutils_hook post
440 + }
441 + python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_installation "$@"
442 + unset -f distutils_installation
443 +
444 + python_merge_intermediate_installation_images "${T}/images"
445 + else
446 + # Mark the package to be rebuilt after a Python upgrade.
447 + python_need_rebuild
448 +
449 + _distutils_prepare_global_options
450 +
451 + for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
452 + _distutils_prepare_current_working_directory "${setup_file}"
453 +
454 + echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@"${_NORMAL}
455 + "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || die "Installation failed"
456 +
457 + _distutils_restore_current_working_directory "${setup_file}"
458 + done
459 + fi
460 +
461 + while read -d $'\0' -r nspkg_pth_file; do
462 + nspkg_pth_files+=("${nspkg_pth_file}")
463 + done < <(find "${ED}" -name "*-nspkg.pth" -type f -print0)
464 +
465 + if [[ "${#nspkg_pth_files[@]}" -gt 0 ]]; then
466 + einfo
467 + einfo "Python namespaces:"
468 + for nspkg_pth_file in "${nspkg_pth_files[@]}"; do
469 + einfo " '${nspkg_pth_file#${ED%/}}':"
470 + while read -r line; do
471 + einfo " $(echo "${line}" | sed -e "s/.*types\.ModuleType('\([^']\+\)').*/\1/")"
472 + done < "${nspkg_pth_file}"
473 + #if ! has "${EAPI:-0}" 0 1 2 3; then
474 + # rm -f "${nspkg_pth_file}" || die "Deletion of '${nspkg_pth_file}' failed"
475 + #fi
476 + done
477 + einfo
478 + fi
479 +
480 + if [[ -e "${ED}usr/local" ]]; then
481 + die "Illegal installation into /usr/local"
482 + fi
483 +
484 + default_docs="AUTHORS Change* CHANGELOG CONTRIBUTORS KNOWN_BUGS MAINTAINERS NEWS README* TODO"
485 +
486 + for doc in ${default_docs}; do
487 + [[ -s "${doc}" ]] && dodoc "${doc}"
488 + done
489 +
490 + if has "${EAPI:-0}" 0 1 2 3; then
491 + if [[ -n "${DOCS}" ]]; then
492 + dodoc ${DOCS} || die "dodoc failed"
493 + fi
494 + else
495 + if [[ -n "${DOCS}" ]]; then
496 + dodoc -r ${DOCS} || die "dodoc failed"
497 + fi
498 + fi
499 +
500 + DISTUTILS_SRC_INSTALL_EXECUTED="1"
501 +}
502 +
503 +# @FUNCTION: distutils_pkg_postinst
504 +# @DESCRIPTION:
505 +# The distutils pkg_postinst function. This function is exported.
506 +# When PYTHON_MODNAME variable is set, then this function calls python_mod_optimize() with modules
507 +# specified in PYTHON_MODNAME variable. Otherwise it calls python_mod_optimize() with module, whose
508 +# name is equal to name of current package, if this module exists.
509 +distutils_pkg_postinst() {
510 + if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
511 + die "${FUNCNAME}() can be used only in pkg_postinst() phase"
512 + fi
513 +
514 + _python_check_python_pkg_setup_execution
515 + _python_initialize_prefix_variables
516 +
517 + if [[ -z "${DISTUTILS_SRC_INSTALL_EXECUTED}" ]]; then
518 + die "${FUNCNAME}() called illegally"
519 + fi
520 +
521 + local pylibdir pymod
522 +
523 + if [[ "$#" -ne 0 ]]; then
524 + die "${FUNCNAME}() does not accept arguments"
525 + fi
526 +
527 + if [[ -z "$(declare -p PYTHON_MODNAME 2> /dev/null)" ]]; then
528 + for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"usr/share/jython-*/Lib; do
529 + if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
530 + PYTHON_MODNAME="${PN}"
531 + fi
532 + done
533 + fi
534 +
535 + if [[ -n "${PYTHON_MODNAME}" ]]; then
536 + if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
537 + python_mod_optimize ${PYTHON_MODNAME}
538 + else
539 + for pymod in ${PYTHON_MODNAME}; do
540 + python_mod_optimize "$(python_get_sitedir)/${pymod}"
541 + done
542 + fi
543 + fi
544 +}
545 +
546 +# @FUNCTION: distutils_pkg_postrm
547 +# @DESCRIPTION:
548 +# The distutils pkg_postrm function. This function is exported.
549 +# When PYTHON_MODNAME variable is set, then this function calls python_mod_cleanup() with modules
550 +# specified in PYTHON_MODNAME variable. Otherwise it calls python_mod_cleanup() with module, whose
551 +# name is equal to name of current package, if this module exists.
552 +distutils_pkg_postrm() {
553 + if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
554 + die "${FUNCNAME}() can be used only in pkg_postrm() phase"
555 + fi
556 +
557 + _python_check_python_pkg_setup_execution
558 + _python_initialize_prefix_variables
559 +
560 + if [[ -z "${DISTUTILS_SRC_INSTALL_EXECUTED}" ]]; then
561 + die "${FUNCNAME}() called illegally"
562 + fi
563 +
564 + local pylibdir pymod
565 +
566 + if [[ "$#" -ne 0 ]]; then
567 + die "${FUNCNAME}() does not accept arguments"
568 + fi
569 +
570 + if [[ -z "$(declare -p PYTHON_MODNAME 2> /dev/null)" ]]; then
571 + for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"usr/share/jython-*/Lib; do
572 + if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
573 + PYTHON_MODNAME="${PN}"
574 + fi
575 + done
576 + fi
577 +
578 + if [[ -n "${PYTHON_MODNAME}" ]]; then
579 + if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
580 + python_mod_cleanup ${PYTHON_MODNAME}
581 + else
582 + for pymod in ${PYTHON_MODNAME}; do
583 + for pylibdir in "${EROOT}"usr/$(get_libdir)/python*; do
584 + if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then
585 + python_mod_cleanup "${pylibdir#${EROOT%/}}/site-packages/${pymod}"
586 + fi
587 + done
588 + done
589 + fi
590 + fi
591 +}
592 +
593 +# @FUNCTION: distutils_get_intermediate_installation_image
594 +# @DESCRIPTION:
595 +# Print path to intermediate installation image.
596 +#
597 +# This function can be used only in distutils_src_install_pre_hook() and distutils_src_install_post_hook().
598 +distutils_get_intermediate_installation_image() {
599 + if [[ "${EBUILD_PHASE}" != "install" ]]; then
600 + die "${FUNCNAME}() can be used only in src_install() phase"
601 + fi
602 +
603 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
604 + die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
605 + fi
606 +
607 + _python_check_python_pkg_setup_execution
608 +
609 + if [[ ! "${FUNCNAME[1]}" =~ ^distutils_src_install_(pre|post)_hook$ ]]; then
610 + die "${FUNCNAME}() can be used only in distutils_src_install_pre_hook() and distutils_src_install_post_hook()"
611 + fi
612 +
613 + if [[ "$#" -ne 0 ]]; then
614 + die "${FUNCNAME}() does not accept arguments"
615 + fi
616 +
617 + echo "${T}/images/${PYTHON_ABI}"
618 +}
619
620 diff --git a/eclass/python.eclass b/eclass/python.eclass
621 new file mode 100644
622 index 0000000..718c040
623 --- /dev/null
624 +++ b/eclass/python.eclass
625 @@ -0,0 +1,3167 @@
626 +# Copyright 1999-2017 Gentoo Foundation
627 +# Distributed under the terms of the GNU General Public License v2
628 +
629 +# @DEAD
630 +# Removal on 2017-03-21.
631 +
632 +# @ECLASS: python.eclass
633 +# @MAINTAINER:
634 +# kde-sunset overlay maintainers
635 +# @BLURB: Eclass for Python packages
636 +# @DESCRIPTION:
637 +# The python eclass contains miscellaneous, useful functions for Python packages.
638 +#
639 +# This eclass is DEPRECATED. Please use python-r1, python-single-r1
640 +# or python-any-r1 instead.
641 +
642 +if [[ ${EAPI} == 6 ]]; then
643 + die "${ECLASS}.eclass is banned in EAPI ${EAPI}"
644 +fi
645 +
646 +if [[ ${_PYTHON_UTILS_R1} ]]; then
647 + die 'python.eclass can not be used with python-r1 suite eclasses.'
648 +fi
649 +
650 +# Must call inherit before EXPORT_FUNCTIONS to avoid QA warning.
651 +if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then
652 + inherit multilib
653 +fi
654 +
655 +# Export pkg_setup every time to avoid issues with eclass inheritance order.
656 +if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then
657 + EXPORT_FUNCTIONS pkg_setup
658 +fi
659 +
660 +# Avoid processing this eclass more than once.
661 +if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then
662 +_PYTHON_ECLASS_INHERITED="1"
663 +
664 +if ! has "${EAPI:-0}" 0 1 2 3 4 5; then
665 + die "API of python.eclass in EAPI=\"${EAPI}\" not established"
666 +fi
667 +
668 +# Please do not add any new versions of Python here! Instead, please
669 +# focus on converting packages to use the new eclasses.
670 +
671 +_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
672 +_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2 3.3)
673 +_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython 2.7-jython)
674 +_PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8 2.7-pypy-1.9 2.7-pypy-2.0)
675 +_PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]})
676 +
677 +# ================================================================================================
678 +# ===================================== HANDLING OF METADATA =====================================
679 +# ================================================================================================
680 +
681 +_PYTHON_ABI_PATTERN_REGEX="([[:alnum:]]|\.|-|\*|\[|\])+"
682 +
683 +_python_check_python_abi_matching() {
684 + local pattern patterns patterns_list="0" PYTHON_ABI
685 +
686 + while (($#)); do
687 + case "$1" in
688 + --patterns-list)
689 + patterns_list="1"
690 + ;;
691 + --)
692 + shift
693 + break
694 + ;;
695 + -*)
696 + die "${FUNCNAME}(): Unrecognized option '$1'"
697 + ;;
698 + *)
699 + break
700 + ;;
701 + esac
702 + shift
703 + done
704 +
705 + if [[ "$#" -ne 2 ]]; then
706 + die "${FUNCNAME}() requires 2 arguments"
707 + fi
708 +
709 + PYTHON_ABI="$1"
710 +
711 + if [[ "${patterns_list}" == "0" ]]; then
712 + pattern="$2"
713 +
714 + if [[ "${pattern}" == *"-cpython" ]]; then
715 + [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ && "${PYTHON_ABI}" == ${pattern%-cpython} ]]
716 + elif [[ "${pattern}" == *"-jython" ]]; then
717 + [[ "${PYTHON_ABI}" == ${pattern} ]]
718 + elif [[ "${pattern}" == *"-pypy-"* ]]; then
719 + [[ "${PYTHON_ABI}" == ${pattern} ]]
720 + else
721 + if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
722 + [[ "${PYTHON_ABI}" == ${pattern} ]]
723 + elif [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
724 + [[ "${PYTHON_ABI%-jython}" == ${pattern} ]]
725 + elif [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then
726 + [[ "${PYTHON_ABI%-pypy-*}" == ${pattern} ]]
727 + else
728 + die "${FUNCNAME}(): Unrecognized Python ABI '${PYTHON_ABI}'"
729 + fi
730 + fi
731 + else
732 + patterns="${2// /$'\n'}"
733 +
734 + while read pattern; do
735 + if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
736 + return 0
737 + fi
738 + done <<< "${patterns}"
739 +
740 + return 1
741 + fi
742 +}
743 +
744 +_python_implementation() {
745 + if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
746 + return 0
747 + elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
748 + return 0
749 + elif [[ "${CATEGORY}/${PN}" == "virtual/pypy" ]]; then
750 + return 0
751 + else
752 + return 1
753 + fi
754 +}
755 +
756 +_python_package_supporting_installation_for_multiple_python_abis() {
757 + [[ -n "${SUPPORT_PYTHON_ABIS}" ]]
758 +}
759 +
760 +# @ECLASS-VARIABLE: PYTHON_DEPEND
761 +# @DESCRIPTION:
762 +# Specification of dependency on dev-lang/python.
763 +# Syntax:
764 +# PYTHON_DEPEND: [[!]USE_flag? ]<version_components_group>[ version_components_group]
765 +# version_components_group: <major_version[:[minimal_version][:maximal_version]]>
766 +# major_version: <2|3|*>
767 +# minimal_version: <minimal_major_version.minimal_minor_version>
768 +# maximal_version: <maximal_major_version.maximal_minor_version>
769 +
770 +_python_parse_PYTHON_DEPEND() {
771 + 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
772 +
773 + version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
774 + version_components_groups="${PYTHON_DEPEND}"
775 +
776 + if [[ "${version_components_groups}" =~ ^((\!)?[[:alnum:]_-]+\?\ )?${version_components_group_regex}(\ ${version_components_group_regex})?$ ]]; then
777 + if [[ "${version_components_groups}" =~ ^(\!)?[[:alnum:]_-]+\? ]]; then
778 + USE_flag="${version_components_groups%\? *}"
779 + version_components_groups="${version_components_groups#* }"
780 + fi
781 + if [[ "${version_components_groups}" =~ ("*".*" "|" *"|^2.*\ (2|\*)|^3.*\ (3|\*)) ]]; then
782 + die "Invalid syntax of PYTHON_DEPEND: Incorrectly specified groups of versions"
783 + fi
784 +
785 + version_components_groups="${version_components_groups// /$'\n'}"
786 + while read version_components_group; do
787 + major_version="${version_components_group:0:1}"
788 + minimal_version="${version_components_group:2}"
789 + minimal_version="${minimal_version%:*}"
790 + maximal_version="${version_components_group:$((3 + ${#minimal_version}))}"
791 +
792 + if [[ "${major_version}" =~ ^(2|3)$ ]]; then
793 + if [[ -n "${minimal_version}" && "${major_version}" != "${minimal_version:0:1}" ]]; then
794 + die "Invalid syntax of PYTHON_DEPEND: Minimal version '${minimal_version}' not in specified group of versions"
795 + fi
796 + if [[ -n "${maximal_version}" && "${major_version}" != "${maximal_version:0:1}" ]]; then
797 + die "Invalid syntax of PYTHON_DEPEND: Maximal version '${maximal_version}' not in specified group of versions"
798 + fi
799 + fi
800 +
801 + if [[ "${major_version}" == "2" ]]; then
802 + python2="1"
803 + python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}")
804 + python2_minimal_version="${minimal_version}"
805 + python2_maximal_version="${maximal_version}"
806 + elif [[ "${major_version}" == "3" ]]; then
807 + python3="1"
808 + python_versions=("${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
809 + python3_minimal_version="${minimal_version}"
810 + python3_maximal_version="${maximal_version}"
811 + else
812 + python_all="1"
813 + python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
814 + python_minimal_version="${minimal_version}"
815 + python_maximal_version="${maximal_version}"
816 + fi
817 +
818 + if [[ -n "${minimal_version}" ]] && ! has "${minimal_version}" "${python_versions[@]}"; then
819 + die "Invalid syntax of PYTHON_DEPEND: Unrecognized minimal version '${minimal_version}'"
820 + fi
821 + if [[ -n "${maximal_version}" ]] && ! has "${maximal_version}" "${python_versions[@]}"; then
822 + die "Invalid syntax of PYTHON_DEPEND: Unrecognized maximal version '${maximal_version}'"
823 + fi
824 +
825 + if [[ -n "${minimal_version}" && -n "${maximal_version}" && "${minimal_version}" > "${maximal_version}" ]]; then
826 + die "Invalid syntax of PYTHON_DEPEND: Minimal version '${minimal_version}' greater than maximal version '${maximal_version}'"
827 + fi
828 + done <<< "${version_components_groups}"
829 +
830 + _PYTHON_ATOMS=()
831 +
832 + _append_accepted_versions_range() {
833 + local accepted_version="0" i
834 + for ((i = "${#python_versions[@]}"; i >= 0; i--)); do
835 + if [[ "${python_versions[${i}]}" == "${python_maximal_version}" ]]; then
836 + accepted_version="1"
837 + fi
838 + if [[ "${accepted_version}" == "1" ]]; then
839 + _PYTHON_ATOMS+=("=dev-lang/python-${python_versions[${i}]}*")
840 + fi
841 + if [[ "${python_versions[${i}]}" == "${python_minimal_version}" ]]; then
842 + accepted_version="0"
843 + fi
844 + done
845 + }
846 +
847 + if [[ "${python_all}" == "1" ]]; then
848 + if [[ -z "${python_minimal_version}" && -z "${python_maximal_version}" ]]; then
849 + _PYTHON_ATOMS+=("dev-lang/python")
850 + else
851 + python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
852 + python_minimal_version="${python_minimal_version:-${python_versions[0]}}"
853 + python_maximal_version="${python_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
854 + _append_accepted_versions_range
855 + fi
856 + else
857 + if [[ "${python3}" == "1" ]]; then
858 + if [[ -z "${python3_minimal_version}" && -z "${python3_maximal_version}" ]]; then
859 + _PYTHON_ATOMS+=("=dev-lang/python-3*")
860 + else
861 + python_versions=("${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
862 + python_minimal_version="${python3_minimal_version:-${python_versions[0]}}"
863 + python_maximal_version="${python3_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
864 + _append_accepted_versions_range
865 + fi
866 + fi
867 + if [[ "${python2}" == "1" ]]; then
868 + if [[ -z "${python2_minimal_version}" && -z "${python2_maximal_version}" ]]; then
869 + _PYTHON_ATOMS+=("=dev-lang/python-2*")
870 + else
871 + python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}")
872 + python_minimal_version="${python2_minimal_version:-${python_versions[0]}}"
873 + python_maximal_version="${python2_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
874 + _append_accepted_versions_range
875 + fi
876 + fi
877 + fi
878 +
879 + unset -f _append_accepted_versions_range
880 +
881 + if [[ "${#_PYTHON_ATOMS[@]}" -gt 1 ]]; then
882 + DEPEND+="${DEPEND:+ }${USE_flag}${USE_flag:+? ( }|| ( ${_PYTHON_ATOMS[@]} )${USE_flag:+ )}"
883 + RDEPEND+="${RDEPEND:+ }${USE_flag}${USE_flag:+? ( }|| ( ${_PYTHON_ATOMS[@]} )${USE_flag:+ )}"
884 + else
885 + DEPEND+="${DEPEND:+ }${USE_flag}${USE_flag:+? ( }${_PYTHON_ATOMS[@]}${USE_flag:+ )}"
886 + RDEPEND+="${RDEPEND:+ }${USE_flag}${USE_flag:+? ( }${_PYTHON_ATOMS[@]}${USE_flag:+ )}"
887 + fi
888 + else
889 + die "Invalid syntax of PYTHON_DEPEND"
890 + fi
891 +}
892 +
893 +if _python_implementation; then
894 + DEPEND=">=app-eselect/eselect-python-20091230"
895 + RDEPEND="${DEPEND}"
896 + PDEPEND="app-admin/python-updater"
897 +fi
898 +
899 +if [[ -n "${PYTHON_DEPEND}" ]]; then
900 + _python_parse_PYTHON_DEPEND
901 +else
902 + _PYTHON_ATOMS=("dev-lang/python")
903 +fi
904 +unset -f _python_parse_PYTHON_DEPEND
905 +
906 +if [[ -n "${NEED_PYTHON}" ]]; then
907 + eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
908 + die "NEED_PYTHON variable is banned"
909 +fi
910 +
911 +# @ECLASS-VARIABLE: PYTHON_USE_WITH
912 +# @DESCRIPTION:
913 +# Set this to a space separated list of USE flags the Python slot in use must be built with.
914 +
915 +# @ECLASS-VARIABLE: PYTHON_USE_WITH_OR
916 +# @DESCRIPTION:
917 +# Set this to a space separated list of USE flags of which one must be turned on for the slot in use.
918 +
919 +# @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT
920 +# @DESCRIPTION:
921 +# Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or
922 +# PYTHON_USE_WITH_OR atoms conditional under a USE flag.
923 +
924 +if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
925 + _PYTHON_USE_WITH_ATOMS_ARRAY=()
926 + if [[ -n "${PYTHON_USE_WITH}" ]]; then
927 + for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
928 + _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH// /,}]")
929 + done
930 + elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
931 + for _USE_flag in ${PYTHON_USE_WITH_OR}; do
932 + for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
933 + _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
934 + done
935 + done
936 + unset _USE_flag
937 + fi
938 + if [[ "${#_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" -gt 1 ]]; then
939 + _PYTHON_USE_WITH_ATOMS="|| ( ${_PYTHON_USE_WITH_ATOMS_ARRAY[@]} )"
940 + else
941 + _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}"
942 + fi
943 + if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
944 + _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )"
945 + fi
946 + DEPEND+="${DEPEND:+ }${_PYTHON_USE_WITH_ATOMS}"
947 + RDEPEND+="${RDEPEND:+ }${_PYTHON_USE_WITH_ATOMS}"
948 + unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
949 +fi
950 +
951 +unset _PYTHON_ATOMS
952 +
953 +# ================================================================================================
954 +# =================================== MISCELLANEOUS FUNCTIONS ====================================
955 +# ================================================================================================
956 +
957 +_python_abi-specific_local_scope() {
958 + [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
959 +}
960 +
961 +_python_initialize_prefix_variables() {
962 + if has "${EAPI:-0}" 0 1 2; then
963 + if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
964 + EROOT="${ROOT%/}${EPREFIX}/"
965 + fi
966 + if [[ -n "${D}" && -z "${ED}" ]]; then
967 + ED="${D%/}${EPREFIX}/"
968 + fi
969 + fi
970 +}
971 +
972 +unset PYTHON_SANITY_CHECKS_EXECUTED PYTHON_SKIP_SANITY_CHECKS
973 +
974 +_python_initial_sanity_checks() {
975 + :
976 +}
977 +
978 +_python_final_sanity_checks() {
979 + 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
980 + local PYTHON_ABI="${PYTHON_ABI}"
981 + for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
982 + # Ensure that appropriate version of Python is installed.
983 + if ! has_version "$(python_get_implementational_package)"; then
984 + die "$(python_get_implementational_package) is not installed"
985 + fi
986 +
987 + # Ensure that EPYTHON variable is respected.
988 + if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
989 + eerror "Path to 'python': '$(type -p python)'"
990 + eerror "ABI: '${ABI}'"
991 + eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
992 + eerror "EPYTHON: '$(PYTHON)'"
993 + eerror "PYTHON_ABI: '${PYTHON_ABI}'"
994 + eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
995 + die "'python' does not respect EPYTHON variable"
996 + fi
997 + done
998 + fi
999 + PYTHON_SANITY_CHECKS_EXECUTED="1"
1000 +}
1001 +
1002 +# @ECLASS-VARIABLE: PYTHON_COLORS
1003 +# @DESCRIPTION:
1004 +# User-configurable colored output.
1005 +PYTHON_COLORS="${PYTHON_COLORS:-0}"
1006 +
1007 +_python_set_color_variables() {
1008 + if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
1009 + _BOLD=$'\e[1m'
1010 + _RED=$'\e[1;31m'
1011 + _GREEN=$'\e[1;32m'
1012 + _BLUE=$'\e[1;34m'
1013 + _CYAN=$'\e[1;36m'
1014 + _NORMAL=$'\e[0m'
1015 + else
1016 + _BOLD=
1017 + _RED=
1018 + _GREEN=
1019 + _BLUE=
1020 + _CYAN=
1021 + _NORMAL=
1022 + fi
1023 +}
1024 +
1025 +_python_check_python_pkg_setup_execution() {
1026 + [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return
1027 +
1028 + if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
1029 + die "python_pkg_setup() not called"
1030 + fi
1031 +}
1032 +
1033 +# @FUNCTION: python_pkg_setup
1034 +# @DESCRIPTION:
1035 +# Perform sanity checks and initialize environment.
1036 +#
1037 +# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
1038 +# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
1039 +python_pkg_setup() {
1040 + if [[ "${EBUILD_PHASE}" != "setup" ]]; then
1041 + die "${FUNCNAME}() can be used only in pkg_setup() phase"
1042 + fi
1043 +
1044 + if [[ "$#" -ne 0 ]]; then
1045 + die "${FUNCNAME}() does not accept arguments"
1046 + fi
1047 +
1048 + export JYTHON_SYSTEM_CACHEDIR="1"
1049 + addwrite "${EPREFIX}/var/cache/jython"
1050 +
1051 + if _python_package_supporting_installation_for_multiple_python_abis; then
1052 + _python_calculate_PYTHON_ABIS
1053 + export EPYTHON="$(PYTHON -f)"
1054 + else
1055 + PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
1056 + fi
1057 +
1058 + if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
1059 + if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
1060 + if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
1061 + use ${PYTHON_USE_WITH_OPT#!} && return
1062 + else
1063 + use !${PYTHON_USE_WITH_OPT} && return
1064 + fi
1065 + fi
1066 +
1067 + python_pkg_setup_check_USE_flags() {
1068 + local python_atom USE_flag
1069 + python_atom="$(python_get_implementational_package)"
1070 +
1071 + for USE_flag in ${PYTHON_USE_WITH}; do
1072 + if ! has_version "${python_atom}[${USE_flag}]"; then
1073 + eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
1074 + die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
1075 + fi
1076 + done
1077 +
1078 + for USE_flag in ${PYTHON_USE_WITH_OR}; do
1079 + if has_version "${python_atom}[${USE_flag}]"; then
1080 + return
1081 + fi
1082 + done
1083 +
1084 + if [[ ${PYTHON_USE_WITH_OR} ]]; then
1085 + eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
1086 + die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
1087 + fi
1088 + }
1089 +
1090 + if _python_package_supporting_installation_for_multiple_python_abis; then
1091 + PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags
1092 + else
1093 + python_pkg_setup_check_USE_flags
1094 + fi
1095 +
1096 + unset -f python_pkg_setup_check_USE_flags
1097 + fi
1098 +
1099 + PYTHON_PKG_SETUP_EXECUTED="1"
1100 +}
1101 +
1102 +_PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|pypy-c|python)'
1103 +
1104 +# @FUNCTION: python_convert_shebangs
1105 +# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories]
1106 +# @DESCRIPTION:
1107 +# Convert shebangs in specified files. Directories can be specified only with --recursive option.
1108 +python_convert_shebangs() {
1109 + _python_check_python_pkg_setup_execution
1110 +
1111 + local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" shebangs_converted="0"
1112 +
1113 + while (($#)); do
1114 + case "$1" in
1115 + -r|--recursive)
1116 + recursive="1"
1117 + ;;
1118 + -q|--quiet)
1119 + quiet="1"
1120 + ;;
1121 + -x|--only-executables)
1122 + only_executables="1"
1123 + ;;
1124 + --)
1125 + shift
1126 + break
1127 + ;;
1128 + -*)
1129 + die "${FUNCNAME}(): Unrecognized option '$1'"
1130 + ;;
1131 + *)
1132 + break
1133 + ;;
1134 + esac
1135 + shift
1136 + done
1137 +
1138 + if [[ "$#" -eq 0 ]]; then
1139 + die "${FUNCNAME}(): Missing Python version and files or directories"
1140 + elif [[ "$#" -eq 1 ]]; then
1141 + die "${FUNCNAME}(): Missing files or directories"
1142 + fi
1143 +
1144 + if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
1145 + python_interpreter="$(PYTHON "$1")"
1146 + else
1147 + python_interpreter="python$1"
1148 + fi
1149 + shift
1150 +
1151 + for argument in "$@"; do
1152 + if [[ ! -e "${argument}" ]]; then
1153 + die "${FUNCNAME}(): '${argument}' does not exist"
1154 + elif [[ -f "${argument}" ]]; then
1155 + files+=("${argument}")
1156 + elif [[ -d "${argument}" ]]; then
1157 + if [[ "${recursive}" == "1" ]]; then
1158 + while read -d $'\0' -r file; do
1159 + files+=("${file}")
1160 + done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
1161 + else
1162 + die "${FUNCNAME}(): '${argument}' is not a regular file"
1163 + fi
1164 + else
1165 + die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
1166 + fi
1167 + done
1168 +
1169 + for file in "${files[@]}"; do
1170 + file="${file#./}"
1171 + [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
1172 +
1173 + if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then
1174 + [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
1175 +
1176 + shebangs_converted="1"
1177 +
1178 + if [[ "${quiet}" == "0" ]]; then
1179 + einfo "Converting shebang in '${file}'"
1180 + fi
1181 +
1182 + sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed"
1183 + fi
1184 + done
1185 +
1186 + if [[ "${shebangs_converted}" == "0" ]]; then
1187 + ewarn "${FUNCNAME}(): Python scripts not found"
1188 + fi
1189 +}
1190 +
1191 +# @FUNCTION: python_clean_py-compile_files
1192 +# @USAGE: [-q|--quiet]
1193 +# @DESCRIPTION:
1194 +# Clean py-compile files to disable byte-compilation.
1195 +python_clean_py-compile_files() {
1196 + _python_check_python_pkg_setup_execution
1197 +
1198 + local file files=() quiet="0"
1199 +
1200 + while (($#)); do
1201 + case "$1" in
1202 + -q|--quiet)
1203 + quiet="1"
1204 + ;;
1205 + -*)
1206 + die "${FUNCNAME}(): Unrecognized option '$1'"
1207 + ;;
1208 + *)
1209 + die "${FUNCNAME}(): Invalid usage"
1210 + ;;
1211 + esac
1212 + shift
1213 + done
1214 +
1215 + while read -d $'\0' -r file; do
1216 + files+=("${file#./}")
1217 + done < <(find -name py-compile -type f -print0)
1218 +
1219 + for file in "${files[@]}"; do
1220 + if [[ "${quiet}" == "0" ]]; then
1221 + einfo "Cleaning '${file}' file"
1222 + fi
1223 + echo "#!/bin/sh" > "${file}"
1224 + done
1225 +}
1226 +
1227 +# @FUNCTION: python_clean_installation_image
1228 +# @USAGE: [-q|--quiet]
1229 +# @DESCRIPTION:
1230 +# Delete needless files in installation image.
1231 +#
1232 +# This function can be used only in src_install() phase.
1233 +python_clean_installation_image() {
1234 + if [[ "${EBUILD_PHASE}" != "install" ]]; then
1235 + die "${FUNCNAME}() can be used only in src_install() phase"
1236 + fi
1237 +
1238 + _python_check_python_pkg_setup_execution
1239 + _python_initialize_prefix_variables
1240 +
1241 + local file files=() quiet="0"
1242 +
1243 + while (($#)); do
1244 + case "$1" in
1245 + -q|--quiet)
1246 + quiet="1"
1247 + ;;
1248 + -*)
1249 + die "${FUNCNAME}(): Unrecognized option '$1'"
1250 + ;;
1251 + *)
1252 + die "${FUNCNAME}(): Invalid usage"
1253 + ;;
1254 + esac
1255 + shift
1256 + done
1257 +
1258 + while read -d $'\0' -r file; do
1259 + files+=("${file}")
1260 + done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0)
1261 +
1262 + if [[ "${#files[@]}" -gt 0 ]]; then
1263 + if [[ "${quiet}" == "0" ]]; then
1264 + ewarn "Deleting byte-compiled Python modules needlessly generated by build system:"
1265 + fi
1266 + for file in "${files[@]}"; do
1267 + if [[ "${quiet}" == "0" ]]; then
1268 + ewarn " ${file}"
1269 + fi
1270 + rm -f "${file}"
1271 +
1272 + # Delete empty __pycache__ directories.
1273 + if [[ "${file%/*}" == *"/__pycache__" ]]; then
1274 + rmdir "${file%/*}" 2> /dev/null
1275 + fi
1276 + done
1277 + fi
1278 +
1279 + python_clean_sitedirs() {
1280 + if [[ -d "${ED}$(python_get_sitedir)" ]]; then
1281 + find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
1282 + fi
1283 + }
1284 + if _python_package_supporting_installation_for_multiple_python_abis; then
1285 + python_execute_function -q python_clean_sitedirs
1286 + else
1287 + python_clean_sitedirs
1288 + fi
1289 +
1290 + unset -f python_clean_sitedirs
1291 +}
1292 +
1293 +# ================================================================================================
1294 +# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============
1295 +# ================================================================================================
1296 +
1297 +# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
1298 +# @DESCRIPTION:
1299 +# Set this in EAPI <= 4 to indicate that current package supports installation for
1300 +# multiple Python ABIs.
1301 +
1302 +# @ECLASS-VARIABLE: PYTHON_TESTS_RESTRICTED_ABIS
1303 +# @DESCRIPTION:
1304 +# Space-separated list of Python ABI patterns. Testing in Python ABIs matching any Python ABI
1305 +# patterns specified in this list is skipped.
1306 +
1307 +# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
1308 +# @DESCRIPTION:
1309 +# Set this to export phase functions for the following ebuild phases:
1310 +# src_prepare(), src_configure(), src_compile(), src_test(), src_install().
1311 +if ! has "${EAPI:-0}" 0 1; then
1312 + python_src_prepare() {
1313 + if [[ "${EBUILD_PHASE}" != "prepare" ]]; then
1314 + die "${FUNCNAME}() can be used only in src_prepare() phase"
1315 + fi
1316 +
1317 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
1318 + die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1319 + fi
1320 +
1321 + _python_check_python_pkg_setup_execution
1322 +
1323 + if [[ "$#" -ne 0 ]]; then
1324 + die "${FUNCNAME}() does not accept arguments"
1325 + fi
1326 +
1327 + python_copy_sources
1328 + }
1329 +
1330 + for python_default_function in src_configure src_compile src_test; do
1331 + eval "python_${python_default_function}() {
1332 + if [[ \"\${EBUILD_PHASE}\" != \"${python_default_function#src_}\" ]]; then
1333 + die \"\${FUNCNAME}() can be used only in ${python_default_function}() phase\"
1334 + fi
1335 +
1336 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
1337 + die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
1338 + fi
1339 +
1340 + _python_check_python_pkg_setup_execution
1341 +
1342 + python_execute_function -d -s -- \"\$@\"
1343 + }"
1344 + done
1345 + unset python_default_function
1346 +
1347 + python_src_install() {
1348 + if [[ "${EBUILD_PHASE}" != "install" ]]; then
1349 + die "${FUNCNAME}() can be used only in src_install() phase"
1350 + fi
1351 +
1352 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
1353 + die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1354 + fi
1355 +
1356 + _python_check_python_pkg_setup_execution
1357 +
1358 + if has "${EAPI:-0}" 0 1 2 3; then
1359 + python_execute_function -d -s -- "$@"
1360 + else
1361 + python_installation() {
1362 + emake DESTDIR="${T}/images/${PYTHON_ABI}" install "$@"
1363 + }
1364 + python_execute_function -s python_installation "$@"
1365 + unset python_installation
1366 +
1367 + python_merge_intermediate_installation_images "${T}/images"
1368 + fi
1369 + }
1370 +
1371 + if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
1372 + EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
1373 + fi
1374 +fi
1375 +
1376 +unset PYTHON_ABIS
1377 +
1378 +_python_calculate_PYTHON_ABIS() {
1379 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
1380 + die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1381 + fi
1382 +
1383 + _python_initial_sanity_checks
1384 +
1385 + if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]]; then
1386 + local PYTHON_ABI
1387 +
1388 + if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
1389 + local cpython_enabled="0"
1390 +
1391 + if [[ -z "${USE_PYTHON}" ]]; then
1392 + die "USE_PYTHON variable is empty"
1393 + fi
1394 +
1395 + for PYTHON_ABI in ${USE_PYTHON}; do
1396 + if ! has "${PYTHON_ABI}" "${_PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; then
1397 + die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
1398 + fi
1399 +
1400 + if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
1401 + cpython_enabled="1"
1402 + fi
1403 +
1404 + if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
1405 + export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
1406 + fi
1407 + done
1408 +
1409 + if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
1410 + die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
1411 + fi
1412 +
1413 + if [[ "${cpython_enabled}" == "0" ]]; then
1414 + die "USE_PYTHON variable does not enable any CPython ABI"
1415 + fi
1416 + else
1417 + local python_version python2_version python3_version support_python_major_version
1418 +
1419 + if ! has_version "dev-lang/python"; then
1420 + die "${FUNCNAME}(): 'dev-lang/python' is not installed"
1421 + fi
1422 +
1423 + python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
1424 +
1425 + if has_version "=dev-lang/python-2*"; then
1426 + python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
1427 +
1428 + support_python_major_version="0"
1429 + for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1430 + if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
1431 + support_python_major_version="1"
1432 + break
1433 + fi
1434 + done
1435 + if [[ "${support_python_major_version}" == "1" ]]; then
1436 + if _python_check_python_abi_matching --patterns-list "${python2_version}" "${RESTRICT_PYTHON_ABIS}"; then
1437 + die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}"
1438 + fi
1439 + else
1440 + python2_version=""
1441 + fi
1442 + fi
1443 +
1444 + if has_version "=dev-lang/python-3*"; then
1445 + python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
1446 +
1447 + support_python_major_version="0"
1448 + for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1449 + if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
1450 + support_python_major_version="1"
1451 + break
1452 + fi
1453 + done
1454 + if [[ "${support_python_major_version}" == "1" ]]; then
1455 + if _python_check_python_abi_matching --patterns-list "${python3_version}" "${RESTRICT_PYTHON_ABIS}"; then
1456 + die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}"
1457 + fi
1458 + else
1459 + python3_version=""
1460 + fi
1461 + fi
1462 +
1463 + if [[ -z "${python2_version}" && -z "${python3_version}" ]]; then
1464 + eerror "${CATEGORY}/${PF} requires at least one of the following packages:"
1465 + for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1466 + if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
1467 + eerror " dev-lang/python:${PYTHON_ABI}"
1468 + fi
1469 + done
1470 + die "No supported version of CPython installed"
1471 + fi
1472 +
1473 + if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then
1474 + eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink"
1475 + eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
1476 + die "Incorrect configuration of Python"
1477 + fi
1478 + if [[ -n "${python3_version}" && "${python_version}" == "3."* && "${python_version}" != "${python3_version}" ]]; then
1479 + eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python3' symlink"
1480 + eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
1481 + die "Incorrect configuration of Python"
1482 + fi
1483 +
1484 + PYTHON_ABIS="${python2_version} ${python3_version}"
1485 + PYTHON_ABIS="${PYTHON_ABIS# }"
1486 + export PYTHON_ABIS="${PYTHON_ABIS% }"
1487 + fi
1488 + fi
1489 +
1490 + _python_final_sanity_checks
1491 +}
1492 +
1493 +_python_prepare_flags() {
1494 + local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable
1495 +
1496 + for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
1497 + eval "_PYTHON_SAVED_${variable}=\"\${!variable}\""
1498 + for prefix in PYTHON_USER_ PYTHON_; do
1499 + if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
1500 + eval "array=(\"\${${prefix}${variable}[@]}\")"
1501 + for element in "${array[@]}"; do
1502 + if [[ "${element}" =~ ^${_PYTHON_ABI_PATTERN_REGEX}\ (\+|-)\ .+ ]]; then
1503 + pattern="${element%% *}"
1504 + element="${element#* }"
1505 + operator="${element%% *}"
1506 + flags="${element#* }"
1507 + if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
1508 + if [[ "${operator}" == "+" ]]; then
1509 + eval "export ${variable}+=\"\${variable:+ }${flags}\""
1510 + elif [[ "${operator}" == "-" ]]; then
1511 + flags="${flags// /$'\n'}"
1512 + old_value="${!variable// /$'\n'}"
1513 + new_value=""
1514 + while read old_flag; do
1515 + while read deleted_flag; do
1516 + if [[ "${old_flag}" == ${deleted_flag} ]]; then
1517 + continue 2
1518 + fi
1519 + done <<< "${flags}"
1520 + new_value+="${new_value:+ }${old_flag}"
1521 + done <<< "${old_value}"
1522 + eval "export ${variable}=\"\${new_value}\""
1523 + fi
1524 + fi
1525 + else
1526 + die "Element '${element}' of ${prefix}${variable} array has invalid syntax"
1527 + fi
1528 + done
1529 + elif [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
1530 + die "${prefix}${variable} should be indexed array"
1531 + fi
1532 + done
1533 + done
1534 +}
1535 +
1536 +_python_restore_flags() {
1537 + local variable
1538 +
1539 + for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS; do
1540 + eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\""
1541 + unset _PYTHON_SAVED_${variable}
1542 + done
1543 +}
1544 +
1545 +# @FUNCTION: python_execute_function
1546 +# @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]
1547 +# @DESCRIPTION:
1548 +# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
1549 +# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
1550 +python_execute_function() {
1551 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
1552 + die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1553 + fi
1554 +
1555 + _python_check_python_pkg_setup_execution
1556 + _python_set_color_variables
1557 +
1558 + 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
1559 +
1560 + while (($#)); do
1561 + case "$1" in
1562 + --action-message)
1563 + action_message_template="$2"
1564 + shift
1565 + ;;
1566 + -d|--default-function)
1567 + default_function="1"
1568 + ;;
1569 + --failure-message)
1570 + failure_message_template="$2"
1571 + shift
1572 + ;;
1573 + -f|--final-ABI)
1574 + final_ABI="1"
1575 + ;;
1576 + --nonfatal)
1577 + nonfatal="1"
1578 + ;;
1579 + -q|--quiet)
1580 + quiet="1"
1581 + ;;
1582 + -s|--separate-build-dirs)
1583 + separate_build_dirs="1"
1584 + ;;
1585 + --source-dir)
1586 + source_dir="$2"
1587 + shift
1588 + ;;
1589 + --)
1590 + shift
1591 + break
1592 + ;;
1593 + -*)
1594 + die "${FUNCNAME}(): Unrecognized option '$1'"
1595 + ;;
1596 + *)
1597 + break
1598 + ;;
1599 + esac
1600 + shift
1601 + done
1602 +
1603 + if [[ -n "${source_dir}" && "${separate_build_dirs}" == 0 ]]; then
1604 + die "${FUNCNAME}(): '--source-dir' option can be specified only with '--separate-build-dirs' option"
1605 + fi
1606 +
1607 + if [[ "${default_function}" == "0" ]]; then
1608 + if [[ "$#" -eq 0 ]]; then
1609 + die "${FUNCNAME}(): Missing function name"
1610 + fi
1611 + function="$1"
1612 + shift
1613 +
1614 + if [[ -z "$(type -t "${function}")" ]]; then
1615 + die "${FUNCNAME}(): '${function}' function is not defined"
1616 + fi
1617 + else
1618 + if has "${EAPI:-0}" 0 1; then
1619 + die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
1620 + fi
1621 +
1622 + if [[ "${EBUILD_PHASE}" == "configure" ]]; then
1623 + if has "${EAPI}" 2 3; then
1624 + python_default_function() {
1625 + econf "$@"
1626 + }
1627 + else
1628 + python_default_function() {
1629 + nonfatal econf "$@"
1630 + }
1631 + fi
1632 + elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
1633 + python_default_function() {
1634 + emake "$@"
1635 + }
1636 + elif [[ "${EBUILD_PHASE}" == "test" ]]; then
1637 + python_default_function() {
1638 + # Stolen from portage's _eapi0_src_test()
1639 + local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
1640 + if ${emake_cmd} -j1 -n check &> /dev/null; then
1641 + ${emake_cmd} -j1 check "$@"
1642 + elif ${emake_cmd} -j1 -n test &> /dev/null; then
1643 + ${emake_cmd} -j1 test "$@"
1644 + fi
1645 + }
1646 + elif [[ "${EBUILD_PHASE}" == "install" ]]; then
1647 + python_default_function() {
1648 + emake DESTDIR="${D}" install "$@"
1649 + }
1650 + else
1651 + die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase"
1652 + fi
1653 + function="python_default_function"
1654 + fi
1655 +
1656 + # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function().
1657 + if _python_abi-specific_local_scope; then
1658 + die "${FUNCNAME}(): Invalid call stack"
1659 + fi
1660 +
1661 + if [[ "${quiet}" == "0" ]]; then
1662 + [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
1663 + [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
1664 + [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
1665 + [[ "${EBUILD_PHASE}" == "configure" ]] && action="Configuration"
1666 + [[ "${EBUILD_PHASE}" == "compile" ]] && action="Building"
1667 + [[ "${EBUILD_PHASE}" == "test" ]] && action="Testing"
1668 + [[ "${EBUILD_PHASE}" == "install" ]] && action="Installation"
1669 + [[ "${EBUILD_PHASE}" == "preinst" ]] && action="Preinstallation"
1670 + [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation"
1671 + [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation"
1672 + [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation"
1673 + fi
1674 +
1675 + _python_calculate_PYTHON_ABIS
1676 + if [[ "${final_ABI}" == "1" ]]; then
1677 + iterated_PYTHON_ABIS="$(PYTHON -f --ABI)"
1678 + else
1679 + iterated_PYTHON_ABIS="${PYTHON_ABIS}"
1680 + fi
1681 + for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
1682 + if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then
1683 + if [[ "${quiet}" == "0" ]]; then
1684 + echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation_and_version) skipped${_NORMAL}"
1685 + fi
1686 + continue
1687 + fi
1688 +
1689 + _python_prepare_flags
1690 +
1691 + if [[ "${quiet}" == "0" ]]; then
1692 + if [[ -n "${action_message_template}" ]]; then
1693 + eval "action_message=\"${action_message_template}\""
1694 + else
1695 + action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation_and_version)..."
1696 + fi
1697 + echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}"
1698 + fi
1699 +
1700 + if [[ "${separate_build_dirs}" == "1" ]]; then
1701 + if [[ -n "${source_dir}" ]]; then
1702 + export BUILDDIR="${S}/${source_dir}-${PYTHON_ABI}"
1703 + else
1704 + export BUILDDIR="${S}-${PYTHON_ABI}"
1705 + fi
1706 + pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
1707 + else
1708 + export BUILDDIR="${S}"
1709 + fi
1710 +
1711 + previous_directory="$(pwd)"
1712 + previous_directory_stack="$(dirs -p)"
1713 + previous_directory_stack_length="$(dirs -p | wc -l)"
1714 +
1715 + if ! has "${EAPI}" 0 1 2 3 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
1716 + EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
1717 + else
1718 + EPYTHON="$(PYTHON)" "${function}" "$@"
1719 + fi
1720 +
1721 + return_code="$?"
1722 +
1723 + _python_restore_flags
1724 +
1725 + if [[ "${return_code}" -ne 0 ]]; then
1726 + if [[ -n "${failure_message_template}" ]]; then
1727 + eval "failure_message=\"${failure_message_template}\""
1728 + else
1729 + failure_message="${action} failed with $(python_get_implementation_and_version) in ${function}() function"
1730 + fi
1731 +
1732 + if [[ "${nonfatal}" == "1" ]]; then
1733 + if [[ "${quiet}" == "0" ]]; then
1734 + ewarn "${failure_message}"
1735 + fi
1736 + elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
1737 + if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
1738 + local enabled_PYTHON_ABIS= other_PYTHON_ABI
1739 + for other_PYTHON_ABI in ${PYTHON_ABIS}; do
1740 + [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}"
1741 + done
1742 + export PYTHON_ABIS="${enabled_PYTHON_ABIS}"
1743 + fi
1744 + if [[ "${quiet}" == "0" ]]; then
1745 + ewarn "${failure_message}"
1746 + fi
1747 + if [[ -z "${PYTHON_ABIS}" ]]; then
1748 + die "${function}() function failed with all enabled Python ABIs"
1749 + fi
1750 + else
1751 + die "${failure_message}"
1752 + fi
1753 + fi
1754 +
1755 + # Ensure that directory stack has not been decreased.
1756 + if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then
1757 + die "Directory stack decreased illegally"
1758 + fi
1759 +
1760 + # Avoid side effects of earlier returning from the specified function.
1761 + while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do
1762 + popd > /dev/null || die "popd failed"
1763 + done
1764 +
1765 + # Ensure that the bottom part of directory stack has not been changed. Restore
1766 + # previous directory (from before running of the specified function) before
1767 + # comparison of directory stacks to avoid mismatch of directory stacks after
1768 + # potential using of 'cd' to change current directory. Restoration of previous
1769 + # directory allows to safely use 'cd' to change current directory in the
1770 + # specified function without changing it back to original directory.
1771 + cd "${previous_directory}"
1772 + if [[ "$(dirs -p)" != "${previous_directory_stack}" ]]; then
1773 + die "Directory stack changed illegally"
1774 + fi
1775 +
1776 + if [[ "${separate_build_dirs}" == "1" ]]; then
1777 + popd > /dev/null || die "popd failed"
1778 + fi
1779 + unset BUILDDIR
1780 + done
1781 +
1782 + if [[ "${default_function}" == "1" ]]; then
1783 + unset -f python_default_function
1784 + fi
1785 +}
1786 +
1787 +# @FUNCTION: python_copy_sources
1788 +# @USAGE: <directory="${S}"> [directory]
1789 +# @DESCRIPTION:
1790 +# Copy unpacked sources of current package to separate build directory for each Python ABI.
1791 +python_copy_sources() {
1792 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
1793 + die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1794 + fi
1795 +
1796 + _python_check_python_pkg_setup_execution
1797 +
1798 + local dir dirs=() PYTHON_ABI
1799 +
1800 + if [[ "$#" -eq 0 ]]; then
1801 + if [[ "${WORKDIR}" == "${S}" ]]; then
1802 + die "${FUNCNAME}() cannot be used with current value of S variable"
1803 + fi
1804 + dirs=("${S%/}")
1805 + else
1806 + dirs=("$@")
1807 + fi
1808 +
1809 + _python_calculate_PYTHON_ABIS
1810 + for PYTHON_ABI in ${PYTHON_ABIS}; do
1811 + for dir in "${dirs[@]}"; do
1812 + cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
1813 + done
1814 + done
1815 +}
1816 +
1817 +# @FUNCTION: python_generate_wrapper_scripts
1818 +# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files]
1819 +# @DESCRIPTION:
1820 +# Generate wrapper scripts. Existing files are overwritten only with --force option.
1821 +# If --respect-EPYTHON option is specified, then generated wrapper scripts will
1822 +# respect EPYTHON variable at run time.
1823 +#
1824 +# This function can be used only in src_install() phase.
1825 +python_generate_wrapper_scripts() {
1826 + if [[ "${EBUILD_PHASE}" != "install" ]]; then
1827 + die "${FUNCNAME}() can be used only in src_install() phase"
1828 + fi
1829 +
1830 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
1831 + die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1832 + fi
1833 +
1834 + _python_check_python_pkg_setup_execution
1835 + _python_initialize_prefix_variables
1836 +
1837 + local eselect_python_option file force="0" quiet="0" PYTHON_ABI PYTHON_ABIS_list python2_enabled="0" python3_enabled="0" respect_EPYTHON="0"
1838 +
1839 + while (($#)); do
1840 + case "$1" in
1841 + -E|--respect-EPYTHON)
1842 + respect_EPYTHON="1"
1843 + ;;
1844 + -f|--force)
1845 + force="1"
1846 + ;;
1847 + -q|--quiet)
1848 + quiet="1"
1849 + ;;
1850 + --)
1851 + shift
1852 + break
1853 + ;;
1854 + -*)
1855 + die "${FUNCNAME}(): Unrecognized option '$1'"
1856 + ;;
1857 + *)
1858 + break
1859 + ;;
1860 + esac
1861 + shift
1862 + done
1863 +
1864 + if [[ "$#" -eq 0 ]]; then
1865 + die "${FUNCNAME}(): Missing arguments"
1866 + fi
1867 +
1868 + _python_calculate_PYTHON_ABIS
1869 + for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1870 + if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
1871 + python2_enabled="1"
1872 + fi
1873 + done
1874 + for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; do
1875 + if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
1876 + python3_enabled="1"
1877 + fi
1878 + done
1879 +
1880 + if [[ "${python2_enabled}" == "1" && "${python3_enabled}" == "1" ]]; then
1881 + eselect_python_option=
1882 + elif [[ "${python2_enabled}" == "1" && "${python3_enabled}" == "0" ]]; then
1883 + eselect_python_option="--python2"
1884 + elif [[ "${python2_enabled}" == "0" && "${python3_enabled}" == "1" ]]; then
1885 + eselect_python_option="--python3"
1886 + else
1887 + die "${FUNCNAME}(): Unsupported environment"
1888 + fi
1889 +
1890 + PYTHON_ABIS_list="$("$(PYTHON -f)" -c "print(', '.join('\"%s\"' % x for x in reversed('${PYTHON_ABIS}'.split())))")"
1891 +
1892 + for file in "$@"; do
1893 + if [[ -f "${file}" && "${force}" == "0" ]]; then
1894 + die "${FUNCNAME}(): '${file}' already exists"
1895 + fi
1896 +
1897 + if [[ "${quiet}" == "0" ]]; then
1898 + einfo "Generating '${file#${ED%/}}' wrapper script"
1899 + fi
1900 +
1901 + cat << EOF > "${file}"
1902 +#!/usr/bin/env python
1903 +# Gentoo '${file##*/}' wrapper script generated by python_generate_wrapper_scripts()
1904 +
1905 +import os
1906 +import re
1907 +import subprocess
1908 +import sys
1909 +
1910 +cpython_ABI_re = re.compile(r"^(\d+\.\d+)$")
1911 +jython_ABI_re = re.compile(r"^(\d+\.\d+)-jython$")
1912 +pypy_ABI_re = re.compile(r"^\d+\.\d+-pypy-(\d+\.\d+)$")
1913 +cpython_interpreter_re = re.compile(r"^python(\d+\.\d+)$")
1914 +jython_interpreter_re = re.compile(r"^jython(\d+\.\d+)$")
1915 +pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$")
1916 +cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)")
1917 +python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)")
1918 +python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
1919 +
1920 +#pypy_versions_mapping = {
1921 +# "1.5": "2.7",
1922 +# "1.6": "2.7",
1923 +# "1.7": "2.7",
1924 +# "1.8": "2.7",
1925 +# "1.9": "2.7",
1926 +# "2.0": "2.7",
1927 +#}
1928 +
1929 +def get_PYTHON_ABI(python_interpreter):
1930 + cpython_matched = cpython_interpreter_re.match(python_interpreter)
1931 + jython_matched = jython_interpreter_re.match(python_interpreter)
1932 + pypy_matched = pypy_interpreter_re.match(python_interpreter)
1933 + if cpython_matched is not None:
1934 + PYTHON_ABI = cpython_matched.group(1)
1935 + elif jython_matched is not None:
1936 + PYTHON_ABI = jython_matched.group(1) + "-jython"
1937 + elif pypy_matched is not None:
1938 + #PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1)
1939 + PYTHON_ABI = "2.7-pypy-" + pypy_matched.group(1)
1940 + else:
1941 + PYTHON_ABI = None
1942 + return PYTHON_ABI
1943 +
1944 +def get_python_interpreter(PYTHON_ABI):
1945 + cpython_matched = cpython_ABI_re.match(PYTHON_ABI)
1946 + jython_matched = jython_ABI_re.match(PYTHON_ABI)
1947 + pypy_matched = pypy_ABI_re.match(PYTHON_ABI)
1948 + if cpython_matched is not None:
1949 + python_interpreter = "python" + cpython_matched.group(1)
1950 + elif jython_matched is not None:
1951 + python_interpreter = "jython" + jython_matched.group(1)
1952 + elif pypy_matched is not None:
1953 + python_interpreter = "pypy-c" + pypy_matched.group(1)
1954 + else:
1955 + python_interpreter = None
1956 + return python_interpreter
1957 +
1958 +EOF
1959 + if [[ "$?" != "0" ]]; then
1960 + die "${FUNCNAME}(): Generation of '$1' failed"
1961 + fi
1962 + if [[ "${respect_EPYTHON}" == "1" ]]; then
1963 + cat << EOF >> "${file}"
1964 +python_interpreter = os.environ.get("EPYTHON")
1965 +if python_interpreter:
1966 + PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1967 + if PYTHON_ABI is None:
1968 + sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
1969 + sys.exit(1)
1970 +else:
1971 + try:
1972 + environment = os.environ.copy()
1973 + environment["ROOT"] = "/"
1974 + eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE)
1975 + if eselect_process.wait() != 0:
1976 + raise ValueError
1977 + except (OSError, ValueError):
1978 + sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
1979 + sys.exit(1)
1980 +
1981 + python_interpreter = eselect_process.stdout.read()
1982 + if not isinstance(python_interpreter, str):
1983 + # Python 3
1984 + python_interpreter = python_interpreter.decode()
1985 + python_interpreter = python_interpreter.rstrip("\n")
1986 +
1987 + PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
1988 + if PYTHON_ABI is None:
1989 + sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
1990 + sys.exit(1)
1991 +
1992 +wrapper_script_path = os.path.realpath(sys.argv[0])
1993 +target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
1994 +if not os.path.exists(target_executable_path):
1995 + sys.stderr.write("%s: '%s' does not exist\n" % (sys.argv[0], target_executable_path))
1996 + sys.exit(1)
1997 +EOF
1998 + if [[ "$?" != "0" ]]; then
1999 + die "${FUNCNAME}(): Generation of '$1' failed"
2000 + fi
2001 + else
2002 + cat << EOF >> "${file}"
2003 +try:
2004 + environment = os.environ.copy()
2005 + environment["ROOT"] = "/"
2006 + eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE)
2007 + if eselect_process.wait() != 0:
2008 + raise ValueError
2009 +except (OSError, ValueError):
2010 + sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
2011 + sys.exit(1)
2012 +
2013 +python_interpreter = eselect_process.stdout.read()
2014 +if not isinstance(python_interpreter, str):
2015 + # Python 3
2016 + python_interpreter = python_interpreter.decode()
2017 +python_interpreter = python_interpreter.rstrip("\n")
2018 +
2019 +PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
2020 +if PYTHON_ABI is None:
2021 + sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
2022 + sys.exit(1)
2023 +
2024 +wrapper_script_path = os.path.realpath(sys.argv[0])
2025 +for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
2026 + target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
2027 + if os.path.exists(target_executable_path):
2028 + break
2029 +else:
2030 + sys.stderr.write("%s: No target script exists for '%s'\n" % (sys.argv[0], wrapper_script_path))
2031 + sys.exit(1)
2032 +
2033 +python_interpreter = get_python_interpreter(PYTHON_ABI)
2034 +if python_interpreter is None:
2035 + sys.stderr.write("%s: Unrecognized Python ABI '%s'\n" % (sys.argv[0], PYTHON_ABI))
2036 + sys.exit(1)
2037 +EOF
2038 + if [[ "$?" != "0" ]]; then
2039 + die "${FUNCNAME}(): Generation of '$1' failed"
2040 + fi
2041 + fi
2042 + cat << EOF >> "${file}"
2043 +
2044 +target_executable = open(target_executable_path, "rb")
2045 +target_executable_first_line = target_executable.readline()
2046 +target_executable.close()
2047 +if not isinstance(target_executable_first_line, str):
2048 + # Python 3
2049 + target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
2050 +
2051 +options = []
2052 +python_shebang_options_matched = python_shebang_options_re.match(target_executable_first_line)
2053 +if python_shebang_options_matched is not None:
2054 + options = [python_shebang_options_matched.group(1)]
2055 +
2056 +cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line)
2057 +
2058 +if cpython_shebang_matched is not None:
2059 + try:
2060 + python_interpreter_path = "${EPREFIX}/usr/bin/%s" % python_interpreter
2061 + os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
2062 + python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
2063 + del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
2064 + if python_verification_process.wait() != 0:
2065 + raise ValueError
2066 +
2067 + python_verification_output = python_verification_process.stdout.read()
2068 + if not isinstance(python_verification_output, str):
2069 + # Python 3
2070 + python_verification_output = python_verification_output.decode()
2071 +
2072 + if not python_verification_output_re.match(python_verification_output):
2073 + raise ValueError
2074 +
2075 + if cpython_interpreter_re.match(python_interpreter) is not None:
2076 + os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
2077 + os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
2078 + os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
2079 +
2080 + if hasattr(os, "execv"):
2081 + os.execv(python_interpreter_path, [python_interpreter_path] + options + sys.argv)
2082 + else:
2083 + sys.exit(subprocess.Popen([python_interpreter_path] + options + sys.argv).wait())
2084 + except (KeyboardInterrupt, SystemExit):
2085 + raise
2086 + except:
2087 + pass
2088 + for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"):
2089 + if variable in os.environ:
2090 + del os.environ[variable]
2091 +
2092 +if hasattr(os, "execv"):
2093 + os.execv(target_executable_path, sys.argv)
2094 +else:
2095 + sys.exit(subprocess.Popen([target_executable_path] + sys.argv[1:]).wait())
2096 +EOF
2097 + if [[ "$?" != "0" ]]; then
2098 + die "${FUNCNAME}(): Generation of '$1' failed"
2099 + fi
2100 + fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
2101 + done
2102 +}
2103 +
2104 +# @ECLASS-VARIABLE: PYTHON_VERSIONED_SCRIPTS
2105 +# @DESCRIPTION:
2106 +# Array of regular expressions of paths to versioned Python scripts.
2107 +# Python scripts in /usr/bin and /usr/sbin are versioned by default.
2108 +
2109 +# @ECLASS-VARIABLE: PYTHON_VERSIONED_EXECUTABLES
2110 +# @DESCRIPTION:
2111 +# Array of regular expressions of paths to versioned executables (including Python scripts).
2112 +
2113 +# @ECLASS-VARIABLE: PYTHON_NONVERSIONED_EXECUTABLES
2114 +# @DESCRIPTION:
2115 +# Array of regular expressions of paths to nonversioned executables (including Python scripts).
2116 +
2117 +# @FUNCTION: python_merge_intermediate_installation_images
2118 +# @USAGE: [-q|--quiet] [--] <intermediate_installation_images_directory>
2119 +# @DESCRIPTION:
2120 +# Merge intermediate installation images into installation image.
2121 +#
2122 +# This function can be used only in src_install() phase.
2123 +python_merge_intermediate_installation_images() {
2124 + if [[ "${EBUILD_PHASE}" != "install" ]]; then
2125 + die "${FUNCNAME}() can be used only in src_install() phase"
2126 + fi
2127 +
2128 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
2129 + die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2130 + fi
2131 +
2132 + _python_check_python_pkg_setup_execution
2133 + _python_initialize_prefix_variables
2134 +
2135 + local absolute_file b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=()
2136 +
2137 + while (($#)); do
2138 + case "$1" in
2139 + -q|--quiet)
2140 + quiet="1"
2141 + ;;
2142 + --)
2143 + shift
2144 + break
2145 + ;;
2146 + -*)
2147 + die "${FUNCNAME}(): Unrecognized option '$1'"
2148 + ;;
2149 + *)
2150 + break
2151 + ;;
2152 + esac
2153 + shift
2154 + done
2155 +
2156 + if [[ "$#" -ne 1 ]]; then
2157 + die "${FUNCNAME}() requires 1 argument"
2158 + fi
2159 +
2160 + intermediate_installation_images_directory="$1"
2161 +
2162 + if [[ ! -d "${intermediate_installation_images_directory}" ]]; then
2163 + die "${FUNCNAME}(): Intermediate installation images directory '${intermediate_installation_images_directory}' does not exist"
2164 + fi
2165 +
2166 + _python_calculate_PYTHON_ABIS
2167 + if [[ "$(PYTHON -f --ABI)" == 3.* ]]; then
2168 + b="b"
2169 + fi
2170 +
2171 + while read -d $'\0' -r file; do
2172 + files+=("${file}")
2173 + done < <("$(PYTHON -f)" -c \
2174 +"import os
2175 +import sys
2176 +
2177 +if hasattr(sys.stdout, 'buffer'):
2178 + # Python 3
2179 + stdout = sys.stdout.buffer
2180 +else:
2181 + # Python 2
2182 + stdout = sys.stdout
2183 +
2184 +files_set = set()
2185 +
2186 +os.chdir(${b}'${intermediate_installation_images_directory}')
2187 +
2188 +for PYTHON_ABI in ${b}'${PYTHON_ABIS}'.split():
2189 + for root, dirs, files in os.walk(PYTHON_ABI + ${b}'${EPREFIX}'):
2190 + root = root[len(PYTHON_ABI + ${b}'${EPREFIX}')+1:]
2191 + files_set.update(root + ${b}'/' + file for file in files)
2192 +
2193 +for file in sorted(files_set):
2194 + stdout.write(file)
2195 + stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of files in intermediate installation images")
2196 +
2197 + for PYTHON_ABI in ${PYTHON_ABIS}; do
2198 + if [[ ! -d "${intermediate_installation_images_directory}/${PYTHON_ABI}" ]]; then
2199 + die "${FUNCNAME}(): Intermediate installation image for Python ABI '${PYTHON_ABI}' does not exist"
2200 + fi
2201 +
2202 + pushd "${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}" > /dev/null || die "pushd failed"
2203 +
2204 + for file in "${files[@]}"; do
2205 + version_executable="0"
2206 + for regex in "/usr/bin/.*" "/usr/sbin/.*" "${PYTHON_VERSIONED_SCRIPTS[@]}"; do
2207 + if [[ "/${file}" =~ ^${regex}$ ]]; then
2208 + version_executable="1"
2209 + break
2210 + fi
2211 + done
2212 + for regex in "${PYTHON_VERSIONED_EXECUTABLES[@]}"; do
2213 + if [[ "/${file}" =~ ^${regex}$ ]]; then
2214 + version_executable="2"
2215 + break
2216 + fi
2217 + done
2218 + if [[ "${version_executable}" != "0" ]]; then
2219 + for regex in "${PYTHON_NONVERSIONED_EXECUTABLES[@]}"; do
2220 + if [[ "/${file}" =~ ^${regex}$ ]]; then
2221 + version_executable="0"
2222 + break
2223 + fi
2224 + done
2225 + fi
2226 +
2227 + [[ "${version_executable}" == "0" ]] && continue
2228 +
2229 + if [[ -L "${file}" ]]; then
2230 + absolute_file="$(readlink "${file}")"
2231 + if [[ "${absolute_file}" == /* ]]; then
2232 + absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file##/}"
2233 + else
2234 + if [[ "${file}" == */* ]]; then
2235 + absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file%/*}/${absolute_file}"
2236 + else
2237 + absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file}"
2238 + fi
2239 + fi
2240 + else
2241 + absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file}"
2242 + fi
2243 +
2244 + [[ ! -x "${absolute_file}" ]] && continue
2245 +
2246 + shebang="$(head -n1 "${absolute_file}")" || die "Extraction of shebang from '${absolute_file}' failed"
2247 +
2248 + if [[ "${version_executable}" == "2" ]]; then
2249 + wrapper_scripts+=("${ED}${file}")
2250 + elif [[ "${version_executable}" == "1" ]]; then
2251 + if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then
2252 + wrapper_scripts+=("${ED}${file}")
2253 + else
2254 + version_executable="0"
2255 + fi
2256 + fi
2257 +
2258 + [[ "${version_executable}" == "0" ]] && continue
2259 +
2260 + if [[ -e "${file}-${PYTHON_ABI}" ]]; then
2261 + die "${FUNCNAME}(): '${EPREFIX}/${file}-${PYTHON_ABI}' already exists"
2262 + fi
2263 +
2264 + mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed"
2265 +
2266 + if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then
2267 + if [[ -L "${file}-${PYTHON_ABI}" ]]; then
2268 + python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${absolute_file}"
2269 + else
2270 + python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}"
2271 + fi
2272 + fi
2273 + done
2274 +
2275 + popd > /dev/null || die "popd failed"
2276 +
2277 + # This is per bug #390691, without the duplication refactor, and with
2278 + # the 3-way structure per comment #6. This enable users with old
2279 + # coreutils to upgrade a lot easier (you need to upgrade python+portage
2280 + # before coreutils can be upgraded).
2281 + if ROOT="/" has_version '>=sys-apps/coreutils-6.9.90'; then
2282 + cp -fr --preserve=all --no-preserve=context "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed"
2283 + elif ROOT="/" has_version sys-apps/coreutils; then
2284 + cp -fr --preserve=all "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed"
2285 + else
2286 + cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed"
2287 + fi
2288 + done
2289 +
2290 + rm -fr "${intermediate_installation_images_directory}"
2291 +
2292 + if [[ "${#wrapper_scripts[@]}" -ge 1 ]]; then
2293 + rm -f "${T}/python_wrapper_scripts"
2294 +
2295 + for file in "${wrapper_scripts[@]}"; do
2296 + echo -n "${file}" >> "${T}/python_wrapper_scripts"
2297 + echo -en "\x00" >> "${T}/python_wrapper_scripts"
2298 + done
2299 +
2300 + while read -d $'\0' -r file; do
2301 + wrapper_scripts_set+=("${file}")
2302 + done < <("$(PYTHON -f)" -c \
2303 +"import sys
2304 +
2305 +if hasattr(sys.stdout, 'buffer'):
2306 + # Python 3
2307 + stdout = sys.stdout.buffer
2308 +else:
2309 + # Python 2
2310 + stdout = sys.stdout
2311 +
2312 +python_wrapper_scripts_file = open('${T}/python_wrapper_scripts', 'rb')
2313 +files = set(python_wrapper_scripts_file.read().rstrip(${b}'\x00').split(${b}'\x00'))
2314 +python_wrapper_scripts_file.close()
2315 +
2316 +for file in sorted(files):
2317 + stdout.write(file)
2318 + stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts")
2319 +
2320 + python_generate_wrapper_scripts $([[ "${quiet}" == "1" ]] && echo --quiet) "${wrapper_scripts_set[@]}"
2321 + fi
2322 +}
2323 +
2324 +# ================================================================================================
2325 +# ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ==========
2326 +# ================================================================================================
2327 +
2328 +unset EPYTHON PYTHON_ABI
2329 +
2330 +# @FUNCTION: python_set_active_version
2331 +# @USAGE: <Python_ABI|2|3>
2332 +# @DESCRIPTION:
2333 +# Set locally active version of Python.
2334 +# If Python_ABI argument is specified, then version of Python corresponding to Python_ABI is used.
2335 +# If 2 argument is specified, then active version of CPython 2 is used.
2336 +# If 3 argument is specified, then active version of CPython 3 is used.
2337 +#
2338 +# This function can be used only in pkg_setup() phase.
2339 +python_set_active_version() {
2340 + if [[ "${EBUILD_PHASE}" != "setup" ]]; then
2341 + die "${FUNCNAME}() can be used only in pkg_setup() phase"
2342 + fi
2343 +
2344 + if _python_package_supporting_installation_for_multiple_python_abis; then
2345 + die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2346 + fi
2347 +
2348 + if [[ "$#" -ne 1 ]]; then
2349 + die "${FUNCNAME}() requires 1 argument"
2350 + fi
2351 +
2352 + _python_initial_sanity_checks
2353 +
2354 + if [[ -z "${PYTHON_ABI}" ]]; then
2355 + if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
2356 + # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
2357 + # so it does not need to be exported to subprocesses.
2358 + PYTHON_ABI="$1"
2359 + if ! _python_implementation && ! has_version "$(python_get_implementational_package)"; then
2360 + die "${FUNCNAME}(): '$(python_get_implementational_package)' is not installed"
2361 + fi
2362 + export EPYTHON="$(PYTHON "$1")"
2363 + elif [[ "$1" == "2" ]]; then
2364 + if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
2365 + die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
2366 + fi
2367 + export EPYTHON="$(PYTHON -2)"
2368 + PYTHON_ABI="${EPYTHON#python}"
2369 + PYTHON_ABI="${PYTHON_ABI%%-*}"
2370 + elif [[ "$1" == "3" ]]; then
2371 + if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
2372 + die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
2373 + fi
2374 + export EPYTHON="$(PYTHON -3)"
2375 + PYTHON_ABI="${EPYTHON#python}"
2376 + PYTHON_ABI="${PYTHON_ABI%%-*}"
2377 + else
2378 + die "${FUNCNAME}(): Unrecognized argument '$1'"
2379 + fi
2380 + fi
2381 +
2382 + _python_final_sanity_checks
2383 +
2384 + # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable.
2385 + PYTHON_REQUESTED_ACTIVE_VERSION="$1"
2386 +}
2387 +
2388 +# @FUNCTION: python_need_rebuild
2389 +# @DESCRIPTION:
2390 +# Mark current package for rebuilding by python-updater after
2391 +# switching of active version of Python.
2392 +python_need_rebuild() {
2393 + if _python_package_supporting_installation_for_multiple_python_abis; then
2394 + die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
2395 + fi
2396 +
2397 + _python_check_python_pkg_setup_execution
2398 +
2399 + if [[ "$#" -ne 0 ]]; then
2400 + die "${FUNCNAME}() does not accept arguments"
2401 + fi
2402 +
2403 + export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
2404 +}
2405 +
2406 +# ================================================================================================
2407 +# ======================================= GETTER FUNCTIONS =======================================
2408 +# ================================================================================================
2409 +
2410 +_PYTHON_ABI_EXTRACTION_COMMAND=\
2411 +'import platform
2412 +import sys
2413 +sys.stdout.write(".".join(str(x) for x in sys.version_info[:2]))
2414 +if platform.system()[:4] == "Java":
2415 + sys.stdout.write("-jython")
2416 +elif hasattr(platform, "python_implementation") and platform.python_implementation() == "PyPy":
2417 + sys.stdout.write("-pypy-" + ".".join(str(x) for x in sys.pypy_version_info[:2]))'
2418 +
2419 +_python_get_implementation() {
2420 + local ignore_invalid="0"
2421 +
2422 + while (($#)); do
2423 + case "$1" in
2424 + --ignore-invalid)
2425 + ignore_invalid="1"
2426 + ;;
2427 + --)
2428 + shift
2429 + break
2430 + ;;
2431 + -*)
2432 + die "${FUNCNAME}(): Unrecognized option '$1'"
2433 + ;;
2434 + *)
2435 + break
2436 + ;;
2437 + esac
2438 + shift
2439 + done
2440 +
2441 + if [[ "$#" -ne 1 ]]; then
2442 + die "${FUNCNAME}() requires 1 argument"
2443 + fi
2444 +
2445 + if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
2446 + echo "CPython"
2447 + elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
2448 + echo "Jython"
2449 + elif [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then
2450 + echo "PyPy"
2451 + else
2452 + if [[ "${ignore_invalid}" == "0" ]]; then
2453 + die "${FUNCNAME}(): Unrecognized Python ABI '$1'"
2454 + fi
2455 + fi
2456 +}
2457 +
2458 +# @FUNCTION: PYTHON
2459 +# @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}">
2460 +# @DESCRIPTION:
2461 +# Print filename of Python interpreter for specified Python ABI. If Python_ABI argument
2462 +# is ommitted, then PYTHON_ABI environment variable must be set and is used.
2463 +# If -2 option is specified, then active version of CPython 2 is used.
2464 +# If -3 option is specified, then active version of CPython 3 is used.
2465 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2466 +# -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously.
2467 +# If --ABI option is specified, then only specified Python ABI is printed instead of
2468 +# filename of Python interpreter.
2469 +# If --absolute-path option is specified, then absolute path to Python interpreter is printed.
2470 +# --ABI and --absolute-path options cannot be specified simultaneously.
2471 +PYTHON() {
2472 + _python_check_python_pkg_setup_execution
2473 +
2474 + local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0"
2475 +
2476 + while (($#)); do
2477 + case "$1" in
2478 + -2)
2479 + python2="1"
2480 + ;;
2481 + -3)
2482 + python3="1"
2483 + ;;
2484 + --ABI)
2485 + ABI_output="1"
2486 + ;;
2487 + -a|--absolute-path)
2488 + absolute_path_output="1"
2489 + ;;
2490 + -f|--final-ABI)
2491 + final_ABI="1"
2492 + ;;
2493 + --)
2494 + shift
2495 + break
2496 + ;;
2497 + -*)
2498 + die "${FUNCNAME}(): Unrecognized option '$1'"
2499 + ;;
2500 + *)
2501 + break
2502 + ;;
2503 + esac
2504 + shift
2505 + done
2506 +
2507 + if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
2508 + die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously"
2509 + fi
2510 +
2511 + if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
2512 + die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously"
2513 + fi
2514 +
2515 + if [[ "$#" -eq 0 ]]; then
2516 + if [[ "${final_ABI}" == "1" ]]; then
2517 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
2518 + die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2519 + fi
2520 + _python_calculate_PYTHON_ABIS
2521 + PYTHON_ABI="${PYTHON_ABIS##* }"
2522 + elif [[ "${python2}" == "1" ]]; then
2523 + PYTHON_ABI="$(ROOT="/" eselect python show --python2 --ABI)"
2524 + if [[ -z "${PYTHON_ABI}" ]]; then
2525 + die "${FUNCNAME}(): Active version of CPython 2 not set"
2526 + elif [[ "${PYTHON_ABI}" != "2."* ]]; then
2527 + die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
2528 + fi
2529 + elif [[ "${python3}" == "1" ]]; then
2530 + PYTHON_ABI="$(ROOT="/" eselect python show --python3 --ABI)"
2531 + if [[ -z "${PYTHON_ABI}" ]]; then
2532 + die "${FUNCNAME}(): Active version of CPython 3 not set"
2533 + elif [[ "${PYTHON_ABI}" != "3."* ]]; then
2534 + die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
2535 + fi
2536 + elif _python_package_supporting_installation_for_multiple_python_abis; then
2537 + if ! _python_abi-specific_local_scope; then
2538 + die "${FUNCNAME}() should be used in ABI-specific local scope"
2539 + fi
2540 + else
2541 + PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
2542 + if [[ -z "${PYTHON_ABI}" ]]; then
2543 + die "${FUNCNAME}(): Failure of extraction of locally active version of Python"
2544 + fi
2545 + fi
2546 + elif [[ "$#" -eq 1 ]]; then
2547 + if [[ "${final_ABI}" == "1" ]]; then
2548 + die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
2549 + fi
2550 + if [[ "${python2}" == "1" ]]; then
2551 + die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously"
2552 + fi
2553 + if [[ "${python3}" == "1" ]]; then
2554 + die "${FUNCNAME}(): '-3' option and Python ABI cannot be specified simultaneously"
2555 + fi
2556 + PYTHON_ABI="$1"
2557 + else
2558 + die "${FUNCNAME}(): Invalid usage"
2559 + fi
2560 +
2561 + if [[ "${ABI_output}" == "1" ]]; then
2562 + echo -n "${PYTHON_ABI}"
2563 + return
2564 + else
2565 + if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2566 + python_interpreter="python${PYTHON_ABI}"
2567 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2568 + python_interpreter="jython${PYTHON_ABI%-jython}"
2569 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
2570 + python_interpreter="pypy-c${PYTHON_ABI#*-pypy-}"
2571 + fi
2572 +
2573 + if [[ "${absolute_path_output}" == "1" ]]; then
2574 + echo -n "${EPREFIX}/usr/bin/${python_interpreter}"
2575 + else
2576 + echo -n "${python_interpreter}"
2577 + fi
2578 + fi
2579 +
2580 + if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then
2581 + echo -n "-${ABI}"
2582 + fi
2583 +}
2584 +
2585 +# @FUNCTION: python_get_implementation
2586 +# @USAGE: [-f|--final-ABI]
2587 +# @DESCRIPTION:
2588 +# Print name of Python implementation.
2589 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2590 +python_get_implementation() {
2591 + _python_check_python_pkg_setup_execution
2592 +
2593 + local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
2594 +
2595 + while (($#)); do
2596 + case "$1" in
2597 + -f|--final-ABI)
2598 + final_ABI="1"
2599 + ;;
2600 + -*)
2601 + die "${FUNCNAME}(): Unrecognized option '$1'"
2602 + ;;
2603 + *)
2604 + die "${FUNCNAME}(): Invalid usage"
2605 + ;;
2606 + esac
2607 + shift
2608 + done
2609 +
2610 + if [[ "${final_ABI}" == "1" ]]; then
2611 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
2612 + die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2613 + fi
2614 + PYTHON_ABI="$(PYTHON -f --ABI)"
2615 + else
2616 + if _python_package_supporting_installation_for_multiple_python_abis; then
2617 + if ! _python_abi-specific_local_scope; then
2618 + die "${FUNCNAME}() should be used in ABI-specific local scope"
2619 + fi
2620 + else
2621 + PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
2622 + fi
2623 + fi
2624 +
2625 + echo "$(_python_get_implementation "${PYTHON_ABI}")"
2626 +}
2627 +
2628 +# @FUNCTION: python_get_implementational_package
2629 +# @USAGE: [-f|--final-ABI]
2630 +# @DESCRIPTION:
2631 +# Print category, name and slot of package providing Python implementation.
2632 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2633 +python_get_implementational_package() {
2634 + _python_check_python_pkg_setup_execution
2635 +
2636 + local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
2637 +
2638 + while (($#)); do
2639 + case "$1" in
2640 + -f|--final-ABI)
2641 + final_ABI="1"
2642 + ;;
2643 + -*)
2644 + die "${FUNCNAME}(): Unrecognized option '$1'"
2645 + ;;
2646 + *)
2647 + die "${FUNCNAME}(): Invalid usage"
2648 + ;;
2649 + esac
2650 + shift
2651 + done
2652 +
2653 + if [[ "${final_ABI}" == "1" ]]; then
2654 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
2655 + die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2656 + fi
2657 + PYTHON_ABI="$(PYTHON -f --ABI)"
2658 + else
2659 + if _python_package_supporting_installation_for_multiple_python_abis; then
2660 + if ! _python_abi-specific_local_scope; then
2661 + die "${FUNCNAME}() should be used in ABI-specific local scope"
2662 + fi
2663 + else
2664 + PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
2665 + fi
2666 + fi
2667 +
2668 + if [[ "${EAPI:-0}" == "0" ]]; then
2669 + if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2670 + echo "=dev-lang/python-${PYTHON_ABI}*"
2671 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2672 + echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
2673 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
2674 + echo "=virtual/pypy-${PYTHON_ABI#*-pypy-}*"
2675 + fi
2676 + else
2677 + if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2678 + echo "dev-lang/python:${PYTHON_ABI}"
2679 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2680 + echo "dev-java/jython:${PYTHON_ABI%-jython}"
2681 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
2682 + echo "virtual/pypy:${PYTHON_ABI#*-pypy-}"
2683 + fi
2684 + fi
2685 +}
2686 +
2687 +# @FUNCTION: python_get_includedir
2688 +# @USAGE: [-b|--base-path] [-f|--final-ABI]
2689 +# @DESCRIPTION:
2690 +# Print path to Python include directory.
2691 +# If --base-path option is specified, then path not prefixed with "/" is printed.
2692 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2693 +python_get_includedir() {
2694 + _python_check_python_pkg_setup_execution
2695 +
2696 + local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
2697 +
2698 + while (($#)); do
2699 + case "$1" in
2700 + -b|--base-path)
2701 + base_path="1"
2702 + ;;
2703 + -f|--final-ABI)
2704 + final_ABI="1"
2705 + ;;
2706 + -*)
2707 + die "${FUNCNAME}(): Unrecognized option '$1'"
2708 + ;;
2709 + *)
2710 + die "${FUNCNAME}(): Invalid usage"
2711 + ;;
2712 + esac
2713 + shift
2714 + done
2715 +
2716 + if [[ "${base_path}" == "0" ]]; then
2717 + prefix="/"
2718 + fi
2719 +
2720 + if [[ "${final_ABI}" == "1" ]]; then
2721 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
2722 + die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2723 + fi
2724 + PYTHON_ABI="$(PYTHON -f --ABI)"
2725 + else
2726 + if _python_package_supporting_installation_for_multiple_python_abis; then
2727 + if ! _python_abi-specific_local_scope; then
2728 + die "${FUNCNAME}() should be used in ABI-specific local scope"
2729 + fi
2730 + else
2731 + PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
2732 + fi
2733 + fi
2734 +
2735 + if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2736 + echo "${prefix}usr/include/python${PYTHON_ABI}"
2737 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2738 + echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include"
2739 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
2740 + echo "${prefix}usr/$(get_libdir)/pypy${PYTHON_ABI#*-pypy-}/include"
2741 + fi
2742 +}
2743 +
2744 +# @FUNCTION: python_get_libdir
2745 +# @USAGE: [-b|--base-path] [-f|--final-ABI]
2746 +# @DESCRIPTION:
2747 +# Print path to Python standard library directory.
2748 +# If --base-path option is specified, then path not prefixed with "/" is printed.
2749 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2750 +python_get_libdir() {
2751 + _python_check_python_pkg_setup_execution
2752 +
2753 + local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
2754 +
2755 + while (($#)); do
2756 + case "$1" in
2757 + -b|--base-path)
2758 + base_path="1"
2759 + ;;
2760 + -f|--final-ABI)
2761 + final_ABI="1"
2762 + ;;
2763 + -*)
2764 + die "${FUNCNAME}(): Unrecognized option '$1'"
2765 + ;;
2766 + *)
2767 + die "${FUNCNAME}(): Invalid usage"
2768 + ;;
2769 + esac
2770 + shift
2771 + done
2772 +
2773 + if [[ "${base_path}" == "0" ]]; then
2774 + prefix="/"
2775 + fi
2776 +
2777 + if [[ "${final_ABI}" == "1" ]]; then
2778 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
2779 + die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2780 + fi
2781 + PYTHON_ABI="$(PYTHON -f --ABI)"
2782 + else
2783 + if _python_package_supporting_installation_for_multiple_python_abis; then
2784 + if ! _python_abi-specific_local_scope; then
2785 + die "${FUNCNAME}() should be used in ABI-specific local scope"
2786 + fi
2787 + else
2788 + PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
2789 + fi
2790 + fi
2791 +
2792 + if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2793 + echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}"
2794 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2795 + echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib"
2796 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
2797 + die "${FUNCNAME}(): PyPy has multiple standard library directories"
2798 + fi
2799 +}
2800 +
2801 +# @FUNCTION: python_get_sitedir
2802 +# @USAGE: [-b|--base-path] [-f|--final-ABI]
2803 +# @DESCRIPTION:
2804 +# Print path to Python site-packages directory.
2805 +# If --base-path option is specified, then path not prefixed with "/" is printed.
2806 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2807 +python_get_sitedir() {
2808 + _python_check_python_pkg_setup_execution
2809 +
2810 + local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}"
2811 +
2812 + while (($#)); do
2813 + case "$1" in
2814 + -b|--base-path)
2815 + base_path="1"
2816 + ;;
2817 + -f|--final-ABI)
2818 + final_ABI="1"
2819 + ;;
2820 + -*)
2821 + die "${FUNCNAME}(): Unrecognized option '$1'"
2822 + ;;
2823 + *)
2824 + die "${FUNCNAME}(): Invalid usage"
2825 + ;;
2826 + esac
2827 + shift
2828 + done
2829 +
2830 + if [[ "${base_path}" == "0" ]]; then
2831 + prefix="/"
2832 + fi
2833 +
2834 + if [[ "${final_ABI}" == "1" ]]; then
2835 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
2836 + die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2837 + fi
2838 + PYTHON_ABI="$(PYTHON -f --ABI)"
2839 + else
2840 + if _python_package_supporting_installation_for_multiple_python_abis; then
2841 + if ! _python_abi-specific_local_scope; then
2842 + die "${FUNCNAME}() should be used in ABI-specific local scope"
2843 + fi
2844 + else
2845 + PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
2846 + fi
2847 + fi
2848 +
2849 + if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2850 + echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}/site-packages"
2851 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2852 + echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib/site-packages"
2853 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
2854 + echo "${prefix}usr/$(get_libdir)/pypy${PYTHON_ABI#*-pypy-}/site-packages"
2855 + fi
2856 +}
2857 +
2858 +# @FUNCTION: python_get_library
2859 +# @USAGE: [-b|--base-path] [-f|--final-ABI] [-l|--linker-option]
2860 +# @DESCRIPTION:
2861 +# Print path to Python library.
2862 +# If --base-path option is specified, then path not prefixed with "/" is printed.
2863 +# If --linker-option is specified, then "-l${library}" linker option is printed.
2864 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2865 +python_get_library() {
2866 + _python_check_python_pkg_setup_execution
2867 +
2868 + local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}"
2869 +
2870 + while (($#)); do
2871 + case "$1" in
2872 + -b|--base-path)
2873 + base_path="1"
2874 + ;;
2875 + -f|--final-ABI)
2876 + final_ABI="1"
2877 + ;;
2878 + -l|--linker-option)
2879 + linker_option="1"
2880 + ;;
2881 + -*)
2882 + die "${FUNCNAME}(): Unrecognized option '$1'"
2883 + ;;
2884 + *)
2885 + die "${FUNCNAME}(): Invalid usage"
2886 + ;;
2887 + esac
2888 + shift
2889 + done
2890 +
2891 + if [[ "${base_path}" == "0" ]]; then
2892 + prefix="/"
2893 + fi
2894 +
2895 + if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
2896 + die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously"
2897 + fi
2898 +
2899 + if [[ "${final_ABI}" == "1" ]]; then
2900 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
2901 + die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2902 + fi
2903 + PYTHON_ABI="$(PYTHON -f --ABI)"
2904 + else
2905 + if _python_package_supporting_installation_for_multiple_python_abis; then
2906 + if ! _python_abi-specific_local_scope; then
2907 + die "${FUNCNAME}() should be used in ABI-specific local scope"
2908 + fi
2909 + else
2910 + PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
2911 + fi
2912 + fi
2913 +
2914 + if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
2915 + if [[ "${linker_option}" == "1" ]]; then
2916 + echo "-lpython${PYTHON_ABI}"
2917 + else
2918 + echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)"
2919 + fi
2920 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
2921 + die "${FUNCNAME}(): Jython does not have shared library"
2922 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
2923 + die "${FUNCNAME}(): PyPy does not have shared library"
2924 + fi
2925 +}
2926 +
2927 +# @FUNCTION: python_get_version
2928 +# @USAGE: [-f|--final-ABI] [-l|--language] [--full] [--major] [--minor] [--micro]
2929 +# @DESCRIPTION:
2930 +# Print version of Python implementation.
2931 +# --full, --major, --minor and --micro options cannot be specified simultaneously.
2932 +# If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed.
2933 +# If --language option is specified, then version of Python language is printed.
2934 +# --language and --full options cannot be specified simultaneously.
2935 +# --language and --micro options cannot be specified simultaneously.
2936 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
2937 +python_get_version() {
2938 + _python_check_python_pkg_setup_execution
2939 +
2940 + local final_ABI="0" language="0" language_version full="0" major="0" minor="0" micro="0" PYTHON_ABI="${PYTHON_ABI}" python_command
2941 +
2942 + while (($#)); do
2943 + case "$1" in
2944 + -f|--final-ABI)
2945 + final_ABI="1"
2946 + ;;
2947 + -l|--language)
2948 + language="1"
2949 + ;;
2950 + --full)
2951 + full="1"
2952 + ;;
2953 + --major)
2954 + major="1"
2955 + ;;
2956 + --minor)
2957 + minor="1"
2958 + ;;
2959 + --micro)
2960 + micro="1"
2961 + ;;
2962 + -*)
2963 + die "${FUNCNAME}(): Unrecognized option '$1'"
2964 + ;;
2965 + *)
2966 + die "${FUNCNAME}(): Invalid usage"
2967 + ;;
2968 + esac
2969 + shift
2970 + done
2971 +
2972 + if [[ "${final_ABI}" == "1" ]]; then
2973 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
2974 + die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
2975 + fi
2976 + else
2977 + if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
2978 + die "${FUNCNAME}() should be used in ABI-specific local scope"
2979 + fi
2980 + fi
2981 +
2982 + if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
2983 + die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously"
2984 + fi
2985 +
2986 + if [[ "${language}" == "1" ]]; then
2987 + if [[ "${final_ABI}" == "1" ]]; then
2988 + PYTHON_ABI="$(PYTHON -f --ABI)"
2989 + elif [[ -z "${PYTHON_ABI}" ]]; then
2990 + PYTHON_ABI="$(PYTHON --ABI)"
2991 + fi
2992 + language_version="${PYTHON_ABI%%-*}"
2993 + if [[ "${full}" == "1" ]]; then
2994 + die "${FUNCNAME}(): '--language' and '--full' options cannot be specified simultaneously"
2995 + elif [[ "${major}" == "1" ]]; then
2996 + echo "${language_version%.*}"
2997 + elif [[ "${minor}" == "1" ]]; then
2998 + echo "${language_version#*.}"
2999 + elif [[ "${micro}" == "1" ]]; then
3000 + die "${FUNCNAME}(): '--language' and '--micro' options cannot be specified simultaneously"
3001 + else
3002 + echo "${language_version}"
3003 + fi
3004 + else
3005 + if [[ "${full}" == "1" ]]; then
3006 + python_command="import sys; print('.'.join(str(x) for x in getattr(sys, 'pypy_version_info', sys.version_info)[:3]))"
3007 + elif [[ "${major}" == "1" ]]; then
3008 + python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[0])"
3009 + elif [[ "${minor}" == "1" ]]; then
3010 + python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[1])"
3011 + elif [[ "${micro}" == "1" ]]; then
3012 + python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[2])"
3013 + else
3014 + if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
3015 + if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
3016 + echo "${PYTHON_ABI}"
3017 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
3018 + echo "${PYTHON_ABI%-jython}"
3019 + elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
3020 + echo "${PYTHON_ABI#*-pypy-}"
3021 + fi
3022 + return
3023 + fi
3024 + python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))"
3025 + fi
3026 +
3027 + if [[ "${final_ABI}" == "1" ]]; then
3028 + "$(PYTHON -f)" -c "${python_command}"
3029 + else
3030 + "$(PYTHON ${PYTHON_ABI})" -c "${python_command}"
3031 + fi
3032 + fi
3033 +}
3034 +
3035 +# @FUNCTION: python_get_implementation_and_version
3036 +# @USAGE: [-f|--final-ABI]
3037 +# @DESCRIPTION:
3038 +# Print name and version of Python implementation.
3039 +# If version of Python implementation is not bound to version of Python language, then
3040 +# version of Python language is additionally printed.
3041 +# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
3042 +python_get_implementation_and_version() {
3043 + _python_check_python_pkg_setup_execution
3044 +
3045 + local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}"
3046 +
3047 + while (($#)); do
3048 + case "$1" in
3049 + -f|--final-ABI)
3050 + final_ABI="1"
3051 + ;;
3052 + -*)
3053 + die "${FUNCNAME}(): Unrecognized option '$1'"
3054 + ;;
3055 + *)
3056 + die "${FUNCNAME}(): Invalid usage"
3057 + ;;
3058 + esac
3059 + shift
3060 + done
3061 +
3062 + if [[ "${final_ABI}" == "1" ]]; then
3063 + if ! _python_package_supporting_installation_for_multiple_python_abis; then
3064 + die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
3065 + fi
3066 + PYTHON_ABI="$(PYTHON -f --ABI)"
3067 + else
3068 + if _python_package_supporting_installation_for_multiple_python_abis; then
3069 + if ! _python_abi-specific_local_scope; then
3070 + die "${FUNCNAME}() should be used in ABI-specific local scope"
3071 + fi
3072 + else
3073 + PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
3074 + fi
3075 + fi
3076 +
3077 + if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-[[:alnum:]]+-[[:digit:]]+\.[[:digit:]]+$ ]]; then
3078 + echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI##*-} (Python ${PYTHON_ABI%%-*})"
3079 + else
3080 + echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI%%-*}"
3081 + fi
3082 +}
3083 +
3084 +# ================================================================================================
3085 +# ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
3086 +# ================================================================================================
3087 +
3088 +# @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY
3089 +# @DESCRIPTION:
3090 +# User-configurable verbosity of tests of Python modules.
3091 +# Supported values: 0, 1, 2, 3, 4.
3092 +PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}"
3093 +
3094 +_python_test_hook() {
3095 + if [[ "$#" -ne 1 ]]; then
3096 + die "${FUNCNAME}() requires 1 argument"
3097 + fi
3098 +
3099 + if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${_PYTHON_TEST_FUNCTION}_$1_hook")" == "function" ]]; then
3100 + "${_PYTHON_TEST_FUNCTION}_$1_hook"
3101 + fi
3102 +}
3103 +
3104 +# @FUNCTION: python_execute_nosetests
3105 +# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
3106 +# @DESCRIPTION:
3107 +# Execute nosetests for all enabled Python ABIs.
3108 +# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
3109 +# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
3110 +python_execute_nosetests() {
3111 + _python_check_python_pkg_setup_execution
3112 + _python_set_color_variables
3113 +
3114 + local PYTHONPATH_template separate_build_dirs
3115 +
3116 + while (($#)); do
3117 + case "$1" in
3118 + -P|--PYTHONPATH)
3119 + PYTHONPATH_template="$2"
3120 + shift
3121 + ;;
3122 + -s|--separate-build-dirs)
3123 + separate_build_dirs="1"
3124 + ;;
3125 + --)
3126 + shift
3127 + break
3128 + ;;
3129 + -*)
3130 + die "${FUNCNAME}(): Unrecognized option '$1'"
3131 + ;;
3132 + *)
3133 + break
3134 + ;;
3135 + esac
3136 + shift
3137 + done
3138 +
3139 + python_test_function() {
3140 + local evaluated_PYTHONPATH
3141 +
3142 + eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
3143 +
3144 + _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook pre
3145 +
3146 + if [[ -n "${evaluated_PYTHONPATH}" ]]; then
3147 + echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
3148 + PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
3149 + else
3150 + echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL}
3151 + nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?"
3152 + fi
3153 +
3154 + _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook post
3155 + }
3156 + if _python_package_supporting_installation_for_multiple_python_abis; then
3157 + python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
3158 + else
3159 + if [[ -n "${separate_build_dirs}" ]]; then
3160 + die "${FUNCNAME}(): Invalid usage"
3161 + fi
3162 + python_test_function "$@" || die "Testing failed"
3163 + fi
3164 +
3165 + unset -f python_test_function
3166 +}
3167 +
3168 +# @FUNCTION: python_execute_py.test
3169 +# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
3170 +# @DESCRIPTION:
3171 +# Execute py.test for all enabled Python ABIs.
3172 +# In ebuilds of packages supporting installation for multiple Python ABIs, this function calls
3173 +# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
3174 +python_execute_py.test() {
3175 + _python_check_python_pkg_setup_execution
3176 + _python_set_color_variables
3177 +
3178 + local PYTHONPATH_template separate_build_dirs
3179 +
3180 + while (($#)); do
3181 + case "$1" in
3182 + -P|--PYTHONPATH)
3183 + PYTHONPATH_template="$2"
3184 + shift
3185 + ;;
3186 + -s|--separate-build-dirs)
3187 + separate_build_dirs="1"
3188 + ;;
3189 + --)
3190 + shift
3191 + break
3192 + ;;
3193 + -*)
3194 + die "${FUNCNAME}(): Unrecognized option '$1'"
3195 + ;;
3196 + *)
3197 + break
3198 + ;;
3199 + esac
3200 + shift
3201 + done
3202 +
3203 + python_test_function() {
3204 + local evaluated_PYTHONPATH
3205 +
3206 + eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
3207 +
3208 + _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook pre
3209 +
3210 + if [[ -n "${evaluated_PYTHONPATH}" ]]; then
3211 + echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL}
3212 + PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?"
3213 + else
3214 + echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL}
3215 + py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?"
3216 + fi
3217 +
3218 + _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook post
3219 + }
3220 + if _python_package_supporting_installation_for_multiple_python_abis; then
3221 + python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
3222 + else
3223 + if [[ -n "${separate_build_dirs}" ]]; then
3224 + die "${FUNCNAME}(): Invalid usage"
3225 + fi
3226 + python_test_function "$@" || die "Testing failed"
3227 + fi
3228 +
3229 + unset -f python_test_function
3230 +}
3231 +
3232 +# @FUNCTION: python_execute_trial
3233 +# @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments]
3234 +# @DESCRIPTION:
3235 +# Execute trial for all enabled Python ABIs.
3236 +# In ebuilds of packages supporting installation for multiple Python ABIs, this function
3237 +# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
3238 +python_execute_trial() {
3239 + _python_check_python_pkg_setup_execution
3240 + _python_set_color_variables
3241 +
3242 + local PYTHONPATH_template separate_build_dirs
3243 +
3244 + while (($#)); do
3245 + case "$1" in
3246 + -P|--PYTHONPATH)
3247 + PYTHONPATH_template="$2"
3248 + shift
3249 + ;;
3250 + -s|--separate-build-dirs)
3251 + separate_build_dirs="1"
3252 + ;;
3253 + --)
3254 + shift
3255 + break
3256 + ;;
3257 + -*)
3258 + die "${FUNCNAME}(): Unrecognized option '$1'"
3259 + ;;
3260 + *)
3261 + break
3262 + ;;
3263 + esac
3264 + shift
3265 + done
3266 +
3267 + python_test_function() {
3268 + local evaluated_PYTHONPATH
3269 +
3270 + eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
3271 +
3272 + _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook pre
3273 +
3274 + if [[ -n "${evaluated_PYTHONPATH}" ]]; then
3275 + echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
3276 + PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
3277 + else
3278 + echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL}
3279 + trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?"
3280 + fi
3281 +
3282 + _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook post
3283 + }
3284 + if _python_package_supporting_installation_for_multiple_python_abis; then
3285 + python_execute_function ${separate_build_dirs:+-s} python_test_function "$@"
3286 + else
3287 + if [[ -n "${separate_build_dirs}" ]]; then
3288 + die "${FUNCNAME}(): Invalid usage"
3289 + fi
3290 + python_test_function "$@" || die "Testing failed"
3291 + fi
3292 +
3293 + unset -f python_test_function
3294 +}
3295 +
3296 +# ================================================================================================
3297 +# ======================= FUNCTIONS FOR HANDLING OF BYTE-COMPILED MODULES ========================
3298 +# ================================================================================================
3299 +
3300 +# @FUNCTION: python_enable_pyc
3301 +# @DESCRIPTION:
3302 +# Tell Python to automatically recompile modules to .pyc/.pyo if the
3303 +# timestamps/version stamps have changed.
3304 +python_enable_pyc() {
3305 + _python_check_python_pkg_setup_execution
3306 +
3307 + if [[ "$#" -ne 0 ]]; then
3308 + die "${FUNCNAME}() does not accept arguments"
3309 + fi
3310 +
3311 + unset PYTHONDONTWRITEBYTECODE
3312 +}
3313 +
3314 +# @FUNCTION: python_disable_pyc
3315 +# @DESCRIPTION:
3316 +# Tell Python not to automatically recompile modules to .pyc/.pyo
3317 +# even if the timestamps/version stamps do not match. This is done
3318 +# to protect sandbox.
3319 +python_disable_pyc() {
3320 + _python_check_python_pkg_setup_execution
3321 +
3322 + if [[ "$#" -ne 0 ]]; then
3323 + die "${FUNCNAME}() does not accept arguments"
3324 + fi
3325 +
3326 + export PYTHONDONTWRITEBYTECODE="1"
3327 +}
3328 +
3329 +_python_vecho() {
3330 + [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@"
3331 +}
3332 +
3333 +_python_clean_compiled_modules() {
3334 + _python_initialize_prefix_variables
3335 + _python_set_color_variables
3336 +
3337 + [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
3338 +
3339 + local base_module_name compiled_file compiled_files=() dir path py_file root
3340 +
3341 + # Strip trailing slash from EROOT.
3342 + root="${EROOT%/}"
3343 +
3344 + for path in "$@"; do
3345 + compiled_files=()
3346 + if [[ -d "${path}" ]]; then
3347 + while read -d $'\0' -r compiled_file; do
3348 + compiled_files+=("${compiled_file}")
3349 + done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
3350 +
3351 + if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
3352 + # Delete empty child directories.
3353 + find "${path}" -type d | sort -r | while read -r dir; do
3354 + if rmdir "${dir}" 2> /dev/null; then
3355 + _python_vecho "<<< ${dir}"
3356 + fi
3357 + done
3358 + fi
3359 + elif [[ "${path}" == *.py ]]; then
3360 + base_module_name="${path##*/}"
3361 + base_module_name="${base_module_name%.py}"
3362 + if [[ -d "${path%/*}/__pycache__" ]]; then
3363 + while read -d $'\0' -r compiled_file; do
3364 + compiled_files+=("${compiled_file}")
3365 + done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0)
3366 + fi
3367 + compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class")
3368 + fi
3369 +
3370 + for compiled_file in "${compiled_files[@]}"; do
3371 + [[ ! -f "${compiled_file}" ]] && continue
3372 + dir="${compiled_file%/*}"
3373 + dir="${dir##*/}"
3374 + if [[ "${compiled_file}" == *.py[co] ]]; then
3375 + if [[ "${dir}" == "__pycache__" ]]; then
3376 + base_module_name="${compiled_file##*/}"
3377 + base_module_name="${base_module_name%.*py[co]}"
3378 + base_module_name="${base_module_name%.*}"
3379 + py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
3380 + else
3381 + py_file="${compiled_file%[co]}"
3382 + fi
3383 + if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
3384 + [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
3385 + else
3386 + [[ -f "${py_file}" ]] && continue
3387 + fi
3388 + _python_vecho "<<< ${compiled_file%[co]}[co]"
3389 + rm -f "${compiled_file%[co]}"[co]
3390 + elif [[ "${compiled_file}" == *\$py.class ]]; then
3391 + if [[ "${dir}" == "__pycache__" ]]; then
3392 + base_module_name="${compiled_file##*/}"
3393 + base_module_name="${base_module_name%\$py.class}"
3394 + py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
3395 + else
3396 + py_file="${compiled_file%\$py.class}.py"
3397 + fi
3398 + if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
3399 + [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
3400 + else
3401 + [[ -f "${py_file}" ]] && continue
3402 + fi
3403 + _python_vecho "<<< ${compiled_file}"
3404 + rm -f "${compiled_file}"
3405 + else
3406 + die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
3407 + fi
3408 +
3409 + # Delete empty parent directories.
3410 + dir="${compiled_file%/*}"
3411 + while [[ "${dir}" != "${root}" ]]; do
3412 + if rmdir "${dir}" 2> /dev/null; then
3413 + _python_vecho "<<< ${dir}"
3414 + else
3415 + break
3416 + fi
3417 + dir="${dir%/*}"
3418 + done
3419 + done
3420 + done
3421 +}
3422 +
3423 +# @FUNCTION: python_mod_optimize
3424 +# @USAGE: [--allow-evaluated-non-sitedir-paths] [-d directory] [-f] [-l] [-q] [-x regular_expression] [--] <file|directory> [files|directories]
3425 +# @DESCRIPTION:
3426 +# Byte-compile specified Python modules.
3427 +# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
3428 +#
3429 +# This function can be used only in pkg_postinst() phase.
3430 +python_mod_optimize() {
3431 + if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
3432 + die "${FUNCNAME}() can be used only in pkg_postinst() phase"
3433 + fi
3434 +
3435 + _python_check_python_pkg_setup_execution
3436 + _python_initialize_prefix_variables
3437 +
3438 + if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
3439 + # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
3440 + 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=() stderr stderr_line
3441 +
3442 + if _python_package_supporting_installation_for_multiple_python_abis; then
3443 + if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
3444 + die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
3445 + fi
3446 + iterated_PYTHON_ABIS="${PYTHON_ABIS}"
3447 + else
3448 + if has "${EAPI:-0}" 0 1 2 3; then
3449 + iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
3450 + else
3451 + iterated_PYTHON_ABIS="${PYTHON_ABI}"
3452 + fi
3453 + fi
3454 +
3455 + # Strip trailing slash from EROOT.
3456 + root="${EROOT%/}"
3457 +
3458 + while (($#)); do
3459 + case "$1" in
3460 + --allow-evaluated-non-sitedir-paths)
3461 + allow_evaluated_non_sitedir_paths="1"
3462 + ;;
3463 + -l|-f|-q)
3464 + options+=("$1")
3465 + ;;
3466 + -d|-x)
3467 + options+=("$1" "$2")
3468 + shift
3469 + ;;
3470 + --)
3471 + shift
3472 + break
3473 + ;;
3474 + -*)
3475 + die "${FUNCNAME}(): Unrecognized option '$1'"
3476 + ;;
3477 + *)
3478 + break
3479 + ;;
3480 + esac
3481 + shift
3482 + done
3483 +
3484 + if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
3485 + die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
3486 + fi
3487 +
3488 + if [[ "$#" -eq 0 ]]; then
3489 + die "${FUNCNAME}(): Missing files or directories"
3490 + fi
3491 +
3492 + while (($#)); do
3493 + if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
3494 + die "${FUNCNAME}(): Invalid argument '$1'"
3495 + elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
3496 + die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
3497 + elif [[ "$1" =~ ^/ ]]; then
3498 + if _python_package_supporting_installation_for_multiple_python_abis; then
3499 + if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
3500 + die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
3501 + fi
3502 + if [[ "$1" != *\$* ]]; then
3503 + die "${FUNCNAME}(): '$1' has invalid syntax"
3504 + fi
3505 + if [[ "$1" == *.py ]]; then
3506 + evaluated_files+=("$1")
3507 + else
3508 + evaluated_dirs+=("$1")
3509 + fi
3510 + else
3511 + if [[ -d "${root}$1" ]]; then
3512 + other_dirs+=("${root}$1")
3513 + elif [[ -f "${root}$1" ]]; then
3514 + other_files+=("${root}$1")
3515 + elif [[ -e "${root}$1" ]]; then
3516 + eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
3517 + else
3518 + eerror "${FUNCNAME}(): '${root}$1' does not exist"
3519 + fi
3520 + fi
3521 + else
3522 + for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
3523 + if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
3524 + site_packages_dirs+=("$1")
3525 + break
3526 + elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
3527 + site_packages_files+=("$1")
3528 + break
3529 + elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
3530 + eerror "${FUNCNAME}(): '$1' is not a regular file or a directory"
3531 + else
3532 + eerror "${FUNCNAME}(): '$1' does not exist"
3533 + fi
3534 + done
3535 + fi
3536 + shift
3537 + done
3538 +
3539 + # Set additional options.
3540 + options+=("-q")
3541 +
3542 + for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
3543 + if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
3544 + return_code="0"
3545 + stderr=""
3546 + ebegin "Compilation and optimization of Python modules for $(python_get_implementation_and_version)"
3547 + if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
3548 + for dir in "${site_packages_dirs[@]}"; do
3549 + dirs+=("${root}$(python_get_sitedir)/${dir}")
3550 + done
3551 + for dir in "${evaluated_dirs[@]}"; do
3552 + eval "dirs+=(\"\${root}${dir}\")"
3553 + done
3554 + stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m compileall "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1"
3555 + if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
3556 + "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &> /dev/null || return_code="1"
3557 + fi
3558 + _python_clean_compiled_modules "${dirs[@]}"
3559 + fi
3560 + if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
3561 + for file in "${site_packages_files[@]}"; do
3562 + files+=("${root}$(python_get_sitedir)/${file}")
3563 + done
3564 + for file in "${evaluated_files[@]}"; do
3565 + eval "files+=(\"\${root}${file}\")"
3566 + done
3567 + stderr+="${stderr:+$'\n'}$("$(PYTHON)" -m py_compile "${files[@]}" 2>&1)" || return_code="1"
3568 + if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
3569 + "$(PYTHON)" -O -m py_compile "${files[@]}" &> /dev/null || return_code="1"
3570 + fi
3571 + _python_clean_compiled_modules "${files[@]}"
3572 + fi
3573 + eend "${return_code}"
3574 + if [[ -n "${stderr}" ]]; then
3575 + eerror "Syntax errors / warnings in Python modules for $(python_get_implementation_and_version):" &> /dev/null
3576 + while read stderr_line; do
3577 + eerror " ${stderr_line}"
3578 + done <<< "${stderr}"
3579 + fi
3580 + fi
3581 + unset dirs files
3582 + done
3583 +
3584 + if _python_package_supporting_installation_for_multiple_python_abis; then
3585 + # Restore previous value of PYTHON_ABI.
3586 + if [[ -n "${previous_PYTHON_ABI}" ]]; then
3587 + PYTHON_ABI="${previous_PYTHON_ABI}"
3588 + else
3589 + unset PYTHON_ABI
3590 + fi
3591 + fi
3592 +
3593 + if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
3594 + return_code="0"
3595 + stderr=""
3596 + ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)"
3597 + if ((${#other_dirs[@]})); then
3598 + stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m compileall "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1"
3599 + if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
3600 + "$(PYTHON ${PYTHON_ABI})" -O -m compileall "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
3601 + fi
3602 + _python_clean_compiled_modules "${other_dirs[@]}"
3603 + fi
3604 + if ((${#other_files[@]})); then
3605 + stderr+="${stderr:+$'\n'}$("$(PYTHON ${PYTHON_ABI})" -m py_compile "${other_files[@]}" 2>&1)" || return_code="1"
3606 + if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
3607 + "$(PYTHON ${PYTHON_ABI})" -O -m py_compile "${other_files[@]}" &> /dev/null || return_code="1"
3608 + fi
3609 + _python_clean_compiled_modules "${other_files[@]}"
3610 + fi
3611 + eend "${return_code}"
3612 + if [[ -n "${stderr}" ]]; then
3613 + eerror "Syntax errors / warnings in Python modules placed outside of site-packages directories for $(python_get_implementation_and_version):" &> /dev/null
3614 + while read stderr_line; do
3615 + eerror " ${stderr_line}"
3616 + done <<< "${stderr}"
3617 + fi
3618 + fi
3619 + else
3620 + # Deprecated part of python_mod_optimize()
3621 +
3622 + local myroot mydirs=() myfiles=() myopts=() return_code="0"
3623 +
3624 + # strip trailing slash
3625 + myroot="${EROOT%/}"
3626 +
3627 + # respect EROOT and options passed to compileall.py
3628 + while (($#)); do
3629 + case "$1" in
3630 + -l|-f|-q)
3631 + myopts+=("$1")
3632 + ;;
3633 + -d|-x)
3634 + myopts+=("$1" "$2")
3635 + shift
3636 + ;;
3637 + --)
3638 + shift
3639 + break
3640 + ;;
3641 + -*)
3642 + die "${FUNCNAME}(): Unrecognized option '$1'"
3643 + ;;
3644 + *)
3645 + break
3646 + ;;
3647 + esac
3648 + shift
3649 + done
3650 +
3651 + if [[ "$#" -eq 0 ]]; then
3652 + die "${FUNCNAME}(): Missing files or directories"
3653 + fi
3654 +
3655 + while (($#)); do
3656 + if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
3657 + die "${FUNCNAME}(): Invalid argument '$1'"
3658 + elif [[ -d "${myroot}/${1#/}" ]]; then
3659 + mydirs+=("${myroot}/${1#/}")
3660 + elif [[ -f "${myroot}/${1#/}" ]]; then
3661 + myfiles+=("${myroot}/${1#/}")
3662 + elif [[ -e "${myroot}/${1#/}" ]]; then
3663 + eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory"
3664 + else
3665 + eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist"
3666 + fi
3667 + shift
3668 + done
3669 +
3670 + # set additional opts
3671 + myopts+=(-q)
3672 +
3673 + PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
3674 +
3675 + ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
3676 + if ((${#mydirs[@]})); then
3677 + "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1"
3678 + "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
3679 + _python_clean_compiled_modules "${mydirs[@]}"
3680 + fi
3681 +
3682 + if ((${#myfiles[@]})); then
3683 + "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1"
3684 + "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null || return_code="1"
3685 + _python_clean_compiled_modules "${myfiles[@]}"
3686 + fi
3687 +
3688 + eend "${return_code}"
3689 + fi
3690 +}
3691 +
3692 +# @FUNCTION: python_mod_cleanup
3693 +# @USAGE: [--allow-evaluated-non-sitedir-paths] [--] <file|directory> [files|directories]
3694 +# @DESCRIPTION:
3695 +# Delete orphaned byte-compiled Python modules corresponding to specified Python modules.
3696 +#
3697 +# This function can be used only in pkg_postrm() phase.
3698 +python_mod_cleanup() {
3699 + if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
3700 + die "${FUNCNAME}() can be used only in pkg_postrm() phase"
3701 + fi
3702 +
3703 + _python_check_python_pkg_setup_execution
3704 + _python_initialize_prefix_variables
3705 +
3706 + local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
3707 +
3708 + if _python_package_supporting_installation_for_multiple_python_abis; then
3709 + if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
3710 + die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
3711 + fi
3712 + iterated_PYTHON_ABIS="${PYTHON_ABIS}"
3713 + else
3714 + if has "${EAPI:-0}" 0 1 2 3; then
3715 + iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
3716 + else
3717 + iterated_PYTHON_ABIS="${PYTHON_ABI}"
3718 + fi
3719 + fi
3720 +
3721 + # Strip trailing slash from EROOT.
3722 + root="${EROOT%/}"
3723 +
3724 + while (($#)); do
3725 + case "$1" in
3726 + --allow-evaluated-non-sitedir-paths)
3727 + allow_evaluated_non_sitedir_paths="1"
3728 + ;;
3729 + --)
3730 + shift
3731 + break
3732 + ;;
3733 + -*)
3734 + die "${FUNCNAME}(): Unrecognized option '$1'"
3735 + ;;
3736 + *)
3737 + break
3738 + ;;
3739 + esac
3740 + shift
3741 + done
3742 +
3743 + if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
3744 + die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
3745 + fi
3746 +
3747 + if [[ "$#" -eq 0 ]]; then
3748 + die "${FUNCNAME}(): Missing files or directories"
3749 + fi
3750 +
3751 + if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
3752 + while (($#)); do
3753 + if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
3754 + die "${FUNCNAME}(): Invalid argument '$1'"
3755 + elif ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
3756 + die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
3757 + elif [[ "$1" =~ ^/ ]]; then
3758 + if _python_package_supporting_installation_for_multiple_python_abis; then
3759 + if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
3760 + die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
3761 + fi
3762 + if [[ "$1" != *\$* ]]; then
3763 + die "${FUNCNAME}(): '$1' has invalid syntax"
3764 + fi
3765 + for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
3766 + eval "search_paths+=(\"\${root}$1\")"
3767 + done
3768 + else
3769 + search_paths+=("${root}$1")
3770 + fi
3771 + else
3772 + for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
3773 + search_paths+=("${root}$(python_get_sitedir)/$1")
3774 + done
3775 + fi
3776 + shift
3777 + done
3778 + else
3779 + # Deprecated part of python_mod_cleanup()
3780 +
3781 + search_paths=("${@#/}")
3782 + search_paths=("${search_paths[@]/#/${root}/}")
3783 + fi
3784 +
3785 + _python_clean_compiled_modules "${search_paths[@]}"
3786 +}
3787 +
3788 +# ================================================================================================
3789 +# ===================================== DEPRECATED FUNCTIONS =====================================
3790 +# ================================================================================================
3791 +
3792 +fi # _PYTHON_ECLASS_INHERITED