Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 302525
Collapse All | Expand All

(-)file_not_specified_in_diff (-29 / +40 lines)
Line  Link Here
0
-- python.eclass
0
++ python.eclass
Lines 9-14 Link Here
9
# @DESCRIPTION:
9
# @DESCRIPTION:
10
# Some useful functions for dealing with Python.
10
# Some useful functions for dealing with Python.
11
11
12
# Prefix note:
13
# have python_get* return WITHOUT EPREFIX, since they should be relative to
14
# EROOT, and sometimes are used with helpers
15
12
inherit multilib
16
inherit multilib
13
17
14
if ! has "${EAPI:-0}" 0 1 2; then
18
if ! has "${EAPI:-0}" 0 1 2; then
Lines 145-159 Link Here
145
	fi
150
	fi
146
151
147
	# Ensure that /usr/bin/python and /usr/bin/python-config are valid.
152
	# Ensure that /usr/bin/python and /usr/bin/python-config are valid.
148
	if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then
153
	if [[ "$(readlink "${EPREFIX}"/usr/bin/python)" != "python-wrapper" ]]; then
149
		eerror "'/usr/bin/python' is not valid symlink."
154
		eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
150
		eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
155
		eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
151
		die "'/usr/bin/python' is not valid symlink"
156
		die "'${EPREFIX}/usr/bin/python' is not valid symlink"
152
	fi
157
	fi
153
	if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
158
	if [[ "$(<"${EPREFIX}"/usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
154
		eerror "'/usr/bin/python-config' is not valid script"
159
		eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
155
		eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
160
		eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
156
		die "'/usr/bin/python-config' is not valid script"
161
		die "'${EPREFIX}/usr/bin/python-config' is not valid script"
157
	fi
162
	fi
158
163
159
	# USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
164
	# USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
Lines 205-218 Link Here
205
		else
210
		else
206
			local python_version python2_version= python3_version= support_python_major_version
211
			local python_version python2_version= python3_version= support_python_major_version
207
212
208
			python_version="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
213
			python_version="$("${EPREFIX}"/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
209
214
210
			if has_version "=dev-lang/python-2*"; then
215
			if has_version "=dev-lang/python-2*"; then
211
				if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then
216
				if [[ "$(readlink "${EPREFIX}"/usr/bin/python2)" != "python2."* ]]; then
212
					die "'/usr/bin/python2' is not valid symlink"
217
					die "'${EPREFIX}/usr/bin/python2' is not valid symlink"
213
				fi
218
				fi
214
219
215
				python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
220
				python2_version="$("${EPREFIX}"/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
216
221
217
				for PYTHON_ABI in ${python2_supported_versions}; do
222
				for PYTHON_ABI in ${python2_supported_versions}; do
218
					support_python_major_version="1"
223
					support_python_major_version="1"
Lines 235-245 Link Here
235
			fi
240
			fi
236
241
237
			if has_version "=dev-lang/python-3*"; then
242
			if has_version "=dev-lang/python-3*"; then
238
				if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then
243
				if [[ "$(readlink "${EPREFIX}"/usr/bin/python3)" != "python3."* ]]; then
239
					die "'/usr/bin/python3' is not valid symlink"
244
					die "'${EPREFIX}/usr/bin/python3' is not valid symlink"
240
				fi
245
				fi
241
246
242
				python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
247
				python3_version="$("${EPREFIX}"/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
243
248
244
				for PYTHON_ABI in ${python3_supported_versions}; do
249
				for PYTHON_ABI in ${python3_supported_versions}; do
245
					support_python_major_version="1"
250
					support_python_major_version="1"
Lines 262-273 Link Here
262
			fi
267
			fi
263
268
264
			if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then
269
			if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then
265
				eerror "Python wrapper is configured incorrectly or /usr/bin/python2 symlink"
270
				eerror "Python wrapper is configured incorrectly or ${EPREFIX}/usr/bin/python2 symlink"
266
				eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
271
				eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
267
				die "Incorrect configuration of Python"
272
				die "Incorrect configuration of Python"
268
			fi
273
			fi
269
			if [[ -n "${python3_version}" && "${python_version}" == "3."* && "${python_version}" != "${python3_version}" ]]; then
274
			if [[ -n "${python3_version}" && "${python_version}" == "3."* && "${python_version}" != "${python3_version}" ]]; then
270
				eerror "Python wrapper is configured incorrectly or /usr/bin/python3 symlink"
275
				eerror "Python wrapper is configured incorrectly or ${EPREFIX}/usr/bin/python3 symlink"
271
				eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
276
				eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
272
				die "Incorrect configuration of Python"
277
				die "Incorrect configuration of Python"
273
			fi
278
			fi
Lines 395-400 Link Here
395
		elif [[ "${EBUILD_PHASE}" == "install" ]]; then
400
		elif [[ "${EBUILD_PHASE}" == "install" ]]; then
396
			python_default_function() {
401
			python_default_function() {
397
				emake DESTDIR="${D}" install
402
				emake DESTDIR="${D}" install
403
				# Remove .py[co] files from the installed image,
404
				# python_mod_optimize will (re)generate them.  Removing
405
				# them here makes sure they don't end up in binpkgs, and
406
				# fixes Bad Marshalling Data in Prefix when the offset
407
				# was changed with a binpkg installation to match the
408
				# target offset.  We aim for consistency: bug #301915
409
				find "${D}" -name "*.py[co]" -delete
398
			}
410
			}
399
		else
411
		else
400
			die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase"
412
			die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase"
Lines 681-687 Link Here
681
		sys.exit(1)
693
		sys.exit(1)
682
else:
694
else:
683
	try:
695
	try:
684
		eselect_process = subprocess.Popen(["/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
696
		eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
685
		if eselect_process.wait() != 0:
697
		if eselect_process.wait() != 0:
686
			raise ValueError
698
			raise ValueError
687
	except (OSError, ValueError):
699
	except (OSError, ValueError):
Lines 706-712 Link Here
706
		else
718
		else
707
			cat << EOF >> "${file}"
719
			cat << EOF >> "${file}"
708
try:
720
try:
709
	eselect_process = subprocess.Popen(["/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
721
	eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], stdout=subprocess.PIPE)
710
	if eselect_process.wait() != 0:
722
	if eselect_process.wait() != 0:
711
		raise ValueError
723
		raise ValueError
712
except (OSError, ValueError):
724
except (OSError, ValueError):
Lines 742-748 Link Here
742
		if [[ "$?" != "0" ]]; then
754
		if [[ "$?" != "0" ]]; then
743
			die "${FUNCNAME}(): Generation of '$1' failed"
755
			die "${FUNCNAME}(): Generation of '$1' failed"
744
		fi
756
		fi
745
		fperms +x "${file#${D%/}}" || die "fperms '${file}' failed"
757
		fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed"
746
	done
758
	done
747
}
759
}
748
760
Lines 860-866 Link Here
860
			if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
872
			if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
861
				die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python"
873
				die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python"
862
			fi
874
			fi
863
			slot="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
875
			slot="$("${EPREFIX}"/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
864
		elif [[ "${final_ABI}" == "1" ]]; then
876
		elif [[ "${final_ABI}" == "1" ]]; then
865
			if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
877
			if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
866
				die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python"
878
				die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python"
Lines 910-916 Link Here
910
		echo -n "${slot}"
922
		echo -n "${slot}"
911
		return
923
		return
912
	elif [[ "${absolute_path_output}" == "1" ]]; then
924
	elif [[ "${absolute_path_output}" == "1" ]]; then
913
		echo -n "/usr/bin/python${slot}"
925
		echo -n "${EPREFIX}/usr/bin/python${slot}"
914
	else
926
	else
915
		echo -n "python${slot}"
927
		echo -n "python${slot}"
916
	fi
928
	fi
Lines 1123-1129 Link Here
1123
	if ! python -c "import Tkinter" >/dev/null 2>&1; then
1135
	if ! python -c "import Tkinter" >/dev/null 2>&1; then
1124
		eerror "You need to recompile python with Tkinter support."
1136
		eerror "You need to recompile python with Tkinter support."
1125
		eerror "Try adding: 'dev-lang/python tk'"
1137
		eerror "Try adding: 'dev-lang/python tk'"
1126
		eerror "in to /etc/portage/package.use"
1138
		eerror "in to ${EPREFIX}/etc/portage/package.use"
1127
		echo
1139
		echo
1128
		die "missing tkinter support with installed python"
1140
		die "missing tkinter support with installed python"
1129
	fi
1141
	fi
Lines 1172-1178 Link Here
1172
		local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
1184
		local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
1173
1185
1174
		# Strip trailing slash from ROOT.
1186
		# Strip trailing slash from ROOT.
1175
		root="${ROOT%/}"
1187
		root="${EROOT%/}"
1176
1188
1177
		# Respect ROOT and options passed to compileall.py.
1189
		# Respect ROOT and options passed to compileall.py.
1178
		while (($#)); do
1190
		while (($#)); do
Lines 1188-1194 Link Here
1188
					ewarn "${FUNCNAME}: Ignoring option '$1'"
1200
					ewarn "${FUNCNAME}: Ignoring option '$1'"
1189
					;;
1201
					;;
1190
				*)
1202
				*)
1191
					if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1203
					if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1192
						die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories"
1204
						die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories"
1193
					elif [[ "$1" =~ ^/ ]]; then
1205
					elif [[ "$1" =~ ^/ ]]; then
1194
						if [[ -d "${root}/$1" ]]; then
1206
						if [[ -d "${root}/$1" ]]; then
Lines 1270-1276 Link Here
1270
		local myroot mydirs=() myfiles=() myopts=() return_code="0"
1282
		local myroot mydirs=() myfiles=() myopts=() return_code="0"
1271
1283
1272
		# strip trailing slash
1284
		# strip trailing slash
1273
		myroot="${ROOT%/}"
1285
		myroot="${EROOT%/}"
1274
1286
1275
		# respect ROOT and options passed to compileall.py
1287
		# respect ROOT and options passed to compileall.py
1276
		while (($#)); do
1288
		while (($#)); do
Lines 1336-1347 Link Here
1336
	[[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME} should only be run in pkg_postrm()"
1348
	[[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME} should only be run in pkg_postrm()"
1337
1349
1338
	# Strip trailing slash from ROOT.
1350
	# Strip trailing slash from ROOT.
1339
	root="${ROOT%/}"
1351
	root="${EROOT%/}"
1340
1352
1341
	if (($#)); then
1353
	if (($#)); then
1342
		if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1354
		if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1343
			while (($#)); do
1355
			while (($#)); do
1344
				if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1356
				if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1345
					die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories"
1357
					die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories"
1346
				elif [[ "$1" =~ ^/ ]]; then
1358
				elif [[ "$1" =~ ^/ ]]; then
1347
					SEARCH_PATH+=("${root}/${1#/}")
1359
					SEARCH_PATH+=("${root}/${1#/}")
Lines 1411-1417 Link Here
1411
python_version() {
1423
python_version() {
1412
	[[ -n "${PYVER}" ]] && return 0
1424
	[[ -n "${PYVER}" ]] && return 0
1413
	local tmpstr
1425
	local tmpstr
1414
	python="${python:-/usr/bin/python}"
1426
	python="${python:-${EPREFIX}/usr/bin/python}"
1415
	tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
1427
	tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
1416
	export PYVER_ALL="${tmpstr#Python }"
1428
	export PYVER_ALL="${tmpstr#Python }"
1417
	export PYVER_MAJOR="${PYVER_ALL:0:1}"
1429
	export PYVER_MAJOR="${PYVER_ALL:0:1}"
Lines 1443-1449 Link Here
1443
		die "${FUNCNAME} should only be run in pkg_postinst()"
1455
		die "${FUNCNAME} should only be run in pkg_postinst()"
1444
1456
1445
	# strip trailing slash
1457
	# strip trailing slash
1446
	myroot="${ROOT%/}"
1458
	myroot="${EROOT%/}"
1447
1459
1448
	# respect ROOT
1460
	# respect ROOT
1449
	for f in "$@"; do
1461
	for f in "$@"; do

Return to bug 302525