Browse code

deprecated eclasses für rdiff-backup

Hanno Böck authored on 02/04/2017 23:46:03
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,599 @@
1
+# Copyright 1999-2017 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+
4
+# @DEAD
5
+# Removal on 2017-03-18.
6
+
7
+# @ECLASS: distutils.eclass
8
+# @MAINTAINER:
9
+# Gentoo Python Project <python@gentoo.org>
10
+# @BLURB: Eclass for packages with build systems using Distutils
11
+# @DESCRIPTION:
12
+# The distutils eclass defines phase functions for packages with build systems using Distutils.
13
+#
14
+# This eclass is DEPRECATED. Please use distutils-r1 instead.
15
+
16
+if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then
17
+	inherit python
18
+fi
19
+
20
+inherit multilib
21
+
22
+case "${EAPI:-0}" in
23
+	6)
24
+		die "${ECLASS}.eclass is banned in EAPI ${EAPI}"
25
+		;;
26
+	0|1)
27
+		EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm
28
+		;;
29
+	*)
30
+		EXPORT_FUNCTIONS src_prepare src_compile src_install pkg_postinst pkg_postrm
31
+		;;
32
+esac
33
+
34
+if [[ -z "$(declare -p PYTHON_DEPEND 2> /dev/null)" ]]; then
35
+	DEPEND="dev-lang/python"
36
+	RDEPEND="${DEPEND}"
37
+fi
38
+
39
+	if has "${EAPI:-0}" 0 1 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
40
+		ewarn
41
+		ewarn "\"${EBUILD}\":"
42
+		ewarn "Deprecation Warning: Usage of distutils.eclass in packages supporting installation"
43
+		ewarn "for multiple Python ABIs in EAPI <=1 is deprecated."
44
+		ewarn "The ebuild should to be fixed. Please report a bug, if it has not been already reported."
45
+		ewarn
46
+	elif has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
47
+		ewarn
48
+		ewarn "\"${EBUILD}\":"
49
+		ewarn "Deprecation Warning: Usage of distutils.eclass in packages not supporting installation"
50
+		ewarn "for multiple Python ABIs in EAPI <=2 is deprecated."
51
+		ewarn "The ebuild should to be fixed. Please report a bug, if it has not been already reported."
52
+		ewarn
53
+	fi
54
+
55
+# 'python' variable is deprecated. Use PYTHON() instead.
56
+if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
57
+	python="python"
58
+else
59
+	python="die"
60
+fi
61
+
62
+# @ECLASS-VARIABLE: DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES
63
+# @DESCRIPTION:
64
+# Set this to use separate source directories for each enabled version of Python.
65
+
66
+# @ECLASS-VARIABLE: DISTUTILS_SETUP_FILES
67
+# @DESCRIPTION:
68
+# Array of paths to setup files.
69
+# Syntax:
70
+#   [current_working_directory|]path_to_setup_file
71
+
72
+# @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS
73
+# @DESCRIPTION:
74
+# Array of global options passed to setup files.
75
+# Syntax in EAPI <4:
76
+#   global_option
77
+# Syntax in EAPI >=4:
78
+#   Python_ABI_pattern global_option
79
+
80
+# @ECLASS-VARIABLE: DISTUTILS_SRC_TEST
81
+# @DESCRIPTION:
82
+# Type of test command used by distutils_src_test().
83
+# IUSE and DEPEND are automatically adjusted, unless DISTUTILS_DISABLE_TEST_DEPENDENCY is set.
84
+# Valid values:
85
+#   setup.py
86
+#   nosetests
87
+#   py.test
88
+#   trial [arguments]
89
+
90
+# @ECLASS-VARIABLE: DISTUTILS_DISABLE_TEST_DEPENDENCY
91
+# @DESCRIPTION:
92
+# Disable modification of IUSE and DEPEND caused by setting of DISTUTILS_SRC_TEST.
93
+
94
+if [[ -n "${DISTUTILS_SRC_TEST}" && ! "${DISTUTILS_SRC_TEST}" =~ ^(setup\.py|nosetests|py\.test|trial(\ .*)?)$ ]]; then
95
+	die "'DISTUTILS_SRC_TEST' variable has unsupported value '${DISTUTILS_SRC_TEST}'"
96
+fi
97
+
98
+if [[ -z "${DISTUTILS_DISABLE_TEST_DEPENDENCY}" ]]; then
99
+	if [[ "${DISTUTILS_SRC_TEST}" == "nosetests" ]]; then
100
+		IUSE="test"
101
+		DEPEND+="${DEPEND:+ }test? ( dev-python/nose )"
102
+	elif [[ "${DISTUTILS_SRC_TEST}" == "py.test" ]]; then
103
+		IUSE="test"
104
+		DEPEND+="${DEPEND:+ }test? ( dev-python/pytest )"
105
+	# trial requires an argument, which is usually equal to "${PN}".
106
+	elif [[ "${DISTUTILS_SRC_TEST}" =~ ^trial(\ .*)?$ ]]; then
107
+		IUSE="test"
108
+		DEPEND+="${DEPEND:+ }test? ( dev-python/twisted-core )"
109
+	fi
110
+fi
111
+
112
+if [[ -n "${DISTUTILS_SRC_TEST}" ]]; then
113
+	EXPORT_FUNCTIONS src_test
114
+fi
115
+
116
+# Scheduled for deletion on 2011-06-01.
117
+if [[ -n "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" ]]; then
118
+	eerror "Use PYTHON_NONVERSIONED_EXECUTABLES=(\".*\") instead of DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS variable."
119
+	die "DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS variable is banned"
120
+fi
121
+
122
+# @ECLASS-VARIABLE: DOCS
123
+# @DESCRIPTION:
124
+# Additional documentation files installed by distutils_src_install().
125
+
126
+_distutils_get_build_dir() {
127
+	if _python_package_supporting_installation_for_multiple_python_abis && [[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
128
+		echo "build-${PYTHON_ABI}"
129
+	else
130
+		echo "build"
131
+	fi
132
+}
133
+
134
+_distutils_get_PYTHONPATH() {
135
+	if _python_package_supporting_installation_for_multiple_python_abis && [[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
136
+		ls -d build-${PYTHON_ABI}/lib* 2> /dev/null
137
+	else
138
+		ls -d build/lib* 2> /dev/null
139
+	fi
140
+}
141
+
142
+_distutils_hook() {
143
+	if [[ "$#" -ne 1 ]]; then
144
+		die "${FUNCNAME}() requires 1 argument"
145
+	fi
146
+	if [[ "$(type -t "distutils_src_${EBUILD_PHASE}_$1_hook")" == "function" ]]; then
147
+		"distutils_src_${EBUILD_PHASE}_$1_hook"
148
+	fi
149
+}
150
+
151
+_distutils_prepare_global_options() {
152
+	local element option pattern
153
+
154
+	if [[ -n "$(declare -p DISTUTILS_GLOBAL_OPTIONS 2> /dev/null)" && "$(declare -p DISTUTILS_GLOBAL_OPTIONS)" != "declare -a DISTUTILS_GLOBAL_OPTIONS="* ]]; then
155
+		die "DISTUTILS_GLOBAL_OPTIONS should be indexed array"
156
+	fi
157
+
158
+	if has "${EAPI:-0}" 0 1 2 3; then
159
+		_DISTUTILS_GLOBAL_OPTIONS=("${DISTUTILS_GLOBAL_OPTIONS[@]}")
160
+	else
161
+		_DISTUTILS_GLOBAL_OPTIONS=()
162
+
163
+		for element in "${DISTUTILS_GLOBAL_OPTIONS[@]}"; do
164
+			if [[ ! "${element}" =~ ^[^[:space:]]+\ . ]]; then
165
+				die "Element '${element}' of DISTUTILS_GLOBAL_OPTIONS array has invalid syntax"
166
+			fi
167
+			pattern="${element%% *}"
168
+			option="${element#* }"
169
+			if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
170
+				_DISTUTILS_GLOBAL_OPTIONS+=("${option}")
171
+			fi
172
+		done
173
+	fi
174
+}
175
+
176
+_distutils_prepare_current_working_directory() {
177
+	if [[ "$1" == *"|"*"|"* ]]; then
178
+		die "Element '$1' of DISTUTILS_SETUP_FILES array has invalid syntax"
179
+	fi
180
+
181
+	if [[ "$1" == *"|"* ]]; then
182
+		echo "${_BOLD}[${1%|*}]${_NORMAL}"
183
+		pushd "${1%|*}" > /dev/null || die "Entering directory '${1%|*}' failed"
184
+	fi
185
+}
186
+
187
+_distutils_restore_current_working_directory() {
188
+	if [[ "$1" == *"|"* ]]; then
189
+		popd > /dev/null || die "Leaving directory '${1%|*}' failed"
190
+	fi
191
+}
192
+
193
+# @FUNCTION: distutils_src_unpack
194
+# @DESCRIPTION:
195
+# The distutils src_unpack function. This function is exported.
196
+distutils_src_unpack() {
197
+	if ! has "${EAPI:-0}" 0 1; then
198
+		die "${FUNCNAME}() cannot be used in this EAPI"
199
+	fi
200
+
201
+	if [[ "${EBUILD_PHASE}" != "unpack" ]]; then
202
+		die "${FUNCNAME}() can be used only in src_unpack() phase"
203
+	fi
204
+
205
+	unpack ${A}
206
+	cd "${S}"
207
+
208
+	distutils_src_prepare
209
+}
210
+
211
+# @FUNCTION: distutils_src_prepare
212
+# @DESCRIPTION:
213
+# The distutils src_prepare function. This function is exported.
214
+distutils_src_prepare() {
215
+	if ! has "${EAPI:-0}" 0 1 && [[ "${EBUILD_PHASE}" != "prepare" ]]; then
216
+		die "${FUNCNAME}() can be used only in src_prepare() phase"
217
+	fi
218
+
219
+	_python_check_python_pkg_setup_execution
220
+
221
+	local distribute_setup_existence="0" ez_setup_existence="0"
222
+
223
+	if [[ "$#" -ne 0 ]]; then
224
+		die "${FUNCNAME}() does not accept arguments"
225
+	fi
226
+
227
+	# Delete ez_setup files to prevent packages from installing Setuptools on their own.
228
+	[[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1"
229
+	rm -fr ez_setup*
230
+	if [[ "${ez_setup_existence}" == "1" ]]; then
231
+		echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py
232
+	fi
233
+
234
+	# Delete distribute_setup files to prevent packages from installing Distribute on their own.
235
+	[[ -d distribute_setup || -f distribute_setup.py ]] && distribute_setup_existence="1"
236
+	rm -fr distribute_setup*
237
+	if [[ "${distribute_setup_existence}" == "1" ]]; then
238
+		echo "def use_setuptools(*args, **kwargs): pass" > distribute_setup.py
239
+	fi
240
+
241
+	if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
242
+		python_copy_sources
243
+	fi
244
+}
245
+
246
+# @FUNCTION: distutils_src_compile
247
+# @DESCRIPTION:
248
+# The distutils src_compile function. This function is exported.
249
+# In ebuilds of packages supporting installation for multiple versions of Python, this function
250
+# calls distutils_src_compile_pre_hook() and distutils_src_compile_post_hook(), if they are defined.
251
+distutils_src_compile() {
252
+	if [[ "${EBUILD_PHASE}" != "compile" ]]; then
253
+		die "${FUNCNAME}() can be used only in src_compile() phase"
254
+	fi
255
+
256
+	_python_check_python_pkg_setup_execution
257
+	_python_set_color_variables
258
+
259
+	local setup_file
260
+
261
+	if _python_package_supporting_installation_for_multiple_python_abis; then
262
+		distutils_building() {
263
+			_distutils_hook pre
264
+
265
+			_distutils_prepare_global_options
266
+
267
+			for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
268
+				_distutils_prepare_current_working_directory "${setup_file}"
269
+
270
+				echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "$(_distutils_get_build_dir)" "$@"${_NORMAL}
271
+				"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "$(_distutils_get_build_dir)" "$@" || return "$?"
272
+
273
+				_distutils_restore_current_working_directory "${setup_file}"
274
+			done
275
+
276
+			_distutils_hook post
277
+		}
278
+		python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_building "$@"
279
+		unset -f distutils_building
280
+	else
281
+		_distutils_prepare_global_options
282
+
283
+		for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
284
+			_distutils_prepare_current_working_directory "${setup_file}"
285
+
286
+			echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"${_NORMAL}
287
+			"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || die "Building failed"
288
+
289
+			_distutils_restore_current_working_directory "${setup_file}"
290
+		done
291
+	fi
292
+}
293
+
294
+_distutils_src_test_hook() {
295
+	if [[ "$#" -ne 1 ]]; then
296
+		die "${FUNCNAME}() requires 1 arguments"
297
+	fi
298
+
299
+	if ! _python_package_supporting_installation_for_multiple_python_abis; then
300
+		return
301
+	fi
302
+
303
+	if [[ "$(type -t "distutils_src_test_pre_hook")" == "function" ]]; then
304
+		eval "python_execute_$1_pre_hook() {
305
+			distutils_src_test_pre_hook
306
+		}"
307
+	fi
308
+
309
+	if [[ "$(type -t "distutils_src_test_post_hook")" == "function" ]]; then
310
+		eval "python_execute_$1_post_hook() {
311
+			distutils_src_test_post_hook
312
+		}"
313
+	fi
314
+}
315
+
316
+# @FUNCTION: distutils_src_test
317
+# @DESCRIPTION:
318
+# The distutils src_test function. This function is exported, when DISTUTILS_SRC_TEST variable is set.
319
+# In ebuilds of packages supporting installation for multiple versions of Python, this function
320
+# calls distutils_src_test_pre_hook() and distutils_src_test_post_hook(), if they are defined.
321
+distutils_src_test() {
322
+	if [[ "${EBUILD_PHASE}" != "test" ]]; then
323
+		die "${FUNCNAME}() can be used only in src_test() phase"
324
+	fi
325
+
326
+	_python_check_python_pkg_setup_execution
327
+	_python_set_color_variables
328
+
329
+	local arguments setup_file
330
+
331
+	if [[ "${DISTUTILS_SRC_TEST}" == "setup.py" ]]; then
332
+		if _python_package_supporting_installation_for_multiple_python_abis; then
333
+			distutils_testing() {
334
+				_distutils_hook pre
335
+
336
+				_distutils_prepare_global_options
337
+
338
+				for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
339
+					_distutils_prepare_current_working_directory "${setup_file}"
340
+
341
+					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}
342
+					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 "$?"
343
+
344
+					_distutils_restore_current_working_directory "${setup_file}"
345
+				done
346
+
347
+				_distutils_hook post
348
+			}
349
+			python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_testing "$@"
350
+			unset -f distutils_testing
351
+		else
352
+			_distutils_prepare_global_options
353
+
354
+			for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
355
+				_distutils_prepare_current_working_directory "${setup_file}"
356
+
357
+				echo ${_BOLD}PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" test "$@"${_NORMAL}
358
+				PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" test "$@" || die "Testing failed"
359
+
360
+				_distutils_restore_current_working_directory "${setup_file}"
361
+			done
362
+		fi
363
+	elif [[ "${DISTUTILS_SRC_TEST}" == "nosetests" ]]; then
364
+		_distutils_src_test_hook nosetests
365
+
366
+		python_execute_nosetests -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- "$@"
367
+	elif [[ "${DISTUTILS_SRC_TEST}" == "py.test" ]]; then
368
+		_distutils_src_test_hook py.test
369
+
370
+		python_execute_py.test -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- "$@"
371
+	# trial requires an argument, which is usually equal to "${PN}".
372
+	elif [[ "${DISTUTILS_SRC_TEST}" =~ ^trial(\ .*)?$ ]]; then
373
+		if [[ "${DISTUTILS_SRC_TEST}" == "trial "* ]]; then
374
+			arguments="${DISTUTILS_SRC_TEST#trial }"
375
+		else
376
+			arguments="${PN}"
377
+		fi
378
+
379
+		_distutils_src_test_hook trial
380
+
381
+		python_execute_trial -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- ${arguments} "$@"
382
+	else
383
+		die "'DISTUTILS_SRC_TEST' variable has unsupported value '${DISTUTILS_SRC_TEST}'"
384
+	fi
385
+}
386
+
387
+# @FUNCTION: distutils_src_install
388
+# @DESCRIPTION:
389
+# The distutils src_install function. This function is exported.
390
+# In ebuilds of packages supporting installation for multiple versions of Python, this function
391
+# calls distutils_src_install_pre_hook() and distutils_src_install_post_hook(), if they are defined.
392
+# It also installs some standard documentation files (AUTHORS, Change*, CHANGELOG, CONTRIBUTORS,
393
+# KNOWN_BUGS, MAINTAINERS, NEWS, README*, TODO).
394
+distutils_src_install() {
395
+	if [[ "${EBUILD_PHASE}" != "install" ]]; then
396
+		die "${FUNCNAME}() can be used only in src_install() phase"
397
+	fi
398
+
399
+	_python_check_python_pkg_setup_execution
400
+	_python_initialize_prefix_variables
401
+	_python_set_color_variables
402
+
403
+	local default_docs doc line nspkg_pth_file nspkg_pth_files=() setup_file
404
+
405
+	if _python_package_supporting_installation_for_multiple_python_abis; then
406
+		distutils_installation() {
407
+			_distutils_hook pre
408
+
409
+			_distutils_prepare_global_options
410
+
411
+			for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
412
+				_distutils_prepare_current_working_directory "${setup_file}"
413
+
414
+				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}
415
+				"$(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 "$?"
416
+
417
+				_distutils_restore_current_working_directory "${setup_file}"
418
+			done
419
+
420
+			_distutils_hook post
421
+		}
422
+		python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_installation "$@"
423
+		unset -f distutils_installation
424
+
425
+		python_merge_intermediate_installation_images "${T}/images"
426
+	else
427
+		# Mark the package to be rebuilt after a Python upgrade.
428
+		python_need_rebuild
429
+
430
+		_distutils_prepare_global_options
431
+
432
+		for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
433
+			_distutils_prepare_current_working_directory "${setup_file}"
434
+
435
+			echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@"${_NORMAL}
436
+			"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || die "Installation failed"
437
+
438
+			_distutils_restore_current_working_directory "${setup_file}"
439
+		done
440
+	fi
441
+
442
+	while read -d $'\0' -r nspkg_pth_file; do
443
+		nspkg_pth_files+=("${nspkg_pth_file}")
444
+	done < <(find "${ED}" -name "*-nspkg.pth" -type f -print0)
445
+
446
+	if [[ "${#nspkg_pth_files[@]}" -gt 0 ]]; then
447
+		einfo
448
+		einfo "Python namespaces:"
449
+		for nspkg_pth_file in "${nspkg_pth_files[@]}"; do
450
+			einfo "    '${nspkg_pth_file#${ED%/}}':"
451
+			while read -r line; do
452
+				einfo "        $(echo "${line}" | sed -e "s/.*types\.ModuleType('\([^']\+\)').*/\1/")"
453
+			done < "${nspkg_pth_file}"
454
+			#if ! has "${EAPI:-0}" 0 1 2 3; then
455
+			#	rm -f "${nspkg_pth_file}" || die "Deletion of '${nspkg_pth_file}' failed"
456
+			#fi
457
+		done
458
+		einfo
459
+	fi
460
+
461
+	if [[ -e "${ED}usr/local" ]]; then
462
+		die "Illegal installation into /usr/local"
463
+	fi
464
+
465
+	default_docs="AUTHORS Change* CHANGELOG CONTRIBUTORS KNOWN_BUGS MAINTAINERS NEWS README* TODO"
466
+
467
+	for doc in ${default_docs}; do
468
+		[[ -s "${doc}" ]] && dodoc "${doc}"
469
+	done
470
+
471
+	if has "${EAPI:-0}" 0 1 2 3; then
472
+		if [[ -n "${DOCS}" ]]; then
473
+			dodoc ${DOCS} || die "dodoc failed"
474
+		fi
475
+	else
476
+		if [[ -n "${DOCS}" ]]; then
477
+			dodoc -r ${DOCS} || die "dodoc failed"
478
+		fi
479
+	fi
480
+
481
+	DISTUTILS_SRC_INSTALL_EXECUTED="1"
482
+}
483
+
484
+# @FUNCTION: distutils_pkg_postinst
485
+# @DESCRIPTION:
486
+# The distutils pkg_postinst function. This function is exported.
487
+# When PYTHON_MODNAME variable is set, then this function calls python_mod_optimize() with modules
488
+# specified in PYTHON_MODNAME variable. Otherwise it calls python_mod_optimize() with module, whose
489
+# name is equal to name of current package, if this module exists.
490
+distutils_pkg_postinst() {
491
+	if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
492
+		die "${FUNCNAME}() can be used only in pkg_postinst() phase"
493
+	fi
494
+
495
+	_python_check_python_pkg_setup_execution
496
+	_python_initialize_prefix_variables
497
+
498
+	if [[ -z "${DISTUTILS_SRC_INSTALL_EXECUTED}" ]]; then
499
+		die "${FUNCNAME}() called illegally"
500
+	fi
501
+
502
+	local pylibdir pymod
503
+
504
+	if [[ "$#" -ne 0 ]]; then
505
+		die "${FUNCNAME}() does not accept arguments"
506
+	fi
507
+
508
+	if [[ -z "$(declare -p PYTHON_MODNAME 2> /dev/null)" ]]; then
509
+		for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"usr/share/jython-*/Lib; do
510
+			if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
511
+				PYTHON_MODNAME="${PN}"
512
+			fi
513
+		done
514
+	fi
515
+
516
+	if [[ -n "${PYTHON_MODNAME}" ]]; then
517
+		if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
518
+			python_mod_optimize ${PYTHON_MODNAME}
519
+		else
520
+			for pymod in ${PYTHON_MODNAME}; do
521
+				python_mod_optimize "$(python_get_sitedir)/${pymod}"
522
+			done
523
+		fi
524
+	fi
525
+}
526
+
527
+# @FUNCTION: distutils_pkg_postrm
528
+# @DESCRIPTION:
529
+# The distutils pkg_postrm function. This function is exported.
530
+# When PYTHON_MODNAME variable is set, then this function calls python_mod_cleanup() with modules
531
+# specified in PYTHON_MODNAME variable. Otherwise it calls python_mod_cleanup() with module, whose
532
+# name is equal to name of current package, if this module exists.
533
+distutils_pkg_postrm() {
534
+	if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
535
+		die "${FUNCNAME}() can be used only in pkg_postrm() phase"
536
+	fi
537
+
538
+	_python_check_python_pkg_setup_execution
539
+	_python_initialize_prefix_variables
540
+
541
+	if [[ -z "${DISTUTILS_SRC_INSTALL_EXECUTED}" ]]; then
542
+		die "${FUNCNAME}() called illegally"
543
+	fi
544
+
545
+	local pylibdir pymod
546
+
547
+	if [[ "$#" -ne 0 ]]; then
548
+		die "${FUNCNAME}() does not accept arguments"
549
+	fi
550
+
551
+	if [[ -z "$(declare -p PYTHON_MODNAME 2> /dev/null)" ]]; then
552
+		for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"usr/share/jython-*/Lib; do
553
+			if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
554
+				PYTHON_MODNAME="${PN}"
555
+			fi
556
+		done
557
+	fi
558
+
559
+	if [[ -n "${PYTHON_MODNAME}" ]]; then
560
+		if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
561
+			python_mod_cleanup ${PYTHON_MODNAME}
562
+		else
563
+			for pymod in ${PYTHON_MODNAME}; do
564
+				for pylibdir in "${EROOT}"usr/$(get_libdir)/python*; do
565
+					if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then
566
+						python_mod_cleanup "${pylibdir#${EROOT%/}}/site-packages/${pymod}"
567
+					fi
568
+				done
569
+			done
570
+		fi
571
+	fi
572
+}
573
+
574
+# @FUNCTION: distutils_get_intermediate_installation_image
575
+# @DESCRIPTION:
576
+# Print path to intermediate installation image.
577
+#
578
+# This function can be used only in distutils_src_install_pre_hook() and distutils_src_install_post_hook().
579
+distutils_get_intermediate_installation_image() {
580
+	if [[ "${EBUILD_PHASE}" != "install" ]]; then
581
+		die "${FUNCNAME}() can be used only in src_install() phase"
582
+	fi
583
+
584
+	if ! _python_package_supporting_installation_for_multiple_python_abis; then
585
+		die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
586
+	fi
587
+
588
+	_python_check_python_pkg_setup_execution
589
+
590
+	if [[ ! "${FUNCNAME[1]}" =~ ^distutils_src_install_(pre|post)_hook$ ]]; then
591
+		die "${FUNCNAME}() can be used only in distutils_src_install_pre_hook() and distutils_src_install_post_hook()"
592
+	fi
593
+
594
+	if [[ "$#" -ne 0 ]]; then
595
+		die "${FUNCNAME}() does not accept arguments"
596
+	fi
597
+
598
+	echo "${T}/images/${PYTHON_ABI}"
599
+}
0 600
new file mode 100644
... ...
@@ -0,0 +1,3167 @@
1
+# Copyright 1999-2017 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+
4
+# @DEAD
5
+# Removal on 2017-03-21.
6
+
7
+# @ECLASS: python.eclass
8
+# @MAINTAINER:
9
+# Gentoo Python Project <python@gentoo.org>
10
+# @BLURB: Eclass for Python packages
11
+# @DESCRIPTION:
12
+# The python eclass contains miscellaneous, useful functions for Python packages.
13
+#
14
+# This eclass is DEPRECATED. Please use python-r1, python-single-r1
15
+# or python-any-r1 instead.
16
+
17
+if [[ ${EAPI} == 6 ]]; then
18
+	die "${ECLASS}.eclass is banned in EAPI ${EAPI}"
19
+fi
20
+
21
+if [[ ${_PYTHON_UTILS_R1} ]]; then
22
+	die 'python.eclass can not be used with python-r1 suite eclasses.'
23
+fi
24
+
25
+# Must call inherit before EXPORT_FUNCTIONS to avoid QA warning.
26
+if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then
27
+	inherit multilib
28
+fi
29
+
30
+# Export pkg_setup every time to avoid issues with eclass inheritance order.
31
+if ! has "${EAPI:-0}" 0 1 2 3 || { has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; }; then
32
+	EXPORT_FUNCTIONS pkg_setup
33
+fi
34
+
35
+# Avoid processing this eclass more than once.
36
+if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then
37
+_PYTHON_ECLASS_INHERITED="1"
38
+
39
+if ! has "${EAPI:-0}" 0 1 2 3 4 5; then
40
+	die "API of python.eclass in EAPI=\"${EAPI}\" not established"
41
+fi
42
+
43
+# Please do not add any new versions of Python here! Instead, please
44
+# focus on converting packages to use the new eclasses.
45
+
46
+_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
47
+_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2 3.3)
48
+_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython 2.7-jython)
49
+_PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8 2.7-pypy-1.9 2.7-pypy-2.0)
50
+_PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]})
51
+
52
+# ================================================================================================
53
+# ===================================== HANDLING OF METADATA =====================================
54
+# ================================================================================================
55
+
56
+_PYTHON_ABI_PATTERN_REGEX="([[:alnum:]]|\.|-|\*|\[|\])+"
57
+
58
+_python_check_python_abi_matching() {
59
+	local pattern patterns patterns_list="0" PYTHON_ABI
60
+
61
+	while (($#)); do
62
+		case "$1" in
63
+			--patterns-list)
64
+				patterns_list="1"
65
+				;;
66
+			--)
67
+				shift
68
+				break
69
+				;;
70
+			-*)
71
+				die "${FUNCNAME}(): Unrecognized option '$1'"
72
+				;;
73
+			*)
74
+				break
75
+				;;
76
+		esac
77
+		shift
78
+	done
79
+
80
+	if [[ "$#" -ne 2 ]]; then
81
+		die "${FUNCNAME}() requires 2 arguments"
82
+	fi
83
+
84
+	PYTHON_ABI="$1"
85
+
86
+	if [[ "${patterns_list}" == "0" ]]; then
87
+		pattern="$2"
88
+
89
+		if [[ "${pattern}" == *"-cpython" ]]; then
90
+			[[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ && "${PYTHON_ABI}" == ${pattern%-cpython} ]]
91
+		elif [[ "${pattern}" == *"-jython" ]]; then
92
+			[[ "${PYTHON_ABI}" == ${pattern} ]]
93
+		elif [[ "${pattern}" == *"-pypy-"* ]]; then
94
+			[[ "${PYTHON_ABI}" == ${pattern} ]]
95
+		else
96
+			if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
97
+				[[ "${PYTHON_ABI}" == ${pattern} ]]
98
+			elif [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
99
+				[[ "${PYTHON_ABI%-jython}" == ${pattern} ]]
100
+			elif [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then
101
+				[[ "${PYTHON_ABI%-pypy-*}" == ${pattern} ]]
102
+			else
103
+				die "${FUNCNAME}(): Unrecognized Python ABI '${PYTHON_ABI}'"
104
+			fi
105
+		fi
106
+	else
107
+		patterns="${2// /$'\n'}"
108
+
109
+		while read pattern; do
110
+			if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
111
+				return 0
112
+			fi
113
+		done <<< "${patterns}"
114
+
115
+		return 1
116
+	fi
117
+}
118
+
119
+_python_implementation() {
120
+	if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
121
+		return 0
122
+	elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
123
+		return 0
124
+	elif [[ "${CATEGORY}/${PN}" == "virtual/pypy" ]]; then
125
+		return 0
126
+	else
127
+		return 1
128
+	fi
129
+}
130
+
131
+_python_package_supporting_installation_for_multiple_python_abis() {
132
+	[[ -n "${SUPPORT_PYTHON_ABIS}" ]]
133
+}
134
+
135
+# @ECLASS-VARIABLE: PYTHON_DEPEND
136
+# @DESCRIPTION:
137
+# Specification of dependency on dev-lang/python.
138
+# Syntax:
139
+#   PYTHON_DEPEND:             [[!]USE_flag? ]<version_components_group>[ version_components_group]
140
+#   version_components_group:  <major_version[:[minimal_version][:maximal_version]]>
141
+#   major_version:             <2|3|*>
142
+#   minimal_version:           <minimal_major_version.minimal_minor_version>
143
+#   maximal_version:           <maximal_major_version.maximal_minor_version>
144
+
145
+_python_parse_PYTHON_DEPEND() {
146
+	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
147
+
148
+	version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
149
+	version_components_groups="${PYTHON_DEPEND}"
150
+
151
+	if [[ "${version_components_groups}" =~ ^((\!)?[[:alnum:]_-]+\?\ )?${version_components_group_regex}(\ ${version_components_group_regex})?$ ]]; then
152
+		if [[ "${version_components_groups}" =~ ^(\!)?[[:alnum:]_-]+\? ]]; then
153
+			USE_flag="${version_components_groups%\? *}"
154
+			version_components_groups="${version_components_groups#* }"
155
+		fi
156
+		if [[ "${version_components_groups}" =~ ("*".*" "|" *"|^2.*\ (2|\*)|^3.*\ (3|\*)) ]]; then
157
+			die "Invalid syntax of PYTHON_DEPEND: Incorrectly specified groups of versions"
158
+		fi
159
+
160
+		version_components_groups="${version_components_groups// /$'\n'}"
161
+		while read version_components_group; do
162
+			major_version="${version_components_group:0:1}"
163
+			minimal_version="${version_components_group:2}"
164
+			minimal_version="${minimal_version%:*}"
165
+			maximal_version="${version_components_group:$((3 + ${#minimal_version}))}"
166
+
167
+			if [[ "${major_version}" =~ ^(2|3)$ ]]; then
168
+				if [[ -n "${minimal_version}" && "${major_version}" != "${minimal_version:0:1}" ]]; then
169
+					die "Invalid syntax of PYTHON_DEPEND: Minimal version '${minimal_version}' not in specified group of versions"
170
+				fi
171
+				if [[ -n "${maximal_version}" && "${major_version}" != "${maximal_version:0:1}" ]]; then
172
+					die "Invalid syntax of PYTHON_DEPEND: Maximal version '${maximal_version}' not in specified group of versions"
173
+				fi
174
+			fi
175
+
176
+			if [[ "${major_version}" == "2" ]]; then
177
+				python2="1"
178
+				python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}")
179
+				python2_minimal_version="${minimal_version}"
180
+				python2_maximal_version="${maximal_version}"
181
+			elif [[ "${major_version}" == "3" ]]; then
182
+				python3="1"
183
+				python_versions=("${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
184
+				python3_minimal_version="${minimal_version}"
185
+				python3_maximal_version="${maximal_version}"
186
+			else
187
+				python_all="1"
188
+				python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
189
+				python_minimal_version="${minimal_version}"
190
+				python_maximal_version="${maximal_version}"
191
+			fi
192
+
193
+			if [[ -n "${minimal_version}" ]] && ! has "${minimal_version}" "${python_versions[@]}"; then
194
+				die "Invalid syntax of PYTHON_DEPEND: Unrecognized minimal version '${minimal_version}'"
195
+			fi
196
+			if [[ -n "${maximal_version}" ]] && ! has "${maximal_version}" "${python_versions[@]}"; then
197
+				die "Invalid syntax of PYTHON_DEPEND: Unrecognized maximal version '${maximal_version}'"
198
+			fi
199
+
200
+			if [[ -n "${minimal_version}" && -n "${maximal_version}" && "${minimal_version}" > "${maximal_version}" ]]; then
201
+				die "Invalid syntax of PYTHON_DEPEND: Minimal version '${minimal_version}' greater than maximal version '${maximal_version}'"
202
+			fi
203
+		done <<< "${version_components_groups}"
204
+
205
+		_PYTHON_ATOMS=()
206
+
207
+		_append_accepted_versions_range() {
208
+			local accepted_version="0" i
209
+			for ((i = "${#python_versions[@]}"; i >= 0; i--)); do
210
+				if [[ "${python_versions[${i}]}" == "${python_maximal_version}" ]]; then
211
+					accepted_version="1"
212
+				fi
213
+				if [[ "${accepted_version}" == "1" ]]; then
214
+					_PYTHON_ATOMS+=("=dev-lang/python-${python_versions[${i}]}*")
215
+				fi
216
+				if [[ "${python_versions[${i}]}" == "${python_minimal_version}" ]]; then
217
+					accepted_version="0"
218
+				fi
219
+			done
220
+		}
221
+
222
+		if [[ "${python_all}" == "1" ]]; then
223
+			if [[ -z "${python_minimal_version}" && -z "${python_maximal_version}" ]]; then
224
+				_PYTHON_ATOMS+=("dev-lang/python")
225
+			else
226
+				python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
227
+				python_minimal_version="${python_minimal_version:-${python_versions[0]}}"
228
+				python_maximal_version="${python_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
229
+				_append_accepted_versions_range
230
+			fi
231
+		else
232
+			if [[ "${python3}" == "1" ]]; then
233
+				if [[ -z "${python3_minimal_version}" && -z "${python3_maximal_version}" ]]; then
234
+					_PYTHON_ATOMS+=("=dev-lang/python-3*")
235
+				else
236
+					python_versions=("${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}")
237
+					python_minimal_version="${python3_minimal_version:-${python_versions[0]}}"
238
+					python_maximal_version="${python3_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
239
+					_append_accepted_versions_range
240
+				fi
241
+			fi
242
+			if [[ "${python2}" == "1" ]]; then
243
+				if [[ -z "${python2_minimal_version}" && -z "${python2_maximal_version}" ]]; then
244
+					_PYTHON_ATOMS+=("=dev-lang/python-2*")
245
+				else
246
+					python_versions=("${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}")
247
+					python_minimal_version="${python2_minimal_version:-${python_versions[0]}}"
248
+					python_maximal_version="${python2_maximal_version:-${python_versions[${#python_versions[@]}-1]}}"
249
+					_append_accepted_versions_range
250
+				fi
251
+			fi
252
+		fi
253
+
254
+		unset -f _append_accepted_versions_range
255
+
256
+		if [[ "${#_PYTHON_ATOMS[@]}" -gt 1 ]]; then
257
+			DEPEND+="${DEPEND:+ }${USE_flag}${USE_flag:+? ( }|| ( ${_PYTHON_ATOMS[@]} )${USE_flag:+ )}"
258
+			RDEPEND+="${RDEPEND:+ }${USE_flag}${USE_flag:+? ( }|| ( ${_PYTHON_ATOMS[@]} )${USE_flag:+ )}"
259
+		else
260
+			DEPEND+="${DEPEND:+ }${USE_flag}${USE_flag:+? ( }${_PYTHON_ATOMS[@]}${USE_flag:+ )}"
261
+			RDEPEND+="${RDEPEND:+ }${USE_flag}${USE_flag:+? ( }${_PYTHON_ATOMS[@]}${USE_flag:+ )}"
262
+		fi
263
+	else
264
+		die "Invalid syntax of PYTHON_DEPEND"
265
+	fi
266
+}
267
+
268
+if _python_implementation; then
269
+	DEPEND=">=app-eselect/eselect-python-20091230"
270
+	RDEPEND="${DEPEND}"
271
+	PDEPEND="app-admin/python-updater"
272
+fi
273
+
274
+if [[ -n "${PYTHON_DEPEND}" ]]; then
275
+	_python_parse_PYTHON_DEPEND
276
+else
277
+	_PYTHON_ATOMS=("dev-lang/python")
278
+fi
279
+unset -f _python_parse_PYTHON_DEPEND
280
+
281
+if [[ -n "${NEED_PYTHON}" ]]; then
282
+	eerror "Use PYTHON_DEPEND variable instead of NEED_PYTHON variable."
283
+	die "NEED_PYTHON variable is banned"
284
+fi
285
+
286
+# @ECLASS-VARIABLE: PYTHON_USE_WITH
287
+# @DESCRIPTION:
288
+# Set this to a space separated list of USE flags the Python slot in use must be built with.
289
+
290
+# @ECLASS-VARIABLE: PYTHON_USE_WITH_OR
291
+# @DESCRIPTION:
292
+# Set this to a space separated list of USE flags of which one must be turned on for the slot in use.
293
+
294
+# @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT
295
+# @DESCRIPTION:
296
+# Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or
297
+# PYTHON_USE_WITH_OR atoms conditional under a USE flag.
298
+
299
+if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
300
+	_PYTHON_USE_WITH_ATOMS_ARRAY=()
301
+	if [[ -n "${PYTHON_USE_WITH}" ]]; then
302
+		for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
303
+			_PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH// /,}]")
304
+		done
305
+	elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
306
+		for _USE_flag in ${PYTHON_USE_WITH_OR}; do
307
+			for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
308
+				_PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
309
+			done
310
+		done
311
+		unset _USE_flag
312
+	fi
313
+	if [[ "${#_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" -gt 1 ]]; then
314
+		_PYTHON_USE_WITH_ATOMS="|| ( ${_PYTHON_USE_WITH_ATOMS_ARRAY[@]} )"
315
+	else
316
+		_PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}"
317
+	fi
318
+	if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
319
+		_PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )"
320
+	fi
321
+	DEPEND+="${DEPEND:+ }${_PYTHON_USE_WITH_ATOMS}"
322
+	RDEPEND+="${RDEPEND:+ }${_PYTHON_USE_WITH_ATOMS}"
323
+	unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
324
+fi
325
+
326
+unset _PYTHON_ATOMS
327
+
328
+# ================================================================================================
329
+# =================================== MISCELLANEOUS FUNCTIONS ====================================
330
+# ================================================================================================
331
+
332
+_python_abi-specific_local_scope() {
333
+	[[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
334
+}
335
+
336
+_python_initialize_prefix_variables() {
337
+	if has "${EAPI:-0}" 0 1 2; then
338
+		if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
339
+			EROOT="${ROOT%/}${EPREFIX}/"
340
+		fi
341
+		if [[ -n "${D}" && -z "${ED}" ]]; then
342
+			ED="${D%/}${EPREFIX}/"
343
+		fi
344
+	fi
345
+}
346
+
347
+unset PYTHON_SANITY_CHECKS_EXECUTED PYTHON_SKIP_SANITY_CHECKS
348
+
349
+_python_initial_sanity_checks() {
350
+	:
351
+}
352
+
353
+_python_final_sanity_checks() {
354
+	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
355
+		local PYTHON_ABI="${PYTHON_ABI}"
356
+		for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
357
+			# Ensure that appropriate version of Python is installed.
358
+			if ! has_version "$(python_get_implementational_package)"; then
359
+				die "$(python_get_implementational_package) is not installed"
360
+			fi
361
+
362
+			# Ensure that EPYTHON variable is respected.
363
+			if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
364
+				eerror "Path to 'python':                 '$(type -p python)'"
365
+				eerror "ABI:                              '${ABI}'"
366
+				eerror "DEFAULT_ABI:                      '${DEFAULT_ABI}'"
367
+				eerror "EPYTHON:                          '$(PYTHON)'"
368
+				eerror "PYTHON_ABI:                       '${PYTHON_ABI}'"
369
+				eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
370
+				die "'python' does not respect EPYTHON variable"
371
+			fi
372
+		done
373
+	fi
374
+	PYTHON_SANITY_CHECKS_EXECUTED="1"
375
+}
376
+
377
+# @ECLASS-VARIABLE: PYTHON_COLORS
378
+# @DESCRIPTION:
379
+# User-configurable colored output.
380
+PYTHON_COLORS="${PYTHON_COLORS:-0}"
381
+
382
+_python_set_color_variables() {
383
+	if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
384
+		_BOLD=$'\e[1m'
385
+		_RED=$'\e[1;31m'
386
+		_GREEN=$'\e[1;32m'
387
+		_BLUE=$'\e[1;34m'
388
+		_CYAN=$'\e[1;36m'
389
+		_NORMAL=$'\e[0m'
390
+	else
391
+		_BOLD=
392
+		_RED=
393
+		_GREEN=
394
+		_BLUE=
395
+		_CYAN=
396
+		_NORMAL=
397
+	fi
398
+}
399
+
400
+_python_check_python_pkg_setup_execution() {
401
+	[[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return
402
+
403
+	if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
404
+		die "python_pkg_setup() not called"
405
+	fi
406
+}
407
+
408
+# @FUNCTION: python_pkg_setup
409
+# @DESCRIPTION:
410
+# Perform sanity checks and initialize environment.
411
+#
412
+# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
413
+# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
414
+python_pkg_setup() {
415
+	if [[ "${EBUILD_PHASE}" != "setup" ]]; then
416
+		die "${FUNCNAME}() can be used only in pkg_setup() phase"
417
+	fi
418
+
419
+	if [[ "$#" -ne 0 ]]; then
420
+		die "${FUNCNAME}() does not accept arguments"
421
+	fi
422
+
423
+	export JYTHON_SYSTEM_CACHEDIR="1"
424
+	addwrite "${EPREFIX}/var/cache/jython"
425
+
426
+	if _python_package_supporting_installation_for_multiple_python_abis; then
427
+		_python_calculate_PYTHON_ABIS
428
+		export EPYTHON="$(PYTHON -f)"
429
+	else
430
+		PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}"
431
+	fi
432
+
433
+	if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
434
+		if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
435
+			if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
436
+				use ${PYTHON_USE_WITH_OPT#!} && return
437
+			else
438
+				use !${PYTHON_USE_WITH_OPT} && return
439
+			fi
440
+		fi
441
+
442
+		python_pkg_setup_check_USE_flags() {
443
+			local python_atom USE_flag
444
+			python_atom="$(python_get_implementational_package)"
445
+
446
+			for USE_flag in ${PYTHON_USE_WITH}; do
447
+				if ! has_version "${python_atom}[${USE_flag}]"; then
448
+					eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
449
+					die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
450
+				fi
451
+			done
452
+
453
+			for USE_flag in ${PYTHON_USE_WITH_OR}; do
454
+				if has_version "${python_atom}[${USE_flag}]"; then
455
+					return
456
+				fi
457
+			done
458
+
459
+			if [[ ${PYTHON_USE_WITH_OR} ]]; then
460
+				eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
461
+				die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
462
+			fi
463
+		}
464
+
465
+		if _python_package_supporting_installation_for_multiple_python_abis; then
466
+			PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags
467
+		else
468
+			python_pkg_setup_check_USE_flags
469
+		fi
470
+
471
+		unset -f python_pkg_setup_check_USE_flags
472
+	fi
473
+
474
+	PYTHON_PKG_SETUP_EXECUTED="1"
475
+}
476
+
477
+_PYTHON_SHEBANG_BASE_PART_REGEX='^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|pypy-c|python)'
478
+
479
+# @FUNCTION: python_convert_shebangs
480
+# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_ABI|Python_version> <file|directory> [files|directories]
481
+# @DESCRIPTION:
482
+# Convert shebangs in specified files. Directories can be specified only with --recursive option.
483
+python_convert_shebangs() {
484
+	_python_check_python_pkg_setup_execution
485
+
486
+	local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" shebangs_converted="0"
487
+
488
+	while (($#)); do
489
+		case "$1" in
490
+			-r|--recursive)
491
+				recursive="1"
492
+				;;
493
+			-q|--quiet)
494
+				quiet="1"
495
+				;;
496
+			-x|--only-executables)
497
+				only_executables="1"
498
+				;;
499
+			--)
500
+				shift
501
+				break
502
+				;;
503
+			-*)
504
+				die "${FUNCNAME}(): Unrecognized option '$1'"
505
+				;;
506
+			*)
507
+				break
508
+				;;
509
+		esac
510
+		shift
511
+	done
512
+
513
+	if [[ "$#" -eq 0 ]]; then
514
+		die "${FUNCNAME}(): Missing Python version and files or directories"
515
+	elif [[ "$#" -eq 1 ]]; then
516
+		die "${FUNCNAME}(): Missing files or directories"
517
+	fi
518
+
519
+	if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
520
+		python_interpreter="$(PYTHON "$1")"
521
+	else
522
+		python_interpreter="python$1"
523
+	fi
524
+	shift
525
+
526
+	for argument in "$@"; do
527
+		if [[ ! -e "${argument}" ]]; then
528
+			die "${FUNCNAME}(): '${argument}' does not exist"
529
+		elif [[ -f "${argument}" ]]; then
530
+			files+=("${argument}")
531
+		elif [[ -d "${argument}" ]]; then
532
+			if [[ "${recursive}" == "1" ]]; then
533
+				while read -d $'\0' -r file; do
534
+					files+=("${file}")
535
+				done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
536
+			else
537
+				die "${FUNCNAME}(): '${argument}' is not a regular file"
538
+			fi
539
+		else
540
+			die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
541
+		fi
542
+	done
543
+
544
+	for file in "${files[@]}"; do
545
+		file="${file#./}"
546
+		[[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
547
+
548
+		if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then
549
+			[[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
550
+
551
+			shebangs_converted="1"
552
+
553
+			if [[ "${quiet}" == "0" ]]; then
554
+				einfo "Converting shebang in '${file}'"
555
+			fi
556
+
557
+			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"
558
+		fi
559
+	done
560
+
561
+	if [[ "${shebangs_converted}" == "0" ]]; then
562
+		ewarn "${FUNCNAME}(): Python scripts not found"
563
+	fi
564
+}
565
+
566
+# @FUNCTION: python_clean_py-compile_files
567
+# @USAGE: [-q|--quiet]
568
+# @DESCRIPTION:
569
+# Clean py-compile files to disable byte-compilation.
570
+python_clean_py-compile_files() {
571
+	_python_check_python_pkg_setup_execution
572
+
573
+	local file files=() quiet="0"
574
+
575
+	while (($#)); do
576
+		case "$1" in
577
+			-q|--quiet)
578
+				quiet="1"
579
+				;;
580
+			-*)
581
+				die "${FUNCNAME}(): Unrecognized option '$1'"
582
+				;;
583
+			*)
584
+				die "${FUNCNAME}(): Invalid usage"
585
+				;;
586
+		esac
587
+		shift
588
+	done
589
+
590
+	while read -d $'\0' -r file; do
591
+		files+=("${file#./}")
592
+	done < <(find -name py-compile -type f -print0)
593
+
594
+	for file in "${files[@]}"; do
595
+		if [[ "${quiet}" == "0" ]]; then
596
+			einfo "Cleaning '${file}' file"
597
+		fi
598
+		echo "#!/bin/sh" > "${file}"
599
+	done
600
+}
601
+
602
+# @FUNCTION: python_clean_installation_image
603
+# @USAGE: [-q|--quiet]
604
+# @DESCRIPTION:
605
+# Delete needless files in installation image.
606
+#
607
+# This function can be used only in src_install() phase.
608
+python_clean_installation_image() {
609
+	if [[ "${EBUILD_PHASE}" != "install" ]]; then
610
+		die "${FUNCNAME}() can be used only in src_install() phase"
611
+	fi
612
+
613
+	_python_check_python_pkg_setup_execution
614
+	_python_initialize_prefix_variables
615
+
616
+	local file files=() quiet="0"
617
+
618
+	while (($#)); do
619
+		case "$1" in
620
+			-q|--quiet)
621
+				quiet="1"
622
+				;;
623
+			-*)
624
+				die "${FUNCNAME}(): Unrecognized option '$1'"
625
+				;;
626
+			*)
627
+				die "${FUNCNAME}(): Invalid usage"
628
+				;;
629
+		esac
630
+		shift
631
+	done
632
+
633
+	while read -d $'\0' -r file; do
634
+		files+=("${file}")
635
+	done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0)
636
+
637
+	if [[ "${#files[@]}" -gt 0 ]]; then
638
+		if [[ "${quiet}" == "0" ]]; then
639
+			ewarn "Deleting byte-compiled Python modules needlessly generated by build system:"
640
+		fi
641
+		for file in "${files[@]}"; do
642
+			if [[ "${quiet}" == "0" ]]; then
643
+				ewarn " ${file}"
644
+			fi
645
+			rm -f "${file}"
646
+
647
+			# Delete empty __pycache__ directories.
648
+			if [[ "${file%/*}" == *"/__pycache__" ]]; then
649
+				rmdir "${file%/*}" 2> /dev/null
650
+			fi
651
+		done
652
+	fi
653
+
654
+	python_clean_sitedirs() {
655
+		if [[ -d "${ED}$(python_get_sitedir)" ]]; then
656
+			find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
657
+		fi
658
+	}
659
+	if _python_package_supporting_installation_for_multiple_python_abis; then
660
+		python_execute_function -q python_clean_sitedirs
661
+	else
662
+		python_clean_sitedirs
663
+	fi
664
+
665
+	unset -f python_clean_sitedirs
666
+}
667
+
668
+# ================================================================================================
669
+# =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============
670
+# ================================================================================================
671
+
672
+# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
673
+# @DESCRIPTION:
674
+# Set this in EAPI <= 4 to indicate that current package supports installation for
675
+# multiple Python ABIs.
676
+
677
+# @ECLASS-VARIABLE: PYTHON_TESTS_RESTRICTED_ABIS
678
+# @DESCRIPTION:
679
+# Space-separated list of Python ABI patterns. Testing in Python ABIs matching any Python ABI
680
+# patterns specified in this list is skipped.
681
+
682
+# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
683
+# @DESCRIPTION:
684
+# Set this to export phase functions for the following ebuild phases:
685
+# src_prepare(), src_configure(), src_compile(), src_test(), src_install().
686
+if ! has "${EAPI:-0}" 0 1; then
687
+	python_src_prepare() {
688
+		if [[ "${EBUILD_PHASE}" != "prepare" ]]; then
689
+			die "${FUNCNAME}() can be used only in src_prepare() phase"
690
+		fi
691
+
692
+		if ! _python_package_supporting_installation_for_multiple_python_abis; then
693
+			die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
694
+		fi
695
+
696
+		_python_check_python_pkg_setup_execution
697
+
698
+		if [[ "$#" -ne 0 ]]; then
699
+			die "${FUNCNAME}() does not accept arguments"
700
+		fi
701
+
702
+		python_copy_sources
703
+	}
704
+
705
+	for python_default_function in src_configure src_compile src_test; do
706
+		eval "python_${python_default_function}() {
707
+			if [[ \"\${EBUILD_PHASE}\" != \"${python_default_function#src_}\" ]]; then
708
+				die \"\${FUNCNAME}() can be used only in ${python_default_function}() phase\"
709
+			fi
710
+
711
+			if ! _python_package_supporting_installation_for_multiple_python_abis; then
712
+				die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
713
+			fi
714
+
715
+			_python_check_python_pkg_setup_execution
716
+
717
+			python_execute_function -d -s -- \"\$@\"
718
+		}"
719
+	done
720
+	unset python_default_function
721
+
722
+	python_src_install() {
723
+		if [[ "${EBUILD_PHASE}" != "install" ]]; then
724
+			die "${FUNCNAME}() can be used only in src_install() phase"
725
+		fi
726
+
727
+		if ! _python_package_supporting_installation_for_multiple_python_abis; then
728
+			die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
729
+		fi
730
+
731
+		_python_check_python_pkg_setup_execution
732
+
733
+		if has "${EAPI:-0}" 0 1 2 3; then
734
+			python_execute_function -d -s -- "$@"
735
+		else
736
+			python_installation() {
737
+				emake DESTDIR="${T}/images/${PYTHON_ABI}" install "$@"
738
+			}
739
+			python_execute_function -s python_installation "$@"
740
+			unset python_installation
741
+
742
+			python_merge_intermediate_installation_images "${T}/images"
743
+		fi
744
+	}
745
+
746
+	if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then
747
+		EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
748
+	fi
749
+fi
750
+
751
+unset PYTHON_ABIS
752
+
753
+_python_calculate_PYTHON_ABIS() {
754
+	if ! _python_package_supporting_installation_for_multiple_python_abis; then
755
+		die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
756
+	fi
757
+
758
+	_python_initial_sanity_checks
759
+
760
+	if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]]; then
761
+		local PYTHON_ABI
762
+
763
+		if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
764
+			local cpython_enabled="0"
765
+
766
+			if [[ -z "${USE_PYTHON}" ]]; then
767
+				die "USE_PYTHON variable is empty"
768
+			fi
769
+
770
+			for PYTHON_ABI in ${USE_PYTHON}; do
771
+				if ! has "${PYTHON_ABI}" "${_PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; then
772
+					die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
773
+				fi
774
+
775
+				if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
776
+					cpython_enabled="1"
777
+				fi
778
+
779
+				if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
780
+					export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
781
+				fi
782
+			done
783
+
784
+			if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
785
+				die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}"
786
+			fi
787
+
788
+			if [[ "${cpython_enabled}" == "0" ]]; then
789
+				die "USE_PYTHON variable does not enable any CPython ABI"
790
+			fi
791
+		else
792
+			local python_version python2_version python3_version support_python_major_version
793
+
794
+			if ! has_version "dev-lang/python"; then