public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 0/5] python*-r1: commonize PYTHON_COMPAT handling
@ 2015-12-17 22:02 Michał Górny
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 1/5] python*-r1.eclass: Commonize PYTHON_COMPAT processing, cache the result Michał Górny
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Michał Górny @ 2015-12-17 22:02 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

Hello,

Here's yet another quick patch set for python*-r1 eclasses. Major
highlights:

* PYTHON_COMPAT processing is commonized and moved into python-utils-r1.
  We no longer have random methods of accessing supported
  and unsupported impls scattered all over the place.

* Supported and unsupported implementations are cached. So we don't have
  to repeatedly check which ones are supported and which are to be
  kipped. May speed up metadata regen a little. Or make it a bit slower.

* python-single-r1: python_gen_cond_dep and python_gen_usedep now
  output correct USE dependencies when only a single impl is supported.

* PYTHON_COMPAT_OVERRIDE is now supported by all eclasses.

* Impl iteration in python-any-r1.eclass is a bit cleaner ;-).

Please review.


Michał Górny (5):
  python*-r1.eclass: Commonize PYTHON_COMPAT processing, cache the
    result
  python-single-r1.eclass: Fix python_gen_* w/ single PYTHON_COMPAT impl
  python-any-r1.eclass: Support PYTHON_COMPAT_OVERRIDE
  python-single-r1.eclass: Support PYTHON_COMPAT_OVERRIDE
  python-any-r1.eclass: Use reverse iter instead of reversing impls
    array

 eclass/python-any-r1.eclass    |  69 +++++++++++++++----------
 eclass/python-r1.eclass        |  47 ++++-------------
 eclass/python-single-r1.eclass | 113 ++++++++++++++++++++++++-----------------
 eclass/python-utils-r1.eclass  |  49 ++++++++++++++++++
 4 files changed, 169 insertions(+), 109 deletions(-)

-- 
2.6.4



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gentoo-dev] [PATCH 1/5] python*-r1.eclass: Commonize PYTHON_COMPAT processing, cache the result
  2015-12-17 22:02 [gentoo-dev] [PATCH 0/5] python*-r1: commonize PYTHON_COMPAT handling Michał Górny
@ 2015-12-17 22:02 ` Michał Górny
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 2/5] python-single-r1.eclass: Fix python_gen_* w/ single PYTHON_COMPAT impl Michał Górny
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Michał Górny @ 2015-12-17 22:02 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

Introduce a common _python_set_impls function in python-utils-r1.eclass
that validates and processes PYTHON_COMPAT, then stores the result in
_PYTHON_SUPPORTED_IMPLS and _PYTHON_UNSUPPORTED_IMPLS variables. Reuse
those variables in all python-r1 suite eclasses, effectively reducing
code duplication and providing cache for repeated implementation support
checks.
---
 eclass/python-any-r1.eclass    | 28 +++++--------------
 eclass/python-r1.eclass        | 47 ++++++++------------------------
 eclass/python-single-r1.eclass | 61 ++++++++++++------------------------------
 eclass/python-utils-r1.eclass  | 49 +++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 102 deletions(-)

diff --git a/eclass/python-any-r1.eclass b/eclass/python-any-r1.eclass
index 721ba45..dbfeded 100644
--- a/eclass/python-any-r1.eclass
+++ b/eclass/python-any-r1.eclass
@@ -71,12 +71,6 @@ if [[ ! ${_PYTHON_ANY_R1} ]]; then
 # @CODE
 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
 # @CODE
-if ! declare -p PYTHON_COMPAT &>/dev/null; then
-	die 'PYTHON_COMPAT not declared.'
-fi
-if [[ $(declare -p PYTHON_COMPAT) != "declare -a"* ]]; then
-	die 'PYTHON_COMPAT must be an array.'
-fi
 
 # @ECLASS-VARIABLE: PYTHON_REQ_USE
 # @DEFAULT_UNSET
@@ -119,16 +113,10 @@ _python_any_set_globals() {
 	local usestr i PYTHON_PKG_DEP
 	[[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]"
 
-	# check for invalid PYTHON_COMPAT
-	for i in "${PYTHON_COMPAT[@]}"; do
-		# the function simply dies on invalid impl
-		_python_impl_supported "${i}"
-	done
+	_python_set_impls
 
 	PYTHON_DEPS=
-	for i in "${_PYTHON_ALL_IMPLS[@]}"; do
-		has "${i}" "${PYTHON_COMPAT[@]}" || continue
-
+	for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		python_export "${i}" PYTHON_PKG_DEP
 
 		PYTHON_DEPS="${PYTHON_PKG_DEP} ${PYTHON_DEPS}"
@@ -209,9 +197,7 @@ python_gen_any_dep() {
 	[[ ${depstr} ]] || die "No dependency string provided"
 
 	local PYTHON_PKG_DEP out=
-	for i in "${_PYTHON_ALL_IMPLS[@]}"; do
-		has "${i}" "${PYTHON_COMPAT[@]}" || continue
-
+	for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)"
 		python_export "${i}" PYTHON_PKG_DEP
 
@@ -242,7 +228,7 @@ _python_EPYTHON_supported() {
 			;;
 	esac
 
-	if has "${i}" "${PYTHON_COMPAT[@]}"; then
+	if has "${i}" "${_PYTHON_SUPPORTED_IMPLS[@]}"; then
 		if python_is_installed "${i}"; then
 			if declare -f python_check_deps >/dev/null; then
 				local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)"
@@ -293,10 +279,8 @@ python_setup() {
 
 	# fallback to best installed impl.
 	local rev_impls=()
-	for i in "${_PYTHON_ALL_IMPLS[@]}"; do
-		if has "${i}" "${PYTHON_COMPAT[@]}"; then
-			rev_impls=( "${i}" "${rev_impls[@]}" )
-		fi
+	for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
+		rev_impls=( "${i}" "${rev_impls[@]}" )
 	done
 
 	for i in "${rev_impls[@]}"; do
diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
index fbc39dc..f7a8541 100644
--- a/eclass/python-r1.eclass
+++ b/eclass/python-r1.eclass
@@ -82,12 +82,6 @@ inherit multibuild python-utils-r1
 # @CODE
 # PYTHON_COMPAT=( python2_7 python3_{3,4} )
 # @CODE
-if ! declare -p PYTHON_COMPAT &>/dev/null; then
-	die 'PYTHON_COMPAT not declared.'
-fi
-if [[ $(declare -p PYTHON_COMPAT) != "declare -a"* ]]; then
-	die 'PYTHON_COMPAT must be an array.'
-fi
 
 # @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
 # @INTERNAL
@@ -186,24 +180,17 @@ fi
 # @CODE
 
 _python_set_globals() {
-	local impls=()
-
 	PYTHON_DEPS=
 	local i PYTHON_PKG_DEP
-	for i in "${PYTHON_COMPAT[@]}"; do
-		_python_impl_supported "${i}" || continue
 
+	_python_set_impls
+
+	for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		python_export "${i}" PYTHON_PKG_DEP
 		PYTHON_DEPS+="python_targets_${i}? ( ${PYTHON_PKG_DEP} ) "
-
-		impls+=( "${i}" )
 	done
 
-	if [[ ${#impls[@]} -eq 0 ]]; then
-		die "No supported implementation in PYTHON_COMPAT."
-	fi
-
-	local flags=( "${impls[@]/#/python_targets_}" )
+	local flags=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/python_targets_}" )
 	local optflags=${flags[@]/%/(-)?}
 
 	# A nice QA trick here. Since a python-single-r1 package has to have
@@ -212,7 +199,7 @@ _python_set_globals() {
 	# it should prevent developers from mistakenly depending on packages
 	# not supporting multiple Python implementations.
 
-	local flags_st=( "${impls[@]/#/-python_single_target_}" )
+	local flags_st=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/-python_single_target_}" )
 	optflags+=,${flags_st[@]/%/(-)}
 
 	IUSE=${flags[*]}
@@ -246,9 +233,7 @@ _python_validate_useflags() {
 
 	local i
 
-	for i in "${PYTHON_COMPAT[@]}"; do
-		_python_impl_supported "${i}" || continue
-
+	for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		use "python_targets_${i}" && return 0
 	done
 
@@ -290,9 +275,7 @@ python_gen_usedep() {
 	local impl pattern
 	local matches=()
 
-	for impl in "${PYTHON_COMPAT[@]}"; do
-		_python_impl_supported "${impl}" || continue
-
+	for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		for pattern; do
 			if [[ ${impl} == ${pattern} ]]; then
 				matches+=(
@@ -333,9 +316,7 @@ python_gen_useflags() {
 	local impl pattern
 	local matches=()
 
-	for impl in "${PYTHON_COMPAT[@]}"; do
-		_python_impl_supported "${impl}" || continue
-
+	for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		for pattern; do
 			if [[ ${impl} == ${pattern} ]]; then
 				matches+=( "python_targets_${impl}" )
@@ -382,9 +363,7 @@ python_gen_cond_dep() {
 	local dep=${1}
 	shift
 
-	for impl in "${PYTHON_COMPAT[@]}"; do
-		_python_impl_supported "${impl}" || continue
-
+	for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		for pattern; do
 			if [[ ${impl} == ${pattern} ]]; then
 				# substitute ${PYTHON_USEDEP} if used
@@ -460,12 +439,8 @@ _python_obtain_impls() {
 
 	MULTIBUILD_VARIANTS=()
 
-	for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
-		if has "${impl}" "${PYTHON_COMPAT[@]}" \
-			&& use "python_targets_${impl}"
-		then
-			MULTIBUILD_VARIANTS+=( "${impl}" )
-		fi
+	for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
+		use "python_targets_${impl}" && MULTIBUILD_VARIANTS+=( "${impl}" )
 	done
 }
 
diff --git a/eclass/python-single-r1.eclass b/eclass/python-single-r1.eclass
index b8684f0..8ef3846 100644
--- a/eclass/python-single-r1.eclass
+++ b/eclass/python-single-r1.eclass
@@ -95,12 +95,6 @@ if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
 # @CODE
 # PYTHON_COMPAT=( python2_7 python3_{3,4} )
 # @CODE
-if ! declare -p PYTHON_COMPAT &>/dev/null; then
-	die 'PYTHON_COMPAT not declared.'
-fi
-if [[ $(declare -p PYTHON_COMPAT) != "declare -a"* ]]; then
-	die 'PYTHON_COMPAT must be an array.'
-fi
 
 # @ECLASS-VARIABLE: PYTHON_REQ_USE
 # @DEFAULT_UNSET
@@ -186,34 +180,24 @@ fi
 # @CODE
 
 _python_single_set_globals() {
-	local impls=()
-	local unimpls=()
+	_python_set_impls
 
 	PYTHON_DEPS=
 	local i PYTHON_PKG_DEP
-	for i in "${_PYTHON_ALL_IMPLS[@]}"; do
-		has "${i}" "${PYTHON_COMPAT[@]}" \
-			&& impls+=( "${i}" ) \
-			|| unimpls+=( "${i}" )
-	done
-
-	if [[ ${#impls[@]} -eq 0 ]]; then
-		die "No supported implementation in PYTHON_COMPAT."
-	fi
 
-	local flags_mt=( "${impls[@]/#/python_targets_}" )
-	local flags=( "${impls[@]/#/python_single_target_}" )
-	local unflags=( "${unimpls[@]/#/-python_single_target_}" )
+	local flags_mt=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/python_targets_}" )
+	local flags=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/python_single_target_}" )
+	local unflags=( "${_PYTHON_UNSUPPORTED_IMPLS[@]/#/-python_single_target_}" )
 
 	local optflags=${flags_mt[@]/%/(-)?},${unflags[@]/%/(-)}
 
 	IUSE="${flags_mt[*]}"
 
-	if [[ ${#impls[@]} -eq 1 ]]; then
+	if [[ ${#_PYTHON_SUPPORTED_IMPLS[@]} -eq 1 ]]; then
 		# There is only one supported implementation; set IUSE and other
 		# variables without PYTHON_SINGLE_TARGET.
 		PYTHON_REQUIRED_USE="${flags_mt[*]}"
-		python_export "${impls[0]}" PYTHON_PKG_DEP
+		python_export "${_PYTHON_SUPPORTED_IMPLS[0]}" PYTHON_PKG_DEP
 		PYTHON_DEPS="${PYTHON_PKG_DEP} "
 		# Force on the python_single_target_* flag for this impl, so
 		# that any dependencies that inherit python-single-r1 and
@@ -228,7 +212,7 @@ _python_single_set_globals() {
 		# on this package.
 		optflags+=,${flags[@]/%/(+)?}
 
-		for i in "${impls[@]}"; do
+		for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 			# The chosen targets need to be in PYTHON_TARGETS as well.
 			# This is in order to enforce correct dependencies on packages
 			# supporting multiple implementations.
@@ -288,9 +272,7 @@ python_gen_usedep() {
 	local impl pattern
 	local matches=()
 
-	for impl in "${PYTHON_COMPAT[@]}"; do
-		_python_impl_supported "${impl}" || continue
-
+	for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		for pattern; do
 			if [[ ${impl} == ${pattern} ]]; then
 				matches+=(
@@ -331,9 +313,7 @@ python_gen_useflags() {
 	local impl pattern
 	local matches=()
 
-	for impl in "${PYTHON_COMPAT[@]}"; do
-		_python_impl_supported "${impl}" || continue
-
+	for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		for pattern; do
 			if [[ ${impl} == ${pattern} ]]; then
 				matches+=( "python_single_target_${impl}" )
@@ -380,9 +360,7 @@ python_gen_cond_dep() {
 	local dep=${1}
 	shift
 
-	for impl in "${PYTHON_COMPAT[@]}"; do
-		_python_impl_supported "${impl}" || continue
-
+	for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		for pattern; do
 			if [[ ${impl} == ${pattern} ]]; then
 				# substitute ${PYTHON_USEDEP} if used
@@ -411,20 +389,15 @@ python_setup() {
 
 	unset EPYTHON
 
-	local impl impls=()
-	for impl in "${PYTHON_COMPAT[@]}"; do
-		_python_impl_supported "${impl}" || continue
-		impls+=( "${impl}" )
-	done
-
-	if [[ ${#impls[@]} -eq 1 ]]; then
-		if use "python_targets_${impls[0]}"; then
+	if [[ ${#_PYTHON_SUPPORTED_IMPLS[@]} -eq 1 ]]; then
+		if use "python_targets_${_PYTHON_SUPPORTED_IMPLS[0]}"; then
 			# Only one supported implementation, enable it explicitly
-			python_export "${impls[0]}" EPYTHON PYTHON
+			python_export "${_PYTHON_SUPPORTED_IMPLS[0]}" EPYTHON PYTHON
 			python_wrapper_setup
 		fi
 	else
-		for impl in "${impls[@]}"; do
+		local impl
+		for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 			if use "python_single_target_${impl}"; then
 				if [[ ${EPYTHON} ]]; then
 					eerror "Your PYTHON_SINGLE_TARGET setting lists more than a single Python"
@@ -452,14 +425,14 @@ python_setup() {
 
 	if [[ ! ${EPYTHON} ]]; then
 		eerror "No Python implementation selected for the build. Please set"
-		if [[ ${#impls[@]} -eq 1 ]]; then
+		if [[ ${#_PYTHON_SUPPORTED_IMPLS[@]} -eq 1 ]]; then
 			eerror "the PYTHON_TARGETS variable in your make.conf to include one"
 		else
 			eerror "the PYTHON_SINGLE_TARGET variable in your make.conf to one"
 		fi
 		eerror "of the following values:"
 		eerror
-		eerror "${impls[@]}"
+		eerror "${_PYTHON_SUPPORTED_IMPLS[@]}"
 		echo
 		die "No supported Python implementation in PYTHON_SINGLE_TARGET/PYTHON_TARGETS."
 	fi
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 7830323..89a7cbf 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -84,6 +84,55 @@ _python_impl_supported() {
 	esac
 }
 
+# @FUNCTION: _python_set_impls
+# @INTERNAL
+# @DESCRIPTION:
+# Check PYTHON_COMPAT for well-formedness and validity, then set
+# two global variables:
+#
+# - _PYTHON_SUPPORTED_IMPLS containing valid implementations supported
+#   by the ebuild (PYTHON_COMPAT - dead implementations),
+#
+# - and _PYTHON_UNSUPPORTED_IMPLS containing valid implementations that
+#   are not supported by the ebuild.
+#
+# Implementations in both variables are ordered using the pre-defined
+# eclass implementation ordering.
+#
+# This function must be called once in global scope by an eclass
+# utilizing PYTHON_COMPAT.
+_python_set_impls() {
+	local i
+
+	if ! declare -p PYTHON_COMPAT &>/dev/null; then
+		die 'PYTHON_COMPAT not declared.'
+	fi
+	if [[ $(declare -p PYTHON_COMPAT) != "declare -a"* ]]; then
+		die 'PYTHON_COMPAT must be an array.'
+	fi
+	for i in "${PYTHON_COMPAT[@]}"; do
+		# trigger validity checks
+		_python_impl_supported "${i}"
+	done
+
+	_PYTHON_SUPPORTED_IMPLS=()
+	_PYTHON_UNSUPPORTED_IMPLS=()
+
+	for i in "${_PYTHON_ALL_IMPLS[@]}"; do
+		if has "${i}" "${PYTHON_COMPAT[@]}"; then
+			_PYTHON_SUPPORTED_IMPLS+=( "${i}" )
+		else
+			_PYTHON_UNSUPPORTED_IMPLS+=( "${i}" )
+		fi
+	done
+
+	if [[ ${#_PYTHON_SUPPORTED_IMPLS[@]} -eq 0 ]]; then
+		die "No supported implementation in PYTHON_COMPAT."
+	fi
+
+	readonly _PYTHON_SUPPORTED_IMPLS _PYTHON_UNSUPPORTED_IMPLS
+}
+
 # @ECLASS-VARIABLE: PYTHON
 # @DEFAULT_UNSET
 # @DESCRIPTION:
-- 
2.6.4



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-dev] [PATCH 2/5] python-single-r1.eclass: Fix python_gen_* w/ single PYTHON_COMPAT impl
  2015-12-17 22:02 [gentoo-dev] [PATCH 0/5] python*-r1: commonize PYTHON_COMPAT handling Michał Górny
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 1/5] python*-r1.eclass: Commonize PYTHON_COMPAT processing, cache the result Michał Górny
@ 2015-12-17 22:02 ` Michał Górny
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 3/5] python-any-r1.eclass: Support PYTHON_COMPAT_OVERRIDE Michał Górny
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Michał Górny @ 2015-12-17 22:02 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

Fix python_gen_useflags() and python_gen_cond_dep() to output correct
flag name when only a single implementation is listed in PYTHON_COMPAT.
In this case, the PYTHON_SINGLE_TARGET flags are not emitted
and PYTHON_TARGETS are used directly instead.
---
 eclass/python-single-r1.eclass | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/eclass/python-single-r1.eclass b/eclass/python-single-r1.eclass
index 8ef3846..4c4f057 100644
--- a/eclass/python-single-r1.eclass
+++ b/eclass/python-single-r1.eclass
@@ -310,13 +310,19 @@ python_gen_usedep() {
 python_gen_useflags() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	local impl pattern
+	local flag_prefix impl pattern
 	local matches=()
 
+	if [[ ${#_PYTHON_SUPPORTED_IMPLS[@]} -eq 1 ]]; then
+		flag_prefix=python_targets
+	else
+		flag_prefix=python_single_target
+	fi
+
 	for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
 		for pattern; do
 			if [[ ${impl} == ${pattern} ]]; then
-				matches+=( "python_single_target_${impl}" )
+				matches+=( "${flag_prefix}_${impl}" )
 				break
 			fi
 		done
@@ -354,9 +360,15 @@ python_gen_useflags() {
 python_gen_cond_dep() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	local impl pattern
+	local flag_prefix impl pattern
 	local matches=()
 
+	if [[ ${#_PYTHON_SUPPORTED_IMPLS[@]} -eq 1 ]]; then
+		flag_prefix=python_targets
+	else
+		flag_prefix=python_single_target
+	fi
+
 	local dep=${1}
 	shift
 
@@ -371,7 +383,7 @@ python_gen_cond_dep() {
 					dep=${dep//\$\{PYTHON_USEDEP\}/${usedep}}
 				fi
 
-				matches+=( "python_single_target_${impl}? ( ${dep} )" )
+				matches+=( "${flag_prefix}_${impl}? ( ${dep} )" )
 				break
 			fi
 		done
-- 
2.6.4



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-dev] [PATCH 3/5] python-any-r1.eclass: Support PYTHON_COMPAT_OVERRIDE
  2015-12-17 22:02 [gentoo-dev] [PATCH 0/5] python*-r1: commonize PYTHON_COMPAT handling Michał Górny
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 1/5] python*-r1.eclass: Commonize PYTHON_COMPAT processing, cache the result Michał Górny
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 2/5] python-single-r1.eclass: Fix python_gen_* w/ single PYTHON_COMPAT impl Michał Górny
@ 2015-12-17 22:02 ` Michał Górny
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 4/5] python-single-r1.eclass: " Michał Górny
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 5/5] python-any-r1.eclass: Use reverse iter instead of reversing impls array Michał Górny
  4 siblings, 0 replies; 6+ messages in thread
From: Michał Górny @ 2015-12-17 22:02 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

---
 eclass/python-any-r1.eclass | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/eclass/python-any-r1.eclass b/eclass/python-any-r1.eclass
index dbfeded..99aac73 100644
--- a/eclass/python-any-r1.eclass
+++ b/eclass/python-any-r1.eclass
@@ -72,6 +72,24 @@ if [[ ! ${_PYTHON_ANY_R1} ]]; then
 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
 # @CODE
 
+# @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
+# @INTERNAL
+# @DESCRIPTION:
+# This variable can be used when working with ebuilds to override
+# the in-ebuild PYTHON_COMPAT. It is a string naming the implementation
+# which will be used to build the package. It needs to be specified
+# in the calling environment, and not in ebuilds.
+#
+# It should be noted that in order to preserve metadata immutability,
+# PYTHON_COMPAT_OVERRIDE does not affect dependencies. The value of
+# EPYTHON and eselect-python preferences are ignored. Dependencies need
+# to be satisfied manually.
+#
+# Example:
+# @CODE
+# PYTHON_COMPAT_OVERRIDE='pypy' emerge -1v dev-python/bar
+# @CODE
+
 # @ECLASS-VARIABLE: PYTHON_REQ_USE
 # @DEFAULT_UNSET
 # @DESCRIPTION:
@@ -253,6 +271,23 @@ _python_EPYTHON_supported() {
 python_setup() {
 	debug-print-function ${FUNCNAME} "${@}"
 
+	# support developer override
+	if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
+		local impls=( ${PYTHON_COMPAT_OVERRIDE} )
+		[[ ${#impls[@]} -eq 1 ]] || die "PYTHON_COMPAT_OVERRIDE must name exactly one implementation for python-any-r1"
+
+		ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python"
+		ewarn "implementation will be used:"
+		ewarn
+		ewarn "	${PYTHON_COMPAT_OVERRIDE}"
+		ewarn
+		ewarn "Dependencies won't be satisfied, and EPYTHON/eselect-python will be ignored."
+
+		python_export "${impls[0]}" EPYTHON PYTHON
+		python_wrapper_setup
+		return
+	fi
+
 	# first, try ${EPYTHON}... maybe it's good enough for us.
 	if [[ ${EPYTHON} ]]; then
 		if _python_EPYTHON_supported "${EPYTHON}"; then
-- 
2.6.4



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-dev] [PATCH 4/5] python-single-r1.eclass: Support PYTHON_COMPAT_OVERRIDE
  2015-12-17 22:02 [gentoo-dev] [PATCH 0/5] python*-r1: commonize PYTHON_COMPAT handling Michał Górny
                   ` (2 preceding siblings ...)
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 3/5] python-any-r1.eclass: Support PYTHON_COMPAT_OVERRIDE Michał Górny
@ 2015-12-17 22:02 ` Michał Górny
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 5/5] python-any-r1.eclass: Use reverse iter instead of reversing impls array Michał Górny
  4 siblings, 0 replies; 6+ messages in thread
From: Michał Górny @ 2015-12-17 22:02 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

---
 eclass/python-single-r1.eclass | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/eclass/python-single-r1.eclass b/eclass/python-single-r1.eclass
index 4c4f057..4d5026f 100644
--- a/eclass/python-single-r1.eclass
+++ b/eclass/python-single-r1.eclass
@@ -96,6 +96,25 @@ if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
 # PYTHON_COMPAT=( python2_7 python3_{3,4} )
 # @CODE
 
+# @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
+# @INTERNAL
+# @DESCRIPTION:
+# This variable can be used when working with ebuilds to override
+# the in-ebuild PYTHON_COMPAT. It is a string naming the implementation
+# which package will be built for. It needs to be specified
+# in the calling environment, and not in ebuilds.
+#
+# It should be noted that in order to preserve metadata immutability,
+# PYTHON_COMPAT_OVERRIDE does not affect IUSE nor dependencies.
+# The state of PYTHON_TARGETS and PYTHON_SINGLE_TARGET is ignored,
+# and the implementation in PYTHON_COMPAT_OVERRIDE is built instead.
+# Dependencies need to be satisfied manually.
+#
+# Example:
+# @CODE
+# PYTHON_COMPAT_OVERRIDE='pypy' emerge -1v dev-python/bar
+# @CODE
+
 # @ECLASS-VARIABLE: PYTHON_REQ_USE
 # @DEFAULT_UNSET
 # @DESCRIPTION:
@@ -401,6 +420,23 @@ python_setup() {
 
 	unset EPYTHON
 
+	# support developer override
+	if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
+		local impls=( ${PYTHON_COMPAT_OVERRIDE} )
+		[[ ${#impls[@]} -eq 1 ]] || die "PYTHON_COMPAT_OVERRIDE must name exactly one implementation for python-single-r1"
+
+		ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python"
+		ewarn "implementation will be used:"
+		ewarn
+		ewarn "	${PYTHON_COMPAT_OVERRIDE}"
+		ewarn
+		ewarn "Dependencies won't be satisfied, and PYTHON_SINGLE_TARGET flags will be ignored."
+
+		python_export "${impls[0]}" EPYTHON PYTHON
+		python_wrapper_setup
+		return
+	fi
+
 	if [[ ${#_PYTHON_SUPPORTED_IMPLS[@]} -eq 1 ]]; then
 		if use "python_targets_${_PYTHON_SUPPORTED_IMPLS[0]}"; then
 			# Only one supported implementation, enable it explicitly
-- 
2.6.4



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-dev] [PATCH 5/5] python-any-r1.eclass: Use reverse iter instead of reversing impls array
  2015-12-17 22:02 [gentoo-dev] [PATCH 0/5] python*-r1: commonize PYTHON_COMPAT handling Michał Górny
                   ` (3 preceding siblings ...)
  2015-12-17 22:02 ` [gentoo-dev] [PATCH 4/5] python-single-r1.eclass: " Michał Górny
@ 2015-12-17 22:02 ` Michał Górny
  4 siblings, 0 replies; 6+ messages in thread
From: Michał Górny @ 2015-12-17 22:02 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

---
 eclass/python-any-r1.eclass | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/eclass/python-any-r1.eclass b/eclass/python-any-r1.eclass
index 99aac73..c6dfc9c 100644
--- a/eclass/python-any-r1.eclass
+++ b/eclass/python-any-r1.eclass
@@ -313,13 +313,9 @@ python_setup() {
 	done
 
 	# fallback to best installed impl.
-	local rev_impls=()
-	for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
-		rev_impls=( "${i}" "${rev_impls[@]}" )
-	done
-
-	for i in "${rev_impls[@]}"; do
-		python_export "${i}" EPYTHON PYTHON
+	# (reverse iteration over _PYTHON_SUPPORTED_IMPLS)
+	for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do
+		python_export "${_PYTHON_SUPPORTED_IMPLS[i]}" EPYTHON PYTHON
 		if _python_EPYTHON_supported "${EPYTHON}"; then
 			python_wrapper_setup
 			return
-- 
2.6.4



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-12-17 22:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-17 22:02 [gentoo-dev] [PATCH 0/5] python*-r1: commonize PYTHON_COMPAT handling Michał Górny
2015-12-17 22:02 ` [gentoo-dev] [PATCH 1/5] python*-r1.eclass: Commonize PYTHON_COMPAT processing, cache the result Michał Górny
2015-12-17 22:02 ` [gentoo-dev] [PATCH 2/5] python-single-r1.eclass: Fix python_gen_* w/ single PYTHON_COMPAT impl Michał Górny
2015-12-17 22:02 ` [gentoo-dev] [PATCH 3/5] python-any-r1.eclass: Support PYTHON_COMPAT_OVERRIDE Michał Górny
2015-12-17 22:02 ` [gentoo-dev] [PATCH 4/5] python-single-r1.eclass: " Michał Górny
2015-12-17 22:02 ` [gentoo-dev] [PATCH 5/5] python-any-r1.eclass: Use reverse iter instead of reversing impls array Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox