FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo Development

 
 
LinkBack Thread Tools
 
Old 04-03-2011, 05:38 PM
Arfrever Frehtes Taifersar Arahesis
 
Default python-namespaces.eclass

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
# 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)
}
 
Old 04-03-2011, 07:28 PM
Tomáš Chvátal
 
Default python-namespaces.eclass

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dne 3.4.2011 19:38, Arfrever Frehtes Taifersar Arahesis napsal(a):
> 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()
>
Why you do so much overquoting in the conditions?

Why do you die on those arguments, just ignore them...

You could use some eclass-debug calls (see other eclasses)

Why do you call those set_metadata right after its creation and delete
it right away, does it save so much time it is better than doing it in
global scope?

Since it is new eclass why are not python namespaces bash array? You
could then stop counting them and so on
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2YykIACgkQHB6c3gNBRYfcLACgnvv+0UVw/YeJyUxwblM72AWJ
Tl4AmgNqdcU7sto0xSqrXFEdCxufd4ik
=zy/K
-----END PGP SIGNATURE-----
 

Thread Tools




All times are GMT. The time now is 07:15 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org