public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH python-r1] Move common utility functions to python-utils-r1.
@ 2012-11-21  9:43 Michał Górny
  2012-11-21 13:54 ` Ian Stakenvicius
  0 siblings, 1 reply; 7+ messages in thread
From: Michał Górny @ 2012-11-21  9:43 UTC (permalink / raw
  To: gentoo-dev; +Cc: python, Michał Górny

Moved: python_export, getters, python_domodule, python_doscript
and the necessary internal functions. No global-scope variables,
no phase functions.
---
 gx86/eclass/python-r1.eclass       | 409 +---------------------------------
 gx86/eclass/python-utils-r1.eclass | 434 +++++++++++++++++++++++++++++++++++++
 2 files changed, 440 insertions(+), 403 deletions(-)
 create mode 100644 gx86/eclass/python-utils-r1.eclass

diff --git a/gx86/eclass/python-r1.eclass b/gx86/eclass/python-r1.eclass
index 84dc50f..6cf4200 100644
--- a/gx86/eclass/python-r1.eclass
+++ b/gx86/eclass/python-r1.eclass
@@ -23,6 +23,11 @@
 # Please note that this eclass is mostly intended to be extended
 # on-request. If you find something you used in other eclasses missing,
 # please don't hack it around and request an enhancement instead.
+#
+# Also, please note that python-r1 will always inherit python-utils-r1
+# as well. Thus, all the functions defined and documented there
+# can be used in the packages using python-r1, and there is no need ever
+# to inherit both.
 
 case "${EAPI}" in
 	0|1|2|3)
@@ -36,7 +41,7 @@ case "${EAPI}" in
 		;;
 esac
 
-inherit multilib
+inherit python-utils-r1
 
 # @ECLASS-VARIABLE: _PYTHON_ALL_IMPLS
 # @INTERNAL
@@ -181,160 +186,6 @@ _python_set_globals
 # ${WORKDIR}/foo-1.3-python2_6
 # @CODE
 
-# @ECLASS-VARIABLE: PYTHON
-# @DESCRIPTION:
-# The absolute path to the current Python interpreter.
-#
-# Set and exported only in commands run by python_foreach_impl().
-#
-# Example value:
-# @CODE
-# /usr/bin/python2.6
-# @CODE
-
-# @ECLASS-VARIABLE: EPYTHON
-# @DESCRIPTION:
-# The executable name of the current Python interpreter.
-#
-# This variable is used consistently with python.eclass.
-#
-# Set and exported only in commands run by python_foreach_impl().
-#
-# Example value:
-# @CODE
-# python2.6
-# @CODE
-
-# @ECLASS-VARIABLE: PYTHON_SITEDIR
-# @DESCRIPTION:
-# The path to Python site-packages directory.
-#
-# Set and exported on request using python_export().
-#
-# Example value:
-# @CODE
-# /usr/lib64/python2.6/site-packages
-# @CODE
-
-# @FUNCTION: python_export
-# @USAGE: [<impl>] <variables>...
-# @DESCRIPTION:
-# Set and export the Python implementation-relevant variables passed
-# as parameters.
-#
-# The optional first parameter may specify the requested Python
-# implementation (either as PYTHON_TARGETS value, e.g. python2_7,
-# or an EPYTHON one, e.g. python2.7). If no implementation passed,
-# the current one will be obtained from ${EPYTHON}.
-#
-# The variables which can be exported are: PYTHON, EPYTHON,
-# PYTHON_SITEDIR. They are described more completely in the eclass
-# variable documentation.
-python_export() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	local impl var
-
-	case "${1}" in
-		python*|jython*)
-			impl=${1/_/.}
-			shift
-			;;
-		pypy-c*)
-			impl=${1}
-			shift
-			;;
-		pypy*)
-			local v=${1#pypy}
-			impl=pypy-c${v/_/.}
-			shift
-			;;
-		*)
-			impl=${EPYTHON}
-			[[ ${impl} ]] || die "python_export: no impl nor EPYTHON"
-			;;
-	esac
-	debug-print "${FUNCNAME}: implementation: ${impl}"
-
-	for var; do
-		case "${var}" in
-			EPYTHON)
-				export EPYTHON=${impl}
-				debug-print "${FUNCNAME}: EPYTHON = ${EPYTHON}"
-				;;
-			PYTHON)
-				export PYTHON=${EPREFIX}/usr/bin/${impl}
-				debug-print "${FUNCNAME}: PYTHON = ${PYTHON}"
-				;;
-			PYTHON_SITEDIR)
-				local dir
-				case "${impl}" in
-					python*)
-						dir=/usr/$(get_libdir)/${impl}
-						;;
-					jython*)
-						dir=/usr/share/${impl}/Lib
-						;;
-					pypy*)
-						dir=/usr/$(get_libdir)/${impl/-c/}
-						;;
-				esac
-
-				export PYTHON_SITEDIR=${EPREFIX}${dir}/site-packages
-				debug-print "${FUNCNAME}: PYTHON_SITEDIR = ${PYTHON_SITEDIR}"
-				;;
-			*)
-				die "python_export: unknown variable ${var}"
-		esac
-	done
-}
-
-# @FUNCTION: python_get_PYTHON
-# @USAGE: [<impl>]
-# @DESCRIPTION:
-# Obtain and print the path to the Python interpreter for the given
-# implementation. If no implementation is provided, ${EPYTHON} will
-# be used.
-#
-# If you just need to have PYTHON set (and exported), then it is better
-# to use python_export() directly instead.
-python_get_PYTHON() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	python_export "${@}" PYTHON
-	echo "${PYTHON}"
-}
-
-# @FUNCTION: python_get_EPYTHON
-# @USAGE: <impl>
-# @DESCRIPTION:
-# Obtain and print the EPYTHON value for the given implementation.
-#
-# If you just need to have EPYTHON set (and exported), then it is better
-# to use python_export() directly instead.
-python_get_EPYTHON() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	python_export "${@}" EPYTHON
-	echo "${EPYTHON}"
-}
-
-# @FUNCTION: python_get_sitedir
-# @USAGE: [<impl>]
-# @DESCRIPTION:
-# Obtain and print the 'site-packages' path for the given
-# implementation. If no implementation is provided, ${EPYTHON} will
-# be used.
-#
-# If you just need to have PYTHON_SITEDIR set (and exported), then it is
-# better to use python_export() directly instead.
-python_get_sitedir() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	python_export "${@}" PYTHON_SITEDIR
-	echo "${PYTHON_SITEDIR}"
-}
-
 # @FUNCTION: python_copy_sources
 # @DESCRIPTION:
 # Create a single copy of the package sources (${S}) for each enabled
@@ -617,97 +468,6 @@ python_export_best() {
 	python_export "${impl}" "${@}"
 }
 
-# @FUNCTION: _python_rewrite_shebang
-# @INTERNAL
-# @USAGE: [<EPYTHON>] <path>...
-# @DESCRIPTION:
-# Replaces 'python' executable in the shebang with the executable name
-# of the specified interpreter. If no EPYTHON value (implementation) is
-# used, the current ${EPYTHON} will be used.
-#
-# All specified files must start with a 'python' shebang. A file not
-# having a matching shebang will be refused. The exact shebang style
-# will be preserved in order not to break anything.
-#
-# Example conversions:
-# @CODE
-# From: #!/usr/bin/python -R
-# To: #!/usr/bin/python2.7 -R
-#
-# From: #!/usr/bin/env FOO=bar python
-# To: #!/usr/bin/env FOO=bar python2.7
-# @CODE
-_python_rewrite_shebang() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	local impl
-	case "${1}" in
-		python*|jython*|pypy-c*)
-			impl=${1}
-			shift
-			;;
-		*)
-			impl=${EPYTHON}
-			[[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON"
-			;;
-	esac
-	debug-print "${FUNCNAME}: implementation: ${impl}"
-
-	local f
-	for f; do
-		local shebang=$(head -n 1 "${f}")
-		debug-print "${FUNCNAME}: path = ${f}"
-		debug-print "${FUNCNAME}: shebang = ${shebang}"
-
-		if [[ "${shebang} " != *'python '* ]]; then
-			eerror "A file does not seem to have a supported shebang:"
-			eerror "  file: ${f}"
-			eerror "  shebang: ${shebang}"
-			die "${FUNCNAME}: ${f} does not seem to have a valid shebang"
-		fi
-
-		sed -i -e "1s:python:${impl}:" "${f}" || die
-	done
-}
-
-# @FUNCTION: _python_ln_rel
-# @INTERNAL
-# @USAGE: <from> <to>
-# @DESCRIPTION:
-# Create a relative symlink.
-_python_ln_rel() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	local from=${1}
-	local to=${2}
-
-	local frpath=${from%/*}/
-	local topath=${to%/*}/
-	local rel_path=
-
-	# remove double slashes
-	frpath=${frpath/\/\///}
-	topath=${topath/\/\///}
-
-	while [[ ${topath} ]]; do
-		local frseg=${frpath%%/*}
-		local toseg=${topath%%/*}
-
-		if [[ ${frseg} != ${toseg} ]]; then
-			rel_path=../${rel_path}${frseg:+${frseg}/}
-		fi
-
-		frpath=${frpath#${frseg}/}
-		topath=${topath#${toseg}/}
-	done
-	rel_path+=${frpath}${1##*/}
-
-	debug-print "${FUNCNAME}: ${from} -> ${to}"
-	debug-print "${FUNCNAME}: rel_path = ${rel_path}"
-
-	ln -fs "${rel_path}" "${to}"
-}
-
 # @FUNCTION: python_replicate_script
 # @USAGE: <path>...
 # @DESCRIPTION:
@@ -743,160 +503,3 @@ python_replicate_script() {
 		_python_ln_rel "${ED}"/usr/bin/python-exec "${f}" || die
 	done
 }
-
-# @ECLASS-VARIABLE: python_scriptroot
-# @DEFAULT_UNSET
-# @DESCRIPTION:
-# The current script destination for python_doscript(). The path
-# is relative to the installation root (${ED}).
-#
-# When unset, ${DESTTREE}/bin (/usr/bin by default) will be used.
-#
-# Can be set indirectly through the python_scriptinto() function.
-#
-# Example:
-# @CODE
-# src_install() {
-#   local python_scriptroot=${GAMES_BINDIR}
-#   python_foreach_impl python_doscript foo
-# }
-# @CODE
-
-# @FUNCTION: python_scriptinto
-# @USAGE: <new-path>
-# @DESCRIPTION:
-# Set the current scriptroot. The new value will be stored
-# in the 'python_scriptroot' environment variable. The new value need
-# be relative to the installation root (${ED}).
-#
-# Alternatively, you can set the variable directly.
-python_scriptinto() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	python_scriptroot=${1}
-}
-
-# @FUNCTION: python_doscript
-# @USAGE: <files>...
-# @DESCRIPTION:
-# Install the given scripts into current python_scriptroot,
-# for the current Python implementation (${EPYTHON}).
-#
-# All specified files must start with a 'python' shebang. The shebang
-# will be converted, the file will be renamed to be EPYTHON-suffixed
-# and a wrapper will be installed in place of the original name.
-#
-# Example:
-# @CODE
-# src_install() {
-#   python_foreach_impl python_doscript ${PN}
-# }
-# @CODE
-python_doscript() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	[[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
-
-	local d=${python_scriptroot:-${DESTTREE}/bin}
-	local INSDESTTREE INSOPTIONS
-
-	insinto "${d}"
-	insopts -m755
-
-	local f
-	for f; do
-		local oldfn=${f##*/}
-		local newfn=${oldfn}-${EPYTHON}
-
-		debug-print "${FUNCNAME}: ${oldfn} -> ${newfn}"
-		newins "${f}" "${newfn}"
-		_python_rewrite_shebang "${D}/${d}/${newfn}"
-
-		# install the wrapper
-		_python_ln_rel "${ED}"/usr/bin/python-exec "${D}/${d}/${oldfn}" || die
-	done
-}
-
-# @ECLASS-VARIABLE: python_moduleroot
-# @DEFAULT_UNSET
-# @DESCRIPTION:
-# The current module root for python_domodule(). The path can be either
-# an absolute system path (it must start with a slash, and ${D} will be
-# prepended to it) or relative to the implementation's site-packages directory
-# (then it must start with a non-slash character).
-#
-# When unset, the modules will be installed in the site-packages root.
-#
-# Can be set indirectly through the python_moduleinto() function.
-#
-# Example:
-# @CODE
-# src_install() {
-#   local python_moduleroot=bar
-#   # installs ${PYTHON_SITEDIR}/bar/baz.py
-#   python_foreach_impl python_domodule baz.py
-# }
-# @CODE
-
-# @FUNCTION: python_moduleinto
-# @USAGE: <new-path>
-# @DESCRIPTION:
-# Set the current module root. The new value will be stored
-# in the 'python_moduleroot' environment variable. The new value need
-# be relative to the site-packages root.
-#
-# Alternatively, you can set the variable directly.
-python_moduleinto() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	python_moduleroot=${1}
-}
-
-# @FUNCTION: python_domodule
-# @USAGE: <files>...
-# @DESCRIPTION:
-# Install the given modules (or packages) into the current
-# python_moduleroot. The list can mention both modules (files)
-# and packages (directories). All listed files will be installed
-# for all enabled implementations, and compiled afterwards.
-#
-# Example:
-# @CODE
-# src_install() {
-#   # (${PN} being a directory)
-#   python_foreach_impl python_domodule ${PN}
-# }
-# @CODE
-python_domodule() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	[[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
-
-	local d
-	if [[ ${python_moduleroot} == /* ]]; then
-		# absolute path
-		d=${python_moduleroot}
-	else
-		# relative to site-packages
-		local PYTHON_SITEDIR=${PYTHON_SITEDIR}
-		[[ ${PYTHON_SITEDIR} ]] || python_export PYTHON_SITEDIR
-
-		d=${PYTHON_SITEDIR}/${python_moduleroot}
-	fi
-
-	local INSDESTTREE
-
-	insinto "${d}"
-	doins -r "${@}"
-
-	# erm, python2.6 can't handle passing files to compileall...
-	case "${EPYTHON}" in
-		python*)
-			"${PYTHON}" -m compileall -q "${D}/${d}"
-			"${PYTHON}" -OO -m compileall -q -f "${D}/${d}"
-			;;
-		*)
-			"${PYTHON}" -m compileall -q "${D}/${d}"
-			;;
-	esac
-}
diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
new file mode 100644
index 0000000..d80b729
--- /dev/null
+++ b/gx86/eclass/python-utils-r1.eclass
@@ -0,0 +1,434 @@
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+# @ECLASS: python-utils-r1
+# @MAINTAINER:
+# Michał Górny <mgorny@gentoo.org>
+# Python herd <python@gentoo.org>
+# @AUTHOR:
+# Author: Michał Górny <mgorny@gentoo.org>
+# Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
+# @BLURB: Utility functions for packages with Python parts.
+# @DESCRIPTION:
+# An utility eclass providing functions to query Python implementations,
+# install Python modules and scripts.
+#
+# This eclass does not set any metadata variables nor export any phase
+# functions. It can be inherited safely.
+
+case "${EAPI}" in
+	0|1|2|3)
+		die "Unsupported EAPI=${EAPI} (too old) for ${ECLASS}"
+		;;
+	4|5)
+		# EAPI=4 makes die behavior clear
+		;;
+	*)
+		die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
+		;;
+esac
+
+inherit multilib
+
+# @ECLASS-VARIABLE: PYTHON
+# @DESCRIPTION:
+# The absolute path to the current Python interpreter.
+#
+# Set and exported only in commands run by python_foreach_impl().
+#
+# Example value:
+# @CODE
+# /usr/bin/python2.6
+# @CODE
+
+# @ECLASS-VARIABLE: EPYTHON
+# @DESCRIPTION:
+# The executable name of the current Python interpreter.
+#
+# This variable is used consistently with python.eclass.
+#
+# Set and exported only in commands run by python_foreach_impl().
+#
+# Example value:
+# @CODE
+# python2.6
+# @CODE
+
+# @ECLASS-VARIABLE: PYTHON_SITEDIR
+# @DESCRIPTION:
+# The path to Python site-packages directory.
+#
+# Set and exported on request using python_export().
+#
+# Example value:
+# @CODE
+# /usr/lib64/python2.6/site-packages
+# @CODE
+
+# @FUNCTION: python_export
+# @USAGE: [<impl>] <variables>...
+# @DESCRIPTION:
+# Set and export the Python implementation-relevant variables passed
+# as parameters.
+#
+# The optional first parameter may specify the requested Python
+# implementation (either as PYTHON_TARGETS value, e.g. python2_7,
+# or an EPYTHON one, e.g. python2.7). If no implementation passed,
+# the current one will be obtained from ${EPYTHON}.
+#
+# The variables which can be exported are: PYTHON, EPYTHON,
+# PYTHON_SITEDIR. They are described more completely in the eclass
+# variable documentation.
+python_export() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local impl var
+
+	case "${1}" in
+		python*|jython*)
+			impl=${1/_/.}
+			shift
+			;;
+		pypy-c*)
+			impl=${1}
+			shift
+			;;
+		pypy*)
+			local v=${1#pypy}
+			impl=pypy-c${v/_/.}
+			shift
+			;;
+		*)
+			impl=${EPYTHON}
+			[[ ${impl} ]] || die "python_export: no impl nor EPYTHON"
+			;;
+	esac
+	debug-print "${FUNCNAME}: implementation: ${impl}"
+
+	for var; do
+		case "${var}" in
+			EPYTHON)
+				export EPYTHON=${impl}
+				debug-print "${FUNCNAME}: EPYTHON = ${EPYTHON}"
+				;;
+			PYTHON)
+				export PYTHON=${EPREFIX}/usr/bin/${impl}
+				debug-print "${FUNCNAME}: PYTHON = ${PYTHON}"
+				;;
+			PYTHON_SITEDIR)
+				local dir
+				case "${impl}" in
+					python*)
+						dir=/usr/$(get_libdir)/${impl}
+						;;
+					jython*)
+						dir=/usr/share/${impl}/Lib
+						;;
+					pypy*)
+						dir=/usr/$(get_libdir)/${impl/-c/}
+						;;
+				esac
+
+				export PYTHON_SITEDIR=${EPREFIX}${dir}/site-packages
+				debug-print "${FUNCNAME}: PYTHON_SITEDIR = ${PYTHON_SITEDIR}"
+				;;
+			*)
+				die "python_export: unknown variable ${var}"
+		esac
+	done
+}
+
+# @FUNCTION: python_get_PYTHON
+# @USAGE: [<impl>]
+# @DESCRIPTION:
+# Obtain and print the path to the Python interpreter for the given
+# implementation. If no implementation is provided, ${EPYTHON} will
+# be used.
+#
+# If you just need to have PYTHON set (and exported), then it is better
+# to use python_export() directly instead.
+python_get_PYTHON() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	python_export "${@}" PYTHON
+	echo "${PYTHON}"
+}
+
+# @FUNCTION: python_get_EPYTHON
+# @USAGE: <impl>
+# @DESCRIPTION:
+# Obtain and print the EPYTHON value for the given implementation.
+#
+# If you just need to have EPYTHON set (and exported), then it is better
+# to use python_export() directly instead.
+python_get_EPYTHON() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	python_export "${@}" EPYTHON
+	echo "${EPYTHON}"
+}
+
+# @FUNCTION: python_get_sitedir
+# @USAGE: [<impl>]
+# @DESCRIPTION:
+# Obtain and print the 'site-packages' path for the given
+# implementation. If no implementation is provided, ${EPYTHON} will
+# be used.
+#
+# If you just need to have PYTHON_SITEDIR set (and exported), then it is
+# better to use python_export() directly instead.
+python_get_sitedir() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	python_export "${@}" PYTHON_SITEDIR
+	echo "${PYTHON_SITEDIR}"
+}
+
+# @FUNCTION: _python_rewrite_shebang
+# @INTERNAL
+# @USAGE: [<EPYTHON>] <path>...
+# @DESCRIPTION:
+# Replaces 'python' executable in the shebang with the executable name
+# of the specified interpreter. If no EPYTHON value (implementation) is
+# used, the current ${EPYTHON} will be used.
+#
+# All specified files must start with a 'python' shebang. A file not
+# having a matching shebang will be refused. The exact shebang style
+# will be preserved in order not to break anything.
+#
+# Example conversions:
+# @CODE
+# From: #!/usr/bin/python -R
+# To: #!/usr/bin/python2.7 -R
+#
+# From: #!/usr/bin/env FOO=bar python
+# To: #!/usr/bin/env FOO=bar python2.7
+# @CODE
+_python_rewrite_shebang() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local impl
+	case "${1}" in
+		python*|jython*|pypy-c*)
+			impl=${1}
+			shift
+			;;
+		*)
+			impl=${EPYTHON}
+			[[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON"
+			;;
+	esac
+	debug-print "${FUNCNAME}: implementation: ${impl}"
+
+	local f
+	for f; do
+		local shebang=$(head -n 1 "${f}")
+		debug-print "${FUNCNAME}: path = ${f}"
+		debug-print "${FUNCNAME}: shebang = ${shebang}"
+
+		if [[ "${shebang} " != *'python '* ]]; then
+			eerror "A file does not seem to have a supported shebang:"
+			eerror "  file: ${f}"
+			eerror "  shebang: ${shebang}"
+			die "${FUNCNAME}: ${f} does not seem to have a valid shebang"
+		fi
+
+		sed -i -e "1s:python:${impl}:" "${f}" || die
+	done
+}
+
+# @FUNCTION: _python_ln_rel
+# @INTERNAL
+# @USAGE: <from> <to>
+# @DESCRIPTION:
+# Create a relative symlink.
+_python_ln_rel() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local from=${1}
+	local to=${2}
+
+	local frpath=${from%/*}/
+	local topath=${to%/*}/
+	local rel_path=
+
+	# remove double slashes
+	frpath=${frpath/\/\///}
+	topath=${topath/\/\///}
+
+	while [[ ${topath} ]]; do
+		local frseg=${frpath%%/*}
+		local toseg=${topath%%/*}
+
+		if [[ ${frseg} != ${toseg} ]]; then
+			rel_path=../${rel_path}${frseg:+${frseg}/}
+		fi
+
+		frpath=${frpath#${frseg}/}
+		topath=${topath#${toseg}/}
+	done
+	rel_path+=${frpath}${1##*/}
+
+	debug-print "${FUNCNAME}: ${from} -> ${to}"
+	debug-print "${FUNCNAME}: rel_path = ${rel_path}"
+
+	ln -fs "${rel_path}" "${to}"
+}
+
+# @ECLASS-VARIABLE: python_scriptroot
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# The current script destination for python_doscript(). The path
+# is relative to the installation root (${ED}).
+#
+# When unset, ${DESTTREE}/bin (/usr/bin by default) will be used.
+#
+# Can be set indirectly through the python_scriptinto() function.
+#
+# Example:
+# @CODE
+# src_install() {
+#   local python_scriptroot=${GAMES_BINDIR}
+#   python_foreach_impl python_doscript foo
+# }
+# @CODE
+
+# @FUNCTION: python_scriptinto
+# @USAGE: <new-path>
+# @DESCRIPTION:
+# Set the current scriptroot. The new value will be stored
+# in the 'python_scriptroot' environment variable. The new value need
+# be relative to the installation root (${ED}).
+#
+# Alternatively, you can set the variable directly.
+python_scriptinto() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	python_scriptroot=${1}
+}
+
+# @FUNCTION: python_doscript
+# @USAGE: <files>...
+# @DESCRIPTION:
+# Install the given scripts into current python_scriptroot,
+# for the current Python implementation (${EPYTHON}).
+#
+# All specified files must start with a 'python' shebang. The shebang
+# will be converted, the file will be renamed to be EPYTHON-suffixed
+# and a wrapper will be installed in place of the original name.
+#
+# Example:
+# @CODE
+# src_install() {
+#   python_foreach_impl python_doscript ${PN}
+# }
+# @CODE
+python_doscript() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	[[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
+
+	local d=${python_scriptroot:-${DESTTREE}/bin}
+	local INSDESTTREE INSOPTIONS
+
+	insinto "${d}"
+	insopts -m755
+
+	local f
+	for f; do
+		local oldfn=${f##*/}
+		local newfn=${oldfn}-${EPYTHON}
+
+		debug-print "${FUNCNAME}: ${oldfn} -> ${newfn}"
+		newins "${f}" "${newfn}"
+		_python_rewrite_shebang "${D}/${d}/${newfn}"
+
+		# install the wrapper
+		_python_ln_rel "${ED}"/usr/bin/python-exec "${D}/${d}/${oldfn}" || die
+	done
+}
+
+# @ECLASS-VARIABLE: python_moduleroot
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# The current module root for python_domodule(). The path can be either
+# an absolute system path (it must start with a slash, and ${D} will be
+# prepended to it) or relative to the implementation's site-packages directory
+# (then it must start with a non-slash character).
+#
+# When unset, the modules will be installed in the site-packages root.
+#
+# Can be set indirectly through the python_moduleinto() function.
+#
+# Example:
+# @CODE
+# src_install() {
+#   local python_moduleroot=bar
+#   # installs ${PYTHON_SITEDIR}/bar/baz.py
+#   python_foreach_impl python_domodule baz.py
+# }
+# @CODE
+
+# @FUNCTION: python_moduleinto
+# @USAGE: <new-path>
+# @DESCRIPTION:
+# Set the current module root. The new value will be stored
+# in the 'python_moduleroot' environment variable. The new value need
+# be relative to the site-packages root.
+#
+# Alternatively, you can set the variable directly.
+python_moduleinto() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	python_moduleroot=${1}
+}
+
+# @FUNCTION: python_domodule
+# @USAGE: <files>...
+# @DESCRIPTION:
+# Install the given modules (or packages) into the current
+# python_moduleroot. The list can mention both modules (files)
+# and packages (directories). All listed files will be installed
+# for all enabled implementations, and compiled afterwards.
+#
+# Example:
+# @CODE
+# src_install() {
+#   # (${PN} being a directory)
+#   python_foreach_impl python_domodule ${PN}
+# }
+# @CODE
+python_domodule() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	[[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
+
+	local d
+	if [[ ${python_moduleroot} == /* ]]; then
+		# absolute path
+		d=${python_moduleroot}
+	else
+		# relative to site-packages
+		local PYTHON_SITEDIR=${PYTHON_SITEDIR}
+		[[ ${PYTHON_SITEDIR} ]] || python_export PYTHON_SITEDIR
+
+		d=${PYTHON_SITEDIR}/${python_moduleroot}
+	fi
+
+	local INSDESTTREE
+
+	insinto "${d}"
+	doins -r "${@}"
+
+	# erm, python2.6 can't handle passing files to compileall...
+	case "${EPYTHON}" in
+		python*)
+			"${PYTHON}" -m compileall -q "${D}/${d}"
+			"${PYTHON}" -OO -m compileall -q -f "${D}/${d}"
+			;;
+		*)
+			"${PYTHON}" -m compileall -q "${D}/${d}"
+			;;
+	esac
+}
-- 
1.8.0



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

* Re: [gentoo-dev] [PATCH python-r1] Move common utility functions to python-utils-r1.
  2012-11-21  9:43 [gentoo-dev] [PATCH python-r1] Move common utility functions to python-utils-r1 Michał Górny
@ 2012-11-21 13:54 ` Ian Stakenvicius
  2012-11-21 15:17   ` Gilles Dartiguelongue
  0 siblings, 1 reply; 7+ messages in thread
From: Ian Stakenvicius @ 2012-11-21 13:54 UTC (permalink / raw
  To: gentoo-dev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 21/11/12 04:43 AM, Michał Górny wrote:
> Moved: python_export, getters, python_domodule, python_doscript and
> the necessary internal functions. No global-scope variables, no
> phase functions. [ Snip! ]

So remind me again, in 10 words or less, why these shouldn't all stay
in python-r1.eclass?  ie, what use case do we have for using
python-utils-r1 but not python-r1 (or vice-versa, depending on which
one inherits the other)?





-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iF4EAREIAAYFAlCs3RIACgkQ2ugaI38ACPBDlgEAq70QL+M5jDtM8zcUJs4y0bkp
fDpQaPIzy6KCvM0e6S8A/iCB2yTSimQimegtIVwUE9RrLLSyifd+IljGP/6xvksB
=Kebg
-----END PGP SIGNATURE-----


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

* Re: [gentoo-dev] [PATCH python-r1] Move common utility functions to python-utils-r1.
  2012-11-21 13:54 ` Ian Stakenvicius
@ 2012-11-21 15:17   ` Gilles Dartiguelongue
  2012-11-21 15:30     ` Ian Stakenvicius
  0 siblings, 1 reply; 7+ messages in thread
From: Gilles Dartiguelongue @ 2012-11-21 15:17 UTC (permalink / raw
  To: gentoo-dev

Le mercredi 21 novembre 2012 à 08:54 -0500, Ian Stakenvicius a écrit :
> On 21/11/12 04:43 AM, Michał Górny wrote:
> > Moved: python_export, getters, python_domodule, python_doscript and
> > the necessary internal functions. No global-scope variables, no
> > phase functions. [ Snip! ]
> 
> So remind me again, in 10 words or less, why these shouldn't all stay
> in python-r1.eclass?  ie, what use case do we have for using
> python-utils-r1 but not python-r1 (or vice-versa, depending on which
> one inherits the other)?

From "[gentoo-dev] python-r1.eclass: the masterplan (dirty RFC)" email:

Le lundi 12 novembre 2012 à 15:43 +0100, Michał Górny a écrit :
> 1) splitting common functions into python-utils-r1.
> 
> The python-utils-r1 eclass would provide means to work with specific
> Python packages like portage. Unlike python-r1, it would not export
> IUSE or require any specific USE flags.
> 
> I'm not insisting on this nor giving it a very high priority. It is
> a straightforward change since python-r1 will inherit the new eclass
> anyway.



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

* Re: [gentoo-dev] [PATCH python-r1] Move common utility functions to python-utils-r1.
  2012-11-21 15:17   ` Gilles Dartiguelongue
@ 2012-11-21 15:30     ` Ian Stakenvicius
  2012-11-22 19:59       ` Michał Górny
  0 siblings, 1 reply; 7+ messages in thread
From: Ian Stakenvicius @ 2012-11-21 15:30 UTC (permalink / raw
  To: gentoo-dev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 21/11/12 10:17 AM, Gilles Dartiguelongue wrote:
> Le mercredi 21 novembre 2012 à 08:54 -0500, Ian Stakenvicius a
> écrit :
>> On 21/11/12 04:43 AM, Michał Górny wrote:
>>> Moved: python_export, getters, python_domodule, python_doscript
>>> and the necessary internal functions. No global-scope
>>> variables, no phase functions. [ Snip! ]
>> 
>> So remind me again, in 10 words or less, why these shouldn't all
>> stay in python-r1.eclass?  ie, what use case do we have for
>> using python-utils-r1 but not python-r1 (or vice-versa, depending
>> on which one inherits the other)?
> 
> From "[gentoo-dev] python-r1.eclass: the masterplan (dirty RFC)"
> email:
> 
> Le lundi 12 novembre 2012 à 15:43 +0100, Michał Górny a écrit :
>> 1) splitting common functions into python-utils-r1.
>> 
>> The python-utils-r1 eclass would provide means to work with
>> specific Python packages like portage. Unlike python-r1, it would
>> not export IUSE or require any specific USE flags.
>> 
>> I'm not insisting on this nor giving it a very high priority. It
>> is a straightforward change since python-r1 will inherit the new
>> eclass anyway.
> 
> 


Ahh ok, so only very specific tools for very specific use cases.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iF4EAREIAAYFAlCs85UACgkQ2ugaI38ACPCxHwD9FvHW2Ke/lcsTDomAIOpEqreH
Vo6YDYUeDTm2GlBhA4cA/1yG0Fkh+7MNBZc31naOAvL7rh51Xhj8KxHHDuPsfKyC
=qsUS
-----END PGP SIGNATURE-----


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

* Re: [gentoo-dev] [PATCH python-r1] Move common utility functions to python-utils-r1.
  2012-11-21 15:30     ` Ian Stakenvicius
@ 2012-11-22 19:59       ` Michał Górny
  2012-11-23  7:06         ` Rémi Cardona
  0 siblings, 1 reply; 7+ messages in thread
From: Michał Górny @ 2012-11-22 19:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: axs

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

On Wed, 21 Nov 2012 10:30:29 -0500
Ian Stakenvicius <axs@gentoo.org> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
> 
> On 21/11/12 10:17 AM, Gilles Dartiguelongue wrote:
> > Le mercredi 21 novembre 2012 à 08:54 -0500, Ian Stakenvicius a
> > écrit :
> >> On 21/11/12 04:43 AM, Michał Górny wrote:
> >>> Moved: python_export, getters, python_domodule, python_doscript
> >>> and the necessary internal functions. No global-scope
> >>> variables, no phase functions. [ Snip! ]
> >> 
> >> So remind me again, in 10 words or less, why these shouldn't all
> >> stay in python-r1.eclass?  ie, what use case do we have for
> >> using python-utils-r1 but not python-r1 (or vice-versa, depending
> >> on which one inherits the other)?
> > 
> > From "[gentoo-dev] python-r1.eclass: the masterplan (dirty RFC)"
> > email:
> > 
> > Le lundi 12 novembre 2012 à 15:43 +0100, Michał Górny a écrit :
> >> 1) splitting common functions into python-utils-r1.
> >> 
> >> The python-utils-r1 eclass would provide means to work with
> >> specific Python packages like portage. Unlike python-r1, it would
> >> not export IUSE or require any specific USE flags.
> >> 
> >> I'm not insisting on this nor giving it a very high priority. It
> >> is a straightforward change since python-r1 will inherit the new
> >> eclass anyway.
> > 
> > 
> 
> 
> Ahh ok, so only very specific tools for very specific use cases.

You could say it's an algo like this:

1) if you want phase functions for distutils & all other automagic,
   use distutils-r1;

2) if you don't want phase functions but want PYTHON_TARGETS and other
   metadata stuff, use python-r1;

3) if you don't want phase functions nor metadata, just some random
   potentially useful functions, use python-utils-r1.

-- 
Best regards,
Michał Górny

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

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

* Re: [gentoo-dev] [PATCH python-r1] Move common utility functions to python-utils-r1.
  2012-11-22 19:59       ` Michał Górny
@ 2012-11-23  7:06         ` Rémi Cardona
  2012-11-23  8:38           ` Michał Górny
  0 siblings, 1 reply; 7+ messages in thread
From: Rémi Cardona @ 2012-11-23  7:06 UTC (permalink / raw
  To: gentoo-dev

Le jeudi 22 novembre 2012 à 20:59 +0100, Michał Górny a écrit :

> You could say it's an algo like this:
> 
> 1) if you want phase functions for distutils & all other automagic,
>    use distutils-r1;
> 
> 2) if you don't want phase functions but want PYTHON_TARGETS and other
>    metadata stuff, use python-r1;
> 
> 3) if you don't want phase functions nor metadata, just some random
>    potentially useful functions, use python-utils-r1.


Please, pretty please: paste this blurb somewhere (near the top) in
*one* of the above three eclasses and modify the other 2 to point
developers to the former eclass.

Cheers,

Rémi



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

* Re: [gentoo-dev] [PATCH python-r1] Move common utility functions to python-utils-r1.
  2012-11-23  7:06         ` Rémi Cardona
@ 2012-11-23  8:38           ` Michał Górny
  0 siblings, 0 replies; 7+ messages in thread
From: Michał Górny @ 2012-11-23  8:38 UTC (permalink / raw
  To: gentoo-dev; +Cc: remi

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

On Fri, 23 Nov 2012 08:06:55 +0100
Rémi Cardona <remi@gentoo.org> wrote:

> Le jeudi 22 novembre 2012 à 20:59 +0100, Michał Górny a écrit :
> 
> > You could say it's an algo like this:
> > 
> > 1) if you want phase functions for distutils & all other automagic,
> >    use distutils-r1;
> > 
> > 2) if you don't want phase functions but want PYTHON_TARGETS and other
> >    metadata stuff, use python-r1;
> > 
> > 3) if you don't want phase functions nor metadata, just some random
> >    potentially useful functions, use python-utils-r1.
> 
> 
> Please, pretty please: paste this blurb somewhere (near the top) in
> *one* of the above three eclasses and modify the other 2 to point
> developers to the former eclass.

I'm working on the official text for python-r1 Developer's Guide. It
will be there when the eclasses are committed.

-- 
Best regards,
Michał Górny

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

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

end of thread, other threads:[~2012-11-23  8:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-21  9:43 [gentoo-dev] [PATCH python-r1] Move common utility functions to python-utils-r1 Michał Górny
2012-11-21 13:54 ` Ian Stakenvicius
2012-11-21 15:17   ` Gilles Dartiguelongue
2012-11-21 15:30     ` Ian Stakenvicius
2012-11-22 19:59       ` Michał Górny
2012-11-23  7:06         ` Rémi Cardona
2012-11-23  8:38           ` 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