bump(eclass/python*): sync python related eclasses from upstream

This commit is contained in:
Michael Marineau 2013-08-04 19:49:16 -04:00
parent e00b276b3e
commit 5fd38ad661
8 changed files with 751 additions and 310 deletions

View File

@ -1,6 +1,6 @@
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/distutils-r1.eclass,v 1.48 2013/01/27 16:39:23 mgorny Exp $
# $Header: /var/cvsroot/gentoo-x86/eclass/distutils-r1.eclass,v 1.74 2013/08/01 13:02:32 mgorny Exp $
# @ECLASS: distutils-r1
# @MAINTAINER:
@ -98,16 +98,9 @@ if [[ ! ${_DISTUTILS_R1} ]]; then
if [[ ! ${DISTUTILS_OPTIONAL} ]]; then
RDEPEND=${PYTHON_DEPS}
DEPEND=${PYTHON_DEPS}
REQUIRED_USE=${PYTHON_REQUIRED_USE}
fi
# @ECLASS-VARIABLE: DISTUTILS_JOBS
# @DEFAULT_UNSET
# @DESCRIPTION:
# The number of parallel jobs to run for distutils-r1 parallel builds.
# If unset, the job-count in ${MAKEOPTS} will be used.
#
# This variable is intended to be set in make.conf.
# @ECLASS-VARIABLE: PATCHES
# @DEFAULT_UNSET
# @DESCRIPTION:
@ -151,7 +144,25 @@ fi
#
# Example:
# @CODE
# HTML_DOCS=( doc/html/ )
# HTML_DOCS=( doc/html/. )
# @CODE
# @ECLASS-VARIABLE: EXAMPLES
# @DEFAULT_UNSET
# @DESCRIPTION:
# An array containing examples installed into 'examples' doc
# subdirectory. The files and directories listed there must exist
# in the directory from which distutils-r1_python_install_all() is run
# (${S} by default).
#
# The 'examples' subdirectory will be marked not to be compressed
# automatically.
#
# If unset, no examples will be installed.
#
# Example:
# @CODE
# EXAMPLES=( examples/. demos/. )
# @CODE
# @ECLASS-VARIABLE: DISTUTILS_IN_SOURCE_BUILD
@ -199,39 +210,110 @@ fi
# @FUNCTION: esetup.py
# @USAGE: [<args>...]
# @DESCRIPTION:
# Run the setup.py using currently selected Python interpreter
# (if ${PYTHON} is set; fallback 'python' otherwise). The setup.py will
# be passed default ${mydistutilsargs[@]}, then any parameters passed
# to this command and optionally a standard option set (e.g. the build
# directory in an ebuild using out-of-source builds).
# Run setup.py using currently selected Python interpreter
# (if ${PYTHON} is set; fallback 'python' otherwise).
#
# setup.py will be passed the following, in order:
# 1. ${mydistutilsargs[@]}
# 2. The 'build' command and standard build options including ${BUILD_DIR}
# 3. Any additional arguments passed to the esetup.py function.
#
# This command dies on failure.
esetup.py() {
debug-print-function ${FUNCNAME} "${@}"
local add_args=()
if [[ ! ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
if [[ ! ${BUILD_DIR} ]]; then
die 'Out-of-source build requested, yet BUILD_DIR unset.'
fi
if [[ ${BUILD_DIR} ]]; then
add_args+=(
build
--build-base "${BUILD_DIR}"
# using a single directory for them helps us export ${PYTHONPATH}
--build-lib "${BUILD_DIR}/lib"
# using a single directory for them helps us export
# ${PYTHONPATH} and ebuilds find the sources independently
# of whether the package installs extensions or not
#
# note: due to some packages (wxpython) relying on separate
# platlib & purelib dirs, we do not set --build-lib (which
# can not be overriden with --build-*lib)
--build-platlib "${BUILD_DIR}/lib"
--build-purelib "${BUILD_DIR}/lib"
# make the ebuild writer lives easier
--build-scripts "${BUILD_DIR}/scripts"
)
# if setuptools is used, adjust egg_info path as well
if "${PYTHON:-python}" setup.py --help egg_info &>/dev/null; then
add_args+=(
egg_info --egg-base "${BUILD_DIR}"
)
fi
elif [[ ! ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
die 'Out-of-source build requested, yet BUILD_DIR unset.'
fi
set -- "${PYTHON:-python}" setup.py \
"${mydistutilsargs[@]}" "${@}" "${add_args[@]}"
"${mydistutilsargs[@]}" "${add_args[@]}" "${@}"
echo "${@}" >&2
"${@}" || die
}
# @FUNCTION: distutils_install_for_testing
# @USAGE: [<args>...]
# @DESCRIPTION:
# Install the package into a temporary location for running tests.
# Update PYTHONPATH appropriately and set TEST_DIR to the test
# installation root. The Python packages will be installed in 'lib'
# subdir, and scripts in 'scripts' subdir (like in BUILD_DIR).
#
# Please note that this function should be only used if package uses
# namespaces (and therefore proper install needs to be done to enforce
# PYTHONPATH) or tests rely on the results of install command.
# For most of the packages, tests built in BUILD_DIR are good enough.
distutils_install_for_testing() {
debug-print-function ${FUNCNAME} "${@}"
# A few notes:
# 1) because of namespaces, we can't use 'install --root',
# 2) 'install --home' is terribly broken on pypy, so we need
# to override --install-lib and --install-scripts,
# 3) non-root 'install' complains about PYTHONPATH and missing dirs,
# so we need to set it properly and mkdir them,
# 4) it runs a bunch of commands which write random files to cwd,
# in order to avoid that, we need to run them ourselves to pass
# alternate build paths,
# 5) 'install' needs to go before 'bdist_egg' or the latter would
# re-set install paths.
TEST_DIR=${BUILD_DIR}/test
local bindir=${TEST_DIR}/scripts
local libdir=${TEST_DIR}/lib
PYTHONPATH=${libdir}:${PYTHONPATH}
local add_args=(
install
--home="${TEST_DIR}"
--install-lib="${libdir}"
--install-scripts="${bindir}"
)
if "${PYTHON:-python}" setup.py --help bdist_egg &>/dev/null; then
add_args+=(
bdist_egg --dist-dir="${TEST_DIR}"
)
fi
mkdir -p "${libdir}" || die
esetup.py "${add_args[@]}"
}
_disable_ez_setup() {
local stub="def use_setuptools(*args, **kwargs): pass"
[[ -f ez_setup.py ]] && echo "${stub}" > ez_setup.py
[[ -f distribute_setup.py ]] && echo "${stub}" > distribute_setup.py
}
# @FUNCTION: distutils-r1_python_prepare_all
# @DESCRIPTION:
# The default python_prepare_all(). It applies the patches from PATCHES
@ -254,11 +336,16 @@ distutils-r1_python_prepare_all() {
fi
fi
# Prevent packages from downloading their own copy of setuptools
_disable_ez_setup
if [[ ${DISTUTILS_IN_SOURCE_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
then
# create source copies for each implementation
python_copy_sources
fi
_DISTUTILS_DEFAULT_CALLED=1
}
# @FUNCTION: distutils-r1_python_prepare
@ -288,7 +375,7 @@ distutils-r1_python_configure() {
distutils-r1_python_compile() {
debug-print-function ${FUNCNAME} "${@}"
esetup.py build "${@}"
esetup.py "${@}"
}
# @FUNCTION: distutils-r1_python_test
@ -319,9 +406,11 @@ _distutils-r1_rename_scripts() {
while IFS= read -r -d '' f; do
debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
if [[ "$(head -n 1 "${f}")" == '#!'*${EPYTHON}* ]]
local shebang
read -r shebang < "${f}"
if [[ ${shebang} == '#!'*${EPYTHON}* ]]
then
debug-print "${FUNCNAME}: matching shebang: $(head -n 1 "${f}")"
debug-print "${FUNCNAME}: matching shebang: ${shebang}"
local newf=${f}-${EPYTHON}
debug-print "${FUNCNAME}: renaming to ${newf#${D}/}"
@ -354,8 +443,7 @@ distutils-r1_python_install() {
debug-print "${FUNCNAME}: [${EPYTHON}] flags: ${flags}"
# enable compilation for the install phase.
local PYTHONDONTWRITEBYTECODE
export PYTHONDONTWRITEBYTECODE
local -x PYTHONDONTWRITEBYTECODE
# python likes to compile any module it sees, which triggers sandbox
# failures if some packages haven't compiled their modules yet.
@ -367,51 +455,16 @@ distutils-r1_python_install() {
esetup.py install "${flags[@]}" --root="${root}" "${@}"
if [[ -d ${root}$(python_get_sitedir)/tests ]]; then
die "Package installs 'tests' package, file collisions likely."
fi
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
_distutils-r1_rename_scripts "${root}"
_distutils-r1_merge_root "${root}" "${D}"
multibuild_merge_root "${root}" "${D}"
fi
}
# @FUNCTION: distutils-r1_merge_root
# @USAGE: <src-root> <dest-root>
# @INTERNAL
# @DESCRIPTION:
# Merge the directory tree from <src-root> to <dest-root>, removing
# the <src-root> in the process.
_distutils-r1_merge_root() {
local src=${1}
local dest=${2}
local lockfile=${T}/distutils-r1-merge-lock
if type -P lockf &>/dev/null; then
# On BSD, we have 'lockf' wrapper.
tar -C "${src}" -f - -c . \
| lockf "${lockfile}" tar -x -f - -C "${dest}"
else
local lock_fd
if type -P flock &>/dev/null; then
# On Linux, we have 'flock' which can lock fd.
redirect_alloc_fd lock_fd "${lockfile}" '>>'
flock ${lock_fd}
else
ewarn "distutils-r1: no locking service found, please report."
fi
cp -a -l -n "${src}"/. "${dest}"/
if [[ ${lock_fd} ]]; then
# Close the lock file when we are done with it.
# Prevents deadlock if we aren't in a subshell.
eval "exec ${lock_fd}>&-"
fi
fi
[[ ${?} == 0 ]] || die "Merging ${EPYTHON} image failed."
rm -rf "${src}"
}
# @FUNCTION: distutils-r1_python_install_all
# @DESCRIPTION:
# The default python_install_all(). It installs the documentation.
@ -419,21 +472,32 @@ distutils-r1_python_install_all() {
debug-print-function ${FUNCNAME} "${@}"
if declare -p DOCS &>/dev/null; then
dodoc -r "${DOCS[@]}" || die "dodoc failed"
# an empty list == don't install anything
if [[ ${DOCS[@]} ]]; then
dodoc -r "${DOCS[@]}"
fi
else
local f
# same list as in PMS
for f in README* ChangeLog AUTHORS NEWS TODO CHANGES \
THANKS BUGS FAQ CREDITS CHANGELOG; do
if [[ -s ${f} ]]; then
dodoc "${f}" || die "(default) dodoc ${f} failed"
dodoc "${f}"
fi
done
fi
if declare -p HTML_DOCS &>/dev/null; then
dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed"
dohtml -r "${HTML_DOCS[@]}"
fi
if declare -p EXAMPLES &>/dev/null; then
local INSDESTTREE=/usr/share/doc/${PF}/examples
doins -r "${EXAMPLES[@]}"
docompress -x "${INSDESTTREE}"
fi
_DISTUTILS_DEFAULT_CALLED=1
}
# @FUNCTION: distutils-r1_run_phase
@ -446,8 +510,9 @@ distutils-r1_python_install_all() {
# directory, with BUILD_DIR pointing at the build directory
# and PYTHONPATH having an entry for the module build directory.
#
# If in-source builds are used, the command is executed in the BUILD_DIR
# (the directory holding per-implementation copy of sources).
# If in-source builds are used, the command is executed in the directory
# holding the per-implementation copy of sources. BUILD_DIR points
# to the 'build' subdirectory.
distutils-r1_run_phase() {
debug-print-function ${FUNCNAME} "${@}"
@ -455,35 +520,20 @@ distutils-r1_run_phase() {
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
pushd "${BUILD_DIR}" >/dev/null || die
fi
else
local PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
export PYTHONPATH
local BUILD_DIR=${BUILD_DIR}/build
fi
local -x PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
local TMPDIR=${T}/${EPYTHON}
mkdir -p "${TMPDIR}" || die
if [[ ${DISTUTILS_NO_PARALLEL_BUILD} || ${DISTUTILS_SINGLE_IMPL} ]]
then
"${@}" 2>&1 | tee -a "${T}/build-${EPYTHON}.log"
else
(
multijob_child_init
"${@}" 2>&1 | tee -a "${T}/build-${EPYTHON}.log"
) &
multijob_post_fork
fi
"${@}"
if [[ ${DISTUTILS_IN_SOURCE_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
then
popd >/dev/null || die
fi
# Store them for reuse.
_DISTUTILS_BEST_IMPL=(
"${EPYTHON}" "${PYTHON}" "${BUILD_DIR}" "${PYTHONPATH}"
)
}
# @FUNCTION: _distutils-r1_run_common_phase
@ -491,50 +541,21 @@ distutils-r1_run_phase() {
# @INTERNAL
# @DESCRIPTION:
# Run the given command, restoring the best-implementation state.
#
# If in-source build is used, the command will be run in the copy
# of sources made for the best Python interpreter.
_distutils-r1_run_common_phase() {
local DISTUTILS_ORIG_BUILD_DIR=${BUILD_DIR}
local EPYTHON=${_DISTUTILS_BEST_IMPL[0]}
local PYTHON=${_DISTUTILS_BEST_IMPL[1]}
local BUILD_DIR=${_DISTUTILS_BEST_IMPL[2]}
local PYTHONPATH=${_DISTUTILS_BEST_IMPL[3]}
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
local MULTIBUILD_VARIANTS
_python_obtain_impls
export EPYTHON PYTHON PYTHONPATH
einfo "common: running ${1}"
"${@}"
}
# @FUNCTION: _distutils-r1_multijob_init
# @INTERNAL
# @DESCRIPTION:
# Init multijob, taking the job-count from ${DISTUTILS_JOBS}.
_distutils-r1_multijob_init() {
debug-print-function ${FUNCNAME} "${@}"
if [[ ! ${DISTUTILS_NO_PARALLEL_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
then
local opts
if [[ ${DISTUTILS_JOBS} ]]; then
opts=-j${DISTUTILS_JOBS}
else
opts=${MAKEOPTS}
fi
multijob_init "${opts}"
fi
}
# @FUNCTION: _distutils-r1_multijob_finish
# @INTERNAL
# @DESCRIPTION:
# Finish multijob if used.
_distutils-r1_multijob_finish() {
debug-print-function ${FUNCNAME} "${@}"
if [[ ! ${DISTUTILS_NO_PARALLEL_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
then
multijob_finish
multibuild_for_best_variant _python_multibuild_wrapper \
distutils-r1_run_phase "${@}"
else
# semi-hack, be careful.
_distutils-r1_run_foreach_impl "${@}"
fi
}
@ -549,7 +570,12 @@ _distutils-r1_run_foreach_impl() {
set -- distutils-r1_run_phase "${@}"
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
python_foreach_impl "${@}"
if [[ ${DISTUTILS_NO_PARALLEL_BUILD} || ${DISTUTILS_SINGLE_IMPL} ]]
then
python_foreach_impl "${@}"
else
python_parallel_foreach_impl "${@}"
fi
else
if [[ ! ${EPYTHON} ]]; then
die "EPYTHON unset, python-single-r1_pkg_setup not called?!"
@ -564,6 +590,8 @@ _distutils-r1_run_foreach_impl() {
distutils-r1_src_prepare() {
debug-print-function ${FUNCNAME} "${@}"
local _DISTUTILS_DEFAULT_CALLED
# common preparations
if declare -f python_prepare_all >/dev/null; then
python_prepare_all
@ -571,19 +599,19 @@ distutils-r1_src_prepare() {
distutils-r1_python_prepare_all
fi
_distutils-r1_multijob_init
if [[ ! ${_DISTUTILS_DEFAULT_CALLED} ]]; then
eqawarn "QA warning: python_prepare_all() didn't call distutils-r1_python_prepare_all"
fi
if declare -f python_prepare >/dev/null; then
_distutils-r1_run_foreach_impl python_prepare
fi
_distutils-r1_multijob_finish
}
distutils-r1_src_configure() {
_distutils-r1_multijob_init
if declare -f python_configure >/dev/null; then
_distutils-r1_run_foreach_impl python_configure
fi
_distutils-r1_multijob_finish
if declare -f python_configure_all >/dev/null; then
_distutils-r1_run_common_phase python_configure_all
@ -593,13 +621,11 @@ distutils-r1_src_configure() {
distutils-r1_src_compile() {
debug-print-function ${FUNCNAME} "${@}"
_distutils-r1_multijob_init
if declare -f python_compile >/dev/null; then
_distutils-r1_run_foreach_impl python_compile
else
_distutils-r1_run_foreach_impl distutils-r1_python_compile
fi
_distutils-r1_multijob_finish
if declare -f python_compile_all >/dev/null; then
_distutils-r1_run_common_phase python_compile_all
@ -609,11 +635,9 @@ distutils-r1_src_compile() {
distutils-r1_src_test() {
debug-print-function ${FUNCNAME} "${@}"
_distutils-r1_multijob_init
if declare -f python_test >/dev/null; then
_distutils-r1_run_foreach_impl python_test
fi
_distutils-r1_multijob_finish
if declare -f python_test_all >/dev/null; then
_distutils-r1_run_common_phase python_test_all
@ -623,19 +647,23 @@ distutils-r1_src_test() {
distutils-r1_src_install() {
debug-print-function ${FUNCNAME} "${@}"
_distutils-r1_multijob_init
if declare -f python_install >/dev/null; then
_distutils-r1_run_foreach_impl python_install
else
_distutils-r1_run_foreach_impl distutils-r1_python_install
fi
_distutils-r1_multijob_finish
local _DISTUTILS_DEFAULT_CALLED
if declare -f python_install_all >/dev/null; then
_distutils-r1_run_common_phase python_install_all
else
_distutils-r1_run_common_phase distutils-r1_python_install_all
fi
if [[ ! ${_DISTUTILS_DEFAULT_CALLED} ]]; then
eqawarn "QA warning: python_install_all() didn't call distutils-r1_python_install_all"
fi
}
_DISTUTILS_R1=1

View File

@ -1,6 +1,6 @@
# Copyright 1999-2012 Gentoo Foundation
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.82 2012/03/15 16:51:54 patrick Exp $
# $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.84 2013/08/03 13:28:22 patrick Exp $
# @ECLASS: distutils.eclass
# @MAINTAINER:
@ -33,15 +33,15 @@ fi
ewarn
ewarn "\"${EBUILD}\":"
ewarn "Deprecation Warning: Usage of distutils.eclass in packages supporting installation"
ewarn "for multiple Python ABIs in EAPI <=1 is deprecated and will be banned on 2011-06-01."
ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
ewarn "for multiple Python ABIs in EAPI <=1 is deprecated."
ewarn "The ebuild should to be fixed. Please report a bug, if it has not been already reported."
ewarn
elif has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
ewarn
ewarn "\"${EBUILD}\":"
ewarn "Deprecation Warning: Usage of distutils.eclass in packages not supporting installation"
ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be banned on 2011-06-01."
ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
ewarn "for multiple Python ABIs in EAPI <=2 is deprecated."
ewarn "The ebuild should to be fixed. Please report a bug, if it has not been already reported."
ewarn
fi
@ -98,7 +98,7 @@ if [[ -z "${DISTUTILS_DISABLE_TEST_DEPENDENCY}" ]]; then
# trial requires an argument, which is usually equal to "${PN}".
elif [[ "${DISTUTILS_SRC_TEST}" =~ ^trial(\ .*)?$ ]]; then
IUSE="test"
DEPEND+="${DEPEND:+ }test? ( dev-python/twisted )"
DEPEND+="${DEPEND:+ }test? ( dev-python/twisted-core )"
fi
fi

View File

@ -1,6 +1,6 @@
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/python-any-r1.eclass,v 1.6 2013/01/21 19:28:16 mgorny Exp $
# $Header: /var/cvsroot/gentoo-x86/eclass/python-any-r1.eclass,v 1.13 2013/08/01 12:49:42 mgorny Exp $
# @ECLASS: python-any-r1
# @MAINTAINER:
@ -20,6 +20,14 @@
# pkg_setup() which finds the best supported implementation and sets it
# as the active one.
#
# Optionally, you can define a python_check_deps() function. It will
# be called by the eclass with EPYTHON set to each matching Python
# implementation and it is expected to check whether the implementation
# fulfills the package requirements. You can use the locally exported
# PYTHON_USEDEP to check USE-dependencies of relevant packages. It
# should return a true value (0) if the Python implementation fulfills
# the requirements, a false value (non-zero) otherwise.
#
# Please note that python-any-r1 will always inherit python-utils-r1
# as well. Thus, all the functions defined there can be used in the
# packages using python-any-r1, and there is no need ever to inherit
@ -106,44 +114,59 @@ fi
# @CODE
_python_build_set_globals() {
local usestr
local usestr i PYTHON_PKG_DEP
[[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]"
PYTHON_DEPS=
local i
for i in "${_PYTHON_ALL_IMPLS[@]}"; do
if has "${i}" "${PYTHON_COMPAT[@]}"
then
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
# check for invalid PYTHON_COMPAT
for i in "${PYTHON_COMPAT[@]}"; do
# the function simply dies on invalid impl
_python_impl_supported "${i}"
done
local v=${i##*[a-z]}
PYTHON_DEPS="${d}:${v/_/.}${usestr} ${PYTHON_DEPS}"
fi
PYTHON_DEPS=
for i in "${_PYTHON_ALL_IMPLS[@]}"; do
has "${i}" "${PYTHON_COMPAT[@]}" || continue
python_export "${i}" PYTHON_PKG_DEP
PYTHON_DEPS="${PYTHON_PKG_DEP} ${PYTHON_DEPS}"
done
PYTHON_DEPS="|| ( ${PYTHON_DEPS})"
}
_python_build_set_globals
# @ECLASS-VARIABLE: PYTHON_USEDEP
# @DESCRIPTION:
# An eclass-generated USE-dependency string for the currently tested
# implementation. It is set locally for python_check_deps() call.
#
# The generate USE-flag list is compatible with packages using python-r1,
# python-single-r1 and python-distutils-ng eclasses. It must not be used
# on packages using python.eclass.
#
# Example use:
# @CODE
# python_check_deps() {
# has_version "dev-python/foo[${PYTHON_USEDEP}]"
# }
# @CODE
#
# Example value:
# @CODE
# python_targets_python2_7(-)?,python_single_target_python2_7(+)?
# @CODE
# @FUNCTION: _python_EPYTHON_supported
# @USAGE: <epython>
# @INTERNAL
# @DESCRIPTION:
# Check whether the specified implementation is supported by package
# (specified in PYTHON_COMPAT).
# (specified in PYTHON_COMPAT). Calls python_check_deps() if declared.
_python_EPYTHON_supported() {
debug-print-function ${FUNCNAME} "${@}"
local i=${1/./_}
local EPYTHON=${1}
local i=${EPYTHON/./_}
case "${i}" in
python*|jython*)
@ -158,7 +181,17 @@ _python_EPYTHON_supported() {
esac
if has "${i}" "${PYTHON_COMPAT[@]}"; then
return 0
local PYTHON_PKG_DEP
python_export "${i}" PYTHON_PKG_DEP
if ROOT=/ has_version "${PYTHON_PKG_DEP}"; then
if declare -f python_check_deps >/dev/null; then
local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)"
python_check_deps
return ${?}
fi
return 0
fi
elif ! has "${i}" "${_PYTHON_ALL_IMPLS[@]}"; then
ewarn "Invalid EPYTHON: ${EPYTHON}"
fi
@ -176,6 +209,7 @@ python-any-r1_pkg_setup() {
if [[ ${EPYTHON} ]]; then
if _python_EPYTHON_supported "${EPYTHON}"; then
python_export EPYTHON PYTHON
python_wrapper_setup
return
fi
fi
@ -190,6 +224,7 @@ python-any-r1_pkg_setup() {
break
elif _python_EPYTHON_supported "${i}"; then
python_export "${i}" EPYTHON PYTHON
python_wrapper_setup
return
fi
done
@ -202,11 +237,19 @@ python-any-r1_pkg_setup() {
fi
done
local PYTHON_PKG_DEP
for i in "${rev_impls[@]}"; do
python_export "${i}" PYTHON_PKG_DEP EPYTHON PYTHON
ROOT=/ has_version "${PYTHON_PKG_DEP}" && return
python_export "${i}" EPYTHON PYTHON
if _python_EPYTHON_supported "${EPYTHON}"; then
python_wrapper_setup
return
fi
done
eerror "No Python implementation found for the build. This is usually"
eerror "a bug in the ebuild. Please report it to bugs.gentoo.org"
eerror "along with the build log."
echo
die "No supported Python implementation installed."
}
_PYTHON_ANY_R1=1

View File

@ -1,6 +1,6 @@
# Copyright 1999-2012 Gentoo Foundation
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/python-distutils-ng.eclass,v 1.29 2012/10/30 17:22:33 mgorny Exp $
# $Header: /var/cvsroot/gentoo-x86/eclass/python-distutils-ng.eclass,v 1.30 2013/07/27 11:17:44 mgorny Exp $
# @ECLASS: python-distutils-ng
# @MAINTAINER:
@ -132,7 +132,7 @@ for impl in ${PYTHON_COMPAT}; do
jython?.?)
dep_str="dev-java/jython:${dep_str: -3}${_PYTHON_USE}" ;;
pypy?.?)
dep_str="dev-python/pypy:${dep_str: -3}${_PYTHON_USE}" ;;
dep_str="virtual/pypy:${dep_str: -3}${_PYTHON_USE}" ;;
*)
die "Unsupported implementation: ${impl}" ;;
esac

View File

@ -1,6 +1,6 @@
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.40 2013/01/30 10:42:25 mgorny Exp $
# $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.56 2013/08/04 08:24:28 mgorny Exp $
# @ECLASS: python-r1
# @MAINTAINER:
@ -48,7 +48,7 @@ elif [[ ${_PYTHON_ANY_R1} ]]; then
die 'python-r1.eclass can not be used with python-any-r1.eclass.'
fi
inherit python-utils-r1
inherit multibuild python-utils-r1
# @ECLASS-VARIABLE: PYTHON_COMPAT
# @REQUIRED
@ -67,13 +67,28 @@ inherit python-utils-r1
# PYTHON_COMPAT=( python{2_5,2_6,2_7} )
# @CODE
if ! declare -p PYTHON_COMPAT &>/dev/null; then
if [[ ${CATEGORY}/${PN} == dev-python/python-exec ]]; then
PYTHON_COMPAT=( "${_PYTHON_ALL_IMPLS[@]}" )
else
die 'PYTHON_COMPAT not declared.'
fi
die 'PYTHON_COMPAT not declared.'
fi
# @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
# @INTERNAL
# @DESCRIPTION:
# This variable can be used when working with ebuilds to override
# the in-ebuild PYTHON_COMPAT. It is a string listing all
# the implementations which package will be built for. It need be
# specified in the calling environment, and not in ebuilds.
#
# It should be noted that in order to preserve metadata immutability,
# PYTHON_COMPAT_OVERRIDE does not affect IUSE nor dependencies.
# The state of PYTHON_TARGETS is ignored, and all the implementations
# in PYTHON_COMPAT_OVERRIDE are built. Dependencies need to be satisfied
# manually.
#
# Example:
# @CODE
# PYTHON_COMPAT_OVERRIDE='pypy2_0 python3_3' emerge -1v dev-python/foo
# @CODE
# @ECLASS-VARIABLE: PYTHON_REQ_USE
# @DEFAULT_UNSET
# @DESCRIPTION:
@ -131,6 +146,24 @@ fi
# python_targets_python2_6(-)?,python_targets_python2_7(-)?
# @CODE
# @ECLASS-VARIABLE: PYTHON_REQUIRED_USE
# @DESCRIPTION:
# This is an eclass-generated required-use expression which ensures at
# least one Python implementation has been enabled.
#
# This expression should be utilized in an ebuild by including it in
# REQUIRED_USE, optionally behind a use flag.
#
# Example use:
# @CODE
# REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
# @CODE
#
# Example value:
# @CODE
# || ( python_targets_python2_6 python_targets_python2_7 )
# @CODE
_python_set_globals() {
local impls=()
@ -162,7 +195,7 @@ _python_set_globals() {
optflags+=,${flags_st[@]/%/(-)}
IUSE=${flags[*]}
#REQUIRED_USE="|| ( ${flags[*]} )"
PYTHON_REQUIRED_USE="|| ( ${flags[*]} )"
PYTHON_USEDEP=${optflags// /,}
# 1) well, python-exec would suffice as an RDEP
@ -173,6 +206,14 @@ _python_set_globals() {
}
_python_set_globals
# @ECLASS-VARIABLE: DISTUTILS_JOBS
# @DEFAULT_UNSET
# @DESCRIPTION:
# The number of parallel jobs to run for distutils-r1 parallel builds.
# If unset, the job-count in ${MAKEOPTS} will be used.
#
# This variable is intended to be set in make.conf.
# @FUNCTION: _python_validate_useflags
# @INTERNAL
# @DESCRIPTION:
@ -203,6 +244,9 @@ _python_validate_useflags() {
# are both in PYTHON_COMPAT and match any of the patterns passed
# as parameters to the function.
#
# Remember to escape or quote the patterns to premature evaluation as a file
# name glob.
#
# When all implementations are requested, please use ${PYTHON_USEDEP}
# instead. Please also remember to set an appropriate REQUIRED_USE
# to avoid ineffective USE flags.
@ -210,7 +254,7 @@ _python_validate_useflags() {
# Example:
# @CODE
# PYTHON_COMPAT=( python{2_7,3_2} )
# DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep python2*)] )"
# DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
# @CODE
#
# It will cause the dependency to look like:
@ -340,34 +384,19 @@ python_gen_cond_dep() {
# @FUNCTION: python_copy_sources
# @DESCRIPTION:
# Create a single copy of the package sources (${S}) for each enabled
# Python implementation.
# Create a single copy of the package sources for each enabled Python
# implementation.
#
# The sources are always copied from S to implementation-specific build
# directories respecting BUILD_DIR.
# The sources are always copied from initial BUILD_DIR (or S if unset)
# to implementation-specific build directory matching BUILD_DIR used by
# python_foreach_abi().
python_copy_sources() {
debug-print-function ${FUNCNAME} "${@}"
_python_validate_useflags
local MULTIBUILD_VARIANTS
_python_obtain_impls
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
_python_impl_supported "${impl}" || continue
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
multibuild_copy_sources
}
# @FUNCTION: _python_check_USE_PYTHON
@ -578,40 +607,102 @@ _python_check_USE_PYTHON() {
fi
}
# @FUNCTION: _python_obtain_impls
# @INTERNAL
# @DESCRIPTION:
# Set up the enabled implementation list.
_python_obtain_impls() {
if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
if [[ ! ${_PYTHON_COMPAT_OVERRIDE_WARNED} ]]; then
ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python"
ewarn "implementations will be enabled:"
ewarn
ewarn " ${PYTHON_COMPAT_OVERRIDE}"
ewarn
ewarn "Dependencies won't be satisfied, and PYTHON_TARGETS will be ignored."
_PYTHON_COMPAT_OVERRIDE_WARNED=1
fi
MULTIBUILD_VARIANTS=( ${PYTHON_COMPAT_OVERRIDE} )
return
fi
_python_validate_useflags
_python_check_USE_PYTHON
MULTIBUILD_VARIANTS=()
for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
if has "${impl}" "${PYTHON_COMPAT[@]}" \
&& use "python_targets_${impl}"
then
MULTIBUILD_VARIANTS+=( "${impl}" )
fi
done
}
# @FUNCTION: _python_multibuild_wrapper
# @USAGE: <command> [<args>...]
# @INTERNAL
# @DESCRIPTION:
# Initialize the environment for Python implementation selected
# for multibuild.
_python_multibuild_wrapper() {
debug-print-function ${FUNCNAME} "${@}"
local -x EPYTHON PYTHON
local -x PATH=${PATH} PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
python_export "${MULTIBUILD_VARIANT}" EPYTHON PYTHON
python_wrapper_setup
"${@}"
}
# @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.
# to the command.
#
# The function will return 0 status if all invocations succeed.
# Otherwise, the return code from first failing invocation will
# be returned.
#
# For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
# locally, and the former two are exported to the command environment.
python_foreach_impl() {
debug-print-function ${FUNCNAME} "${@}"
_python_validate_useflags
_python_check_USE_PYTHON
local MULTIBUILD_VARIANTS
_python_obtain_impls
local impl
local bdir=${BUILD_DIR:-${S}}
multibuild_foreach_variant _python_multibuild_wrapper "${@}"
}
debug-print "${FUNCNAME}: bdir = ${bdir}"
for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
if has "${impl}" "${PYTHON_COMPAT[@]}" \
&& _python_impl_supported "${impl}" \
&& use "python_targets_${impl}"
then
local EPYTHON PYTHON
python_export "${impl}" EPYTHON PYTHON
local BUILD_DIR=${bdir%%/}-${impl}
export EPYTHON PYTHON
# @FUNCTION: python_parallel_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.
#
# The function will return 0 status if all invocations succeed.
# Otherwise, the return code from first failing invocation will
# be returned.
#
# For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
# locally, and the former two are exported to the command environment.
#
# Multiple invocations of the command will be run in parallel, up to
# DISTUTILS_JOBS (defaulting to '-j' option argument from MAKEOPTS).
python_parallel_foreach_impl() {
debug-print-function ${FUNCNAME} "${@}"
einfo "${EPYTHON}: running ${@}"
"${@}" || die "${EPYTHON}: ${1} failed"
fi
done
local MULTIBUILD_JOBS=${MULTIBUILD_JOBS:-${DISTUTILS_JOBS}}
local MULTIBUILD_VARIANTS
_python_obtain_impls
multibuild_parallel_foreach_variant _python_multibuild_wrapper "${@}"
}
# @FUNCTION: python_export_best
@ -623,24 +714,19 @@ python_foreach_impl() {
python_export_best() {
debug-print-function ${FUNCNAME} "${@}"
_python_validate_useflags
[[ ${#} -gt 0 ]] || set -- EPYTHON PYTHON
local impl best
for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
if has "${impl}" "${PYTHON_COMPAT[@]}" \
&& _python_impl_supported "${impl}" \
&& use "python_targets_${impl}"
then
best=${impl}
fi
done
local best MULTIBUILD_VARIANTS
_python_obtain_impls
[[ ${best+1} ]] || die "python_export_best(): no implementation found!"
_python_set_best() {
best=${MULTIBUILD_VARIANT}
}
multibuild_for_best_variant _python_set_best
debug-print "${FUNCNAME}: Best implementation is: ${impl}"
python_export "${impl}" "${@}"
debug-print "${FUNCNAME}: Best implementation is: ${best}"
python_export "${best}" "${@}"
python_wrapper_setup
}
# @FUNCTION: python_replicate_script
@ -654,8 +740,6 @@ python_export_best() {
python_replicate_script() {
debug-print-function ${FUNCNAME} "${@}"
_python_validate_useflags
local suffixes=()
_add_suffix() {
@ -681,24 +765,5 @@ python_replicate_script() {
done
}
# @FUNCTION: run_in_build_dir
# @USAGE: <argv>...
# @DESCRIPTION:
# Run the given command in the directory pointed by BUILD_DIR.
run_in_build_dir() {
debug-print-function ${FUNCNAME} "${@}"
local ret
[[ ${#} -ne 0 ]] || die "${FUNCNAME}: no command specified."
[[ ${BUILD_DIR} ]] || die "${FUNCNAME}: BUILD_DIR not set."
pushd "${BUILD_DIR}" >/dev/null || die
"${@}"
ret=${?}
popd >/dev/null || die
return ${ret}
}
_PYTHON_R1=1
fi

View File

@ -1,6 +1,6 @@
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/python-single-r1.eclass,v 1.15 2013/01/30 10:42:25 mgorny Exp $
# $Header: /var/cvsroot/gentoo-x86/eclass/python-single-r1.eclass,v 1.18 2013/05/21 01:31:02 floppym Exp $
# @ECLASS: python-single-r1
# @MAINTAINER:
@ -133,6 +133,27 @@ fi
# python_targets_python2_7(-)?,python_single_target_python2_7(+)?
# @CODE
# @ECLASS-VARIABLE: PYTHON_REQUIRED_USE
# @DESCRIPTION:
# This is an eclass-generated required-use expression which ensures the following:
# 1. Exactly one PYTHON_SINGLE_TARGET value has been enabled.
# 2. The selected PYTHON_SINGLE_TARGET value is enabled in PYTHON_TARGETS.
#
# This expression should be utilized in an ebuild by including it in
# REQUIRED_USE, optionally behind a use flag.
#
# Example use:
# @CODE
# REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
# @CODE
#
# Example value:
# @CODE
# python_single_target_python2_6? ( python_targets_python2_6 )
# python_single_target_python2_7? ( python_targets_python2_7 )
# ^^ ( python_single_target_python2_6 python_single_target_python2_7 )
# @CODE
_python_single_set_globals() {
local impls=()
@ -144,7 +165,7 @@ _python_single_set_globals() {
# The chosen targets need to be in PYTHON_TARGETS as well.
# This is in order to enforce correct dependencies on packages
# supporting multiple implementations.
#REQUIRED_USE+=" python_single_target_${i}? ( python_targets_${i} )"
PYTHON_REQUIRED_USE+=" python_single_target_${i}? ( python_targets_${i} )"
python_export "${i}" PYTHON_PKG_DEP
PYTHON_DEPS+="python_single_target_${i}? ( ${PYTHON_PKG_DEP} ) "
@ -163,7 +184,7 @@ _python_single_set_globals() {
optflags+=,${flags[@]/%/(+)?}
IUSE="${flags_mt[*]} ${flags[*]}"
#REQUIRED_USE="|| ( ${flags_mt[*]} ) ^^ ( ${flags[*]} )"
PYTHON_REQUIRED_USE+=" ^^ ( ${flags[*]} )"
PYTHON_USEDEP=${optflags// /,}
# 1) well, python-exec would suffice as an RDEP
@ -207,6 +228,7 @@ python-single-r1_pkg_setup() {
fi
python_export "${impl}" EPYTHON PYTHON
python_wrapper_setup
fi
done

View File

@ -1,6 +1,6 @@
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/python-utils-r1.eclass,v 1.16 2013/01/29 21:12:33 mgorny Exp $
# $Header: /var/cvsroot/gentoo-x86/eclass/python-utils-r1.eclass,v 1.30 2013/07/27 11:17:44 mgorny Exp $
# @ECLASS: python-utils-r1
# @MAINTAINER:
@ -34,14 +34,14 @@ fi
if [[ ! ${_PYTHON_UTILS_R1} ]]; then
inherit multilib
inherit multilib toolchain-funcs
# @ECLASS-VARIABLE: _PYTHON_ALL_IMPLS
# @INTERNAL
# @DESCRIPTION:
# All supported Python implementations, most preferred last.
_PYTHON_ALL_IMPLS=(
jython2_5
jython2_5 jython2_7
pypy1_9 pypy2_0
python3_1 python3_2 python3_3
python2_5 python2_6 python2_7
@ -67,7 +67,7 @@ _python_impl_supported() {
# keep in sync with _PYTHON_ALL_IMPLS!
# (not using that list because inline patterns shall be faster)
case "${impl}" in
python2_[567]|python3_[123]|pypy1_9|pypy2_0|jython2_5)
python2_[567]|python3_[123]|pypy1_9|pypy2_0|jython2_[57])
return 0
;;
pypy1_8)
@ -79,10 +79,18 @@ _python_impl_supported() {
}
# @ECLASS-VARIABLE: PYTHON
# @DEFAULT_UNSET
# @DESCRIPTION:
# The absolute path to the current Python interpreter.
#
# Set and exported only in commands run by python_foreach_impl().
# This variable is set automatically in the following contexts:
#
# python-r1: Set in functions called by python_foreach_impl() or after
# calling python_export_best().
#
# python-single-r1: Set after calling python-single-r1_pkg_setup().
#
# distutils-r1: Set within any of the python sub-phase functions.
#
# Example value:
# @CODE
@ -90,12 +98,18 @@ _python_impl_supported() {
# @CODE
# @ECLASS-VARIABLE: EPYTHON
# @DEFAULT_UNSET
# @DESCRIPTION:
# The executable name of the current Python interpreter.
#
# This variable is used consistently with python.eclass.
# This variable is set automatically in the following contexts:
#
# Set and exported only in commands run by python_foreach_impl().
# python-r1: Set in functions called by python_foreach_impl() or after
# calling python_export_best().
#
# python-single-r1: Set after calling python-single-r1_pkg_setup().
#
# distutils-r1: Set within any of the python sub-phase functions.
#
# Example value:
# @CODE
@ -103,6 +117,7 @@ _python_impl_supported() {
# @CODE
# @ECLASS-VARIABLE: PYTHON_SITEDIR
# @DEFAULT_UNSET
# @DESCRIPTION:
# The path to Python site-packages directory.
#
@ -114,6 +129,7 @@ _python_impl_supported() {
# @CODE
# @ECLASS-VARIABLE: PYTHON_INCLUDEDIR
# @DEFAULT_UNSET
# @DESCRIPTION:
# The path to Python include directory.
#
@ -124,7 +140,51 @@ _python_impl_supported() {
# /usr/include/python2.6
# @CODE
# @ECLASS-VARIABLE: PYTHON_LIBPATH
# @DEFAULT_UNSET
# @DESCRIPTION:
# The path to Python library.
#
# Set and exported on request using python_export().
# Valid only for CPython.
#
# Example value:
# @CODE
# /usr/lib64/libpython2.6.so
# @CODE
# @ECLASS-VARIABLE: PYTHON_CFLAGS
# @DEFAULT_UNSET
# @DESCRIPTION:
# Proper C compiler flags for building against Python. Obtained from
# pkg-config or python-config.
#
# Set and exported on request using python_export().
# Valid only for CPython. Requires a proper build-time dependency
# on the Python implementation and on pkg-config.
#
# Example value:
# @CODE
# -I/usr/include/python2.7
# @CODE
# @ECLASS-VARIABLE: PYTHON_LIBS
# @DEFAULT_UNSET
# @DESCRIPTION:
# Proper C compiler flags for linking against Python. Obtained from
# pkg-config or python-config.
#
# Set and exported on request using python_export().
# Valid only for CPython. Requires a proper build-time dependency
# on the Python implementation and on pkg-config.
#
# Example value:
# @CODE
# -lpython2.7
# @CODE
# @ECLASS-VARIABLE: PYTHON_PKG_DEP
# @DEFAULT_UNSET
# @DESCRIPTION:
# The complete dependency on a particular Python package as a string.
#
@ -219,6 +279,62 @@ python_export() {
export PYTHON_INCLUDEDIR=${EPREFIX}${dir}
debug-print "${FUNCNAME}: PYTHON_INCLUDEDIR = ${PYTHON_INCLUDEDIR}"
;;
PYTHON_LIBPATH)
local libname
case "${impl}" in
python*)
libname=lib${impl}
;;
*)
die "${impl} lacks a dynamic library"
;;
esac
local path=${EPREFIX}/usr/$(get_libdir)
export PYTHON_LIBPATH=${path}/${libname}$(get_libname)
debug-print "${FUNCNAME}: PYTHON_LIBPATH = ${PYTHON_LIBPATH}"
;;
PYTHON_CFLAGS)
local val
case "${impl}" in
python2.5|python2.6)
# old versions support python-config only
val=$("${impl}-config" --includes)
;;
python*)
# python-2.7, python-3.2, etc.
val=$($(tc-getPKG_CONFIG) --cflags ${impl/n/n-})
;;
*)
die "${impl}: obtaining ${var} not supported"
;;
esac
export PYTHON_CFLAGS=${val}
debug-print "${FUNCNAME}: PYTHON_CFLAGS = ${PYTHON_CFLAGS}"
;;
PYTHON_LIBS)
local val
case "${impl}" in
python2.5|python2.6)
# old versions support python-config only
val=$("${impl}-config" --libs)
;;
python*)
# python-2.7, python-3.2, etc.
val=$($(tc-getPKG_CONFIG) --libs ${impl/n/n-})
;;
*)
die "${impl}: obtaining ${var} not supported"
;;
esac
export PYTHON_LIBS=${val}
debug-print "${FUNCNAME}: PYTHON_LIBS = ${PYTHON_LIBS}"
;;
PYTHON_PKG_DEP)
local d
case ${impl} in
@ -227,7 +343,7 @@ python_export() {
jython*)
PYTHON_PKG_DEP='dev-java/jython';;
pypy*)
PYTHON_PKG_DEP='dev-python/pypy';;
PYTHON_PKG_DEP='virtual/pypy';;
*)
die "Invalid implementation: ${impl}"
esac
@ -310,9 +426,58 @@ python_get_includedir() {
echo "${PYTHON_INCLUDEDIR}"
}
# @FUNCTION: python_get_library_path
# @USAGE: [<impl>]
# @DESCRIPTION:
# Obtain and print the Python library path for the given implementation.
# If no implementation is provided, ${EPYTHON} will be used.
#
# Please note that this function can be used with CPython only. Use
# in another implementation will result in a fatal failure.
python_get_library_path() {
debug-print-function ${FUNCNAME} "${@}"
python_export "${@}" PYTHON_LIBPATH
echo "${PYTHON_LIBPATH}"
}
# @FUNCTION: python_get_CFLAGS
# @USAGE: [<impl>]
# @DESCRIPTION:
# Obtain and print the compiler flags for building against Python,
# for the given implementation. If no implementation is provided,
# ${EPYTHON} will be used.
#
# Please note that this function can be used with CPython only.
# It requires Python and pkg-config installed, and therefore proper
# build-time dependencies need be added to the ebuild.
python_get_CFLAGS() {
debug-print-function ${FUNCNAME} "${@}"
python_export "${@}" PYTHON_CFLAGS
echo "${PYTHON_CFLAGS}"
}
# @FUNCTION: python_get_LIBS
# @USAGE: [<impl>]
# @DESCRIPTION:
# Obtain and print the compiler flags for linking against Python,
# for the given implementation. If no implementation is provided,
# ${EPYTHON} will be used.
#
# Please note that this function can be used with CPython only.
# It requires Python and pkg-config installed, and therefore proper
# build-time dependencies need be added to the ebuild.
python_get_LIBS() {
debug-print-function ${FUNCNAME} "${@}"
python_export "${@}" PYTHON_LIBS
echo "${PYTHON_LIBS}"
}
# @FUNCTION: _python_rewrite_shebang
# @INTERNAL
# @USAGE: [<EPYTHON>] <path>...
# @INTERNAL
# @DESCRIPTION:
# Replaces 'python' executable in the shebang with the executable name
# of the specified interpreter. If no EPYTHON value (implementation) is
@ -348,8 +513,9 @@ _python_rewrite_shebang() {
local f
for f; do
local shebang=$(head -n 1 "${f}")
local from
local from shebang
read -r shebang < "${f}"
shebang=${shebang%$'\r'}
debug-print "${FUNCNAME}: path = ${f}"
debug-print "${FUNCNAME}: shebang = ${shebang}"
@ -380,8 +546,8 @@ _python_rewrite_shebang() {
}
# @FUNCTION: _python_ln_rel
# @INTERNAL
# @USAGE: <from> <to>
# @INTERNAL
# @DESCRIPTION:
# Create a relative symlink.
_python_ln_rel() {
@ -428,6 +594,15 @@ _python_ln_rel() {
python_optimize() {
debug-print-function ${FUNCNAME} "${@}"
if [[ ${EBUILD_PHASE} == pre* || ${EBUILD_PHASE} == post* ]]; then
eerror "The new Python eclasses expect the compiled Python files to"
eerror "be controlled by the Package Manager. For this reason,"
eerror "the python_optimize function can be used only during src_* phases"
eerror "(src_install most commonly) and not during pkg_* phases."
echo
die "python_optimize is not to be used in pre/post* phases"
fi
[[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
local PYTHON=${PYTHON}
@ -464,7 +639,7 @@ python_optimize() {
"${PYTHON}" -OO -m compileall -q -f -d "${instpath}" "${d}"
;;
*)
"${PYTHON}" -m compileall -q -f -d "${instpath}" "${@}"
"${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"
;;
esac
done
@ -521,7 +696,34 @@ python_scriptinto() {
python_doscript() {
debug-print-function ${FUNCNAME} "${@}"
local f
for f; do
python_newscript "${f}" "${f##*/}"
done
}
# @FUNCTION: python_newscript
# @USAGE: <path> <new-name>
# @DESCRIPTION:
# Install the given script into current python_scriptroot
# for the current Python implementation (${EPYTHON}), and name it
# <new-name>.
#
# The file 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 <new-name>.
#
# Example:
# @CODE
# src_install() {
# python_foreach_impl python_newscript foo.py foo
# }
# @CODE
python_newscript() {
debug-print-function ${FUNCNAME} "${@}"
[[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
[[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <path> <new-name>"
local d=${python_scriptroot:-${DESTTREE}/bin}
local INSDESTTREE INSOPTIONS
@ -529,18 +731,17 @@ python_doscript() {
insinto "${d}"
insopts -m755
local f
for f; do
local oldfn=${f##*/}
local newfn=${oldfn}-${EPYTHON}
local f=${1}
local barefn=${2}
debug-print "${FUNCNAME}: ${oldfn} -> ${newfn}"
newins "${f}" "${newfn}" || die
_python_rewrite_shebang "${ED}/${d}/${newfn}"
local newfn=${barefn}-${EPYTHON}
# install the wrapper
_python_ln_rel "${ED}"/usr/bin/python-exec "${ED}/${d}/${oldfn}" || die
done
debug-print "${FUNCNAME}: ${f} -> ${d}/${newfn}"
newins "${f}" "${newfn}" || die
_python_rewrite_shebang "${ED}/${d}/${newfn}"
# install the wrapper
_python_ln_rel "${ED}"/usr/bin/python-exec "${ED}/${d}/${barefn}" || die
}
# @ECLASS-VARIABLE: python_moduleroot
@ -647,5 +848,99 @@ python_doheader() {
doins -r "${@}" || die
}
# @FUNCTION: python_wrapper_setup
# @USAGE: [<path> [<impl>]]
# @DESCRIPTION:
# Create proper 'python' executable and pkg-config wrappers
# (if available) in the directory named by <path>. Set up PATH
# and PKG_CONFIG_PATH appropriately. <path> defaults to ${T}/${EPYTHON}.
#
# The wrappers will be created for implementation named by <impl>,
# or for one named by ${EPYTHON} if no <impl> passed.
#
# If the named directory contains a python symlink already, it will
# be assumed to contain proper wrappers already and only environment
# setup will be done. If wrapper update is requested, the directory
# shall be removed first.
python_wrapper_setup() {
debug-print-function ${FUNCNAME} "${@}"
local workdir=${1:-${T}/${EPYTHON}}
local impl=${2:-${EPYTHON}}
[[ ${workdir} ]] || die "${FUNCNAME}: no workdir specified."
[[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON specified."
if [[ ! -x ${workdir}/bin/python ]]; then
mkdir -p "${workdir}"/{bin,pkgconfig} || die
# Clean up, in case we were supposed to do a cheap update.
rm -f "${workdir}"/bin/python{,2,3,-config}
rm -f "${workdir}"/bin/2to3
rm -f "${workdir}"/pkgconfig/python{,2,3}.pc
local EPYTHON PYTHON
python_export "${impl}" EPYTHON PYTHON
local pyver
if [[ ${EPYTHON} == python3* ]]; then
pyver=3
else # includes pypy & jython
pyver=2
fi
# Python interpreter
ln -s "${PYTHON}" "${workdir}"/bin/python || die
ln -s python "${workdir}"/bin/python${pyver} || die
local nonsupp=()
# CPython-specific
if [[ ${EPYTHON} == python* ]]; then
ln -s "${PYTHON}-config" "${workdir}"/bin/python-config || die
# Python 2.6+.
if [[ ${EPYTHON} != python2.5 ]]; then
ln -s "${PYTHON/python/2to3-}" "${workdir}"/bin/2to3 || die
else
nonsupp+=( 2to3 )
fi
# Python 2.7+.
if [[ ${EPYTHON} != python2.[56] ]]; then
ln -s "${EPREFIX}"/usr/$(get_libdir)/pkgconfig/${EPYTHON/n/n-}.pc \
"${workdir}"/pkgconfig/python.pc || die
else
# XXX?
ln -s /dev/null "${workdir}"/pkgconfig/python.pc || die
fi
ln -s python.pc "${workdir}"/pkgconfig/python${pyver}.pc || die
else
nonsupp+=( 2to3 python-config )
fi
local x
for x in "${nonsupp[@]}"; do
cat >"${workdir}"/bin/${x} <<__EOF__
#!/bin/sh
echo "${x} is not supported by ${EPYTHON}" >&2
exit 1
__EOF__
chmod +x "${workdir}"/bin/${x} || die
done
# Now, set the environment.
# But note that ${workdir} may be shared with something else,
# and thus already on top of PATH.
if [[ ${PATH##:*} != ${workdir}/bin ]]; then
PATH=${workdir}/bin${PATH:+:${PATH}}
fi
if [[ ${PKG_CONFIG_PATH##:*} != ${workdir}/pkgconfig ]]; then
PKG_CONFIG_PATH=${workdir}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
fi
export PATH PKG_CONFIG_PATH
fi
}
_PYTHON_UTILS_R1=1
fi

View File

@ -1,6 +1,6 @@
# Copyright 1999-2012 Gentoo Foundation
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.164 2012/12/20 06:34:57 floppym Exp $
# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.167 2013/07/27 11:17:44 mgorny Exp $
# @ECLASS: python.eclass
# @MAINTAINER:
@ -33,7 +33,7 @@ fi
_CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7)
_CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2 3.3)
_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython)
_JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython 2.7-jython)
_PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8 2.7-pypy-1.9 2.7-pypy-2.0)
_PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]})
@ -109,7 +109,7 @@ _python_implementation() {
return 0
elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
return 0
elif [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then
elif [[ "${CATEGORY}/${PN}" == "virtual/pypy" ]]; then
return 0
else
return 1
@ -2054,7 +2054,7 @@ python_get_implementational_package() {
elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
echo "=dev-java/jython-${PYTHON_ABI%-jython}*"
elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
echo "=dev-python/pypy-${PYTHON_ABI#*-pypy-}*"
echo "=virtual/pypy-${PYTHON_ABI#*-pypy-}*"
fi
else
if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
@ -2062,7 +2062,7 @@ python_get_implementational_package() {
elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
echo "dev-java/jython:${PYTHON_ABI%-jython}"
elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
echo "dev-python/pypy:${PYTHON_ABI#*-pypy-}"
echo "virtual/pypy:${PYTHON_ABI#*-pypy-}"
fi
fi
}
@ -3001,12 +3001,6 @@ python_mod_optimize() {
fi
else
# Deprecated part of python_mod_optimize()
ewarn
ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01."
ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
ewarn
local myroot mydirs=() myfiles=() myopts=() return_code="0"
@ -3166,12 +3160,6 @@ python_mod_cleanup() {
done
else
# Deprecated part of python_mod_cleanup()
ewarn
ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation"
ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01."
ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax."
ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
ewarn
search_paths=("${@#/}")
search_paths=("${search_paths[@]/#/${root}/}")