Gentoo Archives: gentoo-python

From: "Michał Górny" <mgorny@g.o>
To: gentoo-python@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-python] [PATCH] Add distutils_install_for_testing().
Date: Sat, 09 Feb 2013 15:35:08
Message-Id: 1360424105-5560-1-git-send-email-mgorny@gentoo.org
1 This is a copy and rework of the crazy 'esetup.py install'
2 from logilab-common. A common function which can be used
3 in python_test() to obtain a working installation of almost
4 any distutils or setuptools package.
5 ---
6 gx86/eclass/distutils-r1.eclass | 54 +++++++++++++++++++++++++++++++++++++++++
7 1 file changed, 54 insertions(+)
8
9 diff --git a/gx86/eclass/distutils-r1.eclass b/gx86/eclass/distutils-r1.eclass
10 index 24589f0..963bdf9 100644
11 --- a/gx86/eclass/distutils-r1.eclass
12 +++ b/gx86/eclass/distutils-r1.eclass
13 @@ -239,6 +239,60 @@ esetup.py() {
14 "${@}" || die
15 }
16
17 +# @FUNCTION: distutils_install_for_testing
18 +# @USAGE: [<args>...]
19 +# @DESCRIPTION:
20 +# Install the package into a temporary location for running tests.
21 +# Update PYTHONPATH appropriately and set TEST_DIR to the test
22 +# installation root. The Python packages will be installed in 'lib'
23 +# subdir, and scripts in 'scripts' subdir (like in BUILD_DIR).
24 +#
25 +# Please note that this function should be only used if package uses
26 +# namespaces (and therefore proper install needs to be done to enforce
27 +# PYTHONPATH) or tests rely on the results of install command.
28 +# For most of the packages, tests built in BUILD_DIR are good enough.
29 +distutils_install_for_testing() {
30 + debug-print-function ${FUNCNAME} "${@}"
31 +
32 + # A few notes:
33 + # 1) because of namespaces, we can't use 'install --root',
34 + # 2) 'install --home' is terribly broken on pypy, so we need
35 + # to override --install-lib and --install-scripts,
36 + # 3) non-root 'install' complains about PYTHONPATH and missing dirs,
37 + # so we need to set it properly and mkdir them,
38 + # 4) it runs a bunch of commands which write random files to cwd,
39 + # in order to avoid that, we need to run them ourselves to pass
40 + # alternate build paths,
41 + # 5) 'install' needs to go before 'bdist_egg' or the latter would
42 + # re-set install paths.
43 +
44 + if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
45 + # use 'build' subdirectory to reduce the risk of collisions
46 + local BUILD_DIR=${BUILD_DIR}/build
47 + fi
48 +
49 + TEST_DIR=${BUILD_DIR}/test
50 + local bindir=${TEST_DIR}/scripts
51 + local libdir=${TEST_DIR}/lib
52 + PYTHONPATH=${libdir}:${PYTHONPATH}
53 +
54 + local add_args=(
55 + install
56 + --home="${TEST_DIR}"
57 + --install-lib="${libdir}"
58 + --install-scripts="${bindir}"
59 + )
60 +
61 + if "${PYTHON:-python}" setup.py --help bdist_egg &>/dev/null; then
62 + add_args+=(
63 + bdist_egg --dist-dir="${TEST_DIR}"
64 + )
65 + fi
66 +
67 + mkdir -p "${libdir}" || die
68 + esetup.py "${add_args[@]}"
69 +}
70 +
71 # @FUNCTION: distutils-r1_python_prepare_all
72 # @DESCRIPTION:
73 # The default python_prepare_all(). It applies the patches from PATCHES
74 --
75 1.8.1.2

Replies

Subject Author
[gentoo-python] Re: [PATCH] Add distutils_install_for_testing(). Mike Gilbert <floppym@g.o>