public inbox for gentoo-python@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-python] First steps in python-r1.eclass
@ 2012-09-14  9:10 Michał Górny
  2012-09-14  9:10 ` [gentoo-python] [PATCH 1/2] Support PYTHON_COMPAT being an array Michał Górny
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Michał Górny @ 2012-09-14  9:10 UTC (permalink / raw
  To: gentoo-python; +Cc: python

Just the first few lines to see whether you like the new coding style
and ideas or not. Notice the array comprehensions.

--
Best regards,
Michał Górny



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

* [gentoo-python] [PATCH 1/2] Support PYTHON_COMPAT being an array.
  2012-09-14  9:10 [gentoo-python] First steps in python-r1.eclass Michał Górny
@ 2012-09-14  9:10 ` Michał Górny
  2012-09-14  9:10 ` [gentoo-python] [PATCH 2/2] Move PYTHON_COMPAT, IUSE and REQUIRED_USE to python-r1 Michał Górny
  2012-09-14 20:32 ` [gentoo-python] [PATCH] Generate python depstrings in python-r1 Michał Górny
  2 siblings, 0 replies; 5+ messages in thread
From: Michał Górny @ 2012-09-14  9:10 UTC (permalink / raw
  To: gentoo-python; +Cc: python, Michał Górny

---
 gx86/eclass/python-distutils-ng.eclass | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/gx86/eclass/python-distutils-ng.eclass b/gx86/eclass/python-distutils-ng.eclass
index 3ba6988..e3ec14c 100644
--- a/gx86/eclass/python-distutils-ng.eclass
+++ b/gx86/eclass/python-distutils-ng.eclass
@@ -40,6 +40,9 @@
 # This variable contains a space separated list of implementations (see above) a
 # package is compatible to. It must be set before the `inherit' call. The
 # default is to enable all implementations.
+#
+# PYTHON_COMPAT can be either a scalar or an array. If it's a scalar, the eclass
+# will implicitly convert it to an array.
 
 if [[ -z "${PYTHON_COMPAT}" ]]; then
 	# Default: pure python, support all implementations
@@ -49,6 +52,8 @@ if [[ -z "${PYTHON_COMPAT}" ]]; then
 	PYTHON_COMPAT+=" pypy1_8 pypy1_9"
 fi
 
+PYTHON_COMPAT=( ${PYTHON_COMPAT[@]} )
+
 # @ECLASS-VARIABLE: PYTHON_DISABLE_COMPILATION
 # @DEFAULT_UNSET
 # @DESCRIPTION:
@@ -96,14 +101,14 @@ _python-distutils-ng_get_binary_for_implementation() {
 }
 
 required_use_str=""
-for impl in ${PYTHON_COMPAT}; do
+for impl in ${PYTHON_COMPAT[@]}; do
 	required_use_str+=" python_targets_${impl}"
 done
 required_use_str=" || ( ${required_use_str} )"
 REQUIRED_USE+=" ${required_use_str}"
 unset required_use_str
 
-for impl in ${PYTHON_COMPAT}; do
+for impl in ${PYTHON_COMPAT[@]}; do
 	IUSE+=" python_targets_${impl}"
 	dep_str="${impl/_/.}"
 	case "${dep_str}" in
@@ -155,8 +160,8 @@ _python-distutils-ng_run_for_impl() {
 _python-distutils-ng_run_for_each_impl() {
 	local command="${1}"
 
-	for impl in ${PYTHON_COMPAT}; do
-		use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
+	for impl in ${PYTHON_COMPAT[@]}; do
+		use "python_targets_${impl}" ${PYTHON_COMPAT[@]} || continue
 		_python-distutils-ng_run_for_impl "${impl}" "${command}"
 	done
 }
@@ -255,7 +260,7 @@ python-distutils-ng_newscript() {
 	local destination_directory="/usr/bin"
 	[[ -n "${3}" ]] && destination_directory="${3}"
 
-	for impl in ${PYTHON_COMPAT}; do
+	for impl in ${PYTHON_COMPAT[@]}; do
 		use "python_targets_${impl}" || continue
 		enabled_impls=$((enabled_impls + 1))
 	done
@@ -282,8 +287,8 @@ python-distutils-ng_newscript() {
 		python-distutils-ng_rewrite_hashbang "${D}${destination_directory}/${destination_file}" "${default_impl}"
 	else
 		einfo "Installing ${source_file} for multiple implementations (default: ${default_impl}) in ${destination_directory}"
-		for impl in ${PYTHON_COMPAT}; do
-			use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
+		for impl in ${PYTHON_COMPAT[@]}; do
+			use "python_targets_${impl}" ${PYTHON_COMPAT[@]} || continue
 
 			newins "${source_file}" "${destination_file}-${impl}"
 			fperms 755 "${destination_directory}/${destination_file}-${impl}"
@@ -297,8 +302,8 @@ python-distutils-ng_newscript() {
 # Phase function: src_prepare
 python-distutils-ng_src_prepare() {
 	# Try to run binary for each implementation:
-	for impl in ${PYTHON_COMPAT}; do
-		use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
+	for impl in ${PYTHON_COMPAT[@]}; do
+		use "python_targets_${impl}" ${PYTHON_COMPAT[@]} || continue
 		$(_python-distutils-ng_get_binary_for_implementation "${impl}") \
 			-c "import sys" || die
 	done
@@ -310,8 +315,8 @@ python-distutils-ng_src_prepare() {
 	fi
 
 	# Create a copy of S for each implementation:
-	for impl in ${PYTHON_COMPAT}; do
-		use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
+	for impl in ${PYTHON_COMPAT[@]}; do
+		use "python_targets_${impl}" ${PYTHON_COMPAT[@]} || continue
 
 		einfo "Creating copy for ${impl} in ${WORKDIR}/impl_${impl}"
 		mkdir -p "${WORKDIR}/impl_${impl}" || die
-- 
1.7.12



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

* [gentoo-python] [PATCH 2/2] Move PYTHON_COMPAT, IUSE and REQUIRED_USE to python-r1.
  2012-09-14  9:10 [gentoo-python] First steps in python-r1.eclass Michał Górny
  2012-09-14  9:10 ` [gentoo-python] [PATCH 1/2] Support PYTHON_COMPAT being an array Michał Górny
@ 2012-09-14  9:10 ` Michał Górny
  2012-09-14  9:13   ` Michał Górny
  2012-09-14 20:32 ` [gentoo-python] [PATCH] Generate python depstrings in python-r1 Michał Górny
  2 siblings, 1 reply; 5+ messages in thread
From: Michał Górny @ 2012-09-14  9:10 UTC (permalink / raw
  To: gentoo-python; +Cc: python, Michał Górny

---
 gx86/eclass/python-distutils-ng.eclass | 31 ++------------------
 gx86/eclass/python-r1.eclass           | 53 ++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 29 deletions(-)
 create mode 100644 gx86/eclass/python-r1.eclass

diff --git a/gx86/eclass/python-distutils-ng.eclass b/gx86/eclass/python-distutils-ng.eclass
index e3ec14c..63abdac 100644
--- a/gx86/eclass/python-distutils-ng.eclass
+++ b/gx86/eclass/python-distutils-ng.eclass
@@ -34,26 +34,6 @@
 #    each implementation and python_install_all that will be run in original
 #    directory (so it will not contain any implementation-specific files)
 
-# @ECLASS-VARIABLE: PYTHON_COMPAT
-# @DEFAULT_UNSET
-# @DESCRIPTION:
-# This variable contains a space separated list of implementations (see above) a
-# package is compatible to. It must be set before the `inherit' call. The
-# default is to enable all implementations.
-#
-# PYTHON_COMPAT can be either a scalar or an array. If it's a scalar, the eclass
-# will implicitly convert it to an array.
-
-if [[ -z "${PYTHON_COMPAT}" ]]; then
-	# Default: pure python, support all implementations
-	PYTHON_COMPAT="  python2_5 python2_6 python2_7"
-	PYTHON_COMPAT+=" python3_1 python3_2"
-	PYTHON_COMPAT+=" jython2_5"
-	PYTHON_COMPAT+=" pypy1_8 pypy1_9"
-fi
-
-PYTHON_COMPAT=( ${PYTHON_COMPAT[@]} )
-
 # @ECLASS-VARIABLE: PYTHON_DISABLE_COMPILATION
 # @DEFAULT_UNSET
 # @DESCRIPTION:
@@ -76,6 +56,8 @@ case "${EAPI}" in
 		die "Unsupported EAPI=${EAPI} (unknown) for python-distutils-ng.eclass" ;;
 esac
 
+inherit python-r1
+
 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
 
 DEPEND="${DEPEND} !<sys-apps/portage-2.1.10.58"
@@ -100,16 +82,7 @@ _python-distutils-ng_get_binary_for_implementation() {
 	esac
 }
 
-required_use_str=""
-for impl in ${PYTHON_COMPAT[@]}; do
-	required_use_str+=" python_targets_${impl}"
-done
-required_use_str=" || ( ${required_use_str} )"
-REQUIRED_USE+=" ${required_use_str}"
-unset required_use_str
-
 for impl in ${PYTHON_COMPAT[@]}; do
-	IUSE+=" python_targets_${impl}"
 	dep_str="${impl/_/.}"
 	case "${dep_str}" in
 		python?.?)
diff --git a/gx86/eclass/python-r1.eclass b/gx86/eclass/python-r1.eclass
new file mode 100644
index 0000000..18f9246
--- /dev/null
+++ b/gx86/eclass/python-r1.eclass
@@ -0,0 +1,53 @@
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+# @ECLASS: python-r1
+# @MAINTAINER:
+# Python herd <python@gentoo.org>
+# @AUTHOR:
+# Author: Michał Górny <mgorny@gentoo.org>
+# Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
+# @BLURB: A common eclass for Python packages supporting multiple ABIs.
+# @DESCRIPTION:
+
+case "${EAPI}" in
+	0|1|2|3)
+		die "Unsupported EAPI=${EAPI} (too old) for ${ECLASS}"
+		;;
+	4)
+		# EAPI=4 needed for REQUIRED_USE
+		;;
+	*)
+		die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
+		;;
+esac
+
+# @ECLASS-VARIABLE: _PYTHON_ALL_IMPLS
+# @INTERNAL
+# @DESCRIPTION:
+# All supported Python implementations, most preferred first.
+_PYTHON_ALL_IMPLS=(
+	python2_7 python2_6 python2_5
+	python3_2 python3_1
+	pypy1_9 pypy1_8
+	jython2_5
+)
+
+# @ECLASS-VARIABLE: PYTHON_COMPAT
+# @DESCRIPTION:
+# This variable contains a space separated list of Pythonimplementations
+# a package supports. It must be set before the `inherit' call.
+# The default is to enable all implementations.
+#
+# PYTHON_COMPAT can be either a scalar or an array. If it's a scalar, the eclass
+# will implicitly convert it to an array.
+: ${PYTHON_COMPAT:=${_PYTHON_ALL_IMPLS[@]}}
+
+PYTHON_COMPAT=( ${PYTHON_COMPAT[@]} )
+
+_python_set_globals() {
+	IUSE=${PYTHON_COMPAT[@]/#/python_targets_}
+	REQUIRED_USE="|| ( ${IUSE} )"
+}
+_python_set_globals
-- 
1.7.12



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

* Re: [gentoo-python] [PATCH 2/2] Move PYTHON_COMPAT, IUSE and REQUIRED_USE to python-r1.
  2012-09-14  9:10 ` [gentoo-python] [PATCH 2/2] Move PYTHON_COMPAT, IUSE and REQUIRED_USE to python-r1 Michał Górny
@ 2012-09-14  9:13   ` Michał Górny
  0 siblings, 0 replies; 5+ messages in thread
From: Michał Górny @ 2012-09-14  9:13 UTC (permalink / raw
  To: Michał Górny; +Cc: gentoo-python, python

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

On Fri, 14 Sep 2012 11:10:40 +0200
Michał Górny <mgorny@gentoo.org> wrote:

> +_python_set_globals() {
> +	IUSE=${PYTHON_COMPAT[@]/#/python_targets_}
> +	REQUIRED_USE="|| ( ${IUSE} )"
> +}
> +_python_set_globals

As a note, I'm using a function here so I will be able to introduce
local variables when adding *DEPEND generation.

-- 
Best regards,
Michał Górny

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 316 bytes --]

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

* [gentoo-python] [PATCH] Generate python depstrings in python-r1.
  2012-09-14  9:10 [gentoo-python] First steps in python-r1.eclass Michał Górny
  2012-09-14  9:10 ` [gentoo-python] [PATCH 1/2] Support PYTHON_COMPAT being an array Michał Górny
  2012-09-14  9:10 ` [gentoo-python] [PATCH 2/2] Move PYTHON_COMPAT, IUSE and REQUIRED_USE to python-r1 Michał Górny
@ 2012-09-14 20:32 ` Michał Górny
  2 siblings, 0 replies; 5+ messages in thread
From: Michał Górny @ 2012-09-14 20:32 UTC (permalink / raw
  To: gentoo-python; +Cc: python, Michał Górny

---
 gx86/eclass/python-distutils-ng.eclass | 20 ++------------------
 gx86/eclass/python-r1.eclass           | 28 ++++++++++++++++++++++++++--
 2 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/gx86/eclass/python-distutils-ng.eclass b/gx86/eclass/python-distutils-ng.eclass
index 63abdac..71f8030 100644
--- a/gx86/eclass/python-distutils-ng.eclass
+++ b/gx86/eclass/python-distutils-ng.eclass
@@ -82,24 +82,8 @@ _python-distutils-ng_get_binary_for_implementation() {
 	esac
 }
 
-for impl in ${PYTHON_COMPAT[@]}; do
-	dep_str="${impl/_/.}"
-	case "${dep_str}" in
-		python?.?)
-			dep_str="dev-lang/python:${dep_str: -3}" ;;
-		jython?.?)
-			dep_str="dev-java/jython:${dep_str: -3}" ;;
-		pypy?.?)
-			dep_str="dev-python/pypy:${dep_str: -3}" ;;
-		*)
-			die "Unsupported implementation: ${impl}" ;;
-	esac
-	dep_str="python_targets_${impl}? ( ${dep_str} )"
-
-	RDEPEND="${RDEPEND} ${dep_str}"
-	DEPEND="${DEPEND} ${dep_str}"
-	unset dep_str
-done
+RDEPEND=${PYTHON_DEPEND}
+DEPEND=${PYTHON_DEPEND}
 
 _PACKAGE_SPECIFIC_S="${S#${WORKDIR}/}"
 
diff --git a/gx86/eclass/python-r1.eclass b/gx86/eclass/python-r1.eclass
index 18f9246..3017dd8 100644
--- a/gx86/eclass/python-r1.eclass
+++ b/gx86/eclass/python-r1.eclass
@@ -40,14 +40,38 @@ _PYTHON_ALL_IMPLS=(
 # a package supports. It must be set before the `inherit' call.
 # The default is to enable all implementations.
 #
-# PYTHON_COMPAT can be either a scalar or an array. If it's a scalar, the eclass
-# will implicitly convert it to an array.
+# PYTHON_COMPAT can be either a scalar or an array. If it's a scalar,
+# the eclass will implicitly convert it to an array.
 : ${PYTHON_COMPAT:=${_PYTHON_ALL_IMPLS[@]}}
 
+# @ECLASS-VARIABLE: PYTHON_DEPEND
+# @DESCRIPTION:
+# This is an eclass-generated Python dependency string for all
+# implementations listed in PYTHON_COMPAT.
+
 PYTHON_COMPAT=( ${PYTHON_COMPAT[@]} )
 
 _python_set_globals() {
 	IUSE=${PYTHON_COMPAT[@]/#/python_targets_}
 	REQUIRED_USE="|| ( ${IUSE} )"
+
+	PYTHON_DEPEND=
+	local i
+	for i in ${PYTHON_COMPAT[@]}; do
+		local d
+		case ${i} in
+			python*)
+				d='dev-lang/python';;
+			jython*)
+				d='dev-java/jython';;
+			pypy*)
+				d='dev-python/pypy';;
+			*)
+				die "Invalid implementation: ${i}"
+		esac
+
+		local v=${i##*[a-z]}
+		PYTHON_DEPEND+=" python_targets_${i}? ( ${d}:${v/_/.} )"
+	done
 }
 _python_set_globals
-- 
1.7.12



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

end of thread, other threads:[~2012-09-14 20:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-14  9:10 [gentoo-python] First steps in python-r1.eclass Michał Górny
2012-09-14  9:10 ` [gentoo-python] [PATCH 1/2] Support PYTHON_COMPAT being an array Michał Górny
2012-09-14  9:10 ` [gentoo-python] [PATCH 2/2] Move PYTHON_COMPAT, IUSE and REQUIRED_USE to python-r1 Michał Górny
2012-09-14  9:13   ` Michał Górny
2012-09-14 20:32 ` [gentoo-python] [PATCH] Generate python depstrings in python-r1 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