public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls
@ 2015-01-05 18:18 Michał Górny
  2015-01-05 18:18 ` [gentoo-dev] [PATCH 2/3] [distutils-r1] support restricting *_all() phase impls Michał Górny
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Michał Górny @ 2015-01-05 18:18 UTC (permalink / raw
  To: gentoo-dev; +Cc: python, Michał Górny

Allow limiting accepted implementations in python_setup. This allows
ebuilds to explicitly specify which implementations can be used to
perform specific tasks (e.g. doc build) rather than implicitly relying
on specific implementation preference order.

Example use case:

  IUSE="doc"
  RDEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
  REQUIRED_USE="doc? ( || ( $(python_gen_useflags 'python2*') ) )"

So far, such ebuilds implicitly assumed Python 2 will be preferred over
Python 3, so if any version of Python 2 is enabled, python_setup will
use it.

With the new API, the src_configure() call could look like:

  src_configure() {
      #...

      if use doc; then
          python_setup 'python2*'
          ./build_docs.py
      fi
  }

Therefore explicitly restricting the choice to Python 2.* independently
of eclass-defined implementation order/preference.
---
 eclass/python-r1.eclass | 45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
index 713167d..0f73e3c 100644
--- a/eclass/python-r1.eclass
+++ b/eclass/python-r1.eclass
@@ -737,17 +737,56 @@ python_parallel_foreach_impl() {
 }
 
 # @FUNCTION: python_setup
+# @USAGE: [<impl-pattern>...]
 # @DESCRIPTION:
-# Find the best (most preferred) Python implementation enabled
-# and set the Python build environment up for it.
+# Find the best (most preferred) Python implementation that is enabled
+# and matches at least one of the patterns passed (or '*' if no patterns
+# passed). Set the Python build environment up for that implementation.
 #
 # This function needs to be used when Python is being called outside
 # of python_foreach_impl calls (e.g. for shared processes like doc
 # building). python_foreach_impl sets up the build environment itself.
+#
+# If the specific commands support only a subset of Python
+# implementations, patterns need to be passed to restrict the allowed
+# implementations.
+#
+# Example:
+# @CODE
+# DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
+#
+# src_compile() {
+#   #...
+#   if use doc; then
+#     python_setup 'python2*'
+#     make doc
+#   fi
+# }
+# @CODE
 python_setup() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	python_export_best
+	local best_impl patterns=( "${@-*}" )
+	_python_try_impl() {
+		local pattern
+		for pattern in "${patterns[@]}"; do
+			if [[ ${EPYTHON} == ${pattern} ]]; then
+				best_impl=${EPYTHON}
+			fi
+		done
+	}
+	python_foreach_impl _python_try_impl
+
+	if [[ ! ${best_impl} ]]; then
+		eerror "${FUNCNAME}: none of the enabled implementation matched the patterns."
+		eerror "  patterns: ${@-'(*)'}"
+		eerror "Likely a REQUIRED_USE constraint (possibly USE-conditional) is missing."
+		eerror "  suggested: || ( \$(python_gen_useflags ${@}) )"
+		eerror "(remember to quote all the patterns with '')"
+		die "${FUNCNAME}: no enabled implementation satisfy requirements"
+	fi
+
+	python_export "${best_impl}" EPYTHON PYTHON
 	python_wrapper_setup
 }
 
-- 
2.2.1



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

* [gentoo-dev] [PATCH 2/3] [distutils-r1] support restricting *_all() phase impls
  2015-01-05 18:18 [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls Michał Górny
@ 2015-01-05 18:18 ` Michał Górny
  2015-01-05 18:18 ` [gentoo-dev] [PATCH 3/3] [python-r1] Finally deprecate python_export_best() Michał Górny
  2015-01-13 22:07 ` [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls Michał Górny
  2 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2015-01-05 18:18 UTC (permalink / raw
  To: gentoo-dev; +Cc: python, Michał Górny

Add a DISTUTILS_ALL_SUBPHASE_IMPLS variable that can be used to restrict
implementations for the *_all() sub-phases.

Example use:

  IUSE="doc"
  RDEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
  REQUIRED_USE="doc? ( || ( $(python_gen_useflags 'python2*') ) )"

  pkg_setup() {
      use doc && DISTUTILS_ALL_SUBPHASE_IMPLS=( 'python2*' )
  }

  python_compile_all() {
      use doc && esetup.py doc
  }
---
 eclass/distutils-r1.eclass | 53 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index da5c687..33b2a96 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -181,6 +181,31 @@ fi
 # 'build --build-base ${BUILD_DIR}' to enforce keeping & using built
 # files in the specific root.
 
+# @ECLASS-VARIABLE: DISTUTILS_ALL_SUBPHASE_IMPLS
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# An array of patterns specifying which implementations can be used
+# for *_all() sub-phase functions. If undefined, defaults to '*'
+# (allowing any implementation). If multiple values are specified,
+# implementations matching any of the patterns will be accepted.
+#
+# If the restriction needs to apply conditionally to a USE flag,
+# the variable should be set conditionally as well (e.g. in an early
+# phase function or other convenient location).
+#
+# Please remember to add a matching || block to REQUIRED_USE,
+# to ensure that at least one implementation matching the patterns will
+# be enabled.
+#
+# Example:
+# @CODE
+# REQUIRED_USE="doc? ( || ( $(python_gen_useflags 'python2*') ) )"
+#
+# pkg_setup() {
+#     use doc && DISTUTILS_ALL_SUBPHASE_IMPLS=( 'python2*' )
+# }
+# @CODE
+
 # @ECLASS-VARIABLE: mydistutilsargs
 # @DEFAULT_UNSET
 # @DESCRIPTION:
@@ -624,24 +649,30 @@ distutils-r1_run_phase() {
 # @USAGE: [<argv>...]
 # @INTERNAL
 # @DESCRIPTION:
-# Run the given command, restoring the best-implementation state.
+# Run the given command, restoring the state for a most preferred Python
+# implementation matching DISTUTILS_ALL_SUBPHASE_IMPLS.
 #
 # If in-source build is used, the command will be run in the copy
-# of sources made for the best Python interpreter.
+# of sources made for the selected Python interpreter.
 _distutils-r1_run_common_phase() {
 	local DISTUTILS_ORIG_BUILD_DIR=${BUILD_DIR}
 
 	if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
-		local _DISTUTILS_INITIAL_CWD=${PWD}
-		local MULTIBUILD_VARIANTS
-		_python_obtain_impls
-
-		multibuild_for_best_variant _python_multibuild_wrapper \
-			distutils-r1_run_phase "${@}"
-	else
-		# semi-hack, be careful.
-		_distutils-r1_run_foreach_impl "${@}"
+		local best_impl patterns=( "${DISTUTILS_ALL_SUBPHASE_IMPLS[@]-*}" )
+		_distutils_try_impl() {
+			local pattern
+			for pattern in "${patterns[@]}"; do
+				if [[ ${EPYTHON} == ${pattern} ]]; then
+					best_impl=${MULTIBUILD_VARIANT}
+				fi
+			done
+		}
+		python_foreach_impl _distutils_try_impl
+
+		local PYTHON_COMPAT=( "${best_impl}" )
 	fi
+
+	_distutils-r1_run_foreach_impl "${@}"
 }
 
 # @FUNCTION: _distutils-r1_run_foreach_impl
-- 
2.2.1



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

* [gentoo-dev] [PATCH 3/3] [python-r1] Finally deprecate python_export_best()
  2015-01-05 18:18 [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls Michał Górny
  2015-01-05 18:18 ` [gentoo-dev] [PATCH 2/3] [distutils-r1] support restricting *_all() phase impls Michał Górny
@ 2015-01-05 18:18 ` Michał Górny
  2015-01-13 22:07 ` [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls Michał Górny
  2 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2015-01-05 18:18 UTC (permalink / raw
  To: gentoo-dev; +Cc: python, Michał Górny

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

diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
index 0f73e3c..1ff521b 100644
--- a/eclass/python-r1.eclass
+++ b/eclass/python-r1.eclass
@@ -799,6 +799,9 @@ python_setup() {
 python_export_best() {
 	debug-print-function ${FUNCNAME} "${@}"
 
+	eqawarn "python_export_best() is deprecated. Please use python_setup instead,"
+	eqawarn "combined with python_export if necessary."
+
 	[[ ${#} -gt 0 ]] || set -- EPYTHON PYTHON
 
 	local best MULTIBUILD_VARIANTS
-- 
2.2.1



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

* Re: [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls
  2015-01-05 18:18 [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls Michał Górny
  2015-01-05 18:18 ` [gentoo-dev] [PATCH 2/3] [distutils-r1] support restricting *_all() phase impls Michał Górny
  2015-01-05 18:18 ` [gentoo-dev] [PATCH 3/3] [python-r1] Finally deprecate python_export_best() Michał Górny
@ 2015-01-13 22:07 ` Michał Górny
  2 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2015-01-13 22:07 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 434 bytes --]

Dnia 2015-01-05, o godz. 19:18:28
Michał Górny <mgorny@gentoo.org> napisał(a):

> Allow limiting accepted implementations in python_setup. This allows
> ebuilds to explicitly specify which implementations can be used to
> perform specific tasks (e.g. doc build) rather than implicitly relying
> on specific implementation preference order.

All three committed and wiki docs updated.

-- 
Best regards,
Michał Górny

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 949 bytes --]

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

end of thread, other threads:[~2015-01-13 22:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-05 18:18 [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls Michał Górny
2015-01-05 18:18 ` [gentoo-dev] [PATCH 2/3] [distutils-r1] support restricting *_all() phase impls Michał Górny
2015-01-05 18:18 ` [gentoo-dev] [PATCH 3/3] [python-r1] Finally deprecate python_export_best() Michał Górny
2015-01-13 22:07 ` [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls 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