Gentoo Development Guide

PYTHON-ANY-R1.ECLASS

NAME

python-any-r1.eclass - An eclass for packages having build-time dependency on Python.

DESCRIPTION

A minimal eclass for packages which need any Python interpreter
installed without a need for explicit choice and invariability.
This usually involves packages requiring Python at build-time
but having no other relevance to it.

This eclass provides a minimal PYTHON_DEPS variable with a dependency
string on any of the supported Python implementations. It also exports
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
both.

FUNCTIONS

python_gen_any_dep <dependency-block>

Generate an any-of dependency that enforces a version match between
the Python interpreter and Python packages. <dependency-block> needs
to list one or more dependencies with verbatim '${PYTHON_USEDEP}'
references (quoted!) that will get expanded inside the function.

This should be used along with an appropriate python_check_deps()
that checks which of the any-of blocks were matched.

Determine what the best installed (and supported) Python
implementation is, and set the Python build environment up for it.

This function will call python_check_deps() if defined.

python-any-r1_pkg_setup

Runs python_setup during from-source installs.

In a binary package installs is a no-op. If you need Python in pkg_*
phases of a binary package, call python_setup directly.

ECLASS VARIABLES

PYTHON_COMPAT (REQUIRED)

This variable contains a list of Python implementations the package
supports. It must be set before the `inherit' call. It has to be
an array.

Example:

PYTHON_COMPAT=( python{2_5,2_6,2_7} )

PYTHON_REQ_USE

The list of USEflags required to be enabled on the 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:

PYTHON_REQ_USE="gdbm,ncurses(-)?"

It will cause the Python dependencies to look like:

|| ( dev-lang/python:X.Y[gdbm,ncurses(-)?] ... )

PYTHON_DEPS

This is an eclass-generated Python dependency string for all
implementations listed in PYTHON_COMPAT.

Any of the supported interpreters will satisfy the dependency.

Example use:

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

Example value:

|| ( dev-lang/python:2.7[gdbm]
dev-lang/python:2.6[gdbm] )

PYTHON_USEDEP

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.