public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] python-namespaces.eclass
@ 2011-04-03 17:38 Arfrever Frehtes Taifersar Arahesis
  2011-04-03 19:28 ` [gentoo-dev] python-namespaces.eclass Tomáš Chvátal
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Arfrever Frehtes Taifersar Arahesis @ 2011-04-03 17:38 UTC (permalink / raw
  To: Gentoo Development; +Cc: qa


[-- Attachment #1.1: Type: Text/Plain, Size: 642 bytes --]

I would like to add python-namespaces.eclass. This eclass will be used by a small number of
special packages, which will provide Python namespaces. These packages will be used as
dependencies of other packages already present in the tree.

Ebuilds using this eclass must set PYTHON_NAMESPACES variable before inheriting this eclass.
Example (from net-zope/namespaces-zope):
  PYTHON_NAMESPACES="Products Shared Shared.DC five +zope zope.app"

This eclass provides 3 public functions:
  python-namespaces_src_install()
  python-namespaces_pkg_postinst()
  python-namespaces_pkg_postrm()

-- 
Arfrever Frehtes Taifersar Arahesis

[-- Attachment #1.2: python-namespaces.eclass --]
[-- Type: text/plain, Size: 5384 bytes --]

# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: python-namespaces.eclass
# @MAINTAINER:
# Gentoo Python Project <python@gentoo.org>
# @BLURB: Eclass for packages installing Python namespaces
# @DESCRIPTION:
# The python-namespaces eclass defines phase functions for packages installing Python namespaces.

if ! has "${EAPI:-0}" 4; then
	die "EAPI=\"${EAPI}\" not supported by python-namespaces.eclass"
fi

if [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
	die "python-namespaces.eclass cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
fi

if [[ -z "${PYTHON_NAMESPACES}" ]]; then
	die "PYTHON_NAMESPACES variable not set"
fi

inherit python

# ================================================================================================
# ===================================== HANDLING OF METADATA =====================================
# ================================================================================================

# @ECLASS-VARIABLE: PYTHON_NAMESPACES
# @REQUIRED
# @DESCRIPTION:
# Python namespaces.
# If given namespace is prepended with "+" or "-", then "+" or "-" is prepended to corresponding
# USE flag in generated IUSE.

_python-namespaces_set_metadata() {
	local namespace parent_namespace

	_PYTHON_NAMESPACES=""
	_PYTHON_NAMESPACES_COUNT="0"
	for namespace in ${PYTHON_NAMESPACES}; do
		_PYTHON_NAMESPACES+="${_PYTHON_NAMESPACES:+ }${namespace#[+-]}"
		((_PYTHON_NAMESPACES_COUNT++))
	done

	DESCRIPTION="Python namespaces: ${_PYTHON_NAMESPACES// /, }"
	HOMEPAGE="http://www.gentoo.org/"
	SRC_URI=""

	LICENSE="public-domain"
	SLOT="0"

	if [[ "${_PYTHON_NAMESPACES_COUNT}" -ge 2 ]]; then
		IUSE="${PYTHON_NAMESPACES//./-}"
		REQUIRED_USE="|| ( ${_PYTHON_NAMESPACES//./-} )"

		for namespace in ${_PYTHON_NAMESPACES}; do
			if [[ "${namespace}" == *.* ]]; then
				parent_namespace="${namespace%.*}"
				REQUIRED_USE+=" ${namespace//./-}? ( ${parent_namespace//./-} )"
			fi
		done
	else
		IUSE=""
		REQUIRED_USE=""
	fi

	S="${WORKDIR}"
}
_python-namespaces_set_metadata
unset -f _python-namespaces_set_metadata

# ================================================================================================
# ======================================= PHASE FUNCTIONS ========================================
# ================================================================================================

EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm

_python-namespaces_get_enabled_namespaces() {
	local namespace

	if [[ "${_PYTHON_NAMESPACES_COUNT}" -ge 2 ]]; then
		for namespace in ${_PYTHON_NAMESPACES}; do
			if use ${namespace//./-}; then
				echo ${namespace}
			fi
		done
	else
		echo ${_PYTHON_NAMESPACES}
	fi
}

# @FUNCTION: python-namespaces_src_install
# @DESCRIPTION:
# Implementation of src_install() phase. This function is exported.
# This function installs __init__.py modules corresponding to Python namespaces.
python-namespaces_src_install() {
	if [[ "${EBUILD_PHASE}" != "install" ]]; then
		die "${FUNCNAME}() can be used only in src_install() phase"
	fi

	_python_check_python_pkg_setup_execution

	if [[ "$#" -ne 0 ]]; then
		die "${FUNCNAME}() does not accept arguments"
	fi

	python-namespaces_installation() {
		local namespace
		for namespace in $(_python-namespaces_get_enabled_namespaces); do
			dodir $(python_get_sitedir)/${namespace//.//} || return 1
			echo \
"try:
	import pkg_resources
	pkg_resources.declare_namespace(__name__)
	try:
		del pkg_resources
	except NameError:
		pass
except ImportError:
	import pkgutil
	__path__ = pkgutil.extend_path(__path__, __name__)
	del pkgutil" > "${ED}$(python_get_sitedir)/${namespace//.//}/__init__.py" || return 1
		done
	}
	python_execute_function \
		--action-message 'Installation of Python namespaces with $(python_get_implementation) $(python_get_version)' \
		--failure-message 'Installation of Python namespaces with $(python_get_implementation) $(python_get_version) failed' \
		python-namespaces_installation
	unset -f python-namespaces_installation
}

# @FUNCTION: python-namespaces_pkg_postinst
# @DESCRIPTION:
# Implementation of pkg_postinst() phase. This function is exported.
# This function calls python_mod_optimize() with __init__.py modules corresponding to Python namespaces.
python-namespaces_pkg_postinst() {
	if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
		die "${FUNCNAME}() can be used only in pkg_postinst() phase"
	fi

	_python_check_python_pkg_setup_execution

	if [[ "$#" -ne 0 ]]; then
		die "${FUNCNAME}() does not accept arguments"
	fi

	python_mod_optimize $(for namespace in $(_python-namespaces_get_enabled_namespaces); do echo ${namespace//.//}/__init__.py; done)
}

# @FUNCTION: python-namespaces_pkg_postrm
# @DESCRIPTION:
# Implementation of pkg_postrm() phase. This function is exported.
# This function calls python_mod_cleanup() with __init__.py modules corresponding to Python namespaces.
python-namespaces_pkg_postrm() {
	if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
		die "${FUNCNAME}() can be used only in pkg_postrm() phase"
	fi

	_python_check_python_pkg_setup_execution

	if [[ "$#" -ne 0 ]]; then
		die "${FUNCNAME}() does not accept arguments"
	fi

	python_mod_cleanup $(for namespace in $(_python-namespaces_get_enabled_namespaces); do echo ${namespace//.//}/__init__.py; done)
}

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2011-04-30 22:50 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-03 17:38 [gentoo-dev] python-namespaces.eclass Arfrever Frehtes Taifersar Arahesis
2011-04-03 19:28 ` [gentoo-dev] python-namespaces.eclass Tomáš Chvátal
2011-04-03 23:13   ` Arfrever Frehtes Taifersar Arahesis
2011-04-04 10:04     ` Tomáš Chvátal
2011-04-04 16:02       ` Alec Warner
2011-04-04 17:43       ` [gentoo-dev] python-namespaces.eclass Arfrever Frehtes Taifersar Arahesis
2011-04-05  4:33     ` [gentoo-dev] python-namespaces.eclass Jeroen Roovers
2011-04-04  8:20 ` [gentoo-dev] python-namespaces.eclass Fabian Groffen
2011-04-04 11:48 ` Brian Harring
2011-04-04 18:01   ` Arfrever Frehtes Taifersar Arahesis
2011-04-30 21:27   ` Arfrever Frehtes Taifersar Arahesis
2011-04-30 22:32     ` Brian Harring
2011-04-30 22:49       ` Arfrever Frehtes Taifersar Arahesis

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