Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Gentoo Development (http://www.linux-archive.org/gentoo-development/)
-   -   Initial python-r1.eclass & distutils-r1.eclass (http://www.linux-archive.org/gentoo-development/708285-initial-python-r1-eclass-distutils-r1-eclass.html)

Michał Górny 09-29-2012 08:53 AM

Initial python-r1.eclass & distutils-r1.eclass
 
Hello,

Instead of the floating patches and p-d-ng modifications I sent
earlier, here are the two complete (so far, well, initial :P) eclasses
for review.

They are designed as 'mostly' drop-in python-distutils-ng replacement.

--
Best regards,
Michał Górny
# 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, simple eclass for Python packages.
# @DESCRIPTION:
# A common eclass providing helper functions to build and install
# packages supporting being installed for multiple Python
# implementations.
#
# This eclass sets correct IUSE and REQUIRED_USE. It exports PYTHON_DEPS
# and PYTHON_USEDEP so you can create correct dependencies for your
# package easily. It also provides methods to easily run a command for
# each enabled Python implementation and duplicate the sources for them.

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 last.
_PYTHON_ALL_IMPLS=(
jython2_5
pypy1_8 pypy1_9
python3_1 python3_2
python2_5 python2_6 python2_7
)

# @ECLASS-VARIABLE: PYTHON_COMPAT
# @DESCRIPTION:
# This variable contains a space separated list of Python
# implementations 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[@]}}

# @ECLASS-VARIABLE: PYTHON_REQ_USE
# @DEFAULT_UNSET
# @DESCRIPTION:
# The list of USEflags required to be enabled on the chosen Python
# implementations, formed as a USE-dependency string. It should be valid
# for all implementations in PYTHON_COMPAT, so it may be necessary to
# use USE defaults.
#
# Example:
# @CODE
# PYTHON_REQ_USE="gdbm,ncurses(-)?"
# @CODE
#
# Will cause the Python dependencies to look like:
# @CODE
# python_targets_pythonX_Y? (
# dev-lang/python:X_Y[gdbm,ncurses(-)?] )
# @CODE

# @ECLASS-VARIABLE: PYTHON_DEPS
# @DESCRIPTION:
# This is an eclass-generated Python dependency string for all
# implementations listed in PYTHON_COMPAT. It should be used
# in RDEPEND and/or DEPEND like:
#
# @CODE
# RDEPEND="${PYTHON_DEPS}
# dev-foo/mydep"
# DEPEND="${RDEPEND}"
# @CODE

# @ECLASS-VARIABLE: PYTHON_USEDEP
# @DESCRIPTION:
# This is an eclass-generated USE-dependency string which can be used to
# depend on another Python package being built for the same Python
# implementations. It should be used like:
#
# @CODE
# RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
# @CODE

PYTHON_COMPAT=( ${PYTHON_COMPAT[@]} )

_python_set_globals() {
local flags=( "${PYTHON_COMPAT[@]/#/python_targets_}" )
local optflags=${flags[@]/%/?}

IUSE=${flags[*]}
REQUIRED_USE="|| ( ${flags[*]} )"
PYTHON_USEDEP=${optflags// /,}

PYTHON_DEPS=
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]}
local usestr
[[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]"
PYTHON_DEPS+=" python_targets_${i}? (
${d}:${v/_/.}${usestr} )"
done
}
_python_set_globals

# @FUNCTION: python_get_PYTHON
# @USAGE: <impl>
# @DESCRIPTION:
# Get the Python executable name for the given implementation. Please
# note that this this function returns the 'basename' only.
# If using it for a hashbang, please use #!/usr/bin/env.
python_get_PYTHON() {
local impl=${1/_/.}

case "${impl}" in
python*|jython*)
echo ${impl}
;;
pypy*)
echo pypy-c${impl#pypy}
;;
*)
die "Invalid argument to python_get_PYTHON: ${1}"
;;
esac
}

# @FUNCTION: python_copy_sources
# @DESCRIPTION:
# Create a single copy of the package sources (${S}) for each enabled
# Python implementation.
python_copy_sources() {
local impl
local bdir=${BUILD_DIR:-${S}}

einfo "Will copy sources from ${S}"
# the order is irrelevant here
for impl in ${PYTHON_COMPAT[@]}; do
if use python_targets_${impl}
then
local BUILD_DIR=${bdir%%/}-${impl}

einfo "${impl}: copying to ${BUILD_DIR}"
cp -pr "${S}" "${BUILD_DIR}" || die
fi
done
}

# @FUNCTION: python_foreach_impl
# @USAGE: <command> [<args>...]
# @DESCRIPTION:
# Run the given command for each of the enabled Python implementations.
# If additional parameters are passed, they will be passed through
# to the command. If the command fails, python_foreach_impl dies.
# If necessary, use ':' to force a successful return.
#
# Before the command is run, EPYTHON is set to the name of the current
# Python implementation, PYTHON is set to the correct Python executable
# name and exported, and BUILD_DIR is set to a 'default' build directory
# for given implementation (e.g. ${BUILD_DIR:-${S}}-python2_7).
#
# The command is run inside the build directory. If it doesn't exist
# yet, it is created (as an empty directory!). If your build system does
# not support out-of-source builds, you will likely want to use
# python_copy_sources first.
python_foreach_impl() {
local impl
local bdir=${BUILD_DIR:-${S}}

for impl in ${_PYTHON_ALL_IMPLS[@]}; do
if has ${impl} ${PYTHON_COMPAT[@]} && use python_targets_${impl}
then
local PYTHON=$(python_get_PYTHON "${impl}")
local EPYTHON=${impl}
local BUILD_DIR=${bdir%%/}-${impl}
export PYTHON

mkdir -p "${BUILD_DIR}" || die
pushd "${BUILD_DIR}" &>/dev/null || die
einfo "${EPYTHON}: running ${@}"
"${@}" || die "${EPYTHON}: ${1} failed"
popd || die
fi
done
}
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: distutils-r1
# @MAINTAINER:
# Python herd <python@gentoo.org>
# @AUTHOR:
# Author: MichaÅ? Górny <mgorny@gentoo.org>
# Based on the work of: Krzysztof Pawlik <nelchael@gentoo.org>
# @BLURB: A simple eclass to build Python packages using distutils.
# @DESCRIPTION:
# A simple eclass providing functions to build Python packages using
# the distutils build system. It exports phase functions for all
# the src_* phases. Each of the phases runs two pseudo-phases:
# python_..._all() (e.g. python_prepare_all()) once in ${S}, then
# python_...() (e.g. python_prepare()) for each implementation
# (see: python_foreach_impl() in python-r1).
#
# In distutils-r1_src_prepare(), the 'all' function is run before
# per-implementation ones (because it creates the implementations),
# per-implementation functions are run in a random order.
#
# In remaining phase functions, the per-implementation functions are run
# before the 'all' one, and they are ordered from the least to the most
# preferred implementation (so that 'better' files overwrite 'worse'
# ones).
#
# If the ebuild doesn't specify a particular pseudo-phase function,
# the default one will be used (distutils-r1_...). Defaults are provided
# for all per-implementation pseudo-phases, python_prepare_all()
# and python_install_all(); whenever writing your own pseudo-phase
# functions, you should consider calling the defaults (and especially
# distutils-r1_python_prepare_all).
#
# Please note that distutils-r1 sets RDEPEND and DEPEND for you.

case "${EAPI}" in
0|1|2|3)
die "Unsupported EAPI=${EAPI} (too old) for ${ECLASS}"
;;
4)
;;
*)
die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
;;
esac

inherit eutils python-r1

EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install

RDEPEND=${PYTHON_DEPS}
DEPEND=${PYTHON_DEPS}

# @FUNCTION: distutils-r1_python_prepare_all
# @DESCRIPTION:
# The default python_prepare_all(). It applies the patches from PATCHES
# array, then user patches and finally calls python_copy_sources to
# create copies of resulting sources for each Python implementation.
distutils-r1_python_prepare_all() {
[[ ${PATCHES} ]] && epatch "${PATCHES[@]}"

epatch_user

# create source copies for each implementation
python_copy_sources
}

# @FUNCTION: distutils-r1_python_prepare
# @DESCRIPTION:
# The default python_prepare(). Currently it is a no-op
# but in the future it may apply implementation-specific quirks
# to the build system.
distutils-r1_python_prepare() {
:
}

# @FUNCTION: distutils-r1_python_configure
# @DESCRIPTION:
# The default python_configure(). Currently a no-op.
distutils-r1_python_configure() {
:
}

# @FUNCTION: distutils-r1_python_compile
# @DESCRIPTION:
# The default python_compile(). Runs 'setup.py build' using the correct
# Python implementation.
distutils-r1_python_compile() {
cd "${BUILD_DIR}" || die
"${PYTHON}" setup.py build || die
}

# @FUNCTION: distutils-r1_python_test
# @DESCRIPTION:
# The default python_test(). Currently a no-op.
distutils-r1_python_test() {
:
}

# @FUNCTION: distutils-r1_rename_scripts
# @DESCRIPTION:
# Renames installed Python scripts to be implementation-suffixed.
# ${PYTHON} has to be set to the expected Python executable (which
# hashbang will be grepped for), and ${EPYTHON} to the implementation
# name (for new name).
distutils-r1_rename_scripts() {
local dir f
local wrapdir=${T}/distutils_wrappers

# XXX: change this if we ever allow directories in bin/sbin
for dir in bin sbin usr/bin usr/sbin; do
for f in "${D}"/${dir}/*; do
if [[ -x ${f} ]]; then
if [[ "$(head -n 1 "${f}")" == '#!'*${PYTHON}* ]]
then
local newf=${f}-${EPYTHON}
mv "${f}" "${newf}" || die

mkdir -p "${wrapdir}"/${dir}
ln -fs "${newf##*/}"
"${wrapdir}"/${dir}/"${f##*/}" || die
fi
fi
done
done
}

# @FUNCTION: distutils-r1_python_install
# @DESCRIPTION:
# The default python_install(). Runs 'setup.py install' using
# the correct Python implementation, and appending the optimization
# flags. Then calls distutils-r1_rename_scripts.
distutils-r1_python_install() {
local flags

case "${EPYTHON}" in
jython*)
flags='--compile';;
*)
flags='--compile -O2';;
esac

# XXX: where does it come from?!
unset PYTHONDONTWRITEBYTECODE

cd "${BUILD_DIR}" || die
"${PYTHON}" setup.py install ${flags} --root="${D}" || die

distutils-r1_rename_scripts
}

# @FUNCTION: distutils-r1_python_install_all
# @DESCRIPTION:
# The default python_install_all(). It creates wrappers
# for the implementation-suffixed executables.
distutils-r1_python_install_all() {
local wrapdir=${T}/distutils_wrappers

if [[ -d ${wrapdir} ]]; then
cp -r "${wrapdir}/." "${D}" || die
fi
}

distutils-r1_src_prepare() {
# common preparations
if declare -f python_prepare_all >/dev/null; then
python_prepare_all
else
distutils-r1_python_prepare_all
fi

if declare -f python_prepare >/dev/null; then
python_foreach_impl python_prepare
else
distutils-r1_python_prepare
fi
}

distutils-r1_src_configure() {
if declare -f python_configure >/dev/null; then
python_foreach_impl python_configure
else
distutils-r1_python_configure
fi

if declare -f python_configure_all >/dev/null; then
python_configure_all
fi
}

distutils-r1_src_compile() {
if declare -f python_compile >/dev/null; then
python_foreach_impl python_compile
else
python_foreach_impl distutils-r1_python_compile
fi

if declare -f python_compile_all >/dev/null; then
python_compile_all
fi
}

distutils-r1_src_test() {
if declare -f python_test >/dev/null; then
python_foreach_impl python_test
else
distutils-r1_python_test
fi

if declare -f python_test_all >/dev/null; then
python_test_all
fi
}

distutils-r1_src_install() {
if declare -f python_install >/dev/null; then
python_foreach_impl python_install
else
python_foreach_impl distutils-r1_python_install
fi

if declare -f python_install_all >/dev/null; then
python_install_all
else
distutils-r1_python_install_all
fi
}

Tomáš Chvátal 09-29-2012 10:00 AM

Initial python-r1.eclass & distutils-r1.eclass
 
2012/9/29 Michał Górny <mgorny@gentoo.org>:
> Hello,
>
> Instead of the floating patches and p-d-ng modifications I sent
> earlier, here are the two complete (so far, well, initial :P) eclasses
> for review.
>
> They are designed as 'mostly' drop-in python-distutils-ng replacement.
>
Hi,

the eclasses look pretty, so good job,
just one question tho, would it be possible to use more
debug-something calls so the log file would be populated automatically
with whats going on (same like eg git-2 eclass)?

Cheers

Tom

Markos Chandras 09-29-2012 10:20 AM

Initial python-r1.eclass & distutils-r1.eclass
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On 09/29/2012 09:53 AM, Micha? Grny wrote:
> Hello,
>
> Instead of the floating patches and p-d-ng modifications I sent
> earlier, here are the two complete (so far, well, initial :P)
> eclasses for review.
>
> They are designed as 'mostly' drop-in python-distutils-ng
> replacement.
>
Hi,

Are you saying that you are going to remove the python-distutils-ng
eclass in favour of the new eclasses? I don't quite understand the
reasons to be honest.

- --
Regards,
Markos Chandras / Gentoo Linux Developer / Key ID: B4AFF2C2
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iQIcBAEBCgAGBQJQZstvAAoJEPqDWhW0r/LCC4gQAJmmseSriDS8ahCnkUNBm+61
NGxGijft0zE8qFvdLDH+koQ+ym8/KrMvZcp5U1pLEGDOBVXYj33nOQ9kA24rKBvz
Ro2Ydvxcj0Zo/nXGmLB0Mr9IaW4oWY8A16iY24qCpmPV1AWJXdoB0gdtXcDS4Mm D
+LT19sRMqJstjUXbS02xrWS8lrbcPxVqVkfAPtFo82+/rtceHu+ymSVgJwkTQgBV
9999tKLdI16hK3x9pvceMgaYlC1W32yWq3YUOn3mvFjh4EjANr Z64ED1Q3A+QCYe
pUSwx3BGTZnQK6WQtSer/8O/oW7FoR5DooJTNsg1xrPTEdPd79D28TThy3ollACP
F5GtKyZO5gFK4SxQdbYfo9Su1Wa0XYybLHihnJDUVHuF2/AchSFW4CtGHfxQ4A0g
HWtEgdfRzk5kTUwR2LUhrisei3c6qpB0KGcZZCpi5FF9s150Si 2wlKi2PbffAfil
0vLML3mnZnez5bWzPB1DqHf5eWdM00/BFaG4IQJkipwC3jJQ/rye9ruAv2UTM/Rs
UH6FQCfTRbScaf0E2WCGMIr33//HsIzy7KPAMAyfJWmxsBGwYHtouci7rQgUZIxn
+MdLQuzTYkUgybdnkhLmEeThl8coNwVeEzXwoQZGlciszz6cni Su66WbEEAUxgTP
5F9+vTb5XF1Jq+ZXrrb8
=7EZ5
-----END PGP SIGNATURE-----

Michał Górny 09-29-2012 10:23 AM

Initial python-r1.eclass & distutils-r1.eclass
 
On Sat, 29 Sep 2012 12:00:18 +0200
Tomáš Chvátal <tomas.chvatal@gmail.com> wrote:

> 2012/9/29 Michał Górny <mgorny@gentoo.org>:
> > Hello,
> >
> > Instead of the floating patches and p-d-ng modifications I sent
> > earlier, here are the two complete (so far, well, initial :P) eclasses
> > for review.
> >
> > They are designed as 'mostly' drop-in python-distutils-ng replacement.
> >
> Hi,
>
> the eclasses look pretty, so good job,
> just one question tho, would it be possible to use more
> debug-something calls so the log file would be populated automatically
> with whats going on (same like eg git-2 eclass)?

Can do. Was just lazy ;P.

--
Best regards,
Michał Górny

Michał Górny 09-29-2012 10:45 AM

Initial python-r1.eclass & distutils-r1.eclass
 
On Sat, 29 Sep 2012 12:00:18 +0200
Tomáš Chvátal <tomas.chvatal@gmail.com> wrote:

> 2012/9/29 Michał Górny <mgorny@gentoo.org>:
> > Hello,
> >
> > Instead of the floating patches and p-d-ng modifications I sent
> > earlier, here are the two complete (so far, well, initial :P) eclasses
> > for review.
> >
> > They are designed as 'mostly' drop-in python-distutils-ng replacement.
> >
> Hi,
>
> the eclasses look pretty, so good job,
> just one question tho, would it be possible to use more
> debug-something calls so the log file would be populated automatically
> with whats going on (same like eg git-2 eclass)?

Try now :P.

--
Best regards,
Michał Górny
# 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, simple eclass for Python packages.
# @DESCRIPTION:
# A common eclass providing helper functions to build and install
# packages supporting being installed for multiple Python
# implementations.
#
# This eclass sets correct IUSE and REQUIRED_USE. It exports PYTHON_DEPS
# and PYTHON_USEDEP so you can create correct dependencies for your
# package easily. It also provides methods to easily run a command for
# each enabled Python implementation and duplicate the sources for them.

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 last.
_PYTHON_ALL_IMPLS=(
jython2_5
pypy1_8 pypy1_9
python3_1 python3_2
python2_5 python2_6 python2_7
)

# @ECLASS-VARIABLE: PYTHON_COMPAT
# @DESCRIPTION:
# This variable contains a space separated list of Python
# implementations 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[@]}}

# @ECLASS-VARIABLE: PYTHON_REQ_USE
# @DEFAULT_UNSET
# @DESCRIPTION:
# The list of USEflags required to be enabled on the chosen Python
# implementations, formed as a USE-dependency string. It should be valid
# for all implementations in PYTHON_COMPAT, so it may be necessary to
# use USE defaults.
#
# Example:
# @CODE
# PYTHON_REQ_USE="gdbm,ncurses(-)?"
# @CODE
#
# Will cause the Python dependencies to look like:
# @CODE
# python_targets_pythonX_Y? (
# dev-lang/python:X_Y[gdbm,ncurses(-)?] )
# @CODE

# @ECLASS-VARIABLE: PYTHON_DEPS
# @DESCRIPTION:
# This is an eclass-generated Python dependency string for all
# implementations listed in PYTHON_COMPAT. It should be used
# in RDEPEND and/or DEPEND like:
#
# @CODE
# RDEPEND="${PYTHON_DEPS}
# dev-foo/mydep"
# DEPEND="${RDEPEND}"
# @CODE

# @ECLASS-VARIABLE: PYTHON_USEDEP
# @DESCRIPTION:
# This is an eclass-generated USE-dependency string which can be used to
# depend on another Python package being built for the same Python
# implementations. It should be used like:
#
# @CODE
# RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
# @CODE

PYTHON_COMPAT=( ${PYTHON_COMPAT[@]} )

_python_set_globals() {
local flags=( "${PYTHON_COMPAT[@]/#/python_targets_}" )
local optflags=${flags[@]/%/?}

IUSE=${flags[*]}
REQUIRED_USE="|| ( ${flags[*]} )"
PYTHON_USEDEP=${optflags// /,}

PYTHON_DEPS=
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]}
local usestr
[[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]"
PYTHON_DEPS+=" python_targets_${i}? (
${d}:${v/_/.}${usestr} )"
done
}
_python_set_globals

# @FUNCTION: python_get_PYTHON
# @USAGE: <impl>
# @DESCRIPTION:
# Get the Python executable name for the given implementation. Please
# note that this this function returns the 'basename' only.
# If using it for a hashbang, please use #!/usr/bin/env.
python_get_PYTHON() {
debug-print-function ${FUNCNAME} "${@}"

local impl=${1/_/.}
local ret

case "${impl}" in
python*|jython*)
ret=${impl}
;;
pypy*)
ret=pypy-c${impl#pypy}
;;
*)
die "Invalid argument to python_get_PYTHON: ${1}"
;;
esac

debug-print "${FUNCNAME}: ${impl} -> ${ret}"
echo "${ret}"
}

# @FUNCTION: python_copy_sources
# @DESCRIPTION:
# Create a single copy of the package sources (${S}) for each enabled
# Python implementation.
python_copy_sources() {
debug-print-function ${FUNCNAME} "${@}"

local impl
local bdir=${BUILD_DIR:-${S}}

debug-print "${FUNCNAME}: bdir = ${bdir}"
einfo "Will copy sources from ${S}"
# the order is irrelevant here
for impl in ${PYTHON_COMPAT[@]}; do
if use python_targets_${impl}
then
local BUILD_DIR=${bdir%%/}-${impl}

einfo "${impl}: copying to ${BUILD_DIR}"
debug-print "${FUNCNAME}: [${impl}] cp ${S} => ${BUILD_DIR}"
cp -pr "${S}" "${BUILD_DIR}" || die
fi
done
}

# @FUNCTION: python_foreach_impl
# @USAGE: <command> [<args>...]
# @DESCRIPTION:
# Run the given command for each of the enabled Python implementations.
# If additional parameters are passed, they will be passed through
# to the command. If the command fails, python_foreach_impl dies.
# If necessary, use ':' to force a successful return.
#
# Before the command is run, EPYTHON is set to the name of the current
# Python implementation, PYTHON is set to the correct Python executable
# name and exported, and BUILD_DIR is set to a 'default' build directory
# for given implementation (e.g. ${BUILD_DIR:-${S}}-python2_7).
#
# The command is run inside the build directory. If it doesn't exist
# yet, it is created (as an empty directory!). If your build system does
# not support out-of-source builds, you will likely want to use
# python_copy_sources first.
python_foreach_impl() {
debug-print-function ${FUNCNAME} "${@}"

local impl
local bdir=${BUILD_DIR:-${S}}

debug-print "${FUNCNAME}: bdir = ${bdir}"
for impl in ${_PYTHON_ALL_IMPLS[@]}; do
if has ${impl} ${PYTHON_COMPAT[@]} && use python_targets_${impl}
then
local PYTHON=$(python_get_PYTHON "${impl}")
local EPYTHON=${impl}
local BUILD_DIR=${bdir%%/}-${impl}
export PYTHON

debug-print "${FUNCNAME}: [${impl}] build_dir = ${BUILD_DIR}"

mkdir -p "${BUILD_DIR}" || die
pushd "${BUILD_DIR}" &>/dev/null || die
einfo "${EPYTHON}: running ${@}"
"${@}" || die "${EPYTHON}: ${1} failed"
popd &>/dev/null || die
fi
done
}
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: distutils-r1
# @MAINTAINER:
# Python herd <python@gentoo.org>
# @AUTHOR:
# Author: MichaÅ? Górny <mgorny@gentoo.org>
# Based on the work of: Krzysztof Pawlik <nelchael@gentoo.org>
# @BLURB: A simple eclass to build Python packages using distutils.
# @DESCRIPTION:
# A simple eclass providing functions to build Python packages using
# the distutils build system. It exports phase functions for all
# the src_* phases. Each of the phases runs two pseudo-phases:
# python_..._all() (e.g. python_prepare_all()) once in ${S}, then
# python_...() (e.g. python_prepare()) for each implementation
# (see: python_foreach_impl() in python-r1).
#
# In distutils-r1_src_prepare(), the 'all' function is run before
# per-implementation ones (because it creates the implementations),
# per-implementation functions are run in a random order.
#
# In remaining phase functions, the per-implementation functions are run
# before the 'all' one, and they are ordered from the least to the most
# preferred implementation (so that 'better' files overwrite 'worse'
# ones).
#
# If the ebuild doesn't specify a particular pseudo-phase function,
# the default one will be used (distutils-r1_...). Defaults are provided
# for all per-implementation pseudo-phases, python_prepare_all()
# and python_install_all(); whenever writing your own pseudo-phase
# functions, you should consider calling the defaults (and especially
# distutils-r1_python_prepare_all).
#
# Please note that distutils-r1 sets RDEPEND and DEPEND for you.

case "${EAPI}" in
0|1|2|3)
die "Unsupported EAPI=${EAPI} (too old) for ${ECLASS}"
;;
4)
;;
*)
die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
;;
esac

inherit eutils python-r1

EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install

RDEPEND=${PYTHON_DEPS}
DEPEND=${PYTHON_DEPS}

# @FUNCTION: distutils-r1_python_prepare_all
# @DESCRIPTION:
# The default python_prepare_all(). It applies the patches from PATCHES
# array, then user patches and finally calls python_copy_sources to
# create copies of resulting sources for each Python implementation.
distutils-r1_python_prepare_all() {
debug-print-function ${FUNCNAME} "${@}"

[[ ${PATCHES} ]] && epatch "${PATCHES[@]}"

epatch_user

# create source copies for each implementation
python_copy_sources
}

# @FUNCTION: distutils-r1_python_prepare
# @DESCRIPTION:
# The default python_prepare(). Currently it is a no-op
# but in the future it may apply implementation-specific quirks
# to the build system.
distutils-r1_python_prepare() {
debug-print-function ${FUNCNAME} "${@}"

:
}

# @FUNCTION: distutils-r1_python_configure
# @DESCRIPTION:
# The default python_configure(). Currently a no-op.
distutils-r1_python_configure() {
debug-print-function ${FUNCNAME} "${@}"

:
}

# @FUNCTION: distutils-r1_python_compile
# @DESCRIPTION:
# The default python_compile(). Runs 'setup.py build' using the correct
# Python implementation.
distutils-r1_python_compile() {
debug-print-function ${FUNCNAME} "${@}"

cd "${BUILD_DIR}" || die
set -- "${PYTHON}" setup.py build
echo "${@}"
"${@}" || die
}

# @FUNCTION: distutils-r1_python_test
# @DESCRIPTION:
# The default python_test(). Currently a no-op.
distutils-r1_python_test() {
debug-print-function ${FUNCNAME} "${@}"

:
}

# @FUNCTION: distutils-r1_rename_scripts
# @DESCRIPTION:
# Renames installed Python scripts to be implementation-suffixed.
# ${PYTHON} has to be set to the expected Python executable (which
# hashbang will be grepped for), and ${EPYTHON} to the implementation
# name (for new name).
distutils-r1_rename_scripts() {
debug-print-function ${FUNCNAME} "${@}"

local dir f
local wrapdir=${T}/distutils_wrappers

# XXX: change this if we ever allow directories in bin/sbin
for dir in bin sbin usr/bin usr/sbin; do
for f in "${D}"/${dir}/*; do
if [[ -x ${f} ]]; then
debug-print "${FUNCNAME}: found executable at ${f#${D}/}"

if [[ "$(head -n 1 "${f}")" == '#!'*${PYTHON}* ]]
then
debug-print "${FUNCNAME}: matching shebang: $(head -n 1 "${f}")"

local newf=${f}-${EPYTHON}
debug-print "${FUNCNAME}: renamed to ${newf#${D}/}"
mv "${f}" "${newf}" || die

debug-print "${FUNCNAME}: symlink to ${wrapdir}/${dir}/${f##*/}"

mkdir -p "${wrapdir}"/${dir}
ln -fs "${newf##*/}"
"${wrapdir}/${dir}/${f##*/}" || die
fi
fi
done
done
}

# @FUNCTION: distutils-r1_python_install
# @DESCRIPTION:
# The default python_install(). Runs 'setup.py install' using
# the correct Python implementation, and appending the optimization
# flags. Then calls distutils-r1_rename_scripts.
distutils-r1_python_install() {
debug-print-function ${FUNCNAME} "${@}"

local flags

case "${EPYTHON}" in
jython*)
flags='--compile';;
*)
flags='--compile -O2';;
esac
debug-print "${FUNCNAME}: [${EPYTHON}] flags: ${flags}"

unset PYTHONDONTWRITEBYTECODE

cd "${BUILD_DIR}" || die
set -- "${PYTHON}" setup.py install ${flags} --root="${D}"
echo "${@}"
"${@}" || die

distutils-r1_rename_scripts
}

# @FUNCTION: distutils-r1_python_install_all
# @DESCRIPTION:
# The default python_install_all(). It creates wrappers
# for the implementation-suffixed executables.
distutils-r1_python_install_all() {
debug-print-function ${FUNCNAME} "${@}"

local wrapdir=${T}/distutils_wrappers

if [[ -d ${wrapdir} ]]; then
cp -r "${wrapdir}/." "${D}" || die
fi
}

distutils-r1_src_prepare() {
debug-print-function ${FUNCNAME} "${@}"

# common preparations
if declare -f python_prepare_all >/dev/null; then
python_prepare_all
else
distutils-r1_python_prepare_all
fi

if declare -f python_prepare >/dev/null; then
python_foreach_impl python_prepare
else
distutils-r1_python_prepare
fi
}

distutils-r1_src_configure() {
if declare -f python_configure >/dev/null; then
python_foreach_impl python_configure
else
distutils-r1_python_configure
fi

if declare -f python_configure_all >/dev/null; then
python_configure_all
fi
}

distutils-r1_src_compile() {
debug-print-function ${FUNCNAME} "${@}"

if declare -f python_compile >/dev/null; then
python_foreach_impl python_compile
else
python_foreach_impl distutils-r1_python_compile
fi

if declare -f python_compile_all >/dev/null; then
python_compile_all
fi
}

distutils-r1_src_test() {
debug-print-function ${FUNCNAME} "${@}"

if declare -f python_test >/dev/null; then
python_foreach_impl python_test
else
distutils-r1_python_test
fi

if declare -f python_test_all >/dev/null; then
python_test_all
fi
}

distutils-r1_src_install() {
debug-print-function ${FUNCNAME} "${@}"

if declare -f python_install >/dev/null; then
python_foreach_impl python_install
else
python_foreach_impl distutils-r1_python_install
fi

if declare -f python_install_all >/dev/null; then
python_install_all
else
distutils-r1_python_install_all
fi
}

Michał Górny 09-29-2012 10:49 AM

Initial python-r1.eclass & distutils-r1.eclass
 
On Sat, 29 Sep 2012 11:20:31 +0100
Markos Chandras <hwoarang@gentoo.org> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
>
> On 09/29/2012 09:53 AM, Micha? Górny wrote:
> > Hello,
> >
> > Instead of the floating patches and p-d-ng modifications I sent
> > earlier, here are the two complete (so far, well, initial :P)
> > eclasses for review.
> >
> > They are designed as 'mostly' drop-in python-distutils-ng
> > replacement.
> >
> Hi,
>
> Are you saying that you are going to remove the python-distutils-ng
> eclass in favour of the new eclasses? I don't quite understand the
> reasons to be honest.

The reason is simple -- I can't fix it without changing the API.
Changing the API on a live eclass is confusing, and considering that it
is not used by many packages, it's easier to lastrite it.

Also, this fixes the name not to have any '-ng' nor '-ds9'.

--
Best regards,
Michał Górny

hasufell 09-29-2012 01:49 PM

Initial python-r1.eclass & distutils-r1.eclass
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/29/2012 12:49 PM, Michał Górny wrote:
> On Sat, 29 Sep 2012 11:20:31 +0100 Markos Chandras
> <hwoarang@gentoo.org> wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512
>>
>> On 09/29/2012 09:53 AM, Micha? Górny wrote:
>>> Hello,
>>>
>>> Instead of the floating patches and p-d-ng modifications I sent
>>> earlier, here are the two complete (so far, well, initial :P)
>>> eclasses for review.
>>>
>>> They are designed as 'mostly' drop-in python-distutils-ng
>>> replacement.
>>>
>> Hi,
>>
>> Are you saying that you are going to remove the
>> python-distutils-ng eclass in favour of the new eclasses? I don't
>> quite understand the reasons to be honest.
>
> The reason is simple -- I can't fix it without changing the API.
> Changing the API on a live eclass is confusing, and considering
> that it is not used by many packages, it's easier to lastrite it.
>
> Also, this fixes the name not to have any '-ng' nor '-ds9'.
>

What are the reasons to change the API in the first place? There has
to be a good reason, cause this will involve yet another migration of
many ebuilds. I don't see any bugreports.

I fear this will cause more confusion, i.e. some ebuilds using the old
distutils, some using python-distutils-ng and some using distutils-r1
resulting in weird tree behavior.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJQZvxsAAoJEFpvPKfnPDWzL1IH/iaChrfPET4KArZzaViXJjlL
4pM2tmgByJNAgtFjwLwz3c6lqdJGAV8Uf4VpPTec+Z7lj0v0SD j04YI63CgFZ2N/
R7edGAoJdGOFDv/oOY+bP38PeWpnuguOvEaKI8EEqaJgLne29wPEQ7+KcWe8M6hM
tA41lIIFpK2PN+kIHdItbSl8aRZmm9NorfUCukFfs1odwV+C0B 3rP4mJZQW+TnbR
DmDqFCFQF/r1k+n17wARqvcCL+hBqs/CvTG7K8Z/mNWD/Dove1vMB1ir8p8KnYSO
TULgpcVEK4VuXjHrccLhmO4ODWZiXn/yWKws3z+XmRwIwBB7m9IhC8G32aeyqoE=
=gU6H
-----END PGP SIGNATURE-----

Ian Stakenvicius 09-29-2012 02:19 PM

Initial python-r1.eclass & distutils-r1.eclass
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 29/09/12 09:49 AM, hasufell wrote:
> On 09/29/2012 12:49 PM, Michał Górny wrote:
>> On Sat, 29 Sep 2012 11:20:31 +0100 Markos Chandras
>> <hwoarang@gentoo.org> wrote:
>
>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512
>>>
>>> On 09/29/2012 09:53 AM, Micha? Górny wrote:
>>>> Hello,
>>>>
>>>> Instead of the floating patches and p-d-ng modifications I
>>>> sent earlier, here are the two complete (so far, well,
>>>> initial :P) eclasses for review.
>>>>
>>>> They are designed as 'mostly' drop-in python-distutils-ng
>>>> replacement.
>>>>
>>> Hi,
>>>
>>> Are you saying that you are going to remove the
>>> python-distutils-ng eclass in favour of the new eclasses? I
>>> don't quite understand the reasons to be honest.
>
>> The reason is simple -- I can't fix it without changing the API.
>> Changing the API on a live eclass is confusing, and considering
>> that it is not used by many packages, it's easier to lastrite
>> it.
>
>> Also, this fixes the name not to have any '-ng' nor '-ds9'.
>
>
> What are the reasons to change the API in the first place? There
> has to be a good reason, cause this will involve yet another
> migration of many ebuilds. I don't see any bugreports.
>
> I fear this will cause more confusion, i.e. some ebuilds using the
> old distutils, some using python-distutils-ng and some using
> distutils-r1 resulting in weird tree behavior.
>

Given that at present, distutils-r1 and python-distutils-ng have
identical end-results, I think that the introduction of distutils-r1
to the tree should also involve a sed against all the existing ebuilds
using python-distutils-ng to move them to the new eclass. Then
python-distutils-ng only needs to remain to support overlays.

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

iF4EAREIAAYFAlBnA1YACgkQ2ugaI38ACPBtCgD/UXW804+tsTOnI0RtfWfhiewK
a0W9DXplPRprWYZg4mQBAIWbRf+AJDrIqGvELiwt3p0FXChbCY ypHDmm3tb8ljxL
=isBB
-----END PGP SIGNATURE-----

hasufell 09-29-2012 02:26 PM

Initial python-r1.eclass & distutils-r1.eclass
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/29/2012 04:19 PM, Ian Stakenvicius wrote:
> On 29/09/12 09:49 AM, hasufell wrote:
>> On 09/29/2012 12:49 PM, Michał Górny wrote:
>>> On Sat, 29 Sep 2012 11:20:31 +0100 Markos Chandras
>>> <hwoarang@gentoo.org> wrote:
>
>>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512
>>>>
>>>> On 09/29/2012 09:53 AM, Micha? Górny wrote:
>>>>> Hello,
>>>>>
>>>>> Instead of the floating patches and p-d-ng modifications I
>>>>> sent earlier, here are the two complete (so far, well,
>>>>> initial :P) eclasses for review.
>>>>>
>>>>> They are designed as 'mostly' drop-in python-distutils-ng
>>>>> replacement.
>>>>>
>>>> Hi,
>>>>
>>>> Are you saying that you are going to remove the
>>>> python-distutils-ng eclass in favour of the new eclasses? I
>>>> don't quite understand the reasons to be honest.
>
>>> The reason is simple -- I can't fix it without changing the
>>> API. Changing the API on a live eclass is confusing, and
>>> considering that it is not used by many packages, it's easier
>>> to lastrite it.
>
>>> Also, this fixes the name not to have any '-ng' nor '-ds9'.
>
>
>> What are the reasons to change the API in the first place? There
>> has to be a good reason, cause this will involve yet another
>> migration of many ebuilds. I don't see any bugreports.
>
>> I fear this will cause more confusion, i.e. some ebuilds using
>> the old distutils, some using python-distutils-ng and some using
>> distutils-r1 resulting in weird tree behavior.
>
>
> Given that at present, distutils-r1 and python-distutils-ng have
> identical end-results, I think that the introduction of
> distutils-r1 to the tree should also involve a sed against all the
> existing ebuilds using python-distutils-ng to move them to the new
> eclass. Then python-distutils-ng only needs to remain to support
> overlays.
>
>

That still does not explain the reasons why this work was initiated.

If there is any way to fix the current eclass, that should be preferred.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJQZwUtAAoJEFpvPKfnPDWz+g4IAIL0eFfX6r MHKBxtNkCGt7yo
dnPMiAjlbRwDVkpCBnorATwLpnHhsRfsHtHXkQrNXWzgGvSgOE TpvGzmFgvPzr4L
lvOs3ND8BFZz3OiQuw3K2GrwInbQCXg1oFlKdBuLOom7WxtePV XeJsK3Ck4coGcH
NIfYlQNLaISp0CvUhGg3yF6/PjSCZ9vwfIN7muY1OVspE0DWXCRIZoOs623RixTS
cwzFRIdlxeJgw+JEuLN8wSsXe+Ir3bmmFOiRF+FD6LzjoYdh0x RyGX6Qgg974F7f
yb2aOT2MCMANWrMgdYiNuRZGJNvUagZ78PRIGHWNw+PzDaNC3j XqrTBsGpkk2Fc=
=azK1
-----END PGP SIGNATURE-----

Dirkjan Ochtman 09-29-2012 02:37 PM

Initial python-r1.eclass & distutils-r1.eclass
 
On Sat, Sep 29, 2012 at 4:26 PM, hasufell <hasufell@gentoo.org> wrote:
> That still does not explain the reasons why this work was initiated.
>
> If there is any way to fix the current eclass, that should be preferred.

I tend to agree. Michał, let me first say I value the time you have
invested to make the eclasses better. However, at this point I have a
strong feeling that we have more people willing to write code to fix
things than we have people building consensus on what
features/policies/mechanisms we need to make it easy to write
high-quality ebuilds for Python/distutils. I would prefer discussions
on problems that the current ebuilds have and discussions on how to
solve them, not at the code level, but that the mechanism level.

Cheers,

Dirkjan


All times are GMT. The time now is 05:12 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.