Important: You are required to change your passwords used for Gentoo services and set an email address for your Wiki account if you haven't done so. See the full announcement and Wiki email policy change for more information.

Python-r1/examples

From Gentoo Wiki
Jump to: navigation, search

Distutils examples

Basic example

distutils.eclass distutils-r1
EAPI=4
PYTHON_DEPEND='2:2.6 3:3.2'
SUPPORT_PYTHON_ABIS=1
RESTRICT_PYTHON_ABIS='2.4 2.5 3.1'

inherit base distutils

# …

RDEPEND="app-portage/flaggie
	dev-python/lxml"

PYTHON_MODNAME=installmask

src_prepare() {
	base_src_prepare
	distutils_src_prepare
}
EAPI=5
PYTHON_COMPAT=( python{2_6,2_7,3_2,3_3} )



inherit distutils-r1

# …

RDEPEND="app-portage/flaggie[${PYTHON_USEDEP}]
	dev-python/lxml[${PYTHON_USEDEP}]"







The PYTHON_DEPEND and RESTRICT_PYTHON_ABIS tandem was replaced with a common PYTHON_COMPAT variable. The variable needs to list explicitly every supported Python implementation. It is used to construct USE flags for the implementations and prepare proper dependency strings.

The SUPPORT_PYTHON_ABIS variable was replaced with an implication of eclass choice. The python-r1 and distutils-r1 eclasses require the package to support being built for multiple Python implementations.

The PYTHON_MODNAME variable was removed. The modules are compiled during the install phase, therefore the ebuild is perfectly aware of the module naming.

A PYTHON_USEDEP variable has been introduced. It holds a USE dependency string requiring the dependency to have at least the same Python implementations enabled as the ebuild in question. Its use is for packages that inherit the python-r1 or distutils-r1 eclasses.

The default phase functions handle all the common tasks which base.eclass did. Therefore, it is no longer necessary to use it explicitly.

Running tests using py.test

distutils.eclass distutils-r1
EAPI="4"
SUPPORT_PYTHON_ABIS="1"
DISTUTILS_SRC_TEST="py.test"

inherit distutils

# …
IUSE=""

DEPEND="app-arch/unzip
	dev-python/setuptools"

RDEPEND=""

DOCS="CHANGELOG README.txt"




EAPI="5"
PYTHON_COMPAT=( python{2_5,2_6,2_7,3_1,3_2,3_3} pypy{1_8,1_9} )


inherit distutils-r1

# …
IUSE="test"

DEPEND="app-arch/unzip
	dev-python/setuptools[${PYTHON_USEDEP}]
	test? ( dev-python/pytest[${PYTHON_USEDEP}] )"
RDEPEND=""

DOCS=( CHANGELOG README.txt )

python_test() {
	py.test || die
}

The distutils-r1 eclass does not support various Python test suites out-of-the-box. Therefore, it is necessary to add appropriate dependencies and the python_test() phase function.

In order to use the py.test test suite, it is necessary to depend on dev-python/pytest and call py.test to run the tests.

It should be noted that the DOCS variable in distutils-r1 is a list, not a string.